<!-- 监督检查办法管理-堤防 -->
<script>
import {
  putDFPreventionControlPlan,
  deleteDFMaintenancePlan,
  postDFNewPreventionControlPlan,
  postDFPreventionControlPlanList,
  getDFPreventionControlPlan,
  listUser,
} from "@/api/management";
import { listDikeInfo } from "@/api/yg/dikeInfo";

export default {
  name: "InspectionItems",
  data() {
    return {
      paramsData: {
        name: "",
        type: null,
        dikeName: "",
        selectLevel: "",
        selectType: "",
      },
      dialogVisible: false,
      prohibitEditing: false,
      dikeTypeList: [],
      personnelList: [], // 人员列表
      patrolType: [], // 提醒周期类型
      workMonth: [], // 工作月份
      embankmentList: [], //堤防列表
      dikeLevel: [], // 堤防级别列表
      controlType: [], // 防治类型
      tableData: [], // 检查列表
      pageData: {
        pageNum: 1, // 当前页
        pageSize: 10, // 请求数量
        pageSizes: [10, 20, 50, 100],
        total: 0, // 总数量
      },
      ruleForm: {
        dikeCode: "",
        dikeName: "",
        name: "",
        type: "",
        instruction: "",
        month: "",
        details: [],
        cycleType: "",
        frequency: "",
        operators: [],
        isReminder: 1,
        otherConfig: {
          selectUser: [],
          week: "",
          day: "",
        },
        reminderTime: "",
      },
      rules: {
        dikeCode: [
          { required: true, message: "请选择堤防名称", trigger: "blur" },
        ],
        name: [
          { required: true, message: "请输入防治计划名称", trigger: "blur" },
          { max: 100, message: "名称最长为100个字符", trigger: "blur" },
        ],
        type: [
          { required: true, message: "请选择防治类型", trigger: "change" },
        ],
        instruction: [
          { required: true, message: "请输入防治说明", trigger: "change" },
        ],
        month: [
          { required: true, message: "请选择工作月份", trigger: "change" },
        ],
        cycleType: [
          { required: true, message: "请选择提醒日期", trigger: "change" },
        ],
        frequency: [
          { required: true, message: "请输入次数", trigger: "change" },
        ],
        "otherConfig.selectUser": [
          { required: true, message: "请选择责任人", trigger: "change" },
        ],
        "otherConfig.week": [
          { required: true, message: "请选择星期", trigger: "change" },
        ],
        "otherConfig.day": [
          { required: true, message: "请输入", trigger: "change" },
        ],
        reminderTime: [
          { required: true, message: "请选择提醒时间", trigger: "change" },
        ],
      },
    };
  },
  watch: {
    dialogVisible(newVal, oldVal) {
      if (oldVal) {
        this.prohibitEditing = false;
      }
    },
  },
  methods: {
    // 获取堤防等级
    resolveDikeGrad(dikeGrad) {
      return (
        this.dikeLevel.find((v) => v.dictValue === dikeGrad)?.dictLabel ||
        dikeGrad
      );
    },
    // 获取堤防类型
    resolveDikeType(dikeType) {
      return (
        this.dikeTypeList.find((v) => v.dictValue == dikeType)?.dictLabel ||
        dikeType
      );
    },
    // 获取防治类型
    resolveType(type) {
      return (
        this.controlType.find((v) => v.dictValue == type)?.dictLabel || type
      );
    },
    // 跳转新增办法页面
    handleAddMethod() {
      this.$router.push("methodManageDetails");
    },
    // 跳转编辑办法页面
    handleEditMethod(row) {
      this.$router.push({
        path: "methodManageDetails",
        query: {
          id: row.id,
          mode: "edit",
        },
      });
    },
    // 跳转预览办法页面
    handlePreviewMethod(row) {
      this.$router.push({
        path: "methodManageDetails",
        query: {
          id: row.id,
          mode: "preview",
        },
      });
    },
    // 导出文件
    handleExportMethod() {},
    // 复制办法
    handleCopyMethod() {},
    // 获取列表数据
    getTableData() {
      postDFPreventionControlPlanList({
        data: {
          timeView: {
            timeField: "create_time",
          },
          name: this.paramsData.name,
          type: this.paramsData.type,
          dikeName: this.paramsData.dikeName,
          dikeGrad: this.paramsData.dikeGrad,
          dikeType: this.paramsData.dikeType,
        },
        cv: {
          name: "name",
          type: "like",
          value: this.name,
        },
        params: {
          orderBy: "create_time",
          sort: "desc",
        },
        pageSize: this.pageData.pageSize,
        pageNum: this.pageData.pageNum,
      }).then((res) => {
        if (res) {
          this.tableData = res.records;
          this.pageData.total = res.total;
        }
      });
    },
    // 获取堤防列表信息
    getEmbData() {
      listDikeInfo({
        pageNum: 1,
        pageSize: 20,
        ids: null,
        data: {
          embankmentName: null,
          endStationNumber: null,
          embankmentType: null,
        },
        // 排序方式
        params: {
          // 按哪个字段排序
          orderBy: "create_time",
          // desc降序，升序asc
          sort: "desc",
        },
      }).then((res) => {
        this.embankmentList = res?.records || [];
      });
    },
    // 跳转数据项配置列表
    handleToItemsList(row) {
      this.$router.push({
        path: "methodsItemsList",
        query: {
          id: row.id,
        },
      });
    },
  },
  created() {
    this.getDicts("embankment_type").then((response) => {
      this.dikeTypeList = response.data;
    });
  },
  mounted() {
    // 获取列表数据
    this.getTableData();
    this.getEmbData();
    this.getDicts("dh_jh_type").then((res) => {
      this.controlType = res.data;
    });
  },
};
</script>

