<template>
  <div ref="glfb" id="eventChance2" style="width: 100%;"></div>
</template>
<script>
import {
  onLienRate1,
  onLienRate2,
  onLienRate3,
  colorB,
} from "@/assets/commjs/color";
import { dicData } from "@/assets/commjs/dictypeData";
import yan from "@/assets/commjs/color";
import { getProbabilityDistribution } from "@/api/monitoringpointStatistics/echart";
//import {getPwDurationLineChart} from "@/api/Distributionnetwork/transient/transient";
export default {
  props: {
    item: {
      type: Object,
      default: null,
    },
    item2: {
      type: Object,
      default: null,
    },
  },
  watch: {
    height2(a, b) {
      if (a == 24) {
        this.$refs.glfb.style.height =  document.getElementById('conmentId').offsetHeight -50 + 'px';

      } else {
        return;
      }
    },
    height(a, b) {
      if (a == 6 || a==8 || a==9 || a==16) {
        setTimeout(()=>{
        let str = document.getElementById('overviewdistrib').style.height
        let strsec = str.split('p')
        let height = parseInt(strsec) - 50 +'px'
        this.$refs.glfb.style.height =  height
        },200)
      } else {
        return;
      }
    },
  },
  data() {
    return {
      tableData: [],
      statisticalType: null,
      classificationData: [],
      time: this.timefamt(),
      //暂降类型模拟数据
      eventList: {},
      dataListX:[],
      dataListY:[]
    };
  },
  created() {
    var data = window.sessionStorage.getItem("Info");
    data = eval("(" + data + ")");
    this.deptIndex = data.deptId;
    this.getIndexType();
    this.queryData();
  },
  mounted() {
    setTimeout(()=>{
    let str = document.getElementById('overviewdistrib').style.height
    let strsec = str.split('p')
    let height = parseInt(strsec) - 50 +'px'
     this.$refs.glfb.style.height =  height
    },200)
  },
  methods: {
    queryData() {
      var info = window.sessionStorage.getItem("Info");
        info = eval("(" + info + ")"); 
        var  id =info.deptId;
      var formData = {
        endTime: this.time[0],
        lineIndex: "d14b23ad514bc8db840ab29a29573ce5",
        startTime: this.time[1],
      };
      getProbabilityDistribution(formData).then((res) => {
        this.eventList = res.data;
      //  this.dataListX=[]
      //   this.dataListY=[]
      //   res.data.forEach(item => {
      //   this.dataListX.push(item.name)
      //   this.dataListY.push(item.value)
      // });
      this.eventChance();
      });
    },

    getIndexType() {
      var code = "Indicator_Type";
      this.classificationData = dicData(code, [
        "PLPC",
        "DYPC",
        "SXDYBPHD",
        "CSSB",
        "FXDL",
        "JXBDY",
      ]);
      this.statisticalType = this.classificationData[0];
    },
    timefamt() {
      var date = new Date();
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var day = date.getDate();
      month = month > 9 ? month : "0" + month;
      day = day < 10 ? "0" + day : day;
      var arr = [];
      var today = year + "-" + month + "-" + day;
      var today2 = year + "-01-01";
      arr.push(today);
      arr.push(today2);
      return arr;
    },
    eventChance() {
      var eventValue = this.eventList.eventvalue;
      var pereventValue = this.eventList.pereventvalue;
      const echarts = require("echarts");
      var myChartes = echarts.init(document.getElementById("eventChance2"));
      let echartsColor = JSON.parse(window.localStorage.echartsColor);
      myChartes.clear();
      var option = {
       // backgroundColor: "#fff", //背景色,
        title: {
          text: "暂降幅值的概率分布函数",
          x: "center",
          textStyle: {
            color:'#fff',
            fontSize: yan.EchartObject.titleNamefontSize1,
          },
        },
        legend: {
          show: true,
          right: 10,
          data: ["概率分布", "占比"],

          textStyle: {
            color: '#fff',
            rich: {
              a: {
                verticalAlign: "middle",
              },
            },

            padding: [2, 0, 0, 0], //[上、右、下、左]
          },
        },

        tooltip: {
          //提示框组件
          trigger: "axis",

          axisPointer: {
            type: "shadow",
            label: {
              color: "#fff",
              fontSize: 16,
            },
          },
          textStyle: {
            color: "#fff",
            fontStyle: "normal",
            opacity: 0.35,
            fontSize: 14,
          },
          backgroundColor: "rgba(0,0,0,0.35)",
          borderWidth: 0,
        },
        calculable: true,
        grid: yan.EchartObject.grid111,
        xAxis: [
          {
            type: "category",
            name: "暂降幅值",
            nameGap: 10,
            nameTextStyle: {
              fontSize: 12,
            },
            axisLine: {
              lineStyle: {
                color: '#fff',
              },
            },
            axisLabel: {
             textStyle: {
                fontFamily: yan.EchartObject.fontFamily,
                color: '#fff',
                fontSize:yan.EchartObject.xNamefontSize
              },
            },
            data: [
              "0",
              "10%",
              "20%",
              "30%",
              "40%",
              "50%",
              "60%",
              "70%",
              "80%",
              "90%",
              "100%",
            ],
          },
        ],
        yAxis: [
          {
            type: "value",
            name: "概率分布",
            nameTextStyle: {
              fontSize: 15,
            },
            axisLabel: {
              color: '#fff',
              formatter: "{value}%",
               fontSize: yan.EchartObject.yNamefontSize,
            },
            nameTextStyle: {
              color: '#fff',
            },

            axisLine: {
              show: true,
              lineStyle: {
                color: '#fff',
              },
            },

            splitLine: {
              lineStyle: {
                // 使用深浅的间隔色
                color: '#fff',
                type: "dashed",
                opacity: 0.5,
              },
            },
          },
          {
            type: "value",
            name: "占比",

            nameTextStyle: {
              fontSize: 15,
            },
            axisLabel: {
              formatter: "{value}%",
              color: '#fff',
                fontSize: yan.EchartObject.yNamefontSize,
            },
            nameTextStyle: {
              color: '#fff',
            },

            axisLine: {
              show: true,
              lineStyle: {
                color: '#fff',
              },
            },

            splitLine: {
              lineStyle: {
                // 使用深浅的间隔色
                color: [echartsColor.thread],
                type: "dashed",
                opacity: 0.5,
              },
            },
          },
        ],
        series: [
          {
            name: "概率分布",
            type: "line",
            data: eventValue,
            itemStyle: {
              normal: { show: true, color: echartsColor.FigureColor[0] },
            },
          },
          {
            name: "占比",
            type: "bar",
            data: pereventValue,
            barWidth: 30,
            itemStyle: {
              normal: { show: true, color: echartsColor.FigureColor[1] },
            },
          },
        ],
      };

      myChartes.setOption(option)
window.echartsArr.push(myChartes);
      setTimeout(() => {
        myChartes.resize();
      }, 100);
      this.loadingd = false;
      let _this = this;
      _this.$erd.listenTo(_this.$refs.glfb, (element) => {
        _this.$nextTick(() => {
          myChartes.resize();
        });
      });
      window.onresize = function () {
        myChartes.resize();
      };
    },
  },
};
</script>
