<template>
  <div
    id="itic"
    style="width: 100%; height: 100%;"

    ref="fg13"
    v-loading="isLoading"
  ></div>
</template>

<script>
import { getPwEventFeatureAmplitudeCurve } from "@/api/Distributionnetwork/transient/transient";
export default {
    props:{
        form:{
            type:Object,
            default:undefined
        },
        
    },
  data() {
    return {
      device: null,
      zoom: '', //图表焦点校验
      h: null,
      isLoading: false,
      //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() {},
  mounted() {
    this.setHeight()
        window.addEventListener('resize', this.setHeight)
    this.$nextTick(() => {
      this.iticData();
    });

    //   console.log(this.time[0],'1234567');
  },
  beforeDestroy() {
        window.removeEventListener('resize', this.setHeight)
    },
  methods: {
    setHeight() {
      let domID1 = document.getElementById("itic");
      setTimeout(()=>{
        domID1.style.width = window.sessionStorage.getItem('appwidth') - 40 +'px'
        domID1.style.height = (window.sessionStorage.getItem('appheight')- 180)/2 + 'px'
      },0)

    },
    //公共的方法
    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].duration / 1000;
          var yy = this.datalist[i].featureAmplitude;
          var time = this.datalist[i].startTime.replace("T", " ");
        //   var company = this.datalist[i].gdName;
        //   var substation = this.datalist[i].subName;
        //   var index = this.datalist[i].lineId;
          point = [xx, yy, time];

          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" } },
              });
            }
          }
        }
      }
    },
    //itic曲线图
    async iticData() {
      this.isLoading= true; 
      const data = await getPwEventFeatureAmplitudeCurve(this.form)
      // console.log(data);
      this.datalist = data.data.eventFeatureAmplitudeCurveDataList;
      this.gongfunction();
      let white = "#000";
      const echarts = require("echarts");
      let domID1 = document.getElementById("itic");
      setTimeout(()=>{
        domID1.style.width = window.sessionStorage.getItem('appwidth') - 40 +'px'
        domID1.style.height = (window.sessionStorage.getItem('appheight')- 180)/2 + 'px'
      },0)
      let myChartes = echarts.init(domID1);
      let echartsColor = JSON.parse(window.localStorage.echartsColor);
      this.isLoading = false;
      let option = {
       // backgroundColor: "#f9f9f9", //地图背景色深蓝
        title: {
          text: "ITIC曲线",
          x: "center",
          textStyle: {
              fontSize: 16,
              color: echartsColor.WordColor,
            },
        },
        grid: {
          top: "25%",
          left: "2%",
          right: "2%",
          bottom: "0%",
          containLabel: true,
        },
        toolbox: {
          show: true,
          feature: {
            saveAsImage: { show: true },
          },
        },
        tooltip: {
          trigger: "item",
          show: true,
          formatter: function (a) {
            // console.log(a);
            let relVal = "";
            // relVal =
            //   "<font style='color:" +
            //   white +
            //   "'>供电公司:" +
            //   "&nbsp" +
            //   "&nbsp" +
            //   a.value[3] +
            //   "</font><br/>";
            // relVal +=
            //   "<font style='color:" +
            //   white +
            //   "'>变电站:" +
            //   "&nbsp" +
            //   "&nbsp" +
            //   a.value[4] +
            //   "</font><br/>";
            relVal +=
              "<font style='color:" +
              white +
              "'>发生时刻:" +
              "&nbsp" +
              "&nbsp" +
              a.value[2] +
              "</font><br/>";
            relVal +=
              "<font style='color:" +
              white +
              "'>持续时间:" +
              "&nbsp" +
              "&nbsp" +
              (a.value[0]).toFixed(3) +
              "s</font><br/>";
            relVal +=
              "<font style='color:" +
              white +
              "'>特征幅值:" +
              "&nbsp" +
              "&nbsp" +
              a.value[1] +
              "%</font>";
            return relVal;
          },
          axisPointer: {
            type: "cross",
            label: {
              color: "#fff",
              fontSize: 16,
            },
          },
          textStyle: {
            color: "#fff",
            fontStyle: "normal",
            opacity: 0.35,
            fontSize: 14,
          },
          // backgroundColor: "rgba(0,0,0,0.35)",
          borderWidth: 0
        },
        legend: {
          data: ["上限", "下限", "可容忍事件", "不可容忍事件"],

          x: "1%",
          textStyle: {
            color: echartsColor.WordColor,
            rich: {
              a: {
                verticalAlign: "middle",
              },
            },

            padding: [2, 0, 0, 0], //[上、右、下、左]
          },
        },
        color: ["#FF8C00", "#00BFFF", "green", "red"],
        xAxis: [
          {
            type: "log",
            min: "0.001",
            max: "1000",
            splitLine: {
              show: false,
            },
            name: "s",
            nameTextStyle: {
            padding: 5,
            color:echartsColor.WordColor
          },
          axisLine: {
              lineStyle: {
                color: echartsColor.thread,
              },
            },
            axisLabel: {
              color: echartsColor.WordColor,
            },
          },
        ],
        yAxis: [
          {
            type: "value",
            splitNumber: 10,
            minInterval: 3,
            name: "%",
            nameTextStyle: {
              color: echartsColor.WordColor,
              padding: 0,
            },
              minInterval: 1,
              type: "value",
               axisLine: {
              show: true,
              lineStyle: {
                color: echartsColor.thread,
              },
              },
               axisLabel: {
              color: echartsColor.WordColor,
              },
            splitLine: {
              lineStyle: {
                // 使用深浅的间隔色
                color: [echartsColor.thread],
                type: "dashed",
                opacity: 0.5,
              },
            },
          },
        ],
        series: [
          {
            name: "上限",
            type: "line",
            data: this.top,
            showSymbol: false,
            tooltips: {
              show: false,
            },
          },
          {
            name: "下限",
            type: "line",
            data: this.bot,
            showSymbol: false,
            tooltips: {
              show: false,
            },
          },
          {
            name: "可容忍事件",
            type: "scatter",
            symbol: "circle",
            data: this.pointI,
          },
          {
            name: "不可容忍事件",
            type: "scatter",
            symbol: "circle",
            data: this.pointIun,
          },
        ],
      };
      let pointIData=this.pointI
      let pointIunData=this.pointIun
      this.$emit('transfer-data', data,pointIData,pointIunData)

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

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