<template>
  <div>
    <el-form :inline="true" :model="form" class="demo-form-inline">
      <el-form-item class="box">
        <Area @click="handleNodeClick" ref="area"></Area>
      </el-form-item>

      <el-form-item>
        <Timeinterval :interval="1" ref="interval"></Timeinterval>
      </el-form-item>

      <el-form-item label="电压等级:" class="box">
        <el-select
          v-model.trim="form.valueLevel"
          placeholder="请选择"
          clearable
          multiple
          collapse-tags
        >
          <el-option
            v-for="item in VoltageList"
            :key="item.code"
            :label="item.name"
            :value="item.code"
          >
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="监测点类别:" class="box">
        <el-select
          v-model.trim="form.valueMonitor"
          placeholder="请选择"
          clearable
        >
          <el-option
            v-for="item in category"
            :key="item.value"
            :label="item.label"
            :value="item.label"
          >
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="监测点:" class="box">
        <el-input
          v-model.trim="form.valuePoint"
          placeholder="请输入"
          clearable
        ></el-input>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          @click="onSubmit"
          class="ml10"
          icon="el-icon-search"
          >查询</el-button
        >
        <el-button type="primary" icon="el-icon-download">导出</el-button>
      </el-form-item>
      <el-table
        stripe
        :data="
          detailedData.slice(
            (currentPage - 1) * pageSize,
            currentPage * pageSize
          )
        "
        :height="vh"
        border
        style="width: 100%"
        v-loading="isLoading"
        header-cell-class-name="table_header"
        :cell-style="cellStyle"
      >
        <template v-for="(item, index) in tableHeaderDetailed">
          <el-table-column
            :prop="item.prop"
            :label="item.label"
            :key="index"
            :width="item.width"
          >
          </el-table-column>
        </template>
      </el-table>
      <el-pagination
        background
        align="right"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[20, 30, 40, 50, 100]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="detailedData.length"
        class="mt10"
      >
      </el-pagination>
    </el-form>
  </div>
</template>
<script>
import { getStatisticsData } from "@/api/TransientStateIndex";
import { dicData } from "@/assets/commjs/dictypeData";
import Area from "@/views/components/Area/Area.vue";
import Timeinterval from "@/views/components/Timeinterval.vue";
export default {
  components: { Area, Timeinterval },
  data() {
    return {
      vh: undefined,
      date: "",
      input: "",
      height: null,
      form: {
        valueMonitor: "", //监测点类别
        valueLevel: "", //电压等级
        valuePoint: "", //监测点
      },
      //监测点类别数据
      category: [
        {
          value: "选项1",
          label: "Ⅰ类监测点",
        },
        {
          value: "选项2",
          label: "Ⅱ类监测点",
        },
        {
          value: "选项3",
          label: "Ⅲ类监测点",
        },
      ],
      VoltageList: [], //电压等级数据
      isLoading: false,
      //暂态事件统计
      tableHeaderDetailed: [
        { prop: "company", label: "单位" },
        { prop: "substation", label: "所属变电站" },
        { prop: "stationArea", label: "所属台区" },
        { prop: "userName", label: "用户名称" },
        { prop: "monitoringPoint", label: "监测点类别" },
        { prop: "voltageLevel", label: "监测点电压等级(kV)" },
        { prop: "monitoringName", label: "监测点名称" },
        { prop: "eventMonitoring", label: "当月暂态事件总次数" },
        { prop: "sagMonitoring", label: "当月暂降事件总次数" },
        { prop: "tagMonitoring", label: "当月暂升事件总次数" },
        { prop: "spdMonitoring", label: "当月中断事件总次数" },
      ],
      detailedData: [],
      device: "",
      currentPage: 1, // 当前页码
      total: 20, // 总条数
      pageSize: 20, // 每页的数据条数
    };
  },
  created() {
    this.getclassificationData();
  },
  mounted() {
    this.device = window.devicePixelRatio;
    this.vh = document.getElementById("app-main-in").offsetHeight - 165;
    this.onSubmit();
  },
  methods: {
    //获取统计类型
    getclassificationData() {
      var code = "Dev_Voltage";
      this.classificationData = dicData(code, []);
      this.VoltageList = this.classificationData;
    },
    //每页条数改变时触发 选择一页显示多少行
    handleSizeChange(val) {
      this.currentPage = 1;
      this.pageSize = val;
    },
    //当前页改变时触发 跳转其他页
    handleCurrentChange(val) {
      this.currentPage = val;
    },
    onSubmit() {
      this.isLoading = true;
      this.detailedData = [];
      getStatisticsData().then((res) => {
        // console.log("监测点暂态事件统计:", res);
        this.isLoading = false;
        this.detailedData = res.data;
      });
    },
    // 切换选项
    handleNodeClick(data) {
      // console.log(data);
    },
    cellStyle(row) {
      // console.log(row);
      if (
        row.row.monitoringPoint == "Ⅱ类监测点" ||
        row.row.monitoringPoint == "Ⅲ类监测点"
      ) {
        row.row.substation = "/";
      }
      if (
        row.row.monitoringPoint == "Ⅰ类监测点" ||
        row.row.monitoringPoint == "Ⅲ类监测点"
      ) {
        row.row.stationArea = "/";
      }
      if (
        row.row.monitoringPoint == "Ⅰ类监测点" ||
        row.row.monitoringPoint == "Ⅱ类监测点"
      ) {
        row.row.userName = "/";
      }
    },
  },
};
</script>

<style lang="less" scoped>
@import url("../../../../styles/comStyle.less");
/deep/.el-table .cell {
  text-align: center;
}
/deep/.el-tabs--border-card > .el-tabs__content {
  padding: 10px;
}
/deep/.el-row {
  width: 100%;
}
/deep/.box {
  .el-input {
    width: 150px;
  }
}
/deep/.el-form-item--small.el-form-item {
  margin-bottom: 0;
}
/deep/.form {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  .el-form-item {
    display: flex;
    width: 48%;
    .el-form-item__content {
      flex: 1 !important;
      .el-select {
        width: 100%;
      }
      .el-input__inner {
        width: 100% !important;
      }
      .el-date-editor {
        width: 100%;
      }
    }
  }
}
/deep/.el-table__body-wrapper.is-scrolling-none {
  height: 605px !important;
}
</style>