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

<script>
import * as echarts from 'echarts'

import {
  problemAttributeViewSC,
  problemAttributeViewZN
} from '@/api/allApi/index.js'
export default {
  name: 'PostCheckWebLeftZhu',
  props: {
    type: {
      type: Number,
      default: 3
    },
    queryParams: {
      type: Object,
      default: {}
    }
  },
  data() {
    return {
      problemList: []
    }
  },

  mounted() {
    this.$nextTick(() => {
      this.initList()
    })
  },

  methods: {
    async initList() {
      if (this.type == 3) {
        const res = await problemAttributeViewSC(this.queryParams)
        if (res.code !== 200) return this.$message.error(res.msg)
        this.problemList = [
          res.data.problemCompleteRate * 100,
          res.data.problemSuitableRate * 100,
          res.data.problemEffectiveRate * 100
        ]
      } else {
        const res = await problemAttributeViewZN(this.queryParams)
        if (res.code !== 200) return this.$message.error(res.msg)
        this.problemList = [
          res.data.problemCompleteRate* 100,
          res.data.problemSuitableRate* 100,
          res.data.problemEffectiveRate* 100
        ]
      }
      setTimeout(() => {
        this.initTopLeftChartEcharts()
      }, 100)
    },
    initTopLeftChartEcharts() {
      const option = {
        title: {
          // text: '岗检问题级别占比',
          text: '岗检问题属性整改占比',
          left: 'center'
        },
        //格式化提示
        tooltip: {
          trigger: 'item',
          formatter: '{c}%'
        },
        legend: {
          top: '8%',
          left: 'center'
        },
        xAxis: {
          type: 'category',
          data: ['完整性', '适宜性', '有效性']
        },
        yAxis: {
          axisLabel: {
            formatter: '{value}%'
          },
          minInterval: 1
        },
        series: [
          {
            data: this.problemList,
            type: 'bar',
            barWidth: '25%',
            //格式话label显示
            label: {
              show: true,
              position: 'top', // 顶部显示
              formatter: '{c}%'
            }
          }
        ]
      }
      const leftLeftChart = echarts.init(
        document.getElementById('leftLeftChart')
      ) // 图标初始化
      leftLeftChart.setOption(option) // 渲染页面
      // 随着屏幕大小调节图表
      window.addEventListener('resize', () => {
        leftLeftChart.resize()
      })
    }
  }
}
</script>
