<template>
  <div style="padding: 0.5%">
    <el-row :gutter="10">
      <el-col :span="24" style='display: flex'>

          <el-form :inline="true" :model="ruleForm" class="demo-form-inline" style='margin-left: 15px'>
              <el-form-item label="统计指标:">
                  <el-select
                      v-model="formData.loadType"
                      placeholder="请选择"
                  >
                      <el-option
                          v-for="item in options"
                          :key="item.id"
                          :label="item.name"
                          :value="item.id"
                      >
                      </el-option>
                  </el-select>
              </el-form-item>

              <el-form-item label="统计方式:">
                  <el-radio-group v-model="radio3" size="small" @change="checkbox">
                      <el-radio-button label="增量"></el-radio-button>
                      <el-radio-button label="累计"></el-radio-button>
                  </el-radio-group>
              </el-form-item>
          </el-form>


          <timepicker
              v-if="falg"
              @querfromdata="querfromdata"
              :interval="interval"
          ></timepicker>

      </el-col>

      <el-col :span="24">
        <div
          v-if="radio3 == '增量'"
          id="electri1"
          :style="
            'background:;width:100%;height:' + tableheight + 'px;'
          "
        ></div>
        <div
          v-if="radio3 == '累计'"
          id="electri2"
          :style="
            'background:;width:100%;height:' + tableheight + 'px;'
          "
        ></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";
