<template>
  <div shadow="never" class="homeBoxCard" v-loading="loading">
    <div :style="'height:' + Height" id="worksChartRef" ref="worksChartRef" />
  </div>
</template>
<script>
import { computed, defineComponent, onMounted, ref } from 'vue'
import { useStore } from 'vuex'
import * as echarts from 'echarts'
// import { ChartDataType } from "../../data";

export default defineComponent({
  name: 'CurveCom',
  props: {
    Height: String,
  },
  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('worksChartRef'))
      // 绘制图表
      myChart.setOption({
        tooltip: {
          trigger: 'axis',
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '5%',
          containLabel: true,
        },
        legend: {
          data: ['(kw)'],
          bottom: '5',
        },
        toolbox: {
          show: true,
          feature: {
            // dataView: { show: true, readOnly: false },
            // magicType: { show: true, type: ["line", "bar"] },
            // restore: { show: true },
            saveAsImage: { show: true, color: 'black' },
          },
          iconStyle: {
            borderColor: '#666',
          },
        },
        xAxis: [
          {
            type: 'category',
            data: [
              '5-01',
              '5-02',
              '5-03',
              '5-04',
              '5-05',
              '5-06',
              '5-07',
              '5-08',
              '5-09',
              '5-10',
              '5-11',
              '5-12',
              '5-13',
              '5-14',
              '5-15',
              '5-16',
              '5-17',
              '5-18',
              '5-19',
              '5-20',
              '5-21',
              '5-22',
              '5-23',
              '5-24',
              '5-25',
              '5-26',
              '5-27',
              '5-28',
              '5-29',
              '5-30',
              '5-31',
            ],
            boundaryGap: true,
            axisTick: {
              show: false, //去除刻度线
            },
            axisLabel: {
              color: 'black', // 文本颜色
            },
            axisLine: {
              show: true, // 去除轴线
            },
          },
        ],
        yAxis: [
          {
            name: 'kw',
            type: 'value',
            nameTextStyle: {
              color: 'black',
              fontSize: 10,
            },
            axisTick: {
              show: true, //去除刻度线
            },
            axisLabel: {
              color: 'black', // 文本颜色
            },
            axisLine: {
              show: true, // 去除轴线
              lineStyle: {
                color: 'black',
              },
            },
            splitNumber: 5,
            splitLine: {
              show: false,
              lineStyle: {
                color: '#9d9d9d',
              },
            },
          },
        ],
        series: [
          {
            name: '(kw)',
            type: 'bar',
            data: [
              2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4,
              3.3, 2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0,
              6.4, 3.3, 2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6,
              20.0,
            ],
            markPoint: {
              data: [
                { type: 'max', name: 'Max' },
                // { type: "min", name: "Min" },
              ],
            },
          },
        ],
      })
      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;
  }
}
</style>