<template>
  <div
    id="semif"
    :style="`width:100%;height:${h};`"
    ref="fg"
    v-loading="isLoading"
  ></div>
</template>

<script>
import { getEventFeatureAmplitudeCurve } from "@/api/Statistical-analysis/transientIndicators/transientIndicators";
export default {
    props:{
        form:{
            type:Object,
            default:undefined
        },
        
    },
  data() {
    return {
      device: null,
      zoom: undefined, //图表焦点校验
      h: null,
      isLoading: false,
      //ITIC模拟数据
      datalist: [
        // {
        //   timeid: null,
        //   ms: 0,
        //   describe: null,
        //   wavetype: null,
        //   persisttime: 0.07,
        //   eventvalue: 56.0,
        //   persisttimea: 0.0,
        //   eventvaluea: 0.0,
        //   persisttimeb: 0.0,
        //   eventvalueb: 0.0,
        //   persisttimec: 0.0,
        //   eventvaluec: 0.0,
        //   state: null,
        //   time: "2022-02-20 14:17:34.944",
        //   severity: 0.887,
        //   eventDetailIndex: "a90e7821-acc3-4d53-80f0-49838e8662e6",
        //   lineId: 1641,
        //   eventassIndex: null,
        //   lineName: "电源总进线1",
        //   gdName: "常熟市",
        //   subName: "常熟森泉印染厂_6600087524",
        //   scale: "10kV",
        //   loadType: null,
        //   eventName: null,
        //   fileFlag: "0",
        //   type: "暂降",
        //   eventReason: "其他",
        //   eventType: "其他",
        // },
        // {
        //   timeid: null,
        //   ms: 0,
        //   describe: null,
        //   wavetype: null,
        //   persisttime: 0.075,
        //   eventvalue: 73.0,
        //   persisttimea: 0.0,
        //   eventvaluea: 0.0,
        //   persisttimeb: 0.0,
        //   eventvalueb: 0.0,
        //   persisttimec: 0.0,
        //   eventvaluec: 0.0,
        //   state: null,
        //   time: "2022-02-20 14:17:32.782",
        //   severity: 0.536,
        //   eventDetailIndex: "6578ad55-baaf-4503-988a-4ae9e663b466",
        //   lineId: 1641,
        //   eventassIndex: null,
        //   lineName: "电源总进线1",
        //   gdName: "常熟市",
        //   subName: "常熟森泉印染厂_6600087524",
        //   scale: "10kV",
        //   loadType: null,
        //   eventName: null,
        //   fileFlag: "1",
        //   type: "暂降",
        //   eventReason: "其他",
        //   eventType: "其他",
        // },
      ],
      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.zoom = window.devicePixelRatio;
    if (this.zoom == 1) {
      let heightd = document.getElementById("app-main-in").offsetHeight - 125;
      this.h = heightd / 2 + "px";
    }
    if (this.zoom == 1.25) {
      let heightd = document.getElementById("app-main-in").offsetHeight - 320;
      this.h = heightd / 2 + "px";
    }
    this.$nextTick(() => {
      this.semif();
    });

    //   console.log(this.time[0],'1234567');
  },
  updated() {},
  methods: {
    //公共的方法
    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 semif() {
      this.isLoading= true; 
      const data = await getEventFeatureAmplitudeCurve(this.form)
      // console.log(data);
      this.datalist = data.data.eventFeatureAmplitudeCurveDataList;
      this.gongfunction();
      let white = "#000";
      const echarts = require("echarts");
      let domID1 = document.getElementById("semif");
      let myChartes = echarts.init(domID1);
      this.isLoading = false;
      let option = {
        backgroundColor: "#f9f9f9", //地图背景色深蓝
        title: {
          text: "F47曲线",
          x: "center",
        },
        grid: {
          top: "30%",
          left: "4%",
          right: "5%",
          bottom: "2%",
          containLabel: 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] +
              "s</font><br/>";
            relVal +=
              "<font style='color:" +
              white +
              "'>特征幅值:" +
              "&nbsp" +
              "&nbsp" +
              a.value[1] +
              "%</font>";
            return relVal;
          },
        },
        toolbox: {
          show: true,
          feature: {
            saveAsImage: { show: true },
          },
        },
        legend: {
          data: ["分割线", "可容忍事件", "不可容忍事件"],
          //   selectedMode: false,
          x: "left",
        },
        color: ["yellow", "green", "red"],
        xAxis: [
          {
            type: "log",
            min: "0.001",
            max: "1000",
            splitLine: {
              show: false,
            },
            name: "s",
          },
        ],
        yAxis: [
          {
            type: "value",
            max: function (value) {
              return value.max + 20;
            },
            splitNumber: 10,
            minInterval: 0.1,
            name: "%",
          },
        ],
        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,
          },
        ],
      };
      let pointFData=this.pointF
      let pointFunData=this.pointFun
      this.$emit('transfer-data', data,pointFData,pointFunData)

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

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