<template>
  <div style="padding: 0.5%">
    <el-row :gutter="10">
      <el-col :span="24">
        <timepicker
          :id="id"
          @querfromdata="querfromdata"
          :interval="interval"
          :treenode="treenode"
          :tablename="tablename"
          :name="name"
          :path="path"
          :dataTree="dataTree"
        ></timepicker>
      </el-col>
      <!-- <el-col :span="12">
                <el-button type="primary" style="float:right;margin-right:1%" @click="loadtype">空调策略</el-button>
           </el-col> -->
    </el-row>
    <el-row :gutter="10">
      <el-col :span="24">
        <div
          id="electri2"
          :style="
            'background:;width:100%;height:' + tableheight + 'px;'
          "
        ></div>
      </el-col>
      <!-- <div id="electri2" :style="'background:;width:100%;height:'+(tableheight/2)+'px;zoom:'+(device)"></div>
               </el-col>
               <el-col :span="12">
                <div id="electri3" :style="'background:;width:100%;height:'+(tableheight/2)+'px;zoom:'+(device)"></div>
               </el-col>
               <el-col :span="12">
                <div id="electri4" :style="'background:;width:100%;height:'+(tableheight/2)+'px;zoom:'+(device)"></div>
               </el-col>
               <el-col :span="12">
                <div id="electri5" :style="'background:;width:100%;height:'+(tableheight/2)+'px;zoom:'+(device)"></div>
               </el-col> -->
    </el-row>

    <!--指标策略-->
    <el-dialog
      :close-on-click-modal="false"
      title="指标策略"
      :visible.sync="dialogVisible"
      width="20%"
      :before-close="handleClose"
    >
      <span class="spantext">请勾选需要参与统计的指标:</span>
      <div class="border">
        <el-checkbox-group v-model="checkList" style="padding: 2%">
          <el-checkbox label="三相有功功率" class="check"></el-checkbox>
          <el-checkbox label="三相无功功率" class="check"></el-checkbox>
          <el-checkbox label="三相净有功电能" class="check"></el-checkbox>
          <el-checkbox label="电流总有效值" class="check"> </el-checkbox>
          <el-checkbox label="电压基波幅值" class="check"></el-checkbox>
          <el-checkbox label="电流基波幅值" class="check"></el-checkbox>
          <el-checkbox label="总有有功功率" class="check"></el-checkbox>
        </el-checkbox-group>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >保 存</el-button
        >
      </span>
    </el-dialog>
    <!--负荷策略-->
    <el-dialog
      :close-on-click-modal="false"
      title="负荷策略"
      :visible.sync="dialogVisible2"
      width="30%"
      :before-close="handleClose"
    >
      <span class="spantext">负荷设备树:</span>
      <el-row class="border2">
        <el-col :span="10">
          <el-tree
            :data="treedata"
            :props="defaultProps"
            default-expand-all
            style="height: 30vh; overflow-y: auto"
            :highlight-current="true"
            @node-click="handleNodeClick"
          ></el-tree>
        </el-col>
        <el-col :span="14">
          <el-form
            ref="form"
            :model="form"
            label-width="80px"
            style="margin-top: 20%"
          >
            <el-form-item label="空调名称">
              <el-input
                v-model="form.name"
                placeholder="请输入负荷名称"
                style="width: 86%"
              ></el-input>
            </el-form-item>
            <el-form-item label="负荷终端">
              <el-select v-model="form.region" placeholder="请选择负荷终端">
                <el-option label="2号楼217宿舍" value="shanghai"></el-option>
                <el-option label="号楼218宿舍" value="beijing"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item style="margin-left: 10%">
              <el-button type="primary">删除</el-button>
              <el-button type="primary">新增</el-button>
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible2 = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible2 = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
import ElInputGroup from "@/components/ElInputGroup/el-input-group.vue";
import { getappheight, getheight } from "../../../assets/commjs/common";
import api from "@/api/energy/sysconfig";
import timepicker from "../../components/TimePicker/index4";
import echarts from "echarts";
import FileSaver from "file-saver";
import XLSX from "xlsx";
import json2csv from "json2csv";
export default {
  components: {
    timepicker,
  },
  data() {
    return {
      table: [],
      radio3: "增量",
      dialogVisible: false,
      dialogVisible2: false,
      interval: 4,
      tableData: [],
      checkList: [],
      device: 1,
      path: "",
      tableheight: undefined,
      treedata: [
        {
          id: 0,
          label: "空调负荷",
          children: [
            {
              id: 1,
              label: "1层1号监测点",
            },
            {
              id: 2,
              label: "1层2号监测点",
            },
          ],
        },
        {
          label: "办公负荷",
          id: 11,
          children: [
            {
              id: 12,
              label: "1号楼电梯",
            },
            {
              id: 13,
              label: "1号楼照明",
            },
          ],
        },
        {
          label: "厨房负荷",
          id: 3,
          children: [
            {
              id: 31,
              label: "厨房",
            },
            {
              id: 32,
              label: "保安室",
            },
          ],
        },
      ],
      defaultProps: {
        children: "children",
        label: "label",
      },
      form: {
        name: "",
        region: "",
      },
      formData: {},
      ydata1: [],
      ydata2: [],
      ydata3: [],
    };
  },
  created() {},
  mounted() {
    // this.tableheight = getheight();
    // this.device = window.devicePixelRatio;
    // if (this.device == 1) {
    //   this.tableheight = this.tableheight * 2.25;
    // }
    // if (this.device == 1.25) {
    //   this.tableheight = this.tableheight * 1.8;
    // }
    // if (this.device == 1.5) {
    //   this.tableheight = this.tableheight * 1.93;
    // }
    this.tableheight =  window.sessionStorage.getItem('appheight') - 120
    this.$nextTick(() => {
      this.electritypeEcharts1();
      this.electritypeEcharts2();
      this.electritypeEcharts3();
      this.electritypeEcharts4();
    });
  },
  methods: {
    //指标策略触发事件
    Indexstrategy() {
      this.dialogVisible = true;
    },
    //树节点触发事件
    handleNodeClick(data) {
      //console.log(data);
    },
    //负荷策略触发事件
    loadtype() {
      this.dialogVisible2 = true;
    },
    //事件触发查询方法
    //时间格式转化
    dateFormat(dateData1, dateData2) {
      var timearr = [];
      var date = new Date(dateData1);
      var y = date.getFullYear();
      var m = date.getMonth() + 1;
      m = m < 10 ? "0" + m : m;
      var d = date.getDate();
      d = d < 10 ? "0" + d : d;
      var h = date.getHours();
      h = h < 10 ? "0" + h : h;
      var f = date.getMinutes();
      f = f < 10 ? "0" + f : f;
      var s = date.getSeconds();
      s = s < 10 ? "0" + s : s;
      this.formData.startTime = y + "-" + m + "-" + d;
      timearr.push(this.formData.startTime);
      var date = new Date(dateData2);
      var y = date.getFullYear();
      var m = date.getMonth() + 1;
      m = m < 10 ? "0" + m : m;
      var d = date.getDate();
      d = d < 10 ? "0" + d : d;
      var h = date.getHours();
      h = h < 10 ? "0" + h : h;
      var f = date.getMinutes();
      f = f < 10 ? "0" + f : f;
      var s = date.getSeconds();
      s = s < 10 ? "0" + s : s;
      this.formData.endTime = y + "-" + m + "-" + d;
      timearr.push(this.formData.endTime);
      return timearr;
    },
    formatDate(date) {
     // console.log(date);
      // date = new Date();
      date = new Date(Date.parse(date.replace(/-/g, "/"))); //转换成Data();
      //console.log(date);
      var y = date.getFullYear();
     // console.log(y);
      var m = date.getMonth() + 1;
      m = m < 10 ? "0" + m : m;
      var d = date.getDate();
      d = d < 10 ? "0" + d : d;
      return y + "-" + m + "-" + d;
    },
    //查询触发事件
    querfromdata(data, timehbValue, interval) {
      this.interval = interval;
      this.dateFormat(data[0], data[1]);

      this.loadData();
      //this.Powefactor()
    },
    //处理
    chuli(data) {
      var m = [];
      for (var j = 0; j < data.length; j++) {
        var name = data[j][0];
        var value = Number(data[j][1]).toFixed(2);
        var arr = [name, value];
        m.push(arr);
      }
      return m;
    },
    //获取空调数据
    loadData() {
      api.getAirTendency(this.formData).then((res) => {
        if (res.code == "A0000") {
          if (res.data.length > 0) {
            for (var i = 0; i < res.data.length; i++) {
              if (res.data[i].loadName == "内机开机数量") {
                this.ydata1 = this.chuli(res.data[i].value);
                this.table = this.chuli(res.data[i].value);
              } else if (res.data[i].loadName == "外机温度") {
                this.ydata2 = this.chuli(res.data[i].value);
              } else if (res.data[i].loadName == "耗电量") {
                this.ydata3 = this.chuli(res.data[i].value);
              }
            }
          } else {
            this.ydata1 = [];
            this.ydata2 = [];
            this.ydata3 = [];
          }

          this.electritypeEcharts1();
        }
      });
    },
    //关闭事件
    handleClose() {
      this.dialogVisible = false;
      this.dialogVisible2 = false;
    },
    getDate(strDate) {
      var st = strDate;
      var a = st.split(" ");
      var b = a[0].split("-");
      var c = a[1].split(":");
      var date = new Date(b[0], b[1], b[2], c[0], c[1], c[2]);
      return date;
    },
    electritypeEcharts1() {
      let echarts = require("echarts");
      var myChart = echarts.init(document.getElementById("electri2"));
      const colors = ["#FF00FF", "#006699", "#CC9900"];
      var option = {
        color: colors,
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
          },
        },
        grid: {
          right: "10%",
          left: "5%",
          top: "10%",
          bottom: "6%",
        },
        toolbox: {
          feature: {
            dataView: {
              show: true,
              lang: ["数据视图", "关闭", "导出Excel"],
              //optionToContent为重画表格的函数
              optionToContent: function (opt) {
                //console.log(opt);
                var series = opt.series;
                var arr = [];
                for (var i = 0; i < series[1].data.length; i++) {
                  arr.push([series[1].data[i][0], "该时间耗电量数据未上送"]);
                }
                for (var h = 0; h < arr.length; h++) {
                  for (var k = 0; k < series[0].data.length; k++) {
                    if (arr[h][0] === series[0].data[k][0]) {
                      arr[h][1] = series[0].data[k][1];
                    }
                  }
                }
                // let long=series[0].data.length
                // for(let i=0;i<long;i++){
                //   for(let j=0;j<2;j++){
                //        series[0].data.unshift(['缺失的','0'])
                //   }
                // }
                var tdBodys = "";

                // for(var i=0;i<series.length;i++){
                for (var j = 0; j < series[1].data.length; j++) {
                  tdBodys +=
                    "<tr>" +
                    '<td style="height:20px;border:1px solid;margin:auto;text-align:center;background-color:#a4c4d0;vnd.ms-excel.numberformat:yyyy-mm-dd h:mm">' +
                    "" +
                    series[1].data[j][0] +
                    "</td>" +
                    '<td style="height:20px;border:1px solid;margin:auto;text-align:center;background-color:#a4c4d0">' +
                    arr[j][1] +
                    "</td>" +
                    '<td style="height:20px;border:1px solid;margin:auto;text-align:center;background-color:#a4c4d0">' +
                    series[1].data[j][1] +
                    "</td>" +
                    '<td style="height:20px;border:1px solid;margin:auto;text-align:center;background-color:#a4c4d0">' +
                    series[2].data[j][1] +
                    "</td>" +
                    "</tr>";

                  // }
                }
                var table =
                  '<table id="Mytable" style="width:100%;border:0;margin:auto;text-align:center;border: 1px solid;border-collapse:collapse;">' +
                  '<caption style="font-weight:bold;font-size:20px;height:25px">空调基础信息表</caption>' +
                  "<tr>" +
                  '<th style="text-align: center;border: 1px solid;padding:0 10px;font-weight:bold;background-color:#ccc;height:25px">时间</th>' +
                  '<th style="text-align: center;border: 1px solid;padding:0 10px;font-weight:bold;background-color:#ccc;height:25px">耗电量(kW/h)</th>' +
                  '<th style="text-align: center;border: 1px solid;font-weight:bold;background-color:#ccc;height:25px">内机开机数量(台)</th>' +
                  '<th style="text-align: center;border: 1px solid;padding:0 10px;font-weight:bold;background-color:#ccc;height:25px">外机温度(度)</th>' +
                  "</tr>" +
                  tdBodys +
                  +"</table>";

                return table;
              },
              //contentToOption为重写“刷新”按钮的语句
              contentToOption: function (HTMLDomElement, opt) {
                let et = XLSX.utils.table_to_book(
                  document.getElementById("Mytable")
                );
                let etout = XLSX.write(et, {
                  bookType: "xlsx",
                  bookSST: true,
                  type: "array",
                });
                try {
                  FileSaver.saveAs(
                    new Blob([etout], {
                      type: "application/octet-stream",
                    }),
                    "空调信息表" + "-" + new Date().toLocaleString() + ".xlsx"
                  );
                } catch (e) {}
                return etout;
              },
            },
            //restore: { show: true },
            dataZoom: {
              yAxisIndex: "none",
            },
            saveAsImage: { show: true },
          },
        },
        legend: {
          data: ["耗电量", "内机开机数量", "外机温度"],
        },
        dataZoom: [
          {
            type: "inside",
            start: 0,
            end: 100,
          },
          {
            start: 0,
            end: 100,
          },
        ],
        xAxis: [
          {
            type: 'time',
            // axisTick: {
            //   alignWithLabel: true
            // },
            // prettier-ignore
            // data: ['2022-04-12 12:35', '13:35', '14:35', '15:35', '16:35', '17:35', '18:35', '19:35', '20:35', '21:35', '22:35', '23:35']
          },
        ],
        yAxis: [
          {
            type: "value",
            name: "耗电量",
            position: "right",
            alignTicks: true,
            axisLine: {
              show: true,
              lineStyle: {
                color: colors[0],
              },
            },
            axisLabel: {
              formatter: "{value} kWh",
            },
          },
          {
            type: "value",
            name: "内机开机数量",
            position: "right",
            alignTicks: true,
            offset: 80,
            axisLine: {
              show: true,
              lineStyle: {
                color: colors[1],
              },
            },
            axisLabel: {
              formatter: "{value} 台",
            },
          },
          {
            type: "value",
            name: "温度",
            position: "left",
            alignTicks: true,
            axisLine: {
              show: true,
              lineStyle: {
                color: colors[2],
              },
            },
            axisLabel: {
              formatter: "{value} °C",
            },
            splitLine: {
              show: true,
              background: "#000",
              lineStyle: {
                type: "dashed",
                color: "#55b9b4",
              },
            },
            splitArea: {
              show: true,
              areaStyle: {
                color: "#999999",
                opacity: 0.5,
              },
            },
          },
        ],
        series: [
          {
            name: "耗电量",
            type: "bar",
            data: this.ydata3,
            itemStyle: {
              normal: {
                color: "#FF00FF",
              },
            },
          },
          {
            name: "内机开机数量",
            type: "bar",
            yAxisIndex: 1,
            data: this.ydata1,
            itemStyle: {
              normal: {
                color: "#006699",
              },
            },
          },
          {
            name: "外机温度",
            symbol: "none",
            type: "line",
            yAxisIndex: 2,
            data: this.ydata2,
            itemStyle: {
              normal: {
                color: "#CC9900",
              },
            },
          },
        ],
      };
      // var app = {
      //   currentIndex: -1,
      // };
      // setInterval(function () {
      //   var dataLen = option.series[0].data.length;

      //   // 取消之前高亮的图形
      //   myChart.dispatchAction({
      //     type: 'downplay',
      //     seriesIndex: 0,
      //     dataIndex: app.currentIndex
      //   });
      //   app.currentIndex = (app.currentIndex + 1) % dataLen;
      //   //console.log(app.currentIndex);
      //   // 高亮当前图形
      //   myChart.dispatchAction({
      //     type: 'highlight',
      //     seriesIndex: 0,
      //     dataIndex: app.currentIndex,
      //   });
      //   // 显示 tooltip
      //   myChart.dispatchAction({
      //     type: 'showTip',
      //     seriesIndex: 0,
      //     dataIndex: app.currentIndex
      //   });

      // }, 1000);
      
      option && myChart.setOption(option, true)
window.echartsArr.push(myChart);
    },
    electritypeEcharts2() {
      let echarts = require("echarts");
      var myChart = echarts.init(document.getElementById("electri3"));
      var xData = [
        "2021-01-01",
        "2021-01-02",
        "2021-01-03",
        "2021-01-04",
        "2021-01-05",
        "2021-01-06",
        "2021-01-07",
        "2021-01-08",
        "2021-01-09",
        "2021-01-10",
        "2021-01-11",
        "2021-01-12",
        "2021-02-01",
        "2021-02-02",
        "2021-02-03",
        "2021-02-04",
      ];
      var yData = [
        20, 25, 24, 25, 20, 26, 28, 29, 27, 25, 29, 26, 25, 28, 25, 25,
      ];
      var option = {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            // 坐标轴指示器，坐标轴触发有效
            type: "shadow", // 默认为直线，可选为：'line' | 'shadow'
          },
        },
        grid: {
          left: "2%",
          right: "4%",
          bottom: "6%",
          top: "15%",
          containLabel: true,
        },
        legend: {
          data: ["室外温度"],
          //left: 20,
          top: 12,
          textStyle: {
            color: "#000",
          },
          itemWidth: 12,
          itemHeight: 10,
          // itemGap: 35
        },
        xAxis: {
          type: "category",
          data: xData,
          axisLine: {
            lineStyle: {
              color: "#000",
            },
          },
          axisLabel: {
            // interval: 0,
            // rotate: 40,
            textStyle: {
              fontFamily: "Microsoft YaHei",
            },
          },
        },
        toolbox: {
          show: true,
          feature: {
            saveAsImage: { show: true },
            dataZoom: {
              yAxisIndex: "none",
            },
            //restore: {},
            mark: { show: true },
            //magicType : {show: true, type: ['line', 'bar']}
          },
        },
        yAxis: {
          min: 0,
          max: 40,
          name: "单位(度)",
          axisLine: {
            show: true,
            lineStyle: {
              color: "#000",
            },
          },
          axisLabel: {
            formatter: "{value}",
            color: "#000",
            textStyle: {
              fontSize: 14,
            },
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: "#000",
            },
          },
        },

        dataZoom: [
          {
            show: true,
            height: 6,
            xAxisIndex: [0],
            bottom: "2%",
            start: 0,
            end: 100,
            handleIcon:
              "path://M306.1,413c0,2.2-1.8,4-4,4h-59.8c-2.2,0-4-1.8-4-4V200.8c0-2.2,1.8-4,4-4h59.8c2.2,0,4,1.8,4,4V413z",
            handleSize: "110%",
            handleStyle: {
              color: "#d3dee5",
            },
            textStyle: {
              color: "#fff",
            },
            borderColor: "#90979c",
          },
          {
            type: "inside",
            show: true,
            height: 15,
            start: 0,
            end: 100,
          },
        ],
        series: [
          {
            name: "室外温度",
            type: "bar",
            barWidth: "30%",
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  {
                    offset: 0,
                    color: "#3399CC",
                  },
                  {
                    offset: 1,
                    color: "#3399CC",
                  },
                ]),
                barBorderRadius: 0,
              },
            },
            data: yData,
          },
        ],
      };
      var app = {
        currentIndex: -1,
      };
      setInterval(function () {
        var dataLen = option.series[0].data.length;

        // 取消之前高亮的图形
        myChart.dispatchAction({
          type: "downplay",
          seriesIndex: 0,
          dataIndex: app.currentIndex,
        });
        app.currentIndex = (app.currentIndex + 1) % dataLen;
        //console.log(app.currentIndex);
        // 高亮当前图形
        myChart.dispatchAction({
          type: "highlight",
          seriesIndex: 0,
          dataIndex: app.currentIndex,
        });
        // 显示 tooltip
        myChart.dispatchAction({
          type: "showTip",
          seriesIndex: 0,
          dataIndex: app.currentIndex,
        });
      }, 1000);
      myChart.setOption(option)
