<template>
  <div class="ui-container">
    <el-col :span="24">
      <el-form :model="queryParam" ref="queryForm" :inline="true">
        <el-form-item label="过滤筛选:" prop="searchValue">
          <el-input
            v-model="queryParam.searchValue"
            placeholder="根据策略名称筛选"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置</el-button
          >
        </el-form-item>
<!--        <el-form-item style="float: right; margin-right: 20px">
          <el-button
            type="primary"
            class="el-icon-plus"
            size="mini"
            @click="Add"
            >新增</el-button
          >
        </el-form-item>-->
      </el-form>
    </el-col>
    <el-col :span="24" style="margin-top: 0.5%">
      <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
<!--        <el-tab-pane label="默认测试策略" name="0">
          <el-table
            stripe
            :data="tableData"
            :style="'width: 100%;height:' + tableheight + 'px'"
            :height="tableheight + 'px'"
            row-key="id"
            id="rebateSetTable"
            border
            style="width: 100%"
          >
            <el-table-column
              width="80"
              align="center"
              type="index"
              prop="index"
              label="序号"
            ></el-table-column>
            <el-table-column
              width="200"
              align="center"
              prop="name"
              label="策略名称"
            ></el-table-column>
            <el-table-column
              align="center"
              prop="times"
              label="时间段"
              width="400"
            >
              <template slot-scope="scope">
                <span type="primary" size="small">{{
                  scope.row.startTime + "至" + scope.row.endTime
                }}</span>
              </template>
            </el-table-column>
            <el-table-column
              width="150"
              align="center"
              prop="model"
              label="模式"
            >
              <template slot-scope="scope">
                <span type="primary" size="small">{{
                  modeFormat(scope.row.mode)
                }}</span>
              </template>
            </el-table-column>
            <el-table-column
              width="150"
              align="center"
              prop="temperature"
              label="温度(°C)"
            ></el-table-column>
            <el-table-column
              width="150"
              align="center"
              prop="wind"
              label="风速"
            >
              <template slot-scope="scope">
                <span type="primary" size="small">{{
                  windFormat(scope.row.wind)
                }}</span>
              </template>
            </el-table-column>
            <el-table-column
              width="150"
              align="center"
              prop="wind"
              label="状态"
            >
              <template slot-scope="scope">
                <span type="primary" size="small">{{
                  statusGet(scope.row.status)
                }}</span>
              </template>
            </el-table-column>
            &lt;!&ndash; <el-table-column align="center" prop="sjfw" label="涉及范围" >
             <template slot-scope="scope">
              <el-button v-if="scope.row.sjfw==0" @click="confingview(scope.row)" type="primary" size="mini">配置</el-button>
              <el-button v-if="scope.row.sjfw==1" type="primary" size="mini">查看</el-button>
             </template>
            </el-table-column> &ndash;&gt;
            <el-table-column align="center" prop="caozuo" label="操作">
              <template slot-scope="scope">
                <el-button
                  type="primary"
                  size="mini"
                  @click="getInfo(scope.row.id)"
                  >查看</el-button
                >
                <el-button
                  v-if="scope.row.status === 0"
                  type="primary"
                  size="mini"
                  @click="edit(scope.row.id)"
                  >修改</el-button
                >
                <el-button
                  v-if="scope.row.status !== 1"
                  type="primary"
                  size="mini"
                  @click="deleteData(scope.row.id)"
                  >删除</el-button
                >
                <el-button
                  v-if="scope.row.status === 0"
                  type="primary"
                  @click="startAirStrategy(scope.row.id)"
                  size="mini"
                  >执行</el-button
                >
                <el-button
                  v-if="scope.row.status === 1"
                  type="primary"
                  @click="stopAirStrategy(scope.row.id)"
                  size="mini"
                  >停止</el-button
                >
                <el-button
                  v-if="scope.row.status === 2"
                  @click="querydata(scope.row)"
                  type="primary"
                  size="mini"
                  >趋势查看
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>-->
        <el-tab-pane label="关机策略" name="1">
          <el-table
            stripe
            :data="tableData"
            :style="'width: 100%;height:' + tableheight + 'px'"
            :height="tableheight + 'px'"
            row-key="id"
            id="rebateSetTable"
            border
            style="width: 100%"
          >
            <el-table-column
              width="80"
              align="center"
              type="index"
              prop="index"
              label="序号"
            ></el-table-column>
            <el-table-column
              width="200"
              align="center"
              prop="name"
              label="策略名称"
            ></el-table-column>
            <el-table-column
              width="200"
              align="center"
              prop="type"
              label="策略类型"
            >
              <template slot-scope="scope">
                <el-tag
                  type="danger"
                  size="small"
                  v-if="scope.row.type === 1"
                  style="color: red"
                  >开机策略</el-tag
                >
                <el-tag
                  type="primary"
                  size="small"
                  v-if="scope.row.type === 2"
                  style="color: green"
                  >关机策略</el-tag
                >
              </template>
            </el-table-column>
