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

export default defineComponent({
  name: 'RadarChart',
  props:{
    getTableData:Object,
  },
  setup(props) {

    // 读取数据 func
    const getData = async () => {

      // await store.dispatch("Home/queryWorksChartData");
    }
    function echarts2(){
       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: 20,
            },
            {
              name: '电流平衡度',
              max: 20,
            },
            {
              name: '功率因数',
              max: 20,
            },
            {
              name: '电压合格率',
              max: 20,
            },
            {
              name: '负载率',
              max: 20,
            },
          ],
        },
        series: [
          {
            name: 'Title✍',
            type: 'radar',
            symbolSize: 12,
            itemStyle: {
              borderColor: '#ebebeb',
              borderWidth: 2,
            },
            areaStyle: {
              opacity: 0.3,
            },
            data: [
              {
                itemStyle: {
                  color: '#5eb6db',
                },
                value: [props.getTableData.vtBalunQ?20:0,props.getTableData.elBalunQ?20:0, props.getTableData.cosQ?20:0, props.getTableData.uq?20:0, props.getTableData.iloadQ?20:0],
              },
            ],
          },
        ],
      })
      window.addEventListener('resize', () => {
        myChart.resize()
      })

    }

    const writeValue = (val) => {
    
      val

      getData()
      echarts2()
    }

    //监听变化
    watch(
      () => props.getTableData,
      (newVal, oldVal, clear) => {
        // 执行异步任务，并得到关闭异步任务的 id
        // console.log(newVal)
        let id = writeValue(newVal, oldVal)
        // 如果 watch 监听被重复执行了，则会先清除上次未完成的异步任务
        clear(() => clearTimeout(id))
      },
      { lazy: true }
    )

    onMounted(() => {
      getData()
      echarts2()

     
    })

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