<template>
  <div>
    <div class="query mg-b-8">
      <div class="query-items">
        <div class="query-item">
          <div class="lable">场站：</div>
          <div class="search-input">
            <el-select
              v-model="stationId"
              clearable
              placeholder="请选择"
              popper-class="select"
            >
              <el-option
                v-for="item in ChangZhan"
                :key="item.id"
                :value="item.id"
                :label="item.name"
              ></el-option>
            </el-select>
          </div>
        </div>
        <div class="query-item">
          <div class="lable">开始日期：</div>
          <div class="search-input">
            <el-date-picker
              v-model="startDate"
              type="datetime"
              placeholder="开始日期"
              popper-class="date-select"
              value-format="YYYY-MM-DD HH:mm:ss"
            ></el-date-picker>
          </div>
        </div>
        <div class="query-item">
          <div class="lable">结束日期：</div>
          <div class="search-input">
            <el-date-picker
              v-model="endDate"
              type="datetime"
              placeholder="开始日期"
              popper-class="date-select"
              value-format="YYYY-MM-DD HH:mm:ss"
            ></el-date-picker>
          </div>
        </div>
        <div class="query-item">
          <div class="lable">等级：</div>
          <div class="search-input">
            <el-select
              v-model="level"
              clearable
              placeholder="请选择"
              popper-class="select"
            >
              <el-option
                v-for="item in levelArray"
                :key="item.id"
                :value="item.id"
                :label="item.name"
              />
            </el-select>
          </div>
        </div>
        <div class="query-actions">
          <button class="btn green" @click="getTable()">查询</button>
          <button class="btn green" @click="exportExcel()">导出</button>
        </div>
      </div>
    </div>
    <div class="table-box">
      <div class="title">升压站报警</div>
      <ComTable
        ref="curRef"
        :data="tableData"
        :pageSize="20"
        @onPagging="onChangePage"
        height="73vh"
        v-loading="tableLoading"
        element-loading-text="拼命加载中.."
        element-loading-background="rgba(0, 0, 0, 0.8)"
      ></ComTable>
    </div>
  </div>
</template>
<script>
import ComTable from "@/components/coms/table/table.vue";

export default {
  name: "boosterAlarm",
  components: { ComTable },
  data() {
    let that = this;
    return {
      ChangZhan: [],
      levelArray: [
        {
          id: "",
          name: "请选择",
        },
        {
          id: "1",
          name: "低",
        },
        {
          id: "2",
          name: "中低",
        },
        {
          id: "3",
          name: "中",
        },
        {
          id: "4",
          name: "中高",
        },
        {
          id: "5",
          name: "高",
        },
      ],
      level: "",
      stationId: "MHS_FDC",
      startDate: "",
      endDate: "",
      tableLoading: true,
      pageIndex: 1,
      pageSize: 20,
      tableData: {
        column: [
          {
            name: "场站",
            field: "stationName",
            is_num: false,
            is_light: false,
            sortable: true,
            id: "id",
          },
          {
            name: "变电站",
            field: "",
            is_num: false,
            is_light: false,
            sortable: true,
            id: "id",
          },

          {
            name: "报警时间",
            field: "alertTime",
            is_num: false,
            is_light: false,
            sortable: true,
            id: "id",
          },
          {
            name: "报警描述",
            field: "alertText",
            is_num: false,
            is_light: false,
            sortable: true,
            id: "id",
          },
          {
            name: "处理方式",
            field: "",
            is_num: false,
            is_light: false,
            sortable: true,
            id: "id",
          },
        ],
        data: [],
        currentPageTotal: 0,
      },
    };
  },
  created() {
    this.ChangZhanVal();
    let end = new Date();
    let start = new Date(end.getTime() - 1 * 24 * 60 * 60 * 1000);
    this.endDate = end.formatDate("yyyy-MM-dd hh:mm:ss");
    this.startDate = start.formatDate("yyyy-MM-dd hh:mm:ss");
    this.getTable();
  },
  methods: {
    // 场站
    ChangZhanVal() {
      var that = this;
      that.API.requestData({
        method: "GET",
        baseURL: "http://10.155.32.4:9001/",
        subUrl: "benchmarking/wplist",
        success(res) {
          that.ChangZhan = res.data;
          that.stationId = res.data[0].id;
        },
      });
    },
    getTable() {
      let that = this;
      this.tableLoading = true;
      this.API.requestData({
        timeout: 30000,
        method: "GET",
        baseURL: "http://192.168.1.18:8075/",
        subUrl: "alarm/history/page2",
        data: {
          category1: "SYZ",
          stationid: this.stationId,
          starttime: this.startDate,
          endtime: this.endDate,
          pagenum: this.pageIndex,
          pagesize: this.pageSize,
          rank: that.level,
        },
        success(res) {
          that.tableData.data = res.data.records;
          that.tableLoading = false;
          that.tableData.total = res.data.total;
        },
      });
    },
    onChangePage(params) {
      this.pageIndex = params.pageIndex;
      this.pageSize = params.pageSize;
      this.getTable();
    },
    exportExcel() {
      this.BASE.exportExcel(this.tableData, "升压站报警");
    },
  },
};
</script>
<style scoped>
.title {
  background: rgba(255, 255, 255, 0.1);
  margin-bottom: 8px;
  padding: 1vh;
}
</style>