dataBoard.vue 8.8 KB
<template>
  <div class="marketing data-board">
    <div class="data-board-box">
      <p class="edit-title">数据看板</p>
      <div class="p-20">
        <GLCombiForm ref="dataRef" :rowNumber="1" :formObj="searchForm" :formData="searchFormData" @handleOk="handleSearch"></GLCombiForm>
        <div class="data-view">
          <template v-for="(item,index) in dataList">
            <div :key="index" class="item">
              <div class="name">
                {{item.name}}
                <el-popover class="tips" placement="top" width="260" trigger="hover" :content="item.tips">
                  <img slot="reference" class="tips-icon" src="@/components/glsx-combi-form/images/icon-tip.png" />
                </el-popover>
              </div>
              <div class="value">{{dataBoard[item.key] || 0}}</div>
              <template v-if="item.half">
                <div class="half">
                  日环比:
                  <div :class="['icon',
                  {'up':dataBoard[item.half]>0},
                  {'down':dataBoard[item.half]<0}
                  ]"></div>
                  <span class="num">{{Math.abs(dataBoard[item.half]).toFixed(2) || 0}}%</span>
                </div>
              </template>
            </div>
          </template>
        </div>
      </div>
    </div>
    <div class="data-board-box">
      <p class="edit-title">员工排行榜</p>
      <div class="p-20">
        <GLCombiForm ref="rankRef" :rowNumber="1" :formObj="searchRankForm" :formData="searchFormRankData" @handleOk="handleSearchRank"></GLCombiForm>
        <div class="flex m-b-10 w-100-percent">
          <span class="table-title"></span>
          <el-button :size="size" class="default-blue-btn" type="default" @click="handleExport">导出</el-button>
        </div>
        <GLTable ref="dataTableRef" :getListApi="getListApi" :noDataImg="url" :searchForm="tableSearchForm" :tableParams="tableParams" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn" @setTableFinishFun="setTableFinishFun" :hasNum="false">
          <div slot="shareName" class="flex-align" slot-scope="scope">
            <template v-if="scope.scope.shareAvatar">
              <el-popover placement="top" width="160" trigger="hover" popper-class="table-popover-block">
                <img class="table-popover-img" :src="scope.scope.shareAvatar" />
                <img class="img-36 pointer" slot="reference" :src="scope.scope.shareAvatar" />

              </el-popover>
            </template>
            <span class="m-l-10">{{ scope.scope.shareName }}</span>
            <span class="m-l-10">{{ scope.scope.sharePhone || '' }}</span>
          </div>
        </GLTable>
      </div>
    </div>
  </div>
</template>

<script>
import * as dayjs from 'dayjs'
import { exportFn } from '@/common/constant'
import url from '@/assets/empty.png'