<!--            <el-table-column
              align="center"
              prop="times"
              label="每日执行时间"
              width="150"
            >
              <template slot-scope="scope">
                <span type="primary" size="small">{{
                  scope.row.startTime
                }}</span>
              </template>
            </el-table-column>-->
            <el-table-column
              width="150"
              align="center"
              prop="model"
              label="模式"
            >
              <template slot-scope="scope">
                <span type="primary" size="small">{{
                  modeFormat(scope.row.mode)
                }}</span>
              </template>
            </el-table-column>
            <el-table-column
              width="150"
              align="center"
              prop="temperature"
              label="温度(°C)"
            ></el-table-column>
            <el-table-column
              width="150"
              align="center"
              prop="wind"
              label="风速"
            >
              <template slot-scope="scope">
                <span type="primary" size="small">{{
                  windFormat(scope.row.wind)
                }}</span>
              </template>
            </el-table-column>
            <el-table-column
              width="150"
              align="center"
              prop="wind"
              label="状态"
            >
              <template slot-scope="scope">
                <span type="primary" size="small">{{
                  statusGet(scope.row.status)
                }}</span>
              </template>
            </el-table-column>
            <!-- <el-table-column align="center" prop="sjfw" label="涉及范围" >
             <template slot-scope="scope">
              <el-button v-if="scope.row.sjfw==0" @click="confingview(scope.row)" type="primary" size="mini">配置</el-button>
              <el-button v-if="scope.row.sjfw==1" type="primary" size="mini">查看</el-button>
             </template>
            </el-table-column> -->
            <el-table-column align="center" prop="caozuo" label="操作">
              <template slot-scope="scope">
                <el-button
                  type="primary"
                  size="mini"
                  @click="getInfo(scope.row.id)"
                  >查看</el-button
                >
                <el-button
                  v-if="scope.row.status === 0"
                  type="primary"
                  size="mini"
                  @click="edit(scope.row.id)"
                  >修改</el-button
                >