window.echartsArr.push(myChart);
    },
    electritypeEcharts3() {
      let echarts = require("echarts");
      var myChart = echarts.init(document.getElementById("electri4"));
      var xData = [
        "2021-01-01",
        "2021-01-02",
        "2021-01-03",
        "2021-01-04",
        "2021-01-05",
        "2021-01-06",
        "2021-01-07",
        "2021-01-08",
        "2021-01-09",
        "2021-01-10",
        "2021-01-11",
        "2021-01-12",
        "2021-02-01",
        "2021-02-02",
        "2021-02-03",
        "2021-02-04",
      ];
      var yData = [
        20, 35, 24, 25, 20, 26, 28, 29, 27, 25, 19, 6, 25, 18, 15, 25,
      ];
      var option = {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            // 坐标轴指示器，坐标轴触发有效
            type: "shadow", // 默认为直线，可选为：'line' | 'shadow'
          },
        },
        grid: {
          left: "2%",
          right: "4%",
          bottom: "6%",
          top: "15%",
          containLabel: true,
        },
        legend: {
          data: ["内机开机数量"],
          // left: 20,
          top: 12,
          textStyle: {
            color: "#000",
          },
          itemWidth: 12,
          itemHeight: 10,
          // itemGap: 35
        },
        xAxis: {
          type: "category",
          data: xData,
          axisLine: {
            lineStyle: {
              color: "#000",
            },
          },
          axisLabel: {
            // interval: 0,
            // rotate: 40,
            textStyle: {
              fontFamily: "Microsoft YaHei",
            },
          },
        },
        toolbox: {
          show: true,
          feature: {
            saveAsImage: { show: true },
            dataZoom: {
              yAxisIndex: "none",
            },
            //restore: {},
            mark: { show: true },
            //magicType : {show: true, type: ['line', 'bar']}
          },
        },
        yAxis: {
          min: 0,
          max: 45,
          name: "单位(台)",
          axisLine: {
            show: true,
            lineStyle: {
              color: "#000",
            },
          },
          axisLabel: {
            formatter: "{value}",
            color: "#000",
            textStyle: {
              fontSize: 14,
            },
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: "#000",
            },
          },
        },

        dataZoom: [
          {
            show: true,
            height: 6,
            xAxisIndex: [0],
            bottom: "2%",
            start: 0,
            end: 100,
            handleIcon:
              "path://M306.1,413c0,2.2-1.8,4-4,4h-59.8c-2.2,0-4-1.8-4-4V200.8c0-2.2,1.8-4,4-4h59.8c2.2,0,4,1.8,4,4V413z",
            handleSize: "110%",
            handleStyle: {
              color: "#d3dee5",
            },
            textStyle: {
              color: "#fff",
            },
            borderColor: "#90979c",
          },
          {
            type: "inside",
            show: true,
            height: 15,
            start: 0,
            end: 100,
          },
        ],
        series: [
          {
            name: "内机开机数量",
            type: "bar",
            barWidth: "30%",
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  {
                    offset: 0,
                    color: "#006699",
                  },
                  {
                    offset: 1,
                    color: "#006699",
                  },
                ]),
                barBorderRadius: 0,
              },
            },
            data: yData,
          },
        ],
      };
      var app = {
        currentIndex: -1,
      };
      setInterval(function () {
        var dataLen = option.series[0].data.length;

        // 取消之前高亮的图形
        myChart.dispatchAction({
          type: "downplay",
          seriesIndex: 0,
          dataIndex: app.currentIndex,
        });
        app.currentIndex = (app.currentIndex + 1) % dataLen;
        //console.log(app.currentIndex);
        // 高亮当前图形
        myChart.dispatchAction({
          type: "highlight",
          seriesIndex: 0,
          dataIndex: app.currentIndex,
        });
        // 显示 tooltip
        myChart.dispatchAction({
          type: "showTip",
          seriesIndex: 0,
          dataIndex: app.currentIndex,
        });
      }, 1000);
      myChart.setOption(option)