const dataList = [
  { name: '新增浏览量', key: 'browseCount', tips: '统计时间内,新增页面被浏览的次数(一人多次访问计为多次)', half: 'browseRingRatio' },
  { name: '新增访客数', key: 'fansCount', tips: '统计时间内访问页面的人数(一人多次访问计为一次)', half: 'fansRingRatio' },
  { name: '新增订单数', key: 'orderCount', tips: '统计时间内,新增订单数(只记录已付款的订单)', half: 'orderRingRatio' },
  { name: '累计浏览量', key: 'totalBrowseCount', tips: '页面被浏览的总次数(一人多次访问计为多次)' },
  { name: '累计访客数', key: 'totalFansCount', tips: '访问页面的总人数(一人多次访问计为一次)' },
  { name: '累计订单数', key: 'totalOrderCount', tips: '累计订单总数(只记录已付款的订单)' }
], optionList = [
  { confId: '1', confName: '转发次数' },
  { confId: '2', confName: '访客总数' },
  { confId: '3', confName: '浏览总数' },
  { confId: '4', confName: '成交单量' },
  { confId: '5', confName: '转化率' }
]
export default {
  name: 'ScrmMicroMarketingDataBoard',

  data() {
    return {
      url,
      dataList,
      searchForm: {
        statDate: dayjs().format('YYYY-MM-DD'),
        shareName: ''
      },
      searchFormData: [
        {
          label: '统计日期',
          name: 'statDate',
          type: 'datePicker',
          dateType: 'date',
          pickerOptions: 'beforeRangePickerOptions'
        }
      ],
      searchRankForm: {
        statDimension: '1'
      },
      searchFormRankData: [
        {
          label: '统计维度',
          name: 'statDimension',
          type: 'select',
          width: '215px',
          optionList,
          optionId: 'confId',
          optionLabel: 'confName',
          optionsName: 'statusList'
        },
        {
          label: '员工名称',
          name: 'shareName',
          type: 'input',
          maxlength: 100
        }
      ],
      getListApi: this.$apis.seckillActivity.getRankListApi,
      tableSearchForm: {},
      tableParams: {
        listName: 'list',
        tableColumns: [
          {
            label: '排名',
            prop: 'rankNumber',
          },
          {
            label: '员工',
            prop: 'shareName',
            addHtml: 'shareName',
            width: 220
          },
          {
            label: '转发次数',
            prop: 'shareCount',
          },
          {
            label: '访客总数',
            prop: 'fansCount',
            width: 140
          },
          {
            label: '浏览总数',
            prop: 'browseCount',
          },
          {
            label: '成交单量',
            prop: 'orderCount',
          },
          {
            label: '转化率',
            prop: 'conversionRate',
            formatter: cellValue => {
              return `${cellValue.conversionRate.toFixed(2)}%`
            }
          }
        ]
      },
      pageConf: { pageSize: 'pageSize', pageNum: 'currentPage', totalCount: 'total' },
      dataBoard: {}
    }
  },
  created() {
    this.getDataBoardApi()

  },
  mounted() {
    let [dataResetBtn] = this.$refs.dataRef.$el.getElementsByClassName('el-button--default'),
      [rankResetBtn] = this.$refs.rankRef.$el.getElementsByClassName('el-button--default')
    if (dataResetBtn) dataResetBtn.style.display = 'none'
    if (rankResetBtn) rankResetBtn.style.display = 'none'
  },

  methods: {
    getDataBoardApi() {
      let { activityId } = this.$route.query,
        { statDate } = this.searchForm
      this.$apis.seckillActivity.getDataBoardApi({ activityId, statDimension: dayjs(statDate).format('YYYY-MM-DD') }).then(res => {
        this.dataBoard = res || {}
      })
    },
    getParams() {
      let { activityId } = this.$route.query,
        params = JSON.parse(JSON.stringify(this.searchRankForm))
      params.activityId = activityId
      return params
    },
    handleSearch() {
      this.getDataBoardApi()
    },
    handleSearchRank() {
      this.$refs.dataTableRef.refreshTable()
    },
    handleExport() {
      let params = this.getParams()
      this.$apis.seckillActivity.exportRankListApi(params).then(res => {
        exportFn(res)
      })
    },
    beforeSearchFn() {
      return new Promise(resolve => {
        this.tableSearchForm = this.getParams()
        resolve()
      })
    },
    setTableFinishFun() {
      //接收到的数据为空
      this.$refs.dataTableRef.data.length ? (this.$refs.dataTableRef.tableHeightValues = '') : this.$refs.dataTableRef.setTableHeightFun()
    }
  },
};
</script>

<style lang="scss" scoped>
.data-board {
  &-box {
    background: #ffffff;
    &:last-of-type {
      margin-top: 16px;
    }
    .data-view {
      max-width: 854px;
      display: flex;
      flex-wrap: wrap;
      gap: 16px;
      padding-bottom: 12px;
      .item {
        width: 274px;
        height: 128px;
        background: #f9fafc;
        border-radius: 4px;
        box-sizing: border-box;
        padding: 10px;
        .name {
          font-size: 14px;
          color: #333333;
          display: flex;
          align-items: center;
          height: 21px;
          .tips {
            margin-left: 4px;
          }
        }
        .value {
          padding: 20px 0;
          font-size: 26px;
          color: #333333;
          line-height: 26px;
          font-weight: bold;
        }
        .half {
          font-size: 14px;
          color: #666666;
          line-height: 21px;
          display: flex;
          align-items: center;
          .icon {
            width: 16px;
            height: 16px;
            background-image: url(../../assets/dataBoard/icon-half-default.png);
            background-size: 16px 16px;
          }
          .up {
            background-image: url(../../assets/dataBoard/icon-half-up.png);
          }
          .down {
            background-image: url(../../assets/dataBoard/icon-half-down.png);
          }
          .num {
            margin-left: 4px;
          }
        }
      }
    }
  }
}
</style>