<!--                <el-button
                  v-if="scope.row.status !== 1"
                  type="primary"
                  size="mini"
                  @click="deleteData(scope.row.id)"
                  >删除</el-button
                >
                <el-button
                  v-if="scope.row.status === 0"
                  type="primary"
                  @click="startAirStrategy(scope.row.id)"
                  size="mini"
                  >执行</el-button
                >
                <el-button
                  v-if="scope.row.status === 1"
                  type="primary"
                  @click="stopAirStrategy(scope.row.id)"
                  size="mini"
                  >停止</el-button
                >-->
                <el-button
                  v-if="scope.row.status === 2"
                  @click="querydata(scope.row)"
                  type="primary"
                  size="mini"
                  >趋势查看
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>
      </el-tabs>
    </el-col>

    <el-col style="margin-top: 10px; text-align: right">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageData.pageNum"
        :page-sizes="[10, 20, 25, 30, 50]"
        :page-size="pageData.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pageData.total"
      >
      </el-pagination>
    </el-col>

    <el-dialog
      :close-on-click-modal="false"
      title="趋势图查看"
      :visible.sync="dialogVisible"
      width="70%"
      :before-close="handleClose"
    >
      <el-row>
        <el-col :span="24">
          <div
            id="electri2"
            :style="
              'background:;width:100%;height:' +
              (tableheight - 200) +
              'px;'
            "
          ></div>
        </el-col>
      </el-row>
      <!-- <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
      class='setDialog'
      :close-on-click-modal="false"
      :title="'配置策略' + name"
      :visible.sync="dialogVisible2"
      width="800px"
      destroy-on-close
      :before-close="handleClose"
    >
      <el-form
        :model="ruleForm"
        ref="ruleForm"
        :rules="rules"
        label-width="120px"
        class="demo-ruleForm"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item label="策略名称:" prop="name">
              <el-input
                v-model="ruleForm.name"
                style="width: 100%"
                placeholder="请输入策略名称"
              ></el-input>
            </el-form-item>
            <el-form-item label="策略类型:" prop="type">
              <el-select
                v-model="ruleForm.type"
                style="width: 100%"
                :disabled="typeDisabled"
                placeholder="请输入策略名称"
                @change="selectChange"
              >
                <el-option
                  v-for="item in [
                    { name: '默认策略', value: 0 },
                    { name: '关机策略', value: 2 },
                    { name: '开机策略', value: 1 },
                  ]"
                  :disabled="item.value === 0 ? true : false"
                  :key="item.value"
                  :label="item.name"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
<!--            <el-form-item
              label="执行时间:"
              prop="valueTime"
              v-if="timeControl === 0"
            >
              <el-time-select
                style="width: 100%"
                v-model="valueTime"
                :picker-options="{
                  start: '08:30',
                  step: '00:01',
                  end: '23:30',
                }"
                placeholder="选择时间"
              >
              </el-time-select>
            </el-form-item>
            <el-form-item
              label="时间段:"
              prop="timeRange"
              v-if="timeControl === 1"
            >
              <el-date-picker
                style="width: 100%"
                v-model="ruleForm.timeRange"
                :picker-options="disabledDate"
                type="datetimerange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                format="yyyy-MM-dd HH:mm:ss"
                value-format="yyyy-MM-dd HH:mm:ss"
              >
              </el-date-picker>
            </el-form-item>-->
            <el-form-item label="模式:" prop="mode">
              <el-select
                v-model="ruleForm.mode"
                placeholder="请选择设备"
                style="width: 100%"
                :disabled="airDisabled"
              >
                <el-option label="制冷" value="ModeCool"></el-option>
                <el-option label="制热" value="ModeHeat"></el-option>
                <el-option label="送风" value="ModeSupplyAir"></el-option>
                <el-option label="除湿" value="ModeDry"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="温度:" prop="temperature">
              <el-select
                v-model="ruleForm.temperature"
                placeholder="请选择测点"
                style="width: 100%"
                :disabled="airDisabled"
              >
                <el-option label="16°C" :value="16"></el-option>
                <el-option label="17°C" :value="17"></el-option>
                <el-option label="18°C" :value="18"></el-option>
                <el-option label="19°C" :value="19"></el-option>
                <el-option label="20°C" :value="20"></el-option>
                <el-option label="21°C" :value="21"></el-option>
                <el-option label="22°C" :value="22"></el-option>
                <el-option label="23°C" :value="23"></el-option>
                <el-option label="24°C" :value="24"></el-option>
                <el-option label="25°C" :value="25"></el-option>
                <el-option label="26°C" :value="26"></el-option>
                <el-option label="27°C" :value="27"></el-option>
                <el-option label="28°C" :value="28"></el-option>
                <el-option label="29°C" :value="29"></el-option>
                <el-option label="30°C" :value="30"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="风速:" prop="wind">
              <el-select
                v-model="ruleForm.wind"
                placeholder="请选择设备"
                style="width: 100%"
                :disabled="airDisabled"
              >
                <el-option label="低档" value="SpeedLow"></el-option>
                <el-option label="中低档" value="SpeedMidLow"></el-option>
                <el-option label="中档" value="SpeedMid"></el-option>
                <el-option label="中高档" value="SpeedMidHigh"></el-option>
                <el-option label="高档" value="SpeedHigh"></el-option>
                <el-option label="强劲风" value="SpeedStrong"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="排序:" prop="sort">
              <el-input v-model="ruleForm.sort" style="width: 100%"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="涉及范围:">
              <el-input
                style="width: 100%"
                placeholder="输入关键字进行过滤"
                v-model="filterText"
              >
              </el-input>
              <el-form-item prop="dataTree">
                <el-tree
                  style="width: 100%; height: 50vh; overflow: scroll"
                  :data="dataTree"
                  show-checkbox
                  node-key="lineId"
                  ref="tree"
                  class="filter-tree"
                  default-expand-all
                  highlight-current
                  :filter-node-method="filterNode"
                  :props="defaultProps"
                >
                </el-tree>
              </el-form-item>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button v-if="submitDisabled" type="primary" @click="submit()"
          >保 存</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { getappheight, getheight } from "../../../assets/commjs/common";
