<template>
  <div ref="f47" id="f47emis" style="width: 100%;"></div>
</template>
<script>
import yan from "@/assets/commjs/color";
import { dicData } from "@/assets/commjs/dictypeData";
import { getVoltageToleranceCurve } from "@/api/monitoringpointStatistics/echart";
export default {
  props: {
    item: {
      type: Object,
      default: null,
    },
    item2: {
      type: Object,
      default: null,
    },
    height:{
      type:Number,
      default: null,
    },
    height2:{
      type:Number,
      default: null,
    }
  },
  watch: {
    height2(a, b) {
      if (a == 24) {
        this.$refs.f47.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('f47curveianalysisi').style.height
        let strsec = str.split('p')
        let height = parseInt(strsec) - 50 +'px'
        this.$refs.f47.style.height =  height
        },200)
      } else {
        return;
      }
    },
  },
  data() {
    return {
      tableData: [],
      statisticalType: null,
      classificationData: [],
      time: this.timefamt(),
      formData1:{
        statisticalType:null,
        scale:null,
        manufacturer:null,
        loadType:null,
        monitorFlag: 2,
        powerFlag: 2,
        timeFlag: 1,
        deptIndex:JSON.parse(window.sessionStorage.getItem('Info')).deptId    
      },
      voltageleveloption:[],
      terminaloption:[],
      interfereoption:[],
      classificationData:[],
      //ITIC模拟数据
      datalist: [],
      pointI: [],
      pointIun: [],
      pointF: [],
      pointFun: [],
      white: "#ffffff",
      top: [
        [0.001, 200],
        [0.003, 140],
        [0.003, 120],
        [0.5, 120],
        [0.5, 110],
        [10, 110],
        [1000, 110],
      ],
      bot: [
        [0.02, 0],
        [0.02, 70],
        [0.5, 70],
        [0.5, 80],
        [10, 80],
        [10, 90],
        [1000, 90],
      ],
      part: [
        [0.05, 0],
        [0.05, 50],
        [0.2, 50],
        [0.2, 70],
        [0.5, 70],
        [0.5, 80],
        [10, 80],
        [1000, 80],
      ],
    };
  },
  created() {
    this.getVoltage();
    this.getManufacturer();
    this.getclassificationData();
    this.getLoadType();
    this.queryData();
  },
  mounted() {
    setTimeout(()=>{
    let str = document.getElementById('f47curveianalysisi').style.height
    let strsec = str.split('p')
    let height = parseInt(strsec) - 50 +'px'
     this.$refs.f47.style.height =  height
    },200)
  },
  methods: {
    //字典获取数据电压等级
    getVoltage() {
      var code = "Dev_Voltage_Stand";
      this.voltageleveloption = dicData(code, []);
      this.formData1.scale = this.voltageleveloption;
    },
    //字典获取数据终端厂家
    getManufacturer() {
      var code = "Dev_Manufacturers";
      this.terminaloption = dicData(code, []);
      this.formData1.manufacturer = this.terminaloption;
    },
    //字典获取数据干扰源类型
    getLoadType() {
      var code = "Interference_Source";
      this.interfereoption = dicData(code, []);
      this.formData1.loadType = this.interfereoption;
    },
    //获取统计类型
    getclassificationData() {
      var code = "Statistical_Type";
      this.classificationData = dicData(code, ["Report_Type"]);
      this.formData1.statisticalType = this.classificationData[0];
    },
    queryData() {
      this.formData1.searchBeginTime=this.time[0]
      this.formData1.searchEndTime=this.time[1]
      getVoltageToleranceCurve(this.formData1).then((res) => {
        this.datalist = res.data.voltageToleranceCurveDataList;
        this.gongfunction();
        this.$nextTick(() => {
          this.f47emis();
        });
      });
    },
    //公共的方法
    gongfunction() {
      var standI = 0;
      var unstandI = 0;
      var standF = 0;
      var unstandF = 0;
      this.pointI = [];
      this.pointIun = [];
      this.pointF = [];
      this.pointFun = [];
      var total = 0;
      // console.log(this.datalist);
      total = this.datalist.length;
      if (total == 0) {
      } else {
        for (var i = 0; i < this.datalist.length; i++) {
          var point = [];
          var xx = this.datalist[i].persistTime;
          var yy = this.datalist[i].eventValue * 100;
          var time = this.datalist[i].time.replace("T", " ");
          var company = this.datalist[i].gdName;
          var substation = this.datalist[i].subName;
          var index = this.datalist[i].lineId;
          var eventId = this.datalist[i].eventId;

          point = [xx, yy, time, company, substation, index, eventId];

          if (xx <= 0.003) {
            var line = 0;
            line = 230 - 30000 * xx;
            if (yy > line) {
              unstandI++;
              this.pointIun.push({
                value: point,
                itemStyle: { normal: { color: "red" } },
              });
            } else {
              standI++;
              this.pointI.push({
                value: point,
                itemStyle: { normal: { color: "green" } },
              });
            }
          } else if (xx <= 0.02) {
            if (yy > 120) {
              unstandI++;
              this.pointIun.push({
                value: point,
                itemStyle: { normal: { color: "red" } },
              });
            } else {
              standI++;
              this.pointI.push({
                value: point,
                itemStyle: { normal: { color: "green" } },
              });
            }
          } else if (xx <= 0.5) {
            if (yy > 120 || yy < 70) {
              unstandI++;
              this.pointIun.push({
                value: point,
                itemStyle: { normal: { color: "red" } },
              });
            } else {
              standI++;
              this.pointI.push({
                value: point,
                itemStyle: { normal: { color: "green" } },
              });
            }
          } else if (xx <= 10) {
            if (yy > 110 || yy < 80) {
              unstandI++;
              this.pointIun.push({
                value: point,
                itemStyle: { normal: { color: "red" } },
              });
            } else {
              standI++;
              this.pointI.push({
                value: point,
                itemStyle: { normal: { color: "green" } },
              });
            }
          } else {
            if (yy > 110 || yy < 90) {
              unstandI++;
              this.pointIun.push({
                value: point,
                itemStyle: { normal: { color: "red" } },
              });
            } else {
              standI++;
              this.pointI.push({
                value: point,
                itemStyle: { normal: { color: "green" } },
              });
            }
          }

          if (xx < 0.05) {
            standF++;
            this.pointF.push({
              value: point,
              itemStyle: { normal: { color: "green" } },
            });
          } else if (xx < 0.2) {
            if (yy > 50) {
              standF++;
              this.pointF.push({
                value: point,
                itemStyle: { normal: { color: "green" } },
              });
            } else {
              unstandF++;
              this.pointFun.push({
                value: point,
                itemStyle: { normal: { color: "red" } },
              });
            }
          } else if (xx < 0.5) {
            if (yy > 70) {
              standF++;
              this.pointF.push({
                value: point,
                itemStyle: { normal: { color: "green" } },
              });
            } else {
              unstandF++;
              this.pointFun.push({
                value: point,
                itemStyle: { normal: { color: "red" } },
              });
            }
          } else {
            if (yy > 80) {
              standF++;
              this.pointF.push({
                value: point,
                itemStyle: { normal: { color: "green" } },
              });
            } else {
              unstandF++;
              this.pointFun.push({
                value: point,
                itemStyle: { normal: { color: "red" } },
              });
            }
          }
        }
      }
    },
    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 time1 = year + "-" + month + "-01";
      arr.push(time1);
      var time2 = year + "-" + month + "-" + day ;
      arr.push(time2);
      return arr;
    },
    f47emis() {
      const echarts = require("echarts");
      var myChartes = echarts.init(document.getElementById("f47emis"));
      myChartes.clear();
      let echartsColor = JSON.parse(window.localStorage.echartsColor);
      var option = {
        // backgroundColor: "#f9f9f9", //地图背景色深蓝
        title: {
          // text: "F47曲线",
          x: "center",
          textStyle: {
            fontSize: yan.EchartObject.titleNamefontSize1,
            color: echartsColor.WordColor,
          },
        },
        grid: yan.EchartObject.gridp,
       
        tooltip: {
          trigger: "item",
          show: true,
          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,
          formatter: function (a) {
            let relVal = "";
            relVal =
              "<font style='color:" +
              "'>供电公司:" +
              "&nbsp" +
              "&nbsp" +
              a.value[3] +
              "</font><br/>";
            relVal +=
              "<font style='color:" +
              "'>变电站:" +
              "&nbsp" +
              "&nbsp" +
              a.value[4] +
              "</font><br/>";
            relVal +=
              "<font style='color:" +
              "'>发生时刻:" +
              "&nbsp" +
              "&nbsp" +
              a.value[2] +
              "</font><br/>";
            relVal +=
              "<font style='color:" +
              "'>持续时间:" +
              "&nbsp" +
              "&nbsp" +
              a.value[0].toFixed(3) +
              "s</font><br/>";
            relVal +=
              "<font style='color:" +
              "'>特征幅值:" +
              "&nbsp" +
              "&nbsp" +
              a.value[1].toFixed(3) +
              "%</font>";
            return relVal;
          },
        },
        legend: {
          data: ["分割线", "可容忍事件", "不可容忍事件"],
          // selectedMode: false,
          right: "10px",
          textStyle: {
            color: '#fff',
          },
        },
        color: ["yellow", "green", "red"],
        xAxis: [
          {
            type: "log",
            min: "0.001",
            max: "1000",
            splitLine: {
              show: false,
              lineStyle: {
                color: '#fff',
              },
            },
            name: "s",
            axisLabel: {
              textStyle: {
                fontFamily: yan.EchartObject.fontFamily,
                color: '#fff',
                fontSize: yan.EchartObject.xNamefontSize,
              },
            },
           
            axisLine: {
              show: true,
              lineStyle: {
              color: "#fff",
            },
            },
          },
          
        ],
        yAxis: [
          {
            type: "value",
            splitNumber: 10,
            minInterval: 3,
            name: yan.EchartObject.nuit1,
            axisLine: {
              show: true,
              lineStyle: {
                color: '#fff',
              },
            },
            axisLabel: {
              color: '#fff',
              fontSize: yan.EchartObject.yNamefontSize,
            },
          },
        ],
        series: [
          {
            name: "分割线",
            type: "line",
            data: this.part,
            showSymbol: false,
            tooltips: {
              show: false,
            },
          },
          {
            name: "可容忍事件",
            type: "scatter",
            symbol: "circle",
            data: this.pointF,
          },
          {
            name: "不可容忍事件",
            type: "scatter",
            symbol: "circle",
            data: this.pointFun,
          },
        ],
      };
      myChartes.setOption(option)
window.echartsArr.push(myChartes);
      setTimeout(() => {
        myChartes.resize();
      }, 100);
      this.loadingd = false;
      let _this = this;
      _this.$erd.listenTo(_this.$refs.f47, (element) => {
        _this.$nextTick(() => {
          myChartes.resize();
        });
      });
      window.onresize = function () {
        myChartes.resize();
      };
    },
  },
};
</script>
