<template>
  <!-- 时长分析 -->
  <div class="app-container scroll-auto">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="线路名称" prop="lineNm">
        <el-input
          v-model="queryParams.lineNm"
          placeholder="请输入线路名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="数据状态" prop="excpStDsc">
        <el-input
          v-model="queryParams.excpStDsc"
          placeholder="请输入"
          clearable
        />
      </el-form-item>
      <el-form-item label="推送状态" prop="pushStDsc">
        <el-input
          v-model="queryParams.pushStDsc"
          placeholder="请输入"
          clearable
        />
      </el-form-item>
      <el-form-item label="研判停电性质" prop="judgePoweroffNatureDsc">
        <el-select
          v-model="queryParams.judgePoweroffNatureDsc"
          placeholder="请选择"
          clearable
        >
          <el-option
            v-for="item in judgePoweroffNatureDscList"
            :key="item.dictLabel"
            :label="item.dictLabel"
            :value="item.dictLabel"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="是否可维护" prop="isEdit">
        <el-select v-model="queryParams.isEdit" placeholder="请选择" clearable>
          <el-option label="是" value="1"> </el-option>
          <el-option label="否" value="0"> </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="是否纯专变" prop="isPrivEvent">
        <el-select
          v-model="queryParams.isPrivEvent"
          placeholder="请选择"
          clearable
        >
          <el-option label="是" value="1"> </el-option>
          <el-option label="否" value="0"> </el-option>
        </el-select>
      </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">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          :disabled="!selectedRows.length"
          @click="handleInput(selectedRows[0], '录入原因')"
          >录入原因</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <div class="table">
      <el-table
        style="width: 100%"
        :max-height="500"
        ref="renewalTable"
        v-loading="loading"
        :data="dataList"
        @selection-change="handleSelectionChange"
        :row-class-name="tableRowClassName"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column
          label="事件序号"
          align="center"
          prop="eventSn"
          width="100"
          fixed
        >
          <template slot-scope="scope">
            <a
              style="color: #00afff; cursor: pointer"
              @click="handleDetail(scope.row)"
              >{{ scope.row.eventSn }}</a
            >
          </template>
        </el-table-column>
        <el-table-column
          label="线路名称"
          align="center"
          prop="lineNm"
          :show-overflow-tooltip="true"
          width="160"
          fixed
        />
        <el-table-column
          label="数据状态"
          align="center"
          prop="excpStDsc"
          fixed
        />
        <el-table-column
          label="推送状态"
          align="center"
          prop="pushStDsc"
          :show-overflow-tooltip="true"
          fixed
        />
        <el-table-column
          label="是否可维护"
          align="center"
          prop="isEdit"
          width="100"
          fixed
        >
          <template slot-scope="scope">
            <el-tag v-if="scope.row.isEdit == '1'">是</el-tag>
            <el-tag v-else>否</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="是否纯专变"
          align="center"
          prop="isPrivEvent"
          width="100"
          fixed
        >
          <template slot-scope="scope">
            <el-tag v-if="scope.row.isPrivEvent == '1'">是</el-tag>
            <el-tag v-else>否</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="事件类型"
          align="center"
          prop="endEventTypDsc"
          width="100"
          fixed
        ></el-table-column>
        <el-table-column
          label="停电起始时间"
          align="center"
          prop="poweroffStartTm"
          :show-overflow-tooltip="true"
          width="120"
          fixed
        >
        </el-table-column>
        <el-table-column
          label="停电终止时间"
          align="center"
          prop="poweroffTermTm"
          :show-overflow-tooltip="true"
          width="120"
          fixed
        >
        </el-table-column>
        <el-table-column
          label="停电时户数"
          align="center"
          prop="hourNum"
          width="100"
        />
        <el-table-column
          label="研判停电性质"
          align="center"
          prop="judgePoweroffNatureDsc"
          width="140"
        >
        </el-table-column>
        <el-table-column
          label="所属市公司"
          align="center"
          prop="stdCityOrgNm"
          width="150"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="所属县公司"
          align="center"
          prop="stdCountyOrgNm"
          :show-overflow-tooltip="true"
          width="150"
        />
        <el-table-column
          label="单位编码"
          align="center"
          prop="orgNo"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="变电站名称"
          align="center"
          prop="subsNm"
          width="100"
        />
        <el-table-column
          label="停电户次数"
          align="center"
          prop="householdNum"
          width="90"
        />
        <el-table-column
          label="停电线次数"
          align="center"
          prop="lineNum"
          width="90"
        />
        <el-table-column
          label="停电原因"
          align="center"
          prop="stopReason"
          width="200"
          :show-overflow-tooltip="true"
        />
      </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" />
    <!-- 录入原因 -->
    <InputReasonModel ref="inputReasonRef" @refresh="getList" />
  </div>
</template>

<script>
import DetailsDrawer from "./components/DetailsDrawer.vue";
import InputReasonModel from "./components/InputReasonModel.vue";
import { stopRecordlist } from "@/api/powerdistribution/power-outage-control";
export default {
  components: {
    DetailsDrawer,
    InputReasonModel,
  },
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      dataList: [],
      // 遮罩层
      loading: true,
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        eventSn: null,
        lineNm: null,
        judgePoweroffNatureDsc: null,
        isEdit: null,
        excpStDsc: null,
        pushStDsc: null,
        isPrivEvent: null,
      },
      // 选中数组
      selectedRows: [],
      // 研判停电类型
      judgePoweroffNatureDscList: [],
    };
  },
  created() {
    this.getjudgePoweroffNatureDscList();
    this.getList();
  },
  methods: {
    // 风险类型
    async getjudgePoweroffNatureDscList() {
      const { data } = await this.getDicts("stop_type");
      this.judgePoweroffNatureDscList = data;
    },
    //标红table指定行
    tableRowClassName({ row, rowIndex }) {
      if (row.judgePoweroffNatureDsc == 1) {
        return "warning-row";
      }
      return "";
    },
    // 多选框选中数据
    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]]
        : [];
    },
    /**录入原因*/
    handleInput(row) {
      this.$refs.inputReasonRef.openModel({ ...row });
    },
    // 详情
    handleDetail(row) {
      this.$refs.detailRef.openModel({ ...row });
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      stopRecordlist({
        ...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();
    },
    // handleChange(file) {
    //   let data = new FormData();
    //   data.append("file", file.raw);
    //   importF(data).then((res) => {
    //     if (res.code == 200) {
    //       this.$message.success("导入成功");
    //       this.$emit("refresh");
    //     } else {
    //       this.$message.error("导入失败" || res.msg);
    //     }
    //   });
    // },
  },
};
</script>
<style lang="scss" scoped>
.table {
  height: calc(100% - 180px);
}
::v-deep {
  // .el-table {
  //   height: 100%;
  //   width: 100%;
  //   .el-table__body-wrapper {
  //     z-index: 2;
  //     width: 100% !important;
  //     height: calc(100% - 50px) !important; // 表格高度减去表头的高度
  //     overflow-y: auto;
  //   }
  // }
  .el-table .warning-row {
    color: #f51f1f !important;
  }
}
</style>
