<template>
  <div ref="areahot" id="hotEcharts" style="width: 100%;"></div>
</template>
<script>
import { Integrity1, Integrity2, Integrity3 } from "@/assets/commjs/color";
import { dicData } from "@/assets/commjs/dictypeData";
import { getEventHeatMap } from "@/api/sagSeverity.js";
import yan from "@/assets/commjs/color";
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.areahot.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("areahottu").style.height;
          let strsec = str.split("p");
          let height = parseInt(strsec) - 50 + "px";
          this.$refs.areahot.style.height = height;
        }, 200);
      } else {
        return;
      }
    },
  },
  data() {
    return {
        classificationData: [],
      allData: [],
      time: this.timefamt(),
      formData1: {
        deptIndex: JSON.parse(window.sessionStorage.getItem("Info")).deptId,
        lineGrade: null,
        loadType: null,
        manufacturer: null,
        monitorFlag: 2,
        powerFlag: 1,
        reportFlag: 3,
        scale: null,
        searchBeginTime: "",
        searchEndTime: "",
        serverName: "",
        statFlag: true,
        statisticalType: "",
        timeFlag: 0,
      },
    };
  },
  created() {
    this.getclassificationData();
    this.queryData();
  },
  mounted() {
    setTimeout(() => {
      let str = document.getElementById("areahottu").style.height;
      let strsec = str.split("p");
      let height = parseInt(strsec) - 50 + "px";
      this.$refs.areahot.style.height = height;
    }, 200);
  },
  methods: {
    //获取统计类型
    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];
      getEventHeatMap(this.formData1).then((res) => {
        this.allData = res.data.areaValue;
        this.qualifiedechart();
      });
    },
    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;
    },
    qualifiedechart() {
      let echartsColor = JSON.parse(window.localStorage.echartsColor);
      let xdata = [];
      let xVal = [];
      this.allData.forEach((item) => {
        xdata.push(item.name);
        xVal.push(item.count);
      });
      const echarts = require("echarts");
      var myChartes = echarts.init(document.getElementById("hotEcharts"));
      myChartes.clear();
      //let echartsColor = JSON.parse(window.localStorage.echartsColor);
      let option = {
        title: {
          text: "区域监测点次数",
          left: "center",
          textStyle: {
            fontWeight: "400",
            color: "#fff",
            fontSize: 16,
          },
        },
        legend: {
          data: ["暂降次数"],
          // top: "10%",
          right: "5%",
          textStyle: {
            color: "#fff",
          },
        },
        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,
          formatter: function (params) {
            var tips = "";
            tips += params[0].name + "</br/>";
            for (var i = 0; i < params.length; i++) {
              if (params[i].value == 3.141592) {
                tips += params[i].seriesName + ":暂无数据<br/>";
              } else {
                tips += params[i].seriesName + ":" + params[i].value + "<br/>";
              }
            }
            return tips;
          },
        },
        grid: yan.EchartObject.gridf,
        color: echartsColor.FigureColor,
        xAxis: {
          type: "category",
          name:yan.EchartObject.area,
          axisLine: {
              show: true,
              lineStyle: {
              color: "#fff",
            },
              symbol: ["none", "arrow"],
            },
          axisLabel: {
            textStyle: {
              fontFamily:yan.EchartObject.fontFamily,
              color: "#fff",
              fontSize:yan.EchartObject.xNamefontSize
            },
          },
          axisTick: {
            alignWithLabel: true,
          },
          data: xdata,
        },
        dataZoom: yan.EchartObject.dataZoom,
        yAxis: {
          type: "value",
          name: yan.EchartObject.monitoring,
          minInterval: 20,
          axisLabel: {
            textStyle: {
                fontFamily:yan.EchartObject.fontFamily,
                color: "#fff",
                fontSize:yan.EchartObject.xNamefontSize
                //fontSize:10
              },
          },
          axisTick: {
            show: false,
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: "#fff",
            },
          },
          splitLine: {
            lineStyle: {
              // 使用深浅的间隔色
              color: "#fff",
              type: "dashed",
              opacity: 0.5,
            },
          },
        },
        series: [
          {
            name: "暂降次数",
            data: xVal,
            barMaxWidth:  yan.EchartObject.barMaxWidth,
            type: "bar",
            itemStyle: {
              normal: {
                color: function (params) {
                  if (params.value == 3.141592) {
                    return new echarts.graphic.LinearGradient(
                      0,
                      1,
                      0,
                      0,
                      [
                        {
                          offset: 1,
                          color: "#999999",
                        },
                      ],
                      false
                    );
                  } else {
                    return new echarts.graphic.LinearGradient(
                      0,
                      1,
                      0,
                      0,
                      [
                        {
                          offset: 1,
                          color: echartsColor.FigureColor[0], // 0% 处的颜色
                        },
                      ],
                      false
                    );
                  }
                },
              },
            },
          },
        ],
      };
      myChartes.setOption(option)
window.echartsArr.push(myChartes);
      setTimeout(() => {
        myChartes.resize();
      }, 100);
      this.loadingd = false;
      let _this = this;
      _this.$erd.listenTo(_this.$refs.areahot, (element) => {
        _this.$nextTick(() => {
          myChartes.resize();
        });
      });
      window.onresize = function () {
        myChartes.resize();
      };
    },
  },
};
</script>
