<template>
  <div :class="className" :style="{height:height,width:width}"/>
</template>

<script>
import * as echarts from 'echarts'

require('echarts/theme/macarons') // echarts theme
import resize from '../mixins/resize'
import {procedureCount} from "@/api/common/homedataCbpb";

const animationDuration = 3000

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '210px'
    }
  },
  data() {
    return {
      chart: null,
      chartData: {},
      color: [
        '#87CA8B',
        '#58B1FF',
        '#FBD44A',
        '#7485E5',
        '#AEE5B1',
        '#81C4FF',
        '#AAD7FF',
        '#FFE791',
        '#9AA6EA',
      ],
      dataIn: [
        // 外层数据
      ],
      dataOut: []
    }
  },
  created() {

  },
  mounted() {
    this.$nextTick(() => {
      procedureCount().then(res => {
        this.dataOut = [
          {value: res.data.appNum, name: res.data.app},
          {value: res.data.trainNum, name: res.data.train},
          {value: res.data.excelNum, name: res.data.excel},
          {value: res.data.fileNum, name: res.data.file},
          {value: res.data.guideNum, name: res.data.guide},
          {value: res.data.fingerpostNum, name: res.data.fingerpost}
        ]
        this.initChart()
      })

    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')

      this.chart.setOption({
        color: this.color,
        tooltip: {
          trigger: 'item',
          formatter: "{b}: {c} " + " | " + "{d}%"
        },
        title:
          {
            text: '',
          }
        ,
        legend: {
          orient: 'vertical',
          left: 'left',
          itemWidth: 10,
          itemHeight: 10,
          textStyle: {
            fontSize: 12,
            padding:[0,0]
          },
          selectedMode: true,
          data: ['程序总汇', '指南总汇', '指导书总汇', '附件总汇', '表格总汇', '培训材料'],
        },
        series: [
          {
            name: '',
            type: 'pie',
            selectedMode: 'single',
            radius: ['20%', '80%'],
            label: {
              position: 'outside',
              fontSize: 10,
            },
            animationEasing: 'cubicInOut',
            animationDuration: 1300,
            labelLine: {
              show: true
            },
            data: this.dataOut
          }
        ],
      })
    }
  }
}
</script>
