touchList.vue 9.71 KB
<!-- 完成率分析-->
<template>
  <div class="marketing sop-analysis touch-list">
    <div class="container">
      <div class="title m-b-20">
        SOP名称:
        <span>{{ sopInfo.sopName }}</span>
      </div>

      <div v-loading="loading">
        <div>
          <glsx-combi-form ref="showSearch" :formObj="searchForm" :formData="searchFormData">
            <!-- <span slot="footer">
            <el-button :size="size" type="primary" @click="handleSearch">查询</el-button>
          </span> -->
          </glsx-combi-form>
        </div>

        <div class="analysis-box flex-default">
          <div class="analysis-block">
            <div class="analysis-title-block m-b-20">
              客户总数
              <img src="@/assets/sop/customer-total.png" />
            </div>
            <p class="analysis-num">{{ baseData.sopEventList.length ? sopInfo.customerCount : '-' }}</p>
          </div>
          <div class="analysis-block back-image-green">
            <div class="analysis-title-block m-b-20">
              已触达客户数
              <img src="@/assets/sop/touch-customer.png" />
            </div>
            <p class="analysis-num">{{ baseData.sopEventList.length ? selectedEventInfo.eventStatistics.reachCustomerCount : '-' }}</p>
          </div>
          <div class="analysis-block back-image-blue">
            <div class="analysis-title-block m-b-20">
              触达率
            </div>
            <p class="analysis-num">{{ sopInfo.touchPercent }}</p>
            <div id="completePie" class="chart-pie"></div>
          </div>
        </div>

        <p class="m-b-10">客户触达明细</p>

        <!-- 表格区域 开始 -->
        <GLTable ref="touchListRef" :getListApi="getListApi" :noDataImg="url" :searchForm="searchForm" :tableParams="tableParams" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn" @setTableFinishFun="setTableFinishFun"></GLTable>
        <!-- 表格区域 end -->
      </div>
    </div>
  </div>
</template>

