readStatistics.vue 8.58 KB
<!-- 阅读统计 -->
<template>
  <d2-container class="customer-tags">
    <div class="header" slot="header">
      <d2-search ref="showSearch" class="show-search" :search-form="searchForm" :label-width="'100px'"
        :form-data="showFormData">
      </d2-search>
      <div class="up-btns">
        <el-button size="small" type="primary" @click="handleSearch">
          查询
        </el-button>
        <el-button size="small" @click="handleReset"> 重置 </el-button>
      </div>
    </div>
    <div class="d2-container-content">
      <d2-table-header>
        <el-button size="small" type="primary" @click="exportTable">
          导出
        </el-button>
      </d2-table-header>
      <d2-table ref="table" :get-list-api="getListApi" :search-form="searchFormSearch" :table-params="tableParams"
        :before-search-fn="beforeSearchFn">
        <div slot="customerTagName" slot-scope="scope">
          <span>{{ readType[scope.scope.readType] || '不强制' }}</span>
        </div>
      </d2-table>
    </div>
  </d2-container>
</template>

<script type="text/ecmascript-6">
import { mapActions, mapState } from 'vuex'
import { studyStaffPage, contentManagerTaskExport } from '@api/contentManager'
import { Util, deepClone } from "@/common/util"
import {
  getCustomerFilePage,
  exportCustomerFile,
  getCustomerFileStatic
} from "@api/contentManager"
import noDataImg from "@/assets/empty.png"
import dayjs from "dayjs"
import { listShop4sByRef } from "@api/merchant"
export default {
  name: "readStatistics",
  data() {
    return {
      noDataImg,
      classifyVisible: false,
      searchForm: {
        staffPhone: "",
        staffName: "",
        taskId: ''
      },
      readType: {
        1: '首次强制',
        2: '每天强制',
        0: '不强制'
      },
      searchFormSearch: {},
      currentItem: {},
      showFormData: [
        {
          label: "员工姓名",
          name: "staffName",
          type: "input",
          maxlength: "20",
          isClear: true
        },
        {
          label: "员工手机号",
          name: "phoneNumber",
          type: "input",
          isClear: true,
          maxlength: 11,
          inputType: "number"
        }
      ],
      getListApi: studyStaffPage,
      // 表格参数
      tableParams: {
        listName: "list",
        tableOption: false,
        tableColumns: [
          {
            label: "员工姓名",
            prop: "staffName",
          },
          {
            label: "员工手机号",
            minWidth: 144,
            prop: "phoneNumber"
          },
          {
            label: "发送时间",
            formatter: (cellValue) => {
              return cellValue.createdDate
                ? Util.dateFormate(cellValue.createdDate, "YYYY-MM-DD HH:mm:ss")
                : "-"
            },
            minWidth: 180
          },
          {
            label: "最后查看时间",
            formatter: (cellValue) => {
              return cellValue.latestReadTime
                ? Util.dateFormate(cellValue.latestReadTime, "YYYY-MM-DD HH:mm:ss")
                : "-"
            },
            minWidth: 180
          },
          {
            label: "强制阅读",
            minWidth: 270,
            addHtml: "customerTagName"
          },
          {
            label: "查看次数",
            minWidth: 270,
            prop: "readCount"
          },
        ]
      },
      staticData: {}
    }
  },
  computed: {
    routerInfo() {
      return this.$route.query
    },
    ...mapState({
      dowloadList: (state) => state.d2admin.user.dowloadList
    })
  },
  created() { },
  mounted() {
    this.searchForm.taskId = this.routerInfo.id
    // this.getServiceStore()
    // this.getCustomerFileStatic()
  },
  methods: {
    ...mapActions('d2admin/user', ['actionSetDownloadList']),
    beforeSearchFn(type = 1) {
      return new Promise((resolve, reject) => {
        this.searchForm.taskId = this.routerInfo.id
        this.searchFormSearch = deepClone(this.searchForm)
        // if (this.searchForm?.searchdate?.length) {
        //   let [searchStartDate, searchEndDate] = this.searchForm.searchdate
        //   this.searchFormSearch.startTime = Util.dateFormate(
        //     searchStartDate,
        //     "YYYY-MM-DD"
        //   )
        //   this.searchFormSearch.endTime = Util.dateFormate(
        //     searchEndDate,
        //     "YYYY-MM-DD"
        //   )
        //   const date1 = dayjs(searchStartDate),
        //     date2 = dayjs(searchEndDate),
        //     day = date2.diff(date1, "day") + 1
        //   if (day > 30) {
        //     reject(
        //       `${type == 1 ? "查询" : "导出"
        //       }的时间跨度最大为30天,请重新选择日期范围`
        //     )
        //   }
        // }
        // delete this.searchFormSearch.searchdate
        resolve()
      })
    },
    handleSearch() {
      this.page = this.$options.data.call(this).page
      this.$refs.table.refreshTable(true, true)
      // this.getCustomerFileStatic()
    },
    handleReset() {
      this.searchForm = this.$options.data.call(this).searchForm
      this.handleSearch()
    },
    async exportTable() {
      var params = this.searchForm
      params.method = 'dj.api.smartcarlife.contentManagerTask.study.staff.list.export'
      const list = [
        ...this.dowloadList,
        {
          name: '阅读统计',
          exportParam: JSON.stringify(params),
          status: 'waiting',
          timeid: new Date().getTime()
        }
      ]
      this.actionSetDownloadList({ list, type: 'dowloadList' })
      // try {
      //   await this.beforeSearchFn()
      //   const res = await contentManagerTaskExport({
      //     ...this.searchFormSearch
      //   })
      //   console.log(res)
      //   if (res) window.open(res)
      // } catch (error) {
      //   if (error) this.$message.error(error)
      // }
    },
    customerTagName(list) {
      let tag = []
      list.map((e) => {
        tag.push(e.labelName)
      })
      return tag.join("|")
    },
    getServiceStore() {
      listShop4sByRef({}).then((res) => {
        res ||= []
        this.showFormData.forEach((item, index) => {
          if (item.type === "select" && item.name == "merchantId") {
            this.$set(this.showFormData[index], "optionList", [
              {
                merchantName: "全部",
                merchantId: ""
              },
              ...res
            ])
          }
        })
      })
    },
    async getCustomerFileStatic() {
      try {
        await this.beforeSearchFn()
        const res = await getCustomerFileStatic({
          ...this.searchFormSearch
        })
        console.log(res)
        this.staticData = res || {}
      } catch (error) {
        if (error) this.$message.error(error)
      }
    },
    jumpDetail(row) {
      this.$router.push({
        name: "customerFileDetails",
        query: {
          id: row.id,
          receptionSceneName: row.receptionSceneName,
          receptionScene: row.receptionScene,
          scene: row.bussinessScene
        }
      })
    }
  }
}
</script>

<style scoped lang="scss">
.emptyBg {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 120px 0;

  .noDataImg {
    width: 64px;
    height: 40px;
  }
}

.error-input {
  ::v-deep.el-input__inner {
    border-color: red;
  }
}

.tag-item {
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;

  .tag {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .more-info {
    white-space: nowrap;
    color: #2a58ad;
    cursor: pointer;
    margin-left: 2px;
  }
}

::v-deep.tags-popover {
  max-width: 50vw;
}

.static-box {
  display: flex;
  gap: 0 16px;
  margin-bottom: 12px;

  .static-item {
    flex: 1;
    flex-shrink: 0;
    height: 82px;
    background: #f8faff;
    border-radius: 5px;
    box-sizing: border-box;
    padding: 16px 20px;

    .static-title {
      font-size: 14px;
      color: #333333;
      line-height: 20px;
      margin-bottom: 4px;
    }

    .static-value {
      display: flex;
      font-weight: 700;
      font-size: 24px;
      line-height: 30px;
      align-items: baseline;

      ::v-deep.static-unit {
        font-weight: 600;
        font-size: 14px;
        margin: 0 2px;
      }
    }
  }
}

.online-status {
  display: flex;
  justify-content: center;
  align-items: center;

  .dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 8px;
  }

  .gray {
    background-color: #c5c5c5;
  }

  .orange {
    background-color: #fdb757;
  }

  .blue {
    background-color: #2a58ad;
  }
}
</style>