export default {
  components: {
    timepicker,
  },
  data() {
    return {
      falg: false,
      radio3: "增量",
      formData: {
        startTime: "",
        endTime: "",
        loadType: "",
        type: 0,
      },
      dialogVisible: false,
      dialogVisible2: false,
      interval: 4,
      //统计指标
      value: 0,
      options: [],
      tableData: [],
      checkList: [],
      device: 1,
      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: "",
      },
      ydata1: [],
      ydata2: [],
      ydata3: [],
      ydata4: [],
      ydata5: [],
      ydata6: [],
      ydata7: [],

      ydata11: [],
      ydata22: [],
      ydata33: [],
      ydata44: [],
      ydata55: [],
      ydata66: [],
      ydata77: [],
    };
  },
  created() {
    this.getTarget();
  },
  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();
    });
  },
  methods: {
    //获取指标数据
    getTarget() {
      var p = {
        statisticalName: "电度统计",
      };
      api.getEleStatisticalTree(p).then((res) => {
        if (res.code == "A0000") {
          this.options = res.data.binds;
          this.formData.loadType = this.options[0].id;
          this.falg = true;
        }
      });
    },
    //指标策略触发事件
    Indexstrategy() {
      this.dialogVisible = true;
    },
    //树节点触发事件
    handleNodeClick(data) {
      console.log(data);
    },
    //负荷策略触发事件
    loadtype() {
      this.dialogVisible2 = true;
    },
    //关闭事件
    handleClose() {
      this.dialogVisible = false;
      this.dialogVisible2 = false;
    },
    //切换事件
    checkbox(val) {
      this.radio3 = val;

      if (val == "增量") {
        this.formData.type = 0;
        this.loadData();
      } else {
        this.formData.type = 1;
        this.loadeleData();
      }
    },
    //时间格式化
    //时间格式转化
    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;
    },
    //查询触发事件
    querfromdata(data, timehbValue, interval) {
      this.interval = interval;
      this.dateFormat(data[0], data[1]);
      this.loadData();
      this.loadeleData();
    },
    //处理
    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.getElectTendency(this.formData).then((res) => {
        if (res.code == "A0000") {
          for (var i = 0; i < res.data.length; i++) {
            if (res.data[i].loadName == "高压进线") {
              this.ydata6 = this.chuli(res.data[i].value);
            } else if (res.data[i].loadName == "光伏发电") {
              this.ydata5 = this.chuli(res.data[i].value);
            } else if (res.data[i].loadName == "空调负荷") {
              this.ydata1 = 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 if (res.data[i].loadName == "宿舍负荷") {
              this.ydata4 = this.chuli(res.data[i].value);
            } else if (res.data[i].loadName == "总负荷") {
              this.ydata7 = this.chuli(res.data[i].value);
            }
          }
          this.electritypeEcharts1();
          //this.Powefactor()
        }
      });
    },
    //获取电度累计数据
    loadeleData() {
      api.getElectTendency(this.formData).then((res) => {
        if (res.code == "A0000") {
          for (var i = 0; i < res.data.length; i++) {
            if (res.data[i].loadName == "高压进线") {
              this.ydata66 = this.chuli(res.data[i].value);
            } else if (res.data[i].loadName == "光伏发电") {
              this.ydata55 = this.chuli(res.data[i].value);
            } else if (res.data[i].loadName == "空调负荷") {
              this.ydata11 = this.chuli(res.data[i].value);
            } else if (res.data[i].loadName == "办公负荷") {
              this.ydata22 = this.chuli(res.data[i].value);
            } else if (res.data[i].loadName == "厨房负荷") {
              this.ydata33 = this.chuli(res.data[i].value);
            } else if (res.data[i].loadName == "宿舍负荷") {
              this.ydata44 = this.chuli(res.data[i].value);
            } else if (res.data[i].loadName == "总负荷") {
              this.ydata77 = this.chuli(res.data[i].value);
            }
          }
          this.electritypeEcharts2();
          //this.Powefactor()
        }
      });
    },

    electritypeEcharts1() {
      let echarts = require("echarts");
      var myChart1 = echarts.init(document.getElementById("electri1"));
      // 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 option1 = {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
          },
          formatter: function (params) {
            console.log(params);
            var tips = "";
            tips += params[0].data[0] + "</br/>";

            for (var i = 0; i < params.length; i++) {
              tips +=
                params[i].seriesName + ":" + params[i].value[1] + "kWh<br/>";
            }
            return tips;
          },
        },
        grid: {
          left: "2%",
          right: "6%",
          bottom: "6%",
          top: "10%",
          containLabel: true,
        },
        legend: {
          data: [
            "空调负荷",
            "办公负荷",
            "厨房负荷",
            "宿舍负荷",
            "光伏发电",
            "高压进线",
            "总负荷",
          ],
        },
        dataZoom: [
          {
            type: "inside",
            start: 0,
            end: 100,
          },
          {
            start: 0,
            end: 100,
          },
        ],
        xAxis: [
          {
            type: "time",
          },
        ],
        toolbox: {
          show: true,
          feature: {
            dataZoom: {
              yAxisIndex: "none",
            },
            //dataView: { readOnly: false },
            //magicType: { type: ['line', 'bar'] },
            //restore: {},
            saveAsImage: {},
          },
        },
        yAxis: [
          {
            type: "value",
            axisLabel: {
              //  formatter:function (value, index) {
              //          return value.toFixed(2)+'kW';
              //  }
              formatter: "{value} kWh",
            },
          },
        ],
        series: [
          {
            name: "空调负荷",
            type: "line",
            symbol: "circle",
            symbolSize: 5,
            smooth: true,
            barWidth: 22,
            stack: "空调负荷",
            itemStyle: {
              normal: {
                color: "#00CCFF",
              },
            },
            markPoint: {
              data: [
                {
                  type: "max",
                  name: "Max",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: "max", // 自定义文字内容
                  },
                },
                {
                  type: "min",
                  name: "Min",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: "min", // 自定义文字内容
                  },
                },
              ],
            },
            markLine: {
              data: [
                {
                  type: "average",
                  name: "Avg",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: function (params) {
                      // alert(params)
                      var tips = "";
                      tips += "平均值" + params.value;
                      console.log(params);
                      return tips;
                    },
                  },
                },
              ],
            },
            data: this.ydata1,
          },
          {
            name: "办公负荷",
            type: "line",
            symbol: "circle",
            symbolSize: 5,
            smooth: true,
            barWidth: 22,
            stack: "办公负荷",
            itemStyle: {
              normal: {
                color: "#006699",
              },
            },
            markPoint: {
              data: [
                {
                  type: "max",
                  name: "Max",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: "max", // 自定义文字内容
                  },
                },
                {
                  type: "min",
                  name: "Min",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: "min", // 自定义文字内容
                  },
                },
              ],
            },
            markLine: {
              data: [
                {
                  type: "average",
                  name: "Avg",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: function (params) {
                      // alert(params)
                      var tips = "";
                      tips += "平均值" + params.value;
                      console.log(params);
                      return tips;
                    },
                  },
                },
              ],
            },
            data: this.ydata2,
          },
          {
            name: "厨房负荷",
            type: "line",
            symbol: "circle",
            symbolSize: 5,
            smooth: true,
            barWidth: 22,
            stack: "厨房负荷",
            itemStyle: {
              normal: {
                color: "#996600",
              },
            },
            markPoint: {
              data: [
                {
                  type: "max",
                  name: "Max",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: "max", // 自定义文字内容
                  },
                },
                {
                  type: "min",
                  name: "Min",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: "min", // 自定义文字内容
                  },
                },
              ],
            },
            markLine: {
              data: [
                {
                  type: "average",
                  name: "Avg",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: function (params) {
                      // alert(params)
                      var tips = "";
                      tips += "平均值" + params.value;
                      console.log(params);
                      return tips;
                    },
                  },
                },
              ],
            },
            data: this.ydata3,
          },
          {
            name: "宿舍负荷",
            type: "line",
            symbol: "circle",
            symbolSize: 5,
            smooth: true,
            barWidth: 22,
            stack: "宿舍负荷",
            itemStyle: {
              normal: {
                color: "#CC00FF",
              },
            },
            markPoint: {
              data: [
                {
                  type: "max",
                  name: "Max",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: "max", // 自定义文字内容
                  },
                },
                {
                  type: "min",
                  name: "Min",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: "min", // 自定义文字内容
                  },
                },
              ],
            },
            markLine: {
              data: [
                {
                  type: "average",
                  name: "Avg",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: function (params) {
                      // alert(params)
                      var tips = "";
                      tips += "平均值" + params.value;
                      console.log(params);
                      return tips;
                    },
                  },
                },
              ],
            },
            data: this.ydata4,
          },
          {
            name: "光伏发电",
            type: "line",
            symbol: "circle",
            symbolSize: 5,
            smooth: true,
            barWidth: 22,
            stack: "光伏发电",
            itemStyle: {
              normal: {
                color: "#66FF00",
              },
            },
            markPoint: {
              data: [
                {
                  type: "max",
                  name: "Max",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: "max", // 自定义文字内容
                  },
                },
                {
                  type: "min",
                  name: "Min",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: "min", // 自定义文字内容
                  },
                },
              ],
            },
            markLine: {
              data: [
                {
                  type: "average",
                  name: "Avg",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: function (params) {
                      // alert(params)
                      var tips = "";
                      tips += "平均值" + params.value;
                      console.log(params);
                      return tips;
                    },
                  },
                },
              ],
            },
            data: this.ydata5,
          },
          {
            name: "高压进线",
            type: "line",
            symbol: "circle",
            symbolSize: 5,
            smooth: true,
            barWidth: 22,
            stack: "高压进线",
            itemStyle: {
              normal: {
                color: "#CC3333",
              },
            },
            markPoint: {
              data: [
                {
                  type: "max",
                  name: "Max",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: "max", // 自定义文字内容
                  },
                },
                {
                  type: "min",
                  name: "Min",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: "min", // 自定义文字内容
                  },
                },
              ],
            },
            markLine: {
              data: [
                {
                  type: "average",
                  name: "Avg",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: function (params) {
                      // alert(params)
                      var tips = "";
                      tips += "平均值" + params.value;
                      console.log(params);
                      return tips;
                    },
                  },
                },
              ],
            },
            data: this.ydata6,
          },
          {
            name: "总负荷",
            type: "line",
            symbol: "circle",
            symbolSize: 5,
            smooth: true,
            barWidth: 22,
            stack: "总负荷",
            itemStyle: {
              normal: {
                color: "#FFCC33",
              },
            },
            markPoint: {
              data: [
                {
                  type: "max",
                  name: "Max",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: "max", // 自定义文字内容
                  },
                },
                {
                  type: "min",
                  name: "Min",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: "min", // 自定义文字内容
                  },
                },
              ],
            },
            markLine: {
              data: [
                {
                  type: "average",
                  name: "Avg",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: function (params) {
                      // alert(params)
                      var tips = "";
                      tips += "平均值" + params.value;
                      console.log(params);
                      return tips;
                    },
                  },
                },
              ],
            },
            data: this.ydata7,
          },
        ],
      };
      myChart1.clear();
      
      option1 && myChart1.setOption(option1, true)
