statisticsPage.vue 6.89 KB
<!-- 员工群发 - 统计列表 -->
<template>
  <div>
    <!-- class="order-detail" -->
    <d2-container>
      <!-- <div class="offline-account"> -->
      <div class="header"
           slot="header"
           style="padding: 10px 20px">
        <div class="header-bar">
          <h3>{{ title }}</h3>
          <div class="btn">
            <el-button size="small"
                       @click="handleRecord"> 返回 </el-button>
          </div>
        </div>
        <d2-search ref="showSearch"
                   class="show-search"
                   :search-form="searchForm"
                   :label-width="labelWidth"
                   :form-data="showFormData" />
        <div class="up-btns">
          <el-button @click="handleSearch"
                     size="small"
                     type="primary">
            查询
          </el-button>
          <el-button size="small"
                     @click="handleReset"> 重置 </el-button>
        </div>
      </div>
      <!-- </d2-container>
          <d2-container> -->
      <div class="d2-container-content">
        <d2-table-header>
          <auth-button category="Button" />
        </d2-table-header>
        <d2-table ref="recordTable"
                  :get-list-api="getListApi"
                  :search-form="searchFormSearch"
                  :table-params="tableParams"
                  :before-search-fn="beforeSearchFn">
        </d2-table>
      </div>
    </d2-container>
  </div>
</template>

<script>
import { Util, deepClone } from "@/common/util"
import { mapActions, mapState } from "vuex"
import { getStatisticPage } from "@api/contentManager"
export default {
  name: "StatisticPage",
  data() {
    return {
      userInfo: this.$store.state.d2admin.user.info,
      labelWidth: "100px",
      searchForm: {
        staffName: "",
        phoneNumber: "",
        lookDate: ""
      },
      searchFormSearch: {},
      showFormData: [
        {
          label: "员工姓名",
          name: "staffName",
          type: "input",
          maxlength: "20",
          isClear: true
        },
        {
          label: "手机号",
          name: "phoneNumber",
          type: "input",
          inputType: "number",
          maxlength: "11",
          isClear: true
        },
        {
          label: "查看时间",
          name: "lookDate",
          type: "datePicker",
          isClear: true,
          pickerOptions: "rangePickerOptions"
        }
      ],
      getListApi: getStatisticPage,
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: "list",
        tableOption: false,
        tableColumns: [
          {
            label: "员工姓名",
            prop: "staffName"
            // width: '200px'
          },
          {
            label: "员工手机号",
            prop: "phoneNumber"
            // width: '150px'
          },
          {
            label: "发送时间",
            prop: "sendTime",
            // width: '150px',
            formatter: (cellValue) => {
              return cellValue.sendTime
                ? Util.dateFormate(cellValue.sendTime, "YYYY-MM-DD HH:mm:ss")
                : "--"
            }
          },
          {
            label: "首次查看时间",
            prop: "firstViewTime",
            // width: '150px',
            formatter: (cellValue) => {
              return cellValue.firstViewTime
                ? Util.dateFormate(
                  cellValue.firstViewTime,
                  "YYYY-MM-DD HH:mm:ss"
                )
                : "--"
            }
          },
          {
            label: "总浏览时长",
            prop: "totalViewTime",
            formatter: (cellValue) => {
              return cellValue.totalViewTime ? cellValue.totalViewTime + "s" : '--'
            }
          }
        ]
      },
      baseData: {},
      title: ""
    }
  },
  computed: {
    ...mapState({
      dowloadList: (state) => state.d2admin.user.dowloadList
    })
  },
  mounted() {
    this.title = this.$route.query.title
    this.getBaseData()
  },

  methods: {
    ...mapActions({
      get: "d2admin/base/get",
      close: "d2admin/page/close"
    }),
    ...mapActions("d2admin/user", ["actionSetDownloadList"]),

    async getBaseData() {
      this.getOptionsList()
    },

    beforeSearchFn() {
      return new Promise((resolve) => {
        this.searchFormSearch = deepClone(this.searchForm)
        if (this.searchFormSearch.lookDate) {
          this.searchFormSearch.startDate = Util.dateFormate(
            this.searchFormSearch.lookDate[0],
            "YYYY-MM-DD"
          )
          this.searchFormSearch.endDate = Util.dateFormate(
            this.searchFormSearch.lookDate[1],
            "YYYY-MM-DD"
          )
          delete this.searchFormSearch.lookDate
        }
        this.searchFormSearch.taskId = this.$route.query.id
        resolve()
      })
    },

    getOptionsList() {
      this.showFormData.forEach((item, index) => {
        if (item.type === "select") {
          if (
            this.baseData[item.optionsName].length &&
            this.baseData[item.optionsName][0][
            this.showFormData[index].optionLabel
            ] !== "全部"
          ) {
            const temp = {}
            temp[this.showFormData[index].optionId] = ""
            temp[this.showFormData[index].optionLabel] = "全部"
            this.baseData[item.optionsName].unshift(temp)
          }
          this.$set(
            this.showFormData[index],
            "optionList",
            this.baseData[item.optionsName]
          )
        }
      })
    },

    handleSearch() {
      this.$refs.recordTable.refreshTable(false, true)
    },
    handleReset() {
      this.searchForm = {
        staffName: "",
        phoneNumber: "",
        lookDate: ""
      }
      this.$refs.recordTable.refreshTable(false, true)
    },

    handleExport() {
      var params = this.searchFormSearch
      // 去除为null的值
      for (const key in params) {
        if (
          params[key] === null ||
          params[key] === "" ||
          params[key].length == 0
        ) {
          delete params[key]
        }
      }
      // 内容管理统计信息导出
      params.method =
        "dj.api.smartcarlife.contentManagerTask.statistic.export.async"
      const list = [
        ...this.dowloadList,
        {
          name: "统计信息",
          exportParam: JSON.stringify(params),
          status: "waiting",
          timeid: new Date().getTime()
        }
      ]
      this.actionSetDownloadList({ list, type: "dowloadList" })
    },

    handleRecord() {
      this.$router.push({ name: "staffMassSending" })
    }
  }
}
</script>
<style scoped lang="scss">
.count-txt {
  font-weight: 700;
  color: #2a58ad;
  margin: 0 2px;
}

.leftSpan {
  display: inline-block;
  box-sizing: border-box;
  margin-right: 10px;
}
.header-bar {
  display: flex;
  align-items: center;
  .btn {
    margin-left: 15px;
  }
}
</style>