<template>
  <div class="body slider-right">
    <div class="top-title">基础信息管理</div>
    <div class="table-box">
      <el-button
        class="search-btn"
        style="margin-right: 16px; margin-bottom: 8px; float: right"
        type="success"
        @click="handleAddMethod()"
        >添加</el-button
      >
      <el-table class="table" height="640" :data="tableData" border>
        <el-table-column type="index" align="center" label="序号" width="60" />
        <el-table-column prop="name" align="center" label="名称" />
        <el-table-column prop="createTime" align="center" label="发布时间">
        </el-table-column>
        <el-table-column prop="updateTime" align="center" label="更新时间" />
        <el-table-column
          prop="status"
          align="center"
          sortable
          label="当前状态"
        />
        <el-table-column prop="address" align="center" label="操作">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              @click="handleEditMethod(scope.row)"
              >编辑</el-button
            >
            <el-button
              type="text"
              size="small"
              @click="handlePreviewMethod(scope.row)"
              >预览</el-button
            >
            <el-button
              type="text"
              size="small"
              @click="handleExportMethod(scope.row)"
              >导出</el-button
            >
            <el-button
              type="text"
              size="small"
              @click="handleCopyMethod(scope.row)"
              >复制</el-button
            >
            <el-button
              type="text"
              size="small"
              @click="handleToItemsList(scope.row)"
              >配置数据项</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        class="pagination"
        style="margin-top: 16px; margin-right: 16px; float: right"
        :current-page="pageData.pageNum"
        :page-sizes="pageData.pageSizes"
        layout="total, prev, pager, next, sizes, jumper"
        :total="pageData.total"
        @size-change="getTableData()"
      >
      </el-pagination>
    </div>
  </div>
</template>

<style scoped lang="less">
.body {
  width: 100%;
  min-height: calc(100vh - 56px);
  padding-left: 24px;

  .top-title {
    height: 40px;
    background-color: white;
    display: flex;
    padding-left: 16px;
    align-items: center;
    font-weight: 600;
  }

  .table-box {
    width: 100%;
    min-height: calc(100vh - 56px - 64px);
    margin-top: 24px;
    padding: 16px;
    background-color: white;

    .top-search {
      margin-bottom: 8px;

      .search-input {
        width: 202px;
        margin-right: 10px;
      }
    }

    .table {
      height: calc(680px - 34px);
    }
  }

  .search-btn {
    margin-left: 10px;
    background-color: #37b29e;
    border: none;

    &:hover {
      background-color: #5ac6b9;
    }

    &:active {
      background-color: #2b8070;
    }
  }
}

/deep/.el-input__count {
  height: 15px;
  line-height: 15px;
  margin-right: 10px;
  margin-bottom: -4px;
}
</style>
