<template>
  <div class="app-container scroll-auto">
    <el-form
      ref="queryForm"
      :model="queryParams"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="作业类型" prop="opTypDsc">
        <el-select v-model="queryParams.opTypDsc" placeholder="请选择">
          <el-option
            v-for="(ite, i) in workTypeList"
            :key="i"
            :label="ite.dictLabel"
            :value="ite.dictLabel"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="专业类型" prop="majorTypDsc">
        <el-select v-model="queryParams.majorTypDsc" placeholder="请选择">
          <el-option
            v-for="(ite, i) in zyTypeList"
            :key="i"
            :label="ite.dictLabel"
            :value="ite.dictLabel"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="管理单位" prop="mgmtOrgNm">
        <el-input
          v-model="queryParams.mgmtOrgNm"
          placeholder="请输入"
        ></el-input>
      </el-form-item>
      <el-form-item label="作业班组" prop="workTeamNm">
        <el-input
          v-model="queryParams.workTeamNm"
          placeholder="请输入"
        ></el-input>
      </el-form-item>
      <el-form-item label="工作负责人" prop="workPrincipNm">
        <el-input
          v-model="queryParams.workPrincipNm"
          placeholder="请输入"
        ></el-input>
      </el-form-item>
      <el-form-item label="作业地址" prop="opAddr">
        <el-input v-model="queryParams.opAddr" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item label="作业风险" prop="opRiskLvlDsc">
        <el-input
          v-model="queryParams.opRiskLvlDsc"
          placeholder="请输入"
        ></el-input>
      </el-form-item>
      <el-form-item label="作业单位" prop="submitOrgNm">
        <el-select
          v-model="queryParams.submitOrgNm"
          placeholder="请选择"
          clearable
        >
          <el-option label="全部" value=""> </el-option>
          <el-option
            v-for="item in workUnitOptions"
            :key="item.organName"
            :label="item.organName"
            :value="item.organName"
          >
          </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="handleUpdate(selectedRows[0], '录入临时计划原因')"
          >录入临时计划原因</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <div class="table">
      <el-table
        ref="renewalTable"
        v-loading="loading"
        :data="dataList"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column prop="" label="序号" width="80" align="center">
          <template slot-scope="scope">
            {{
              scope.$index +
              (queryParams.pageNum - 1) * queryParams.pageSize +
              1
            }}
          </template>
        </el-table-column>
        <el-table-column
          label="作业内容"
          align="center"
          prop="opContent"
          :show-overflow-tooltip="true"
        >
          <template slot-scope="scope">
            <a
              @click="handleDetail(scope.row, '明细')"
              style="color: #00afff; cursor: pointer"
              >{{ scope.row.opContent }}</a
            >
          </template>
        </el-table-column>
        <el-table-column
          label="作业地址"
          align="center"
          prop="opAddr"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="线路/变电站"
          prop="subsOrLineNm"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          label="电压等级"
          prop="voltLvlDsc"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          label="作业类型"
          prop="opTypDsc"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          label="管理单位"
          prop="mgmtOrgNm"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          label="作业单位"
          prop="submitOrgNm"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          label="工作负责人"
          prop="workPrincipNm"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          label="作业班组"
          prop="workTeamNm"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          label="作业风险"
          prop="opRiskLvlDsc"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          label="作业人数"
          prop="mainBusiOrgOpNum"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          label="作业开始时间"
          prop="planStartWkTm"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          label="作业结束时间"
          prop="planEndTm"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column label="专业类型" align="center" prop="majorTypDsc">
        </el-table-column>
        <el-table-column
          label="临时计划原因"
          align="center"
          prop="planReason"
          :show-overflow-tooltip="true"
        />
        <!-- <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="handleUpdate(scope.row, '明细')"
              >明细</el-button
            >
          </template>
        </el-table-column> -->
      </el-table>
      <pagination
        class="page-box"
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <WorkPlanModel ref="workPlanModelRef" @refresh="getList()"></WorkPlanModel>
    <WorkPlanDetailModel ref="workPlanDetailModelRef"></WorkPlanDetailModel>
  </div>
</template>

<script>
import { getWorkPlanList } from "@/api/secure/pdm-work-plan";
import { getWorkUnitList } from "@/api/secure/daily-newspaper";
import WorkPlanModel from "../components/WorkPlanModel.vue";
import WorkPlanDetailModel from "../components/WorkPlanDetailModel.vue";
export default {
  components: { WorkPlanModel, WorkPlanDetailModel },
  data() {
    return {
      dataList: [],
      // 显示搜索条件
      showSearch: true,
      // 遮罩层
      loading: true,
      total: 0,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        opTypDsc: "",
        opTypDsc: "",
        mgmtOrgNm: "",
        workTeamNm: "",
        workPrincipNm: "",
        submitOrgNm: "",
        opRiskLvlDsc: "",
        opAddr: "",
        majorTypDsc: "",
        pageNum: 1,
        pageSize: 10,
      },
      planTypCd: "",
      // 选中数组
      selectedRows: [],
      // 作业类型
      workTypeList: [],
      // 专业类型
      zyTypeList: [],
      // 作业单位
      workUnitOptions: [],
    };
  },
  async mounted() {
    const { data } = await this.getDicts("power_plan_typ_cd");
    this.planTypCd = data && data.length ? data[1].dictValue : undefined;
    this.getWorkUnit();
    this.getWorkType();
    this.getZyType();
    this.getList();
  },
  methods: {
    // 作业单位
    async getWorkUnit() {
      const { data } = await getWorkUnitList();
      this.workUnitOptions = data;
    },
    // 作业类型
    async getWorkType() {
      const { data } = await this.getDicts("homework_type");
      this.workTypeList = data;
    },
    // 专业类型
    async getZyType() {
      const { data } = await this.getDicts("professional_type");
      this.zyTypeList = data;
    },
    // 多选框选中数据
    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]]
        : [];
    },
    /** 修改按钮操作 */
    handleUpdate(row, title) {
      this.$refs.workPlanModelRef.openModel({ ...row }, title, 2);
    },
    handleDetail(row, title) {
      this.$refs.workPlanDetailModelRef.openModel({ ...row }, title, 2);
    },
    /** 查询列表 */
    async getList() {
      this.loading = true;
      getWorkPlanList({ ...this.queryParams, planTypCd: this.planTypCd }).then(
        (response) => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.pageNum = 1;
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>
<style lang="scss" scoped>
.table {
  height: calc(100% - 180px);
}
::v-deep {
  .el-table {
    height: 100%;
    width: 100%;
    .el-table__body-wrapper {
      width: 100% !important;
      height: calc(100% - 50px) !important; // 表格高度减去表头的高度
      overflow-y: scroll;
    }
  }
}
</style>
