<template>
  <view class="charts-container">
    <qiun-data-charts type="rose" :opts="opts" :chartData="chartData" @getIndex="handleChartClick" />
  </view>
</template>

<script>
import { getHomePageListApi } from '@/api/phaseTwo/homePage'
export default {
  data() {
    return {
      chartData: {},
      opts: {
        timing: 'easeOut',
        duration: 1000,
        rotate: false,
        rotateLock: false,
        color: ['#1890FF', '#91CB74', '#FAC858', '#EE6666', '#73C0DE', '#3CA272', '#FC8452', '#9A60B4', '#ea7ccc'],
        padding: [5, 5, 5, 5],
        fontSize: 13,
        fontColor: '#666666',
        dataLabel: false,
        dataPointShape: true,
        dataPointShapeType: 'solid',
        touchMoveLimit: 60,
        enableScroll: false,
        enableMarkLine: false,
        legend: {
          show: true,
          position: 'right',
          lineHeight: 25,
          float: 'right',
          padding: 25,
          margin: 5,
          backgroundColor: 'rgba(0,0,0,0)',
          borderColor: 'rgba(0,0,0,0)',
          borderWidth: 0,
          fontSize: 12,
          fontColor: '#666666',
          hiddenColor: '#CECECE',
          itemGap: 10
        },
        extra: {
          rose: {
            type: 'radius',
            minRadius: 50,
            activeOpacity: 0.5,
            activeRadius: 10,
            offsetAngle: 0,
            labelWidth: 15,
            border: true,
            borderWidth: 2,
            borderColor: '#FFFFFF',
            linearType: 'none'
          },
          tooltip: {
            showBox: true,
            showArrow: true,
            showCategory: false,
            borderWidth: 0,
            borderRadius: 0,
            borderColor: '#000000',
            borderOpacity: 0.7,
            bgColor: '#000000',
            bgOpacity: 0.7,
            gridType: 'solid',
            dashLength: 4,
            gridColor: '#CCCCCC',
            boxPadding: 3,
            fontSize: 13,
            lineHeight: 20,
            fontColor: '#FFFFFF',
            legendShow: true,
            legendShape: 'auto',
            splitLine: true,
            horizentalLine: false,
            xAxisLabel: false,
            yAxisLabel: false,
            labelBgColor: '#FFFFFF',
            labelBgOpacity: 0.7,
            labelFontColor: '#666666'
          }
        }
      }
    }
  },
  mounted() {
    this.getServerData()
  },
  methods: {
    getServerData() {
      getHomePageListApi().then(res => {
        setTimeout(() => {
          const { level110, level220, level500, level800, level1000, levelOther } = res.data.proMsgBean
          let data = {
            series: [
              {
                data: [
                  {
                    name: '110kv',
                    value: level110,
                    legendText: `110kv       ${level110}`
                  },
                  {
                    name: '220kv',
                    value: level220,
                    legendText: `220kv       ${level220}`
                  },
                  {
                    name: '500kv',
                    value: level500,
                    legendText: `500kv       ${level500}`
                  },
                  {
                    name: '800kv',
                    value: level800,
                    legendText: `800kv       ${level800}`
                  },
                  {
                    name: '1000kv及以上',
                    value: level1000,
                    legendText: `1000kv及以上 ${level1000}`
                  },
                  {
                    name: '其他',
                    value: levelOther,
                    legendText: `其他         ${levelOther}`
                  }
                ]
              }
            ]
          }
          this.chartData = JSON.parse(JSON.stringify(data))
        }, 500)
      })
    },
    handleChartClick(index) {
      const { currentIndex } = index // 获取当前点击的图表索引
      const chartsData = this.chartData.series[0].data
      const currenRows = chartsData[currentIndex]
      console.log('currenRows选中的工程类型', currenRows.name)

      // 电压等级信息
      const voltageLevel = {
        currentIndex,
        name: currenRows.name
      }
      uni.navigateTo({ url: `/pages/realName/index/pages/project?voltageLevel=${JSON.stringify(voltageLevel)}` })
    }
  }
}
</script>

<style scoped>
.charts-container {
  width: 100%;
  height: 100%;
}
</style>
