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

<script>
import {
  coverageRateView1,
  coverageRateView2,
  coverageRateView3,
  coverageRateView4
} from '@/api/allApi/index.js'
import * as echarts from 'echarts'
export default {
  name: 'PostCheckWebTopLeftOneChart',
  props: {
    type: {
      type: Number,
      default: 1
    },
    queryParams: {
      type: Object,
      default: {}
    },
    selType:{
      type: Number,
      default: 1
    }
  },
  data() {
    return {
      dataObj :{}
    }
  },

  mounted() {
    this.initList()
  },

  methods: {
    async initList() {
      this.queryParams.selType = this.selType
      if (this.type == 1) {
        const res = await coverageRateView1(this.queryParams)
        if (res.code !== 200) return this.$message.error(res.msg)
        console.log(res.data);
        this.dataObj = res.data
      }
      if (this.type == 2) {
        const res = await coverageRateView2(this.queryParams)
        if (res.code !== 200) return this.$message.error(res.msg)
        this.dataObj = res.data
      }
      setTimeout(() => {
        this.initTopLeftOneChart()
      }, 100)
    },
    initTopLeftOneChart() {
      const option = {
        tooltip: {
          trigger: 'item'
        },
        legend: {
          top: '5%',
          left: 'center'
        },
        series: [
          {
            type: 'pie',
            avoidLabelOverlap: false,
            radius: '65%',
            label: {
              show: false,
              position: 'center',
              normal: {
                formatter: '{b}：{d}%',
                position: 'inner'
              }
            },
            emphasis: {
              label: {
                show: true,
                fontSize: 15,
                fontWeight: 'bold'
              }
            },
            labelLine: {
              show: false
            },
            data: [
              { value: this.dataObj.mantotal, name: '总人数' },
              { value: this.dataObj.cmantotal, name: '检查人数' }
            ]
          }
        ]
      }
      const topLeftOneChart = echarts.init(
        document.getElementById('topLeftOneChart')
      ) // 图标初始化
      topLeftOneChart.setOption(option) // 渲染页面
      // 随着屏幕大小调节图表
      window.addEventListener('resize', () => {
        topLeftOneChart.resize()
      })
    }
  }
}
</script>

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