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

      <div class="analysis-box flex-default">
        <div class="analysis-block">
          <div class="analysis-title-block m-b-20">
            营销事件总数
            <img src="@/assets/sop/sop-event.png" />
          </div>
          <p class="analysis-num">{{ sopInfo.sopStatistics ? sopInfo.sopStatistics.eventCount : '-' }}</p>
        </div>
        <div class="analysis-block back-image-green">
          <div class="analysis-title-block m-b-20">
            已完成事件数
            <img src="@/assets/sop/completed-event.png" />
          </div>
          <p class="analysis-num">{{ sopInfo.sopStatistics ? sopInfo.sopStatistics.finishEventCount : '-' }}</p>
        </div>
        <div class="analysis-block back-image-orange">
          <div class="analysis-title-block m-b-20">
            <div>
              失败事件数
              <el-popover placement="top" width="200" trigger="hover" content="因企微、短信等限制无法正常执行的事件">
                <img slot="reference" class="tips-icon" src="@/assets/icon-tip.png" />
              </el-popover>
            </div>
            <img src="@/assets/sop/completed-fail.png" />
          </div>
          <p class="analysis-num">{{ sopInfo.sopStatistics ? sopInfo.sopStatistics.failEventCount || '-' : '-' }}</p>
        </div>
        <div class="analysis-block back-image-blue">
          <div class="analysis-title-block m-b-20">
            完成率
          </div>
          <p class="analysis-num">{{ sopInfo.completedPercent }}</p>
          <div id="completePie" class="chart-pie"></div>
        </div>
      </div>

      <p class="m-b-10">日营销事件明细</p>

      <!-- 表格区域 开始 -->
      <GLTable ref="completeListRef" :getListApi="getListApi" :noDataImg="url" :searchForm="searchForm" :tableParams="tableParams" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn" @setTableFinishFun="setTableFinishFun">
        <template slot="failEventCount" slot-scope="scope">
          <el-popover v-show="scope.scope.failEventList" placement="bottom-end" width="200" trigger="click" :content="scope.scope.failEventList">
            <span class="cursor-pointer" slot="reference" @click="handleGetFailEvent(scope.scope)">{{ scope.scope.eventStatistics ? scope.scope.eventStatistics.failEventCount : '-' }}</span>
          </el-popover>
          <span v-show="!scope.scope.failEventList" class="cursor-pointer" slot="reference" @click="handleGetFailEvent(scope.scope)">{{ scope.scope.eventStatistics ? scope.scope.eventStatistics.failEventCount : '-' }}</span>
        </template>
      </GLTable>
      <!-- 表格区域 end -->
    </div>
  </div>
</template>

<script>
import * as echarts from 'echarts'
import url from '@/assets/empty.png'
import { pieOption } from './pieOption'
export default {
  name: 'completeList',
  data() {
    return {
      size: 'small',
      url: url,
      sopInfo: {
        completedPercent: '',
        sopStatistics: {}
      },
      searchForm: {},
      // 表格
      getListApi: this.$apis.sop.getEventListApi,
      tableParams: {
        listName: 'list',
        tableColumns: [
          {
            label: '营销事件',
            prop: 'sopName',
            formatter: cellValue => {
              var repeatTxt = ''
              var weekToTxt = {
                1: '一',
                2: '二',
                3: '三',
                4: '四',
                5: '五',
                6: '六',
                7: '日'
              }
              switch (cellValue.repeatMode) {
                case 1:
                  repeatTxt = ' 每天重复推送至'
                  break
                case 2:
                  repeatTxt = ' 每周' + weekToTxt[cellValue.repeatTime] + '重复推送至'
                  break
                case 3:
                  repeatTxt = ' 每月' + cellValue.repeatTime + '重复推送至'
                  break
              }
              return cellValue.eventStartDate + ' ' + cellValue.eventTime + (cellValue.repeatFlag == 'Y' ? repeatTxt : ' 单次') + (cellValue.repeatFlag == 'Y' ? ' ' + cellValue.eventEndDate : '')
            }
          },
          {
            label: '营销渠道',
            prop: 'pushChannelType',
            width: '140',
            formatter: cellValue => {
              var pushChannelTypeList = {
                1: '企业微信',
                2: '短信',
                3: '微信朋友圈'
              }
              return pushChannelTypeList[cellValue.pushChannelType]
            }
          },
          {
            label: '营销事件总数',
            prop: 'eventStatistics',
            width: '140',
            formatter: cellValue => {
              return cellValue.eventStatistics ? cellValue.eventStatistics.eventCount : '-'
            }
          },
          {
            label: '已完成事件数',
            prop: 'finishEventCount',
            width: '140',
            formatter: cellValue => {
              return cellValue.eventStatistics ? cellValue.eventStatistics.finishEventCount : '-'
            }
          },
          {
            label: '失败事件数',
            prop: 'failEventCount',
            width: '140',
            addHtml: 'failEventCount'
          }
        ]
      },
      pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' }
    }
  },

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

  mounted() {
    this.getBaseInfo()
  },

  methods: {
    beforeSearchFn() {
      return new Promise(resolve => {
        this.searchForm.sopId = this.sopId
        resolve()
      })
    },

    setTableFinishFun() {
      //接收到的数据为空
      this.$refs.completeListRef.data.length ? (this.$refs.completeListRef.tableHeightValues = '') : this.$refs.completeListRef.setTableHeightFun()
    },

    getBaseInfo() {
      this.$apis.sop.getSopBaseInfoApi({ sopId: this.sopId }).then(res => {
        this.sopInfo = res
        this.sopInfo.completedPercent = Math.round((this.sopInfo.sopStatistics.finishEventCount / this.sopInfo.sopStatistics.eventCount) * 100).toFixed(0) + '%'
        this.drawPie()
      })
    },

    handleGetFailEvent(row) {
      this.$apis.sop.getFailEventList({ id: row.id }).then(res => {
        let idx = this.$refs.completeListRef.data.findIndex(item => item.id == row.id)
        this.$refs.completeListRef.data[idx].failEventList = res
      })
    },

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

      // option.series[0].name = item.sopName
      option.series[0].data = [
        {
          value: this.sopInfo.sopStatistics.finishEventCount,
          name: '已触发的营销事件'
        },
        {
          value: this.sopInfo.sopStatistics.eventCount - this.sopInfo.sopStatistics.finishEventCount,
          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-orange {
      background-image: linear-gradient(0deg, #f8f8fc 0%, #fff6f0 100%);
    }
    .analysis-block.back-image-blue {
      background-image: linear-gradient(0deg, #f8f8fc 0%, #f0f0ff 100%);
    }
  }
}
</style>