<template>
  <div id='safecheck-ring' style="width: 100%;height: 100%">
  </div>
</template>

<script>
  export default {
    title: '收费',
    data () {
    },
    methods: {
      init () {
        var colorarr = ['#00FFFF', '#f27c79', '#00FFA8', '#897bd3']
        var option = {
          backgroundColor: '#ffffff00',
          animation: true,
          title: {
            x: 'center',
            y: 'center',
            textStyle: {
              color: '#fff',
              fontSize: 60,
              fontWeight: 'normal',
              align: 'center',
              width: '200px'
            },
            subtextStyle: {
              color: '#fff',
              fontSize: 20,
              fontWeight: 'normal',
              align: 'center'
            }
          },
          legend: {
            width: '70%',
            textStyle: {
              color: '#fff',
              fontSize: 12
            },
            orient: 'vertical',
            icon: 'circle',
            bottom: '10%',
            right: '10%',
            itemGap: 10,
            data: ['到访不遇', '无法检查','正常入户','拒绝检查']
          },
          series: [{
            type: 'pie',
            center: ['30%', '60%'],
            radius: ['30%', '55%'],
            color: colorarr,
            startAngle: 135,
            labelLine: {
              normal: {
                length: 20
              }
            },
            label: {
              show: true,
              formatter: '{b|{b}}\n{per|{d}%}',
              rich: {
                a: {
                  color: '#999',
                  lineHeight: 22,
                  align: 'center'
                },
                hr: {
                  borderColor: '#aaa',
                  width: '100%',
                  borderWidth: 1,
                  height: 0
                },
                b: {
                  fontSize: 10,
                  padding: [5, 0],
                  color: '#fff'
                },
                c: {
                  fontSize: 10,
                  color: '#eee'
                },
                per: {
                  color: '#FDF44E',
                  fontSize: 10,
                  borderRadius: 2
                }
              },
              position: 'outside'
            },
            data: [{
              name: '到访不遇',
              value: 259574
            }, {
              name: '无法检查',
              value: 503
            }, {
              name: '正常入户',
              value: 471544
            }, {
              name: '拒绝检查',
              value: 4700
            }]
          }]
        }
        let barchart = this.$echarts.init(document.getElementById('safecheck-ring'))
        console.log(option)
        barchart.setOption(option)
        let index = -1 // 高亮所在下标
        let dataLength = colorarr.length   // 当前饼图有多少个扇形
        // 用定时器控制饼图高亮
        // this.mTime = setInterval(() => {
        //   // 清除之前的高亮
        //   barchart.dispatchAction({
        //     type: 'downplay',
        //     seriesIndex: 0,
        //     dataIndex: index
        //   })
        //   index = (index + 1) % dataLength
        //   // 当前下标高亮
        //   barchart.dispatchAction({
        //     type: 'highlight',
        //     seriesIndex: 0,
        //     dataIndex: index
        //   })
        //   if (index > dataLength) {
        //     index = 0
        //   }
        // }, 1000)
        // 鼠标划入
        barchart.on('mouseover', () => {
          // 停止定时器，清除之前的高亮
          // clearInterval(this.mTime)
          this.echartsPie.dispatchAction({
            type: 'downplay',
            seriesIndex: 0,
            dataIndex: index
          })
        })
      }
    },
    ready () {
      this.init()
    },
    props: {}
  }
</script>
<style scoped>
</style>

