<template>
  <div style="width: 100%; height: 100%">
    <div
      id="leftChart"
      class="echart"
      :style="{
        width: '98%',
        height: '100%'
      }"
    />
  </div>
</template>

<script>
import * as echarts from 'echarts'
import { checkedProblem } from '@/api/allApi/index.js'
export default {
  name: 'PostCheckWebLeftBottom',

  data() {
    return {
      data: []
    }
  },

  mounted() {
    this.initTotalView()
    setTimeout(() => {
      this.initLeftEcharts()
    }, 100)
  },
  methods: {
    async initTotalView() {
      const res = await checkedProblem()
      if (res.code !== 200) return this.$message.error(res.msg)
      this.data = [
        res.data.problemComplete,
        res.data.problemEffective,
        res.data.problemSuitable,
        res.data.problemTotal
      ]

      localStorage.setItem('newVal', JSON.stringify(this.data));
    },
    initLeftEcharts() {
      const option = {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            type: 'category',
            data: ['完整性', '有效性', '适宜性', '总数量'],
            axisTick: {
              alignWithLabel: true
            }
          }
        ],
        yAxis: [
          {
            name: '问题',
            type: 'value'
          }
        ],
        textStyle: {
          color: '#000' //将文本颜色设为红色
        },
        series: [
          {
            type: 'bar',
            barWidth: '20%',
            color: '#1352b6',
            data:JSON.parse(localStorage.getItem('newVal'))
          }
        ]
      }
      const leftChart = echarts.init(document.getElementById('leftChart')) // 图标初始化
      leftChart.setOption(option) // 渲染页面
      // 随着屏幕大小调节图表
      window.addEventListener('resize', () => {
        leftChart.resize()
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>