<template>
  <div class="app-container-Ylrq">
    <div id="YlrqChart" :style="{height:height,width:width}"></div>
  </div>
</template>

<script>
import {devYlrqSafeData} from "@/api/sems/home";

export default {
  props: {
    width: {
      type: String,
      default: '200px'
    },
    height: {
      type: String,
      default: '2.2rem'
    },
  },
  data() {
    return {
      chart: null,
      ylrqSafeOption:  {
        title: {
          text: this.$t('压力容器安全状况等级'),
          left: 'center',
          textStyle: {
            fontSize: 10,
          }
        },
        tooltip: {
          trigger: 'item'
        },
        series: [
          {
            name: this.$t('安全等级'),
            type: 'pie',
            radius: '50%',
            data: [
              {value: 1048, name: '1'},
              {value: 735, name: '2'},
              {value: 580, name: '3'},
              {value: 580, name: '4'},
              {value: 580, name: '5'},
              {value: 580, name: 'N/A'},
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      }
    }
  },
  mounted() {
    // 基于准备好的dom，初始化echarts实例
    this.chart = this.echarts.init(document.getElementById('YlrqChart'))
  },
  methods: {
    nowSize(val){
      //当前视口宽度
      let nowClientWidth = document.documentElement.clientWidth;
      //换算方法
      return val * (nowClientWidth/1920);
    },
    initChart() {
      this.ylrqSafeOption.title.textStyle.fontSize = this.nowSize(14)
      this.chart.clear()
      this.chart.setOption(this.ylrqSafeOption)
      window.addEventListener('resize', () => {
        this.chart.resize()
      })
    },
    devYlrqSafeData(plantIds ,unitIds){
      let params = {
        'plantIds': plantIds,
        'unitIds': unitIds
      }
      devYlrqSafeData(params).then(response => {
        this.ylrqSafeOption.series[0].data[0].value =  response.data.safeData[0]
        this.ylrqSafeOption.series[0].data[1].value=  response.data.safeData[1]
        this.ylrqSafeOption.series[0].data[2].value=  response.data.safeData[2]
        this.ylrqSafeOption.series[0].data[3].value=  response.data.safeData[3]
        this.ylrqSafeOption.series[0].data[4].value=  response.data.safeData[4]
        this.ylrqSafeOption.series[0].data[5].value=  response.data.safeData[5]
        this.initChart()
      });
    }
  }
}
</script>