window.echartsArr.push(myChart1);
    },
    electritypeEcharts2() {
      let echarts = require("echarts");
      var myChart = echarts.init(document.getElementById("electri2"));
      // 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: "cross",
          },
          formatter: function (params) {
            console.log(params);
            var tips = "";
            tips += params[0].data[0] + "<br/>";

            for (var i = 0; i < params.length; i++) {
              tips +=
                params[i].seriesName + ":" + params[i].value[1] + "kWh<br/>";
            }
            return tips;
          },
        },
        grid: {
          left: "2%",
          right: "7%",
          bottom: "6%",
          top: "10%",
          containLabel: true,
        },
        legend: {
          data: [
            "空调负荷",
            "办公负荷",
            "厨房负荷",
            "宿舍负荷",
            "光伏发电",
            "高压进线",
            "总负荷",
          ],
        },
        xAxis: [
          {
            type: "time",
          },
        ],
        dataZoom: [
          {
            type: "inside",
            start: 0,
            end: 100,
          },
          {
            start: 0,
            end: 100,
          },
        ],
        toolbox: {
          show: true,
          feature: {
            dataZoom: {
              yAxisIndex: "none",
            },
            //dataView: { readOnly: false },
            //magicType: { type: ['line', 'bar'] },
            //restore: {},
            saveAsImage: {},
          },
        },
        yAxis: [
          {
            type: "value",
            axisLabel: {
              //  formatter:function (value, index) {
              //          return value.toFixed(2)+'kW';
              //  }
              formatter: "{value} kWh",
            },
          },
        ],
        series: [
          {
            name: "空调负荷",
            type: "line",
            symbol: "circle",
            symbolSize: 5,
            smooth: true,
            barWidth: 22,
            stack: "空调负荷",
            itemStyle: {
              normal: {
                color: "#00CCFF",
              },
            },
            markPoint: {
              data: [
                {
                  type: "max",
                  name: "Max",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: "max", // 自定义文字内容
                  },
                },
                {
                  type: "min",
                  name: "Min",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: "min", // 自定义文字内容
                  },
                },
              ],
            },
            markLine: {
              data: [
                {
                  type: "average",
                  name: "Avg",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: function (params) {
                      // alert(params)
                      var tips = "";
                      tips += "平均值:";
                      tips += params.value;
                      console.log(params);
                      return tips;
                    },
                  },
                },
              ],
            },
            data: this.ydata11,
          },
          {
            name: "办公负荷",
            type: "line",
            symbol: "circle",
            symbolSize: 5,
            smooth: true,
            barWidth: 22,
            stack: "办公负荷",
            itemStyle: {
              normal: {
                color: "#006699",
              },
            },
            markPoint: {
              data: [
                {
                  type: "max",
                  name: "Max",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: "max", // 自定义文字内容
                  },
                },
                {
                  type: "min",
                  name: "Min",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: "min", // 自定义文字内容
                  },
                },
              ],
            },
            markLine: {
              data: [
                {
                  type: "average",
                  name: "Avg",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: function (params) {
                      // alert(params)
                      var tips = "";
                      tips += "平均值:";
                      tips += params.value;
                      console.log(params);
                      return tips;
                    },
                  },
                },
              ],
            },
            data: this.ydata22,
          },
          {
            name: "厨房负荷",
            type: "line",
            symbol: "circle",
            symbolSize: 5,
            smooth: true,
            barWidth: 22,
            stack: "厨房负荷",
            itemStyle: {
              normal: {
                color: "#996600",
              },
            },
            markPoint: {
              data: [
                {
                  type: "max",
                  name: "Max",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: "max", // 自定义文字内容
                  },
                },
                {
                  type: "min",
                  name: "Min",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: "min", // 自定义文字内容
                  },
                },
              ],
            },
            markLine: {
              data: [
                {
                  type: "average",
                  name: "Avg",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: function (params) {
                      // alert(params)
                      var tips = "";
                      tips += "平均值:";
                      tips += params.value;
                      console.log(params);
                      return tips;
                    },
                  },
                },
              ],
            },
            data: this.ydata33,
          },
          {
            name: "宿舍负荷",
            type: "line",
            symbol: "circle",
            symbolSize: 5,
            smooth: true,
            barWidth: 22,
            stack: "宿舍负荷",
            itemStyle: {
              normal: {
                color: "#CC00FF",
              },
            },
            markPoint: {
              data: [
                {
                  type: "max",
                  name: "Max",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: "max", // 自定义文字内容
                  },
                },
                {
                  type: "min",
                  name: "Min",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: "min", // 自定义文字内容
                  },
                },
              ],
            },
            markLine: {
              data: [
                {
                  type: "average",
                  name: "Avg",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: function (params) {
                      // alert(params)
                      var tips = "";
                      tips += "平均值:";
                      tips += params.value;
                      console.log(params);
                      return tips;
                    },
                  },
                },
              ],
            },
            data: this.ydata44,
          },
          {
            name: "光伏发电",
            type: "line",
            symbol: "circle",
            symbolSize: 5,
            smooth: true,
            barWidth: 22,
            stack: "光伏发电",
            itemStyle: {
              normal: {
                color: "#66FF00",
              },
            },
            markPoint: {
              data: [
                {
                  type: "max",
                  name: "Max",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: "max", // 自定义文字内容
                  },
                },
                {
                  type: "min",
                  name: "Min",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: "min", // 自定义文字内容
                  },
                },
              ],
            },
            markLine: {
              data: [
                {
                  type: "average",
                  name: "Avg",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: function (params) {
                      // alert(params)
                      var tips = "";
                      tips += "平均值:";
                      tips += params.value;
                      console.log(params);
                      return tips;
                    },
                  },
                },
              ],
            },
            data: this.ydata55,
          },
          {
            name: "高压进线",
            type: "line",
            symbol: "circle",
            symbolSize: 5,
            smooth: true,
            barWidth: 22,
            stack: "高压进线",
            itemStyle: {
              normal: {
                color: "#CC3333",
              },
            },
            markPoint: {
              data: [
                {
                  type: "max",
                  name: "Max",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: "max", // 自定义文字内容
                  },
                },
                {
                  type: "min",
                  name: "Min",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: "min", // 自定义文字内容
                  },
                },
              ],
            },
            markLine: {
              data: [
                {
                  type: "average",
                  name: "Avg",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: function (params) {
                      // alert(params)
                      var tips = "";
                      tips += "平均值:";
                      tips += params.value;
                      console.log(params);
                      return tips;
                    },
                  },
                },
              ],
            },
            data: this.ydata66,
          },
          {
            name: "总负荷",
            symbol: "circle",
            symbolSize: 5,
            type: "line",
            smooth: true,
            barWidth: 22,
            stack: "总负荷",
            itemStyle: {
              normal: {
                color: "#FFCC33",
              },
            },
            markPoint: {
              data: [
                {
                  type: "max",
                  name: "Max",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: "max", // 自定义文字内容
                  },
                },
                {
                  type: "min",
                  name: "Min",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: "min", // 自定义文字内容
                  },
                },
              ],
            },
            markLine: {
              data: [
                {
                  type: "average",
                  name: "Avg",
                  label: {
                    color: "#000", // 文字颜色
                    padding: [0, 0, 5, 0], // 可用padding调整图片内文字距离
                    show: true,
                    formatter: function (params) {
                      // alert(params)
                      var tips = "";
                      tips += "平均值:";
                      tips += params.value;
                      console.log(params);
                      return tips;
                    },
                  },
                },
              ],
            },
            data: this.ydata77,
          },
        ],
      };
      // 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.clear();
      
      option && myChart.setOption(option, true)
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: 30vh;
  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>