<template>
  <div class="manage-container">
    <div class="manage-input">
      <el-form ref="queryForm" :model="queryForm" label-width="80px">
        <vab-query-form>
          <el-form-item width="330" prop="type" label="站点">
            <el-cascader
              v-model="queryForm.device"
              :options="deviceData"
              :props="{
                value: 'id',
                label: 'name',
                children: 'deviceList',
              }"
              clearable
              filterable
              @change="changeDevice"
            ></el-cascader>
          </el-form-item>
          <el-form-item width="100" prop="time" label="日期">
            <el-date-picker
              v-model="queryForm.time"
              size="small"
              type="daterange"
              align="right"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              @change="changeTime"
            ></el-date-picker>
          </el-form-item>
        </vab-query-form>
      </el-form>
    </div>
    <div class="manage-button">
      <el-form-item width="100">
        <el-button size="small" @click="resetForm()">重置</el-button>
        <el-button type="primary" size="small" @click="search">查询</el-button>
      </el-form-item>
    </div>
    <el-table
      id="table"
      v-loading="listLoading"
      :data="tableData"
      border
      stripe
      style="width: 100%"
    >
      <el-table-column
        prop="name"
        label="站点"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="风机指示灯-故障"
        label="风机指示灯-故障"
        align="center"
        sortable
      ></el-table-column>
      <el-table-column
        prop="电磁阀指示灯-故障"
        label="电磁阀指示灯-故障"
        align="center"
        sortable
      ></el-table-column>
      <el-table-column
        prop="水泵指示灯-故障"
        label="水泵指示灯-故障"
        align="center"
        sortable
      ></el-table-column>
      <el-table-column
        prop="抽水泵状态-故障"
        label="抽水泵状态-故障"
        align="center"
        sortable
      ></el-table-column>
      <el-table-column
        prop="站点离线"
        label="站点离线"
        align="center"
        sortable
      ></el-table-column>
      <el-table-column
        prop="风机状态-故障"
        label="风机状态-故障"
        align="center"
        sortable
      ></el-table-column>
      <el-table-column
        prop="加药泵指示灯-故障"
        label="加药泵指示灯-故障"
        align="center"
        sortable
      ></el-table-column>
      <el-table-column
        prop="水泵状态-故障"
        label="水泵状态-故障"
        align="center"
        sortable
      ></el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getFaultDetails, getProjectDeviceTree } from '@/api/operation';
import { getDate, getPastTime } from '@/common/times';
export default {
  data() {
    return {
      listLoading: true,
      title: '故障详情',
      tableData: [],
      deviceData: [],
      queryForm: {
        page: 1,
        size: 20,
        start: '',
        end: '',
        projectId: '',
        deviceId: '',
      },
    };
  },
  created() {
    this.getProjectDeviceTree();
    this.queryForm.start = this.$route.query.start;
    this.queryForm.end = this.$route.query.end;
    this.queryForm.projectId = this.$route.query.projectId;
    this.queryForm.deviceId = this.$route.query.deviceId;
    this.getFaultDetails();
  },
  methods: {
    // loadScript() {
    //   const row = this.$route.query.row;
    //   this.dialogFormVisible = true;
    //   this.queryForm.start = row.start;
    //   this.queryForm.end = row.end;
    //   this.queryForm.projectId = row.projectId;
    //   this.queryForm.deviceId = row.deviceId;
    //   this.getFaultDetails();
    // },
    changeTime() {
      this.queryForm.start = getDate(this.queryForm.time[0]);
      this.queryForm.end = getDate(this.queryForm.time[1]);
    },
    // 层级显示站点
    async getProjectDeviceTree() {
      const { data } = await getProjectDeviceTree();
      this.deviceData = data;
    },
    //搜索
    search() {
      this.getFaultDetails(this.queryForm);
    },
    resetForm() {
      this.$refs.queryForm.resetFields();
    },
    changeDevice(e) {
      this.queryForm.projectId = e[0];
      this.queryForm.deviceId = e[1];
    },
    async getFaultDetails() {
      const { data } = await getFaultDetails(this.queryForm);
      this.listLoading = false;
      this.tableData = data;
    },
  },
};
</script>

<style>
#mapContainer {
  width: 100%;
  height: 400px;
}
</style>
