equity-echart.vue 2.98 KB
<template>
  <div class="output-panel">
    <div :id="echartId" class="echart-view"></div>
  </div>
</template>

<script>
import * as echarts from 'echarts'
export default {
  name: 'echartOutput',

  data() {
    return {}
  },
  props: {
    outputCircle: {
      type: Object
    },
     echartId: {
      type: String,
      default: ''
    },
  },
  watch: {
    outputCircle: {
      handler(value) {
        this.getOutput()
      },
      deep: true
    }
  },
  methods: {
    getOutput() {
      var chartDom = document.getElementById(this.echartId)
      var myChart = echarts.init(chartDom)
      var option

      option = {
        tooltip: {
          trigger: 'item',
          formatter: function (params) {
            return '占比 ' + params.value + '%' + '<br>' + params.data.name + ': ' + params.data.ratio
          }
        },
        legend: {
          left: 'center',
          top: '2%',
          icon: 'stack',
          itemHeight: 2,
          itemWidth: 12,
          data: [
            {
              name: '商城'
            },
            {
              name: '门店服务套餐'
            },
            {
              name: '精品升级'
            },
            {
              name: '其他'
            }
          ]
        },
        color: ['#5850FF', '#64C0A2', '#FACD67', '#F7A7B3', '#34911A'],
        series: [
          {
            name: '访问来源',
            type: 'pie',
            radius: '70%',
            center: ['50%', '53%'],
            data: [
              { value: this.outputCircle.shopmallTotalOutputValueRadio, name: '商城', unit: '%', ratio: this.outputCircle.shopmallTotalOutputValue },
              { value: this.outputCircle.equityTotalOutputValueRadio, name: '门店服务套餐', unit: '%', ratio: this.outputCircle.equityTotalOutputValue },
              { value: this.outputCircle.boutiqueUpgradeTotalOutputValueRadio, name: '精品升级', unit: '%', ratio: this.outputCircle.boutiqueUpgradeTotalOutputValue },
              { value: this.outputCircle.otherTotalOutputValueRadio, name: '其他', unit: '%', ratio: this.outputCircle.otherTotalOutputValue }
            ],
            itemStyle: {
              normal: {
                label: {
                  show: true
                },
                labelLine: {
                  show: true,
                  length: 10
                }
              }
            }
          }
        ]
      }

      option && myChart.setOption(option)
      myChart.on('click', res => {
        let url
        switch (res.data.name) {
          case '精品升级':
            url = '/services/inSale/upgrade'
            break
          case '商城':
            url = '/marketing/orderManage/index'
            break
          case '会员套餐':
            url = '/marketing/memberCenter/setmeal'
            break
        }
        this.$history.push(url)
      })
    }
  }
}
</script> 

<style lang="scss" scoped>
.output-panel {
  width: 100%;
}
.echart-view {
  height: 260px;
}
</style>>