import api from "@/api/energy/sysconfig.js";
import echarts from "echarts";
import runningstate from "@/views/components/runningstate";
import fa from "@/components/HighLevelSearchForm/components/transfer/locale/lang/fa";

export default {
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val);
    },

    activeName(val) {
      if (val === "0") {
        this.airDisabled = false;
        this.timeControl = 1;
        this.typeDisabled = true;
      } else {
        this.airDisabled = true;
        this.timeControl = 0;
        this.typeDisabled = false;
      }
    },
  },
  data() {
    return {
      activeName: "1", //0 默认测试策略 1 开关机策略
      device: 1,
      name: "",
      filterText: "",
      tableheight: undefined,
      tableData: [],
      dialogVisible: false,
      dialogVisible2: false,
      loading: false,

      ydata1: [],
      ydata2: [],
      ydata3: [],

      ruleForm: {
        name: "",
        timeRange: [],
        mode: "ModeCool",
        temperature: 26,
        wind: "SpeedMid",
        sort: 0,
        date: "",
        type: 0,
      },

      submitDisabled: true, //提交按钮
      typeDisabled: true,
      airDisabled: true, //模式调节失效控制标识

      timeControl: 1,

      valueTime: "",
      pageData: {
        pageNum: 1,
        pageSize: 20,
        total: 0,
      },
      queryParam: {
        searchValue: undefined,
      },
      operatorFlag: 0, //0.新增 1.修改
      dataTree: [],
      defaultProps: {
        children: "children",
        label: "name",
      },
      // 表单校验
      rules: {
        name: [{ required: true, message: "名称不能为空", trigger: "blur" }],
        type: [
          { required: true, message: "策略类型不能为空", trigger: "blur" },
        ],
        timeRange: [
          { required: true, message: "时间范围不可为空", trigger: "blur" },
        ],
        mode: [
          { required: true, message: "空调模式不可为空", trigger: "blur" },
        ],
        temperature: [
          { required: true, message: "空调温度不可为空", trigger: "blur" },
        ],
        wind: [
          { required: true, message: "空调风速不可为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getPageList();
    this.getAirLineTree();
  },
  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') - 190
  },
  methods: {
    //策略类型切换事件
    selectChange() {
      if (this.ruleForm.type === 1) {
        this.airDisabled = true;
      } else {
        this.airDisabled = false;
      }
    },

    //tabs点击事件
    handleClick(tab, event) {
      this.tableData = [];
      if (this.activeName === 0) {
        this.ruleForm.type = 0;
        this.airDisabled = false;
        this.resetQuery();
      } else {
        this.ruleForm.type = 1;
        this.airDisabled = true;
        this.resetQuery();
      }
    },

    filterNode(value, dataTree) {
      if (!value) return true;
      return dataTree.name.indexOf(value) !== -1;
    },
    //处理
    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;
    },

    Add() {
      this.name = "新增";
      this.operatorFlag = 0;
      this.dialogVisible2 = true;

      if (this.activeName === "0") {
        this.typeDisabled = true;
        this.ruleForm.type = 0;
        this.timeControl = 1;
        this.airDisabled = false;
      } else {
        this.typeDisabled = false;
        this.ruleForm.type = 1;
        this.timeControl = 0;
        this.airDisabled = true;
      }
    },
    //趋势图查看触发事件
    querydata(row) {
      this.dialogVisible = true;

      this.getAirTendencyForIds(row);
      /* this.$nextTick(() => {
        this.electritypeEcharts1()
      })*/
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getPageList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.$refs["queryForm"].resetFields();
      this.getPageList();
    },
    //关闭弹出框
    handleClose() {
      this.dialogVisible = false;
      this.dialogVisible2 = false;
      this.submitDisabled = true;
    },
    //趋势图事件
    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, readOnly: false },
            //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",
              },
            },
          },
        ],
      };

      option && myChart.setOption(option, true)
