<template>
  <div shadow="never" class="homeBoxCard" v-loading="loading">
    <div class="height260" id="radarChart" ref="radarChart" />
  </div>
</template>
<script>
import { computed, defineComponent, onMounted, ref } from 'vue'
import { useStore } from 'vuex'
import * as echarts from 'echarts'

export default defineComponent({
  name: 'RadarChart',
  setup() {
    const store = useStore()

    // 总数
    const total = computed(() => store.state.Home.worksChartData.total)
    // num
    const num = computed(() => store.state.Home.worksChartData.num)

    // 读取数据 func
    const loading = ref(true)
    const getData = async () => {
      // loading.value = true;
      // await store.dispatch("Home/queryWorksChartData");
      loading.value = false
    }

    onMounted(() => {
      getData()
      let myChart = echarts.init(document.getElementById('radarChart'))
      // 绘制图表
      myChart.setOption({
        backgroundColor: '#FFF',
        tooltip: {},
        grid: {
          left: '20',
          right: '40',
          top: '-20',
          bottom: '0',
          containLabel: true,
        },
        radar: {
          radius: '60%',
          center: ['50%', '55%'],
          splitNumber: 5,
          nameGap: '15',
          name: {
            textStyle: {
              color: '#a8a8a8',
            },
          },
          axisLine: {
            lineStyle: {
              color: '#ebebeb',
            },
          },
          splitLine: {
            lineStyle: {
              width: 1,
              color: '#ebebeb',
            },
          },
          splitArea: {
            areaStyle: {
              color: ['#f8f8f8', '#fff'].reverse(),
            },
          },
          indicator: [
            {
              name: '谐波畸变率',
              max: 100,
            },
            {
              name: '电压平衡度',
              max: 100,
            },
            {
              name: '电压合格率',
              max: 100,
            },
            {
              name: '功率因数',
              max: 100,
            },
            {
              name: '电流平衡度',
              max: 100,
            },
            {
              name: '负载率',
              max: 100,
            },
          ],
        },
        series: [
          {
            name: 'Title✍',
            type: 'radar',
            symbolSize: 12,
            itemStyle: {
              borderColor: '#ebebeb',
              borderWidth: 2,
            },
            areaStyle: {
              opacity: 0.3,
            },
            data: [
              {
                itemStyle: {
                  color: '#5eb6db',
                },
                value: [20, 33, 80, 50, 30, 40, 100],
              },
            ],
          },
        ],
      })
     window.addEventListener('resize', () => {
        myChart.resize()
      })
    })

    return {
      loading,
      total,
      num,
    }
  },
})
</script>
<style lang="scss" scoped>
.homeBoxCard {
  margin-bottom: 24px;
  ::v-deep(.el-card__header) {
    padding-left: 12px;
    padding-right: 12px;
  }
  ::v-deep(.el-card__body) {
    padding: 12px;
    font-size: 14px;
    line-height: 1.5715;
  }
  ::v-deep(.el-divider) {
    margin: 8px 0;
  }
  .num {
    font-size: 30px;
    color: #515a6e;
  }
  .height260 {
    height: 260px;
  }
}
</style>