<template>
  <!-- 总目标 -->
  <div class="">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="线路名称" prop="electLineName">
        <el-input
          v-model="queryParams.electLineName"
          placeholder="请输入线路名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="主分支名称" prop="branchName" label-width="100px">
        <el-input
          v-model="queryParams.branchName"
          placeholder="请输入主分支名称"
          clearable
          @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>
    <el-row :gutter="10" class="mb8">
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <div class="table">
      <el-table ref="renewalTable" v-loading="loading" :data="dataList">
        <el-table-column
          label="事件序号"
          align="center"
          prop="eventNo"
          width="100"
          fixed
        >
          <template slot-scope="scope">
            <a
              style="color: #00afff; cursor: pointer"
              @click="handleDetail(scope.row)"
              >{{ scope.row.eventNo }}</a
            >
          </template>
        </el-table-column>
        <el-table-column
          label="线路名称"
          align="center"
          prop="electLineName"
          :show-overflow-tooltip="true"
          width="160"
          fixed
        />
        <el-table-column
          label="主分支名称"
          align="center"
          prop="branchName"
          :show-overflow-tooltip="true"
          width="120"
          fixed
        />
        <el-table-column
          label="数据状态"
          align="center"
          prop="dataStatus"
          fixed
        />
        <el-table-column
          label="推送状态"
          align="center"
          prop="pushStatus"
          fixed
        />
        <el-table-column
          label="是否可维护"
          align="center"
          prop="isMaintainable"
          width="100"
          fixed
        />
        <el-table-column
          label="是否纯专变"
          align="center"
          prop="isPureSpecia"
          width="100"
          fixed
        />
        <el-table-column
          label="事件类型"
          align="center"
          prop="eventType"
          fixed
        />
        <el-table-column
          label="停电起始时间"
          align="center"
          prop="powerOutageStart"
          width="180"
          fixed
        >
        </el-table-column>
        <el-table-column
          label="停电终止时间"
          align="center"
          prop="powerOutageEnd"
          width="180"
          fixed
        >
        </el-table-column>
        <el-table-column
          label="可靠性停电时户数"
          align="center"
          prop="powerOutageDuringHouseholds"
          width="100"
        />
        <el-table-column
          label="研判停电性质"
          align="center"
          prop="powerOutageNature"
          width="100"
        />
        <el-table-column
          label="所属市公司"
          align="center"
          prop="city"
          width="150"
        />
        <el-table-column
          label="所属县公司"
          align="center"
          prop="county"
          width="150"
        />
        <el-table-column
          label="所属供电所"
          align="center"
          prop="station"
          width="150"
        />
        <el-table-column label="单位编码" align="center" prop="oranNo" />
        <el-table-column
          label="变电站名称"
          align="center"
          prop="substationName"
          width="100"
        />
        <el-table-column
          label="停电户次数"
          align="center"
          prop="powerOutageHouseholds"
        />
        <el-table-column
          label="停电线次数"
          align="center"
          prop="powerOutageLine"
        />
        <el-table-column
          label="目标时户数"
          align="center"
          prop="powerOutageLine"
        />
        <el-table-column
          label="时户数差异"
          align="center"
          prop="powerOutageLine"
        />
      </el-table>
      <pagination
        class="page-box"
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <!-- 详情 -->
    <DetailsDrawer ref="detailRef" />
  </div>
</template>

<script>
import DetailsDrawer from "./DetailsDrawer.vue";
import { listMaintenanceStatistics } from "@/api/powerdistribution/maintenance";
export default {
  components: {
    DetailsDrawer,
    // InputReasonModel,
  },
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      dataList: [],
      // 遮罩层
      loading: true,
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        eventNo: null,
        electLineName: null,
        branchName: null,
        dataStatus: null,
        pushStatus: null,
        isMaintainable: null,
        isPureSpecia: null,
        eventType: null,
        powerOutageStart: null,
        powerOutageEnd: null,
        powerOutageDuringHouseholds: null,
        powerOutageNature: null,
        city: null,
        county: null,
        station: null,
        oranNo: null,
        substationName: null,
        powerOutageHouseholds: null,
        powerOutageLine: null,
        faultFreeDuration: null,
        rewardAmount: null,
      },
      // 选中数组
      selectedRows: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 多选框选中数据
    handleSelectionChange(selectedRows) {
      if (selectedRows.length > 1) {
        // 只保留最新选择的项
        this.$refs.renewalTable.clearSelection();
        this.$refs.renewalTable.toggleRowSelection(
          selectedRows[selectedRows.length - 1]
        );
      }
      // 记录选择的行
      this.selectedRows = selectedRows[selectedRows.length - 1]
        ? [selectedRows[selectedRows.length - 1]]
        : [];
    },
    // 详情
    handleDetail(row) {
      this.$refs.detailRef.openModel({ ...row });
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      listMaintenanceStatistics({
        ...this.queryParams,
      }).then((response) => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.pageNum = 1;
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>
<style lang="scss" scoped>
.table {
  height: calc(100% - 150px);
}
::v-deep {
  .el-table {
    height: 100%;
    width: 100%;
    .el-table__body-wrapper {
      width: 100% !important;
      height: calc(100% - 50px) !important; // 表格高度减去表头的高度
      overflow-y: scroll;
    }
  }
}
</style>
