<template>
  <div class="app-container">
    <el-form ref="queryForm" :model="queryParams" size="small" :inline="true">
      <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.dictValue"
          ></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.dictValue"
          ></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="submitOrgNm">
        <el-select
          style="margin-right: 8px"
          size="mini"
          v-model="queryParams.submitOrgNm"
          placeholder="请选择"
          clearable
        >
          <el-option label="全部" value=""> </el-option>
          <el-option
            v-for="item in workUnitOptions"
            :key="item.organAbbr"
            :label="item.organAbbr"
            :value="item.organAbbr"
          >
          </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>
    <div class="table">
      <el-table v-loading="loading" :data="dataList">
        <el-table-column prop="date" 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>
      <pagination
        class="page-box"
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <WorkPlanDetailModel ref="workPlanDetailModelRef"></WorkPlanDetailModel>
  </div>
</template>

<script>
import { getWorkPlanList } from "@/api/secure/pdm-work-plan";
import { getWorkUnitList } from "@/api/secure/daily-newspaper";
import WorkPlanDetailModel from "../components/WorkPlanDetailModel.vue";
export default {
  components: { WorkPlanDetailModel },
  data() {
    return {
      dataList: [],
      // 遮罩层
      loading: true,
      total: 0,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        opTypDsc: "",
        opTypDsc: "",
        mgmtOrgNm: "",
        workTeamNm: "",
        workPrincipNm: "",
        submitOrgNm: "",
        pageNum: 1,
        pageSize: 10,
      },
      // 作业类型
      workTypeList: [],
      // 专业类型
      zyTypeList: [],
      // 作业单位
      workUnitOptions: [],
    };
  },
  created() {
    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;
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      getWorkPlanList({ ...this.queryParams, dataFlag: 1 }).then((response) => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handleDetail(row, title) {
      this.$refs.workPlanDetailModelRef.openModel({ ...row }, title);
    },
    /** 搜索按钮操作 */
    handleQuery() {
      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>
