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

const data = [
  {
    name: '本期',
    list: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    listDate: [
      '00:00:00',
      '02:00:00',
      '04:00:00',
      '06:00:00',
      '08:00:00',
      '10:00:00',
      '12:00:00',
      '14:00:00',
      '16:00:00',
      '18:00:00',
      '20:00:00',
      '22:00:00',
    ],
  },
  {
    name: '上期',
    list: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    listDate: [
      '00:00:00',
      '02:00:00',
      '04:00:00',
      '06:00:00',
      '08:00:00',
      '10:00:00',
      '12:00:00',
      '14:00:00',
      '16:00:00',
      '18:00:00',
      '20:00:00',
      '22:00:00',
    ],
  },
]

const dataAll = [
  {
    name: '本期',
    type: 'line',
    smooth: false,
    data: [0, 0.1, 0, 0, 0, 0, 0, 0, 0, 0.7, 0, 0],
    symbolSize: 6,
    markPoint: {
      data: [
        { type: 'max', name: 'Max' },
        { type: 'min', name: 'Min' },
      ],
    },
  },
  {
    name: '上期',
    type: 'line',
    smooth: false,
    data: [0, 0, 0.2, 0, 0, 0, 0, 0.8, 0, 0, 0, 0],
    symbolSize: 6,
    markPoint: {
      data: [
        { type: 'max', name: 'Max' },
        { type: 'min', name: 'Min' },
      ],
    },
  },
]

export default defineComponent({
  name: 'CurveCom',
  setup() {
    const store = useStore()
    const chainChartRef = ref(null)

    // 总数
    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(chainChartRef.value)
      // 绘制图表
      myChart.setOption({
        color: ['#FEB70D', '#50F335', '#0DC8FE'],
        title: {
          text: '同比分析',
          left: '2.5%',
          textStyle: {
            color: '#9d9d9d',
            fontSize: 14,
            fontWeight: 600,
          },
        },
        tooltip: {
          trigger: 'axis',
        },
        // 图列组件
        legend: {
          itemHeight: 10, //改变圆圈大小
          itemWidth: 26, //改变圆圈大小
          itemGap: 30,
          textStyle: {
            color: 'black',
          },

          left: 'center',
          // bottom: '0',
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '5%',
          containLabel: true,
        },
        xAxis: {
          type: 'category',
          boundaryGap: true,
          data: data[0].listDate.map((val) => {
            return val.split(':')[0] + ':' + val.split(':')[1]
          }),
          axisTick: {
            show: false, //去除刻度线
          },
          axisLabel: {
            color: 'black', // 文本颜色
          },
          axisLine: {
            show: false, // 去除轴线
          },
        },
        yAxis: {
          nameTextStyle: {
            color: 'black',
            fontSize: 10,
          },
          type: 'value',
          axisTick: {
            show: true, //去除刻度线
          },
          axisLabel: {
            color: 'black', // 文本颜色
          },
          axisLine: {
            show: true, // 去除轴线
            lineStyle: {
              color: 'black',
            },
          },
          splitNumber: 5,
          splitLine: {
            show: true,
            lineStyle: {
              color: '#9d9d9d',
            },
          },
        },
        series: dataAll,
      })
      window.onresize = function () {
        // 自适应大小
        myChart.resize()
      }
    })

    return {
      chainChartRef,
      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;
  }
  .height300 {
    height: 15rem;
  }
}
</style>