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

<script>
import * as echarts from 'echarts'

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

  mounted() {
    this.initList()
  },

  methods: {
    async initList() {
      if (this.type == 3) {
        const res = await problemCategoryViewSC(this.queryParams)
        if (res.code !== 200) return this.$message.error(res.msg)
        this.problemList = [
          res.data.problemCategoryOneRate * 100,
          res.data.problemCategoryTwoRate * 100,
          res.data.problemCategoryThreeRate * 100,
          res.data.problemCategoryFourRate * 100,
          res.data.problemCategoryFiveRate * 100,
          res.data.problemCategorySixRate * 100
        ]
      } else {
        const res = await problemCategoryViewZN(this.queryParams)
        if (res.code !== 200) return this.$message.error(res.msg)
        this.problemList = [
          res.data.problemCategoryOneRate * 100,
          res.data.problemCategoryTwoRate * 100,
          res.data.problemCategoryThreeRate * 100,
          res.data.problemCategoryFourRate * 100,
          res.data.problemCategoryFiveRate * 100,
          res.data.problemCategorySixRate * 100
        ]
      }
      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.problemList,
            type: 'bar',
            barWidth: '40%',
            //格式话label显示
            label: {
              show: true,
              position: 'top', // 顶部显示
              formatter: '{c}%'
            }
          }
        ]
      }
      const leftCenterZhu = echarts.init(
        document.getElementById('leftCenterZhu')
      ) // 图标初始化
      leftCenterZhu.setOption(option) // 渲染页面
      // 随着屏幕大小调节图表
      window.addEventListener('resize', () => {
        leftCenterZhu.resize()
      })
    }
  }
}
</script>