window.echartsArr.push(myChart);
    },
    //配置事件
    confingview(row) {
      this.dialogVisible2 = true;
    },
    edit(id) {
      this.dialogVisible2 = true;
      this.name = "修改";
      this.operatorFlag = 1;
      this.getAirStrategyInfo(id);
    },

    getInfo(id) {
      this.dialogVisible2 = true;
      this.name = "查看详情";
      this.operatorFlag = 1;
      this.submitDisabled = false;
      this.getAirStrategyInfo(id);
    },

    startAirStrategy(id) {
      api.startAirStrategy(id).then((response) => {
        if (response.code === "A0000") {
          this.$message({
            type: "info",
            message: "执行成功",
          });
          this.getPageList();
        }
      });
    },
    deleteData(id) {
      this.$confirm("确认删除吗?", {
        distinguishCancelAndClose: true,
        confirmButtonText: "确认",
        cancelButtonText: "取消",
      })
        .then(() => {
          api.delAirStrategy(id).then((response) => {
            if (response.code === "A0000") {
              this.$message({
                type: "info",
                message: "删除成功",
              });
              this.getPageList();
            }
          });
        })
        .catch((action) => {});
    },

    //提交按钮
    submit() {
      this.$refs["ruleForm"].validate((valid) => {
        if (valid) {
          let arr = this.$refs.tree.getCheckedKeys(true);
          if (arr.length === 0) {
            this.$message({ message: "监测点不可为空", type: "warning" });
            return;
          }

          let obj = {
            name: this.ruleForm.name,
            startTime: this.ruleForm.timeRange[0],
            endTime: this.ruleForm.timeRange[1],
            mode: this.ruleForm.mode,
            temperature: this.ruleForm.temperature,
            wind: this.ruleForm.wind,
            sort: this.ruleForm.sort,
            lineIds: arr,
            type: this.ruleForm.type,
          };

          if (this.activeName === "1") {
            obj.startTime = this.valueTime;
            obj.endTime = this.valueTime;
          }

          if (this.operatorFlag === 1) {
            //修改
            obj.id = this.ruleForm.id;
            api.updateAirStrategy(obj).then((response) => {
              if (response.code === "A0000") {
                this.$message({ message: "修改成功", type: "success" });
                this.dialogVisible2 = false;
                this.getPageList();
              }
            });
          } else {
            //新增
            api.addAirStrategy(obj).then((response) => {
              if (response.code === "A0000") {
                this.$message({ message: "新增成功", type: "success" });
                this.dialogVisible2 = false;
                this.getPageList();
              }
            });
          }
        }
      });
    },

    //查询列表
    getPageList() {
      this.loading = true;
      this.queryParam.type = this.activeName;
      api.listAirStrategy(this.queryParam).then((response) => {
        if (response.code === "A0000") {
          this.tableData = response.data.records;
          this.pageData.total = response.data.total;
          this.pageData.pageSize = response.data.size;
          this.pageData.pageNum = response.data.current;
          this.loading = false;
        }
      });
    },

    //不可选日期
    disabledDate(time) {
      return time.getTime() > Date.now();
    },

    //分页
    handleSizeChange(val) {
      this.pageData.pageSize = val;
      this.getPageList();
    },
    handleCurrentChange(val) {
      this.pageData.pageNum = val;
      this.getPageList();
    },

    panduanStop(row) {
      let dateStart = row.startTime;
      dateStart = dateStart.substring(0, 19);
      dateStart = dateStart.replace(/-/g, "/");
      let timestampStart = new Date(dateStart).getTime();
      let dateNew = new Date(timestampStart);

      let date = row.endTime;
      date = date.substring(0, 19);
      date = date.replace(/-/g, "/");
      let timestamp = new Date(date).getTime();
      let dateOld = new Date(timestamp);

      console.log(new Date() >= dateNew && new Date() <= dateOld);
      return new Date() >= dateNew && new Date() <= dateOld;
    },

    modeFormat(val) {
      switch (val) {
        case "ModeCool":
          return "制冷";
          break;
        case "ModeHeat":
          return "制热";
          break;
        case "ModeDry":
          return "除湿";
          break;
        case "ModeSupplyAir":
          return "送风";
          break;
      }
    },
    windFormat(val) {
      switch (val) {
        case "SpeedLow":
          return "低档";
          break;
        case "SpeedMidLow":
          return "中低档";
          break;
        case "SpeedMid":
          return "中档";
          break;
        case "SpeedMidHigh":
          return "中高档";
          break;
        case "SpeedHigh":
          return "高档";
          break;
        case "SpeedStrong":
          return "强劲风";
          break;
      }
    },
    statusGet(val) {
      switch (val) {
        case 0:
          return "待执行";
          break;
        case 1:
          return "执行中";
          break;
        case 2:
          return "执行成功";
          break;
        case 3:
          return "执行失败";
          break;
        case 4:
          return "停止";
          break;
      }
    },

    //获取空调监测点树

    getAirLineTree() {
      api.getAirLineTree().then((response) => {
        if (response.code === "A0000") {
          let data = [
            {
              name: "空调管理",
              id: "0",
              level: 1,
              lineId: null,
              pid: null,
              sort: null,
              state: null,
              children: [],
            },
          ];
          data[0].children = response.data;
          this.dataTree = data;
        }
      });
    },

    getAirTendencyForIds(row) {
      let data = {
        startTime: row.startTime,
        endTime: row.endTime,
      };

      api.getAirTendency(data).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);
              } 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();
        }
      });
    },

    getAirStrategyInfo(id) {
      api.getAirStrategyInfo(id).then((response) => {
        if (response.code === "A0000") {
          let time = [];
          this.ruleForm.id = response.data.id;
          this.ruleForm.name = response.data.name;
          this.ruleForm.mode = response.data.mode;
          this.ruleForm.temperature = response.data.temperature;
          this.ruleForm.wind = response.data.wind;
          this.ruleForm.type = response.data.type;
          time.push(response.data.startTime);
          time.push(response.data.endTime);
          this.ruleForm.timeRange = time;
          this.ruleForm.sort = response.data.sort;
          this.$refs.tree.setCheckedKeys(response.data.lineIds, true);
        }
      });
    },

    stopAirStrategy(id) {
      this.$confirm("此操作不会影响已经执行的任务", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        api.stopAirStrategy(id).then((response) => {
          if (response.code === "A0000") {
            this.$message({
              type: "info",
              message: "执行成功",
            });
            this.getPageList();
          }
        });
      });
    },
  },
};
</script>
<style scoped lang='scss'>
.ui-container {
  padding: 30px;
  height: 100%;
  width: 100%;
}

</style>
