statisticsDialog.vue 5.25 KB
<template>
  <baseDialog
    :is-show.sync="dialogShow"
    :config="dialogConfig.setting"
    :dialog-config="dialogConfig.config"
    @closeDialog="handleDetailClose"
  >
    <div class='flex'>
      <d2-search
        ref="showSearch"
        class="show-search"
        :search-form="searchForm"
        :label-width="'90px'"
        :form-data="showFormData"
      >
      </d2-search>
      <el-button size="small" class="bts-search" type="primary" @click="handleSearch">
        查询
      </el-button>
      <el-button size="small" @click="handleReset"> 重置 </el-button>
      </div>

    <el-button size="small" style="margin-left:979px;"  @click="exportTable">
      导出
    </el-button>
    <d2-table
      ref="table"
      :get-list-api="getListApi"
      :search-form="searchFormSearch"
      :table-params="tableParams"
      :before-search-fn="beforeSearchFn"
      :layout="'total,prev, pager, next'"
    >
    </d2-table>
  </baseDialog>
</template>
    
    <script>
import { Util, deepClone } from "@/common/util"
import { getRecordBrowseList, recordBrowseExport } from "@api/verbal"
export default {
  name: "StatisticsDialog",
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    id: {
      type: Number,
      default: ""
    }
  },
  computed: {
    dialogShow: {
      get() {
        return this.visible
      },
      set(val) {
        this.$emit("update:visible", val)
      }
    }
  },
  mounted() {
  },
  data() {
    return {
      getListApi: getRecordBrowseList,
      searchFormSearch: {},
      searchForm: {
        staffPhone: "",
        staffName:"",
        merchantName:"",
        updateDate: [],
        pushStatus: ""
      },
      showFormData: [
        {
          label: "手机号",
          name: "staffPhone",
          type: "input",
          placeholder: "请输入",
          maxlength: "11",
          isClear: true
        },
        {
          label: "员工名称",
          name: "staffName",
          placeholder: "请输入",
          type: "input",
          maxlength: "40",
          isClear: true
        },
        {
          label: "门店名称",
          name: "merchantName",
          placeholder: "请输入",
          type: "input",
          isClear: true
        },
        {
          label: "浏览时间",
          name: "updateDate",
          type: "datePicker",
          isClear: true,
          pickerOptions: "rangePickerOptions"
        }
      ],
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: "list",
        tableOption: false,
        tableColumns: [

          {
            label: "员工名称",
            prop: "staffName"
          },
          {
            label: "手机号",
            prop: "staffPhone"
          },
          {
            label: "门店名称",
            prop: "merchantName"
          },
          {
            label: "浏览时间",
            prop: "startTime"
          },
          {
            label: "浏览时长",
            prop:'sustainTimeStr'
            // formatter: (cellValue) => {
            //   const secondsToMinutesAndSeconds = (seconds) => {
            //     const minutes = Math.floor(seconds / 60),
            //       remainingSeconds = seconds % 60
            //     let str = ""
            //     if (minutes > 0) str += `${minutes}分`
            //     return (str += `${remainingSeconds}秒`)
            //   }
            //   return cellValue.sustainTime
            //     ? secondsToMinutesAndSeconds(cellValue.sustainTime)
            //     : "0秒"
            // }
          }
        ]
      },
      dialogConfig: {
        setting: {
          showClose: true,
          appendToBody: false,
          btnList: []
        },
        config: {
          title: "统计",
          width: "1080px"
        }
      }
    }
  },
  methods: {
    handleSearch() {
      this.page = this.$options.data.call(this).page
      this.$refs.table.refreshTable(true, true)
    },
    handleReset() {
      this.searchForm = this.$options.data.call(this).searchForm
      this.handleSearch()
    },
    async exportTable() {
      try {
        await this.beforeSearchFn()
        const res = await recordBrowseExport({
          ...this.searchFormSearch
        })
        if (res) window.open(res)
      } catch (error) {
        if (error) this.$message.error(error)
      }
    },
    handleDetailClose() {
      this.dialogShow = false
    },
    beforeSearchFn(type = 1) {
      return new Promise((resolve, reject) => {
        this.searchFormSearch = deepClone(this.searchForm)
        this.searchFormSearch.id=this.id
        if (this.searchForm?.updateDate?.length) {
          let [startTime, endTime] = this.searchForm.updateDate
          this.searchFormSearch.startTime = Util.dateFormate(
            startTime,
            "YYYY-MM-DD HH:mm:ss"
          )
          this.searchFormSearch.endTime = Util.dateFormate(
            endTime,
            "YYYY-MM-DD"
          )+" 23:59:59"
        }
        delete this.searchFormSearch.updateDate
        resolve()
      })
    }
  }
}
</script>
    
    <style lang="scss" scoped>

.bts-search{
    margin-left:565px;
}
.show-search{
    ::v-deep{
         .d2-search-block {
        padding:0 !important;
    }
    }
    
}
</style>