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

<script>
import { problemLevelView3, problemLevelView4 } from '@/api/allApi/index.js'
import * as echarts from 'echarts'
export default {
  name: 'PostCheckWebTopRigthChart',
  props: {
    type: {
      type: Number,
      default: 1
    },
    queryParams: {
      type: Object,
      default: {}
    }
  },
  data() {
    return {
      dataList: []
    }
  },

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

  methods: {
    async initList() {
      this.dataList = []
      if (this.type == 3) {
        const res = await problemLevelView3(this.queryParams)
        if (res.code !== 200) return this.$message.error(res.msg)
        this.dataList = [
          res.data.problemLeveOneRate * 100,
          res.data.problemLeveTwoRate * 100
        ]
      } else {
        const res = await problemLevelView4(this.queryParams)
        if (res.code !== 200) return this.$message.error(res.msg)

        this.dataList = [
          res.data.problemLeveOneRate * 100,
          res.data.problemLeveTwoRate * 100
        ]
      }
      this.dataList = JSON.parse(JSON.stringify(this.dataList))
      setTimeout(() => {
        this.initTopLeftChartEcharts()
      }, 100)
    },
    initTopLeftChartEcharts() {
      const option = {
        title: {
          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.dataList,
            type: 'bar',
            barWidth: '25%',
            //格式话label显示
            label: {
              show: true,
              position: 'top', // 顶部显示
              formatter: '{c}%'
            }
          }
        ]
      }
      const twoTopRightZhu = echarts.init(
        document.getElementById('twoTopRightZhu')
      ) // 图标初始化
      twoTopRightZhu.setOption(option) // 渲染页面
      // 随着屏幕大小调节图表
      window.addEventListener('resize', () => {
        twoTopRightZhu.resize()
      })
    }
  }
}
</script>

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