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

export default defineComponent({
  name: 'LoopRadarChart',
  setup() {
    let lineChartBanlance = ref(null)

    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(lineChartBanlance.value)
      // 绘制图表
      myChart.setOption({
        backgroundColor: '#FFF',
        tooltip: {},
        grid: {
          left: '20',
          right: '40',
          top: '-20',
          bottom: '0',
          containLabel: true,
        },
        radar: {
          shape: 'circle',
          radius: '70%',
          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: 'Ua',
              max: 100,
            },
            {
              name: 'Ub',
              max: 100,
            },
            {
              name: 'Uc',
              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 {
      lineChartBanlance,
      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: 200px;
  }
}
</style>