StoresRanking.vue 6.7 KB
<template>
  <div class="store-ranking-wrap">
    <template v-if="tabIndex == 0">
      <div class="weekTitle headline">新增客户分布</div>
      <template v-if="staffDistributionVOList.length > 0">
        <van-swipe :loop="false" :width="170" :show-indicators="false">
          <template v-for="(i, index) in staffDistributionVOList">
            <van-swipe-item :key="i.id">
              <template v-if="index == 0">
                <div class="sprite-icon icon-crown"></div>
              </template>
              <div class="customers-portrait">
                <template v-if="i.staffId != -1">
                  <img :src="i.thumbAvatar" alt="" />
                </template>
                <template v-else>
                  <img src="@/assets/images/general.png" alt="" />
                </template>

                <template v-if="index == 0">
                  <div class="sprite-icon icon-huangguan"></div>
                </template>
              </div>
              <div class="gray-text">{{ i.staffName }}</div>
              <div class="gray-text location">
                新增
                <span>{{ i.newlyQyCount }}</span>
                位客户
              </div>
              <div class="rate">占{{ (i.newlyQyRatio * 100).toFixed(0) }}%</div>
            </van-swipe-item>
          </template>
        </van-swipe>
      </template>
    </template>
    <template v-if="tabIndex == 1">
      <div class="weekTitle headline">新增产值分布</div>

      <canvas class="canvas" id="pieChart" v-show="productionValueReportList.length > 0"></canvas>
    </template>
    <template v-if="(tabIndex == 0 && staffDistributionVOList.length == 0) || (tabIndex == 1 && productionValueReportList.length == 0)">
      <Empty></Empty>
    </template>
  </div>
</template>

<script type='text/ecmascript-6'>
import F2 from '@antv/f2/lib/index-all'
import { mapState } from 'vuex'
export default {
  name: 'StoresRanking',
  data() {
    return {
      chart: null,
      orderSource: {
        1: '商城订单',
        2: '直播订单',
        3: '活动订单',
        4: '门店服务套餐',
        5: '精品升级',
        6: '权益提单',
        7: '商城订单'
      }
    }
  },
  computed: {
    ...mapState({
      tabIndex: state => state.report.tabIndex,
      reportType: state => state.report.reportType,
      productionValueReportList: state => state.report.productionValueReportList,
      staffDistributionVOList: state => state.report.staffDistributionVOList
    })
  },
  watch: {
    tabIndex: {
      handler(n) {
        this.$nextTick(() => {
          this.initCanvas()
        })
      },
      deep: true
    },
    productionValueReportList: {
      handler(n) {
        this.$nextTick(() => {
          this.initCanvas()
        })
      },
      deep: true
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initCanvas()
    })
  },
  methods: {
    initCanvas() {
      //tabIndex 0 客户 1 产值
      let { reportType, tabIndex } = this
      if (tabIndex == 1 && reportType == 0) this.initPieChart()
    },
    initPieChart(id = 'pieChart') {
      let { productionValueReportList, orderSource } = this
      productionValueReportList.map(e => (e.count = 'count'))
      this.chart && this.chart.clear()
      this.chart = null
      this.chart = new F2.Chart({
        id,
        pixelRatio: window.devicePixelRatio,
        padding: [40, 40, 40, 40]
      })
      this.chart.source(productionValueReportList)
      this.chart.coord('polar', {
        transposed: true,
        radius: 0.9,
        innerRadius: 0.6
      })
      this.chart.axis(false)
      this.chart.legend(false)
      this.chart.tooltip(false)
      // this.chart.guide().html({
      //   position: ['50%', '50%'],
      //   html: '<div style="text-align: center;width:150px;height: 50px;">\n      <p style="font-size: 12px;color: #999;margin: 0" id="title"></p>\n      <p style="font-size: 18px;color: #343434;margin: 0;font-weight: bold;" id="money"></p>\n      </div>'
      // })
      this.chart.interval().position('count*newProductionValue').adjust('stack').color('orderSource', ['#3975C6', '#43B899', '#FFC667', '#FF9DAA'])
      this.chart.pieLabel({
        sidePadding: 10,
        activeShape: true,
        label1(data, color) {
          return {
            text: `${orderSource[data.orderSource]}-占${data.newProductionValueRate}`,
            fill: color
          }
        },
        label2(data) {
          return {
            text: `¥${data.newProductionValue}`,
            fill: '#333',
            fontSize: 12,
            fontWeight: 'bold'
          }
        },
        onClick(ev) {
          const data = ev.data
          if (data) {
          }
        }
      })
      this.chart.render()
    },
    click(tabIndex) {
      this.tabIndex = tabIndex
      this.$emit('change', tabIndex)
    }
  }
}
</script>

<style lang='scss' scoped>
.store-ranking-wrap {
  height: auto;
  margin-bottom: 80px;
  .van-swipe {
    height: 180px;
    .van-swipe-item {
      height: 180px;
      background-color: #ffffff;
      margin-right: 10px;
      flex-flow: column;
      display: flex;
      align-items: center;
      padding: 20px 0 0 0;
      box-sizing: border-box;
      position: relative;
      .icon-crown {
        position: absolute;
        top: 0;
        left: 11px;
      }
      .customers-portrait {
        width: 40px;
        height: 40px;
        position: relative;
        img {
          width: 100%;
          height: 100%;
          border-radius: 50%;
        }
        .icon-huangguan {
          position: absolute;
          top: 0;
          right: -7px;
        }
      }
      .gray-text {
        margin: 10px 0 0 0;
        color: #999999;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        width: 100%;
        text-align: center;
        span {
          font-size: 14px;
          font-weight: 500;
          color: #3975c6;
          line-height: 15px;
        }
      }
      .rate {
        width: 68px;
        height: 24px;
        background: #e4ebf2;
        border-radius: 12px;
        font-size: 12px;
        font-weight: 400;
        color: #333333;
        line-height: 24px;
        margin-top: 11px;
        text-align: center;
      }
    }
  }

  .weekTitle {
    margin: 30px 0 15px 0;
    color: #333333;
    line-height: 25px;
  }
  .weekTitle::before {
    content: '.';
    width: 3px;
    height: 15px;
    background: #3975c6;
    border-radius: 2px;
    color: #3975c6;
    margin-right: 5px;
    box-sizing: border-box;
  }
}
.canvas {
  width: 345px;
  height: 195px;
  background-color: #ffffff;
}
.store-ranking-wrap /deep/ .van-swipe__track {
  margin-right: 10px;
  height: auto;
  .van-swipe-item {
    width: 140px !important;
  }
}
</style>