window.echartsArr.push(myChart);
    },
    electritypeEcharts4() {
      let echarts = require("echarts");
      var myChart = echarts.init(document.getElementById("electri5"));
      var xData = [
        "2021-01-01",
        "2021-01-02",
        "2021-01-03",
        "2021-01-04",
        "2021-01-05",
        "2021-01-06",
        "2021-01-07",
        "2021-01-08",
        "2021-01-09",
        "2021-01-10",
        "2021-01-11",
        "2021-01-12",
        "2021-02-01",
        "2021-02-02",
        "2021-02-03",
        "2021-02-04",
      ];
      var yData = [
        50, 75, 84, 65, 90, 56, 68, 89, 67, 95, 69, 96, 75, 58, 85, 65,
      ];
      var option = {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            // 坐标轴指示器，坐标轴触发有效
            type: "shadow", // 默认为直线，可选为：'line' | 'shadow'
          },
        },
        grid: {
          left: "2%",
          right: "4%",
          bottom: "6%",
          top: "15%",
          containLabel: true,
        },
        legend: {
          data: ["内机开机时间"],
          // left: 20,
          top: 12,
          textStyle: {
            color: "#000",
          },
          itemWidth: 12,
          itemHeight: 10,
          // itemGap: 35
        },
        xAxis: {
          type: "category",
          data: xData,
          axisLine: {
            lineStyle: {
              color: "#000",
            },
          },
          axisLabel: {
            // interval: 0,
            // rotate: 40,
            textStyle: {
              fontFamily: "Microsoft YaHei",
            },
          },
        },
        toolbox: {
          show: true,
          feature: {
            saveAsImage: { show: true },
            dataZoom: {
              yAxisIndex: "none",
            },
            //restore: {},
            mark: { show: true },
            //magicType : {show: true, type: ['line', 'bar']}
          },
        },
        yAxis: {
          min: 0,
          max: 100,
          name: "单位(小时)",
          axisLine: {
            show: true,
            lineStyle: {
              color: "#000",
            },
          },
          axisLabel: {
            formatter: "{value}",
            color: "#000",
            textStyle: {
              fontSize: 14,
            },
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: "#000",
            },
          },
        },

        dataZoom: [
          {
            show: true,
            height: 6,
            xAxisIndex: [0],
            bottom: "2%",
            start: 0,
            end: 100,
            handleIcon:
              "path://M306.1,413c0,2.2-1.8,4-4,4h-59.8c-2.2,0-4-1.8-4-4V200.8c0-2.2,1.8-4,4-4h59.8c2.2,0,4,1.8,4,4V413z",
            handleSize: "110%",
            handleStyle: {
              color: "#d3dee5",
            },
            textStyle: {
              color: "#fff",
            },
            borderColor: "#90979c",
          },
          {
            type: "inside",
            show: true,
            height: 15,
            start: 0,
            end: 100,
          },
        ],
        series: [
          {
            name: "内机开机时间",
            type: "bar",
            barWidth: "30%",
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  {
                    offset: 0,
                    color: "green",
                  },
                  {
                    offset: 1,
                    color: "green",
                  },
                ]),
                barBorderRadius: 0,
              },
            },
            data: yData,
          },
        ],
      };
      var app = {
        currentIndex: -1,
      };
      setInterval(function () {
        var dataLen = option.series[0].data.length;

        // 取消之前高亮的图形
        myChart.dispatchAction({
          type: "downplay",
          seriesIndex: 0,
          dataIndex: app.currentIndex,
        });
        app.currentIndex = (app.currentIndex + 1) % dataLen;
        //console.log(app.currentIndex);
        // 高亮当前图形
        myChart.dispatchAction({
          type: "highlight",
          seriesIndex: 0,
          dataIndex: app.currentIndex,
        });
        // 显示 tooltip
        myChart.dispatchAction({
          type: "showTip",
          seriesIndex: 0,
          dataIndex: app.currentIndex,
        });
      }, 1000);
      myChart.setOption(option)
window.echartsArr.push(myChart);
    },
  },
};
</script>
<style lang='scss' scoped>
.spantext {
  font-size: 14px;
  font-weight: bold;
}
.border {
  border: 1px solid rgb(15, 15, 15);
  height: 20vh;
  width: 100%;
  margin: 0 auto;
}
.check {
  margin-top: 2%;
  margin-left: 25%;
}
.border2 {
  border: 1px solid rgb(15, 15, 15);
}
::v-deep .el-tree {
  color: rgb(1, 15, 27);
  font-weight: bold;
  // background: rgba(87, 122, 133, 0.39);
}
</style>