analyze.vue 5.12 KB
<!--
 * @Description: 售后客户价值分析
 * @Author: huyue
 * @Date: 2022-06-23 15:05:21
 * @LastEditors: huyue
 * @LastEditTime: 2022-06-29 19:47:17
-->
<template>
  <div>
    <div class="title">售后客户价值分析</div>
    <template v-if="barData.length > 0">
      <div class="analyze-content" :style="{ height: height - 5 + 'vh' }">
        <div class="content-left">
          <div id="analyzeBar" style="height: 100%"></div>
        </div>
        <div class="contetn-right">
          <pie-chart :id="chart.id" :list="analyzeData" :height="height - 5 + 'vh'" :radius="chart.radius" :size="chart.size"></pie-chart>
        </div>
      </div>
    </template>
    <div class="empty" :style="{ height: height - 4.9 + 'vh' }" v-else>
      <img src="../../assets/images/empty.png" alt="" />
    </div>
  </div>
</template>

<script>
import * as echarts from 'echarts'
import datas from '../../utils/data'
import { changeMixin } from '../../mixins/index'
export default {
  name: 'Analyze',
  props: ['height'],
  mixins: [changeMixin],
  data() {
    return {
      analyzeData: [],
      chart: {
        id: 'analyzePie',
        radius: ['60%', '78%'],
        size:'0.8vw'
      },
      barChart: '',
      option: {},
      barData: [],
      key: '重要价值',
      isBrand: false,
      brandName: ''
    }
  },
  mounted() {},
  methods: {
    getChart() {
      this.barChart = echarts.init(document.getElementById('analyzeBar'))
      // resize
      window.addEventListener('resize', () => {
        this.barChart.resize()
      })
      this.option = {
        grid: {
          left: '3%',
          right: '4%',
          top: '2%',
          bottom: '2%',
          containLabel: true
        },
        yAxis: {
          type: 'category',
          data: datas.Customer.valueType.value.map(item => item.name).reverse(),
          splitLine: {
            show: false
          },
          axisTick: {
            show: false
          },
          axisLine: {
            show: false
          }
        },
        xAxis: {
          type: 'value',
          splitLine: {
            show: false
          },
          axisLabel: {
            show: false
          }
        },
        series: [
          {
            // data: [120, 200, 150, 80, 70, 110, 130, 300],
            data: this.barData.reverse(),
            type: 'bar',
            barWidth: 12,
            itemStyle: {
              normal: {
                label: {
                  show: true,
                  position: 'center',
                  textStyle: {
                    fontSize: '12',
                    color: '#fff',
                    height: '12',
                    padding: [1, 0, 0, 0]
                  }
                },
                color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [
                  {
                    offset: 0,
                    color: '#F79902'
                  },
                  {
                    offset: 1,
                    color: '#EB6001'
                  }
                ])
              }
            }
          }
        ]
      }
      this.barChart.clear()
      this.barChart.setOption(this.option)
      // 鼠标划入
      this.barChart.on('mouseover', data => {
        this.initPieData(data.name)
      })
    },
    getValueType() {
      let analyzeApi = !this.isBrand ? 'aftersaleother' : 'afterMerchantSaleother'
      const params = {
        req: {
          queryItem: 'valueanalyse',
          // queryTime: "2022-06-23",
          queryTime: this.getCurrentDate(),
          queryType: this.watchReportParams.reportType
        }
      }
      if (this.isBrand) params.req.brandName = this.brandName
      this.api.afterSales[analyzeApi](params).then(res => {
        this.analyzeData = []
        this.barData = []
        if (res.data.dataList.length > 0) {
          const reqData = JSON.parse(res.data.dataList[0].distribution)
          this.distributionRank = JSON.parse(res.data.dataList[0].distributionRank)
          this.barData = []
          for (let i in reqData) {
            this.barData.push(reqData[i])
          }
          this.$nextTick(() => {
            this.getChart()
            this.initPieData(this.key)
          })
        }
      })
    },
    initPieData(name) {
      this.analyzeData = []
      datas.Customer.valueType.value.map(item => {
        if (item.name == name) {
          const distributionRank = this.distributionRank[item.value]
          Object.keys(distributionRank).forEach(item => {
            this.analyzeData.push({
              name: item,
              value: distributionRank[item]
            })
          })
        }
      })
    },
    init(newVal) {
      this.isBrand = false
      if (newVal && newVal.brand) {
        this.isBrand = true
        this.brandName = newVal.brand.name
      }
      this.getValueType()
    }
  }
}
</script>

<style lang="scss" scoped>
.title {
  padding: 1vh 8px;
  height: 4vh;
}
.analyze-content {
  display: flex;
  padding: 0 8px;
  box-sizing: border-box;
  .bg {
    background-color: #262525;
  }
  .content-left {
    flex: 1;
    height: 100%;
  }
  .contetn-right {
    width: 50%;
    margin-left: 8px;
  }
}
</style>