<script>
import * as echarts from 'echarts'
import * as dayjs from 'dayjs'
import url from '@/assets/empty.png'
import { pieOption } from './pieOption'
export default {
  name: 'touchList',
  data() {
    return {
      size: 'small',
      url: url,
      loading: false,
      searchForm: {
        sopId: '',
        eventId: ''
      },
      sopInfo: {},
      selectedEventInfo: {
        eventStatistics: {}
      },
      // 搜索
      searchFormData: [
        {
          label: '营销事件',
          name: 'eventId',
          type: 'select',
          width: '415px',
          optionList: [],
          optionId: 'id',
          optionLabel: 'confName',
          optionsName: 'sopEventList',
          changeAttr: (val, targetItem) => {
            this.searchForm.eventId = val
            this.selectedEventInfo = this.baseData.sopEventList.find(item => item.id == val)
            this.getBaseInfo()
            this.$refs.touchListRef.refreshTable()
          }
        }
      ],
      // 表格
      getListApi: this.$apis.sop.getSopCustomerStatisticsListApi,
      tableParams: {
        listName: 'list',
        tableColumns: [
          {
            label: '客户名称',
            prop: 'customerName',
            formatter: cellValue => {
              return cellValue.customerName || '-'
            }
          },
          {
            label: '客户手机号',
            prop: 'customerPhone',
            width: '110',
            formatter: cellValue => {
              return cellValue.customerPhone || '-'
            }
          },
          {
            label: '推送人',
            prop: 'pusherName'
          },
          {
            label: '推送时间',
            prop: 'pusherTime'
          },
          {
            label: '初次查看时间',
            prop: 'firstViewDate',
            formatter: cellValue => {
              return cellValue.firstViewDate ? dayjs(cellValue.firstViewDate).format('YYYY-MM-DD HH:mm:ss') : '未查看'
            }
          },
          {
            label: '查看次数',
            prop: 'viewCount',
            formatter: cellValue => {
              return cellValue.viewCount || '0'
            }
          }
          // {
          //   label: '查看总时长',
          //   prop: ''
          // }
        ]
      },
      pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
      baseData: {
        sopEventList: []
      }
    }
  },

  props: {
    sopId: {
      type: String,
      default: ''
    }
  },

  mounted() {
    this.getBaseData()
    this.$refs.touchListRef.tableHeightValues = '400px'
  },

  methods: {
    getBaseInfo() {
      this.$apis.sop.getSopBaseInfoApi({ sopId: this.sopId }).then(res => {
        this.sopInfo = res
        this.sopInfo.touchPercent = this.baseData.sopEventList.length && this.sopInfo.customerCount ? Math.round((this.selectedEventInfo.eventStatistics.reachCustomerCount / this.sopInfo.customerCount) * 100).toFixed(0) + '%' : '-'
        this.drawPie()
      })
    },

    getBaseData() {
      this.loading = true
      var params = {
        sopId: this.sopId,
        ifFilter: 'Y',
        pageNum: 1,
        pageSize: 999999
      }
      var pushChannelTypeList = {
        1: '企业微信',
        2: '短信',
        3: '微信朋友圈'
      }
      this.$apis.sop
        .getEventListApi(params)
        .then(res => {
          this.baseData.sopEventList = res.list
          if (this.baseData.sopEventList.length) {
            this.baseData.sopEventList.forEach(item => {
              item.confName = item.eventStartDate + (item.repeatFlag == 'Y' ? '-' + item.eventEndDate : '') + ' ' + item.eventTime + ' ' + pushChannelTypeList[item.pushChannelType]
            })
            this.getOptionsList('searchFormData', false)
            this.searchForm.eventId = this.baseData.sopEventList[0].id
            this.selectedEventInfo = this.baseData.sopEventList[0]
          }
          this.getBaseInfo()
          this.$refs.touchListRef.refreshTable()
        })
        .finally(() => {
          this.loading = false
        })
    },

    beforeSearchFn() {
      return new Promise((resolve, reject) => {
        this.searchForm.sopId = this.sopId
        this.baseData.sopEventList.length ? resolve() : reject()
      })
    },

    getOptionsList(formName, hasAll = true, refreshSigle) {
      if (refreshSigle) {
        var item = this[formName].find(k => k.name == refreshSigle)
        var index = this[formName].findIndex(k => k.name == refreshSigle)
        this.$set(this[formName][index], 'optionList', this.$common.utils.deepClone(this.baseData[item.optionsName]))
        if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
          const temp = {}
          temp[this[formName][index].optionId] = ''
          temp[this[formName][index].optionLabel] = '全部'
          this[formName][index].optionList.unshift(temp)
        }
      } else {
        this[formName].forEach((item, index) => {
          if (item.type === 'select' && this.baseData[item.optionsName].length) {
            this.$set(this[formName][index], 'optionList', this.$common.utils.deepClone(this.baseData[item.optionsName]))
            if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
              const temp = {}
              temp[this[formName][index].optionId] = ''
              temp[this[formName][index].optionLabel] = '全部'
              this[formName][index].optionList.unshift(temp)
            }
          }
        })
      }
    },
    setTableFinishFun() {
      //接收到的数据为空
      this.$refs.touchListRef.data.length ? (this.$refs.touchListRef.tableHeightValues = '') : this.$refs.touchListRef.setTableHeightFun()
    },

    drawPie() {
      if (this.baseData.sopEventList.length) {
        let chartDom = document.getElementById('completePie')
        let myChart = echarts.init(chartDom)
        let option = JSON.parse(JSON.stringify(pieOption))

        option.series[0].data = [
          {
            value: this.selectedEventInfo.eventStatistics.reachCustomerCount ? this.selectedEventInfo.eventStatistics.reachCustomerCount : 0,
            name: '已触达的客户数'
          },
          {
            value: this.sopInfo.customerCount - this.selectedEventInfo.eventStatistics.reachCustomerCount,
            name: '未触达的客户数'
          }
        ]

        option && myChart.setOption(option)
      }
    }
  }
}
</script>

<style lang="scss">
.sop-analysis {
  .title {
    height: 32px;
    line-height: 32px;
    font-size: 20px;
    font-weight: 600;
  }
  .analysis-box {
    margin-bottom: 40px;
    .analysis-block {
      position: relative;
      box-sizing: border-box;
      width: 216px;
      height: 116px;
      padding: 10px 20px 20px;
      margin-right: 20px;
      flex-basis: 0 0 auto;
      background: #ffffff;
      background-image: linear-gradient(0deg, #f8f8fc 0%, #f0f7ff 100%);
      box-shadow: 0px 10px 20px 0px rgba(88, 80, 255, 0.1);
      .analysis-title-block {
        display: flex;
        justify-content: space-between;
        align-items: center;
        height: 40px;
        line-height: 40px;
        font-size: 14px;
        color: #666666;
      }
      .chart-pie {
        position: absolute;
        top: 20px;
        right: 20px;
        width: 70px;
        height: 74px;
      }
      .analysis-num {
        font-size: 26px;
        font-weight: 600;
      }
    }
    .analysis-block.back-image-green {
      background-image: linear-gradient(0deg, #f8f8fc 0%, #f0fffa 100%);
    }
    .analysis-block.back-image-blue {
      background-image: linear-gradient(0deg, #f8f8fc 0%, #f0f0ff 100%);
    }
  }
}
</style>