<template>
  <el-container>
    <el-header v-if="isSearch">
      <el-form style="margin: 10px 0" :inline="true">
        <el-form-item label="分析对象名称：">
          <el-select
            v-model="search.hazardId"
            @change="changeCellList(1)"
            clearable
          >
            <el-option
              :label="item.hazardName"
              :value="item.id"
              v-for="item in analysisList"
              :key="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="分析单元名称：">
          <el-select
            v-model="search.riskUnitId"
            clearable
            @change="changeEventList(1)"
          >
            <el-option
              :label="item.riskUnitName"
              :value="item.id"
              v-for="item in cellList"
              :key="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="风险事件名称：">
          <el-select
            v-model="search.riskEventId"
            clearable
            @change="changeMeasureList(1)"
          >
            <el-option
              :label="item.riskEventName"
              :value="item.id"
              v-for="item in eventList"
              :key="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="管控项措施：">
          <el-select v-model="search.riskMeasureId" clearable>
            <el-option
              :label="item.item"
              :value="item.id"
              v-for="item in measureList"
              :key="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="隐患排查内容：">
          <el-input
            type="text"
            v-model="search.troubleshootContent"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="岗位：">
          <el-select v-model="search.postId" clearable>
            <el-option
              :label="item.postName"
              :value="item.postId"
              v-for="item in postList"
              :key="item.postId"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="巡查类型：">
          <el-select v-model="search.checkType" clearable>
            <el-option
              :label="item.label"
              :value="item.value"
              v-for="item in checkCycleOptions"
              :key="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="巡查周期：">
          <el-select v-model="search.checkCycleUnit" clearable>
            <el-option
              :label="item.label"
              :value="item.value"
              v-for="item in checkCycleUnitOptions"
              :key="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="时间：">
          <el-date-picker
            clearable
            v-model="search.time"
            type="daterange"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="隐患级别：">
          <el-select v-model="search.troubleshootLevel" clearable>
            <el-option label="一般隐患" :value="0" />
            <el-option label="重大隐患" :value="1" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button
            style="margin-left: 10px"
            type="primary"
            icon="el-icon-search"
            @click="initList"
          >
            搜索
          </el-button>
          <el-button class="commonBtn" icon="el-icon-refresh" @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </el-header>
    <el-main>
      <div class="headerTop">
        <div>
          <el-button type="primary" class="el-icon-plus" @click="doAdd(1)">
            新增</el-button
          >
          <!-- <el-button type="primary" class="el-icon-upload2"> 导入</el-button> -->
          <!-- <el-button type="primary" class="el-icon-download"> 导出</el-button> -->
          <el-button
            type="primary"
            class="el-icon-delete"
            @click="doBatchDelete"
          >
            删除</el-button
          >
        </div>
        <div>
          <right-toolbar
            @queryTable="initList"
            :search="true"
            @update:showSearch="isSearch = !isSearch"
          ></right-toolbar>
        </div>
      </div>

      <el-table
        height="calc(100% - 200px)"
        :data="list"
        :row-style="{ height: '0px' }"
        :header-cell-style="{ 'text-align': 'center', padding: '0px' }"
        :cell-style="{ 'text-align': 'center', padding: '2px' }"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" align="center" width="50" />
        <el-table-column label="序号" align="center" width="50">
          <template slot-scope="scope">
            <span> {{ (pageNum - 1) * pageSize + (scope.$index + 1) }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="分析对象名称"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.hazardName }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="分析单元名称"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.riskUnitName }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="风险事件名称"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.riskEventName }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="管控项措施"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.item }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="隐患排查内容"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.troubleshootContent }}</span>
          </template>
        </el-table-column>
        <el-table-column label="岗位" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row.postName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="巡查类型" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ initCheckCycle(scope.row.checkType) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="巡查频次" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            <span v-if="scope.row.checkTypeCount === 1"
              >{{ scope.row.checkCycle }}次 /
              {{ scope.row.checkCycleUnit }}</span
            >
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column label="开始时间" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            <span v-if="scope.row.checkTypeCount === 2">{{
              scope.row.startDate ? scope.row.startDate : "-"
            }}</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column label="结束时间" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            <span v-if="scope.row.checkTypeCount === 2">{{
              scope.row.endDate ? scope.row.endDate : "-"
            }}</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column label="隐患级别" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{
              scope.row.troubleshootLevel === 1 ? "重大隐患" : "一般隐患"
            }}</span>
          </template>
        </el-table-column>

        <el-table-column label="操作" fixed="right" align="center" width="120">
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click="doAdd(2, scope.row)">
              编辑
            </el-button>
            <el-button type="text" size="mini" @click="doDelete(scope.row)">
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :page.sync="pageNum"
        :limit.sync="pageSize"
        :page-sizes="[10, 20, 30, 50]"
        :total="total"
        @pagination="initList"
      />
    </el-main>

    <!-- 新增/编辑 的dialog -->
    <el-dialog
      :visible.sync="dialogVisible"
      width="700px"
      v-if="dialogVisible"
      :title="isEdit"
      :show-close="false"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleFormRef"
        label-width="150px"
        class="demo-ruleForm"
      >
        <el-form-item label="分析对象名称：" prop="hazardId">
          <el-select
            v-model="ruleForm.hazardId"
            @change="changeCellList(2)"
            clearable
            style="width: 70%"
          >
            <el-option
              :label="item.hazardName"
              :value="item.id"
              v-for="item in analysisList"
              :key="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="分析单元名称：" prop="riskUnitId">
          <el-select
            v-model="ruleForm.riskUnitId"
            clearable
            @change="changeEventList(2)"
            style="width: 70%"
          >
            <el-option
              :label="item.riskUnitName"
              :value="item.id"
              v-for="item in cellList1"
              :key="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="风险事件名称：" prop="riskEventId">
          <el-select
            v-model="ruleForm.riskEventId"
            clearable
            style="width: 70%"
            @change="changeMeasureList(2)"
          >
            <el-option
              :label="item.riskEventName"
              :value="item.id"
              v-for="item in eventList1"
              :key="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="管控项措施：" prop="riskMeasureId">
          <el-select
            v-model="ruleForm.riskMeasureId"
            clearable
            style="width: 70%"
          >
            <el-option
              :label="item.item"
              :value="item.id"
              v-for="item in measureList1"
              :key="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="隐患排查内容：" prop="troubleshootContent">
          <el-input
            style="width: 70%"
            type="text"
            v-model="ruleForm.troubleshootContent"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="岗位：" prop="postId">
          <el-select v-model="ruleForm.postId" clearable style="width: 70%">
            <el-option
              :label="item.postName"
              :value="item.postId"
              v-for="item in postList"
              :key="item.postId"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="巡查类型：" prop="checkType">
          <el-select v-model="ruleForm.checkType" clearable style="width: 70%">
            <el-option
              :label="item.label"
              :value="item.value"
              v-for="item in checkCycleOptions"
              :key="item.value"
            />
          </el-select>
        </el-form-item>

        <el-form-item el-form-item label="巡查方式：" prop="checkTypeCount">
          <el-radio-group
            v-model="ruleForm.checkTypeCount"
            @change="changeKong"
          >
            <el-radio :label="1">单位周期内N次</el-radio>
            <el-radio :label="2">时间段内1次</el-radio>
          </el-radio-group>
        </el-form-item>
        <div v-if="ruleForm.checkTypeCount === 1">
          <el-form-item label="巡查周期单位：" prop="checkCycleUnit">
            <el-select
              v-model="ruleForm.checkCycleUnit"
              clearable
              style="width: 70%"
            >
              <el-option
                :label="item.label"
                :value="item.value"
                v-for="item in checkCycleUnitOptions"
                :key="item.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="巡查频次：" prop="checkCycle">
            <el-input
              style="width: 70%"
              type="text"
              v-model="ruleForm.checkCycle"
              clearable
            ></el-input>
          </el-form-item>
        </div>
        <div v-else>
          <el-form-item label="开始时间：" prop="startDate">
            <el-date-picker
              @change="ruleForm.endDate = ''"
              style="width: 70%"
              v-model="ruleForm.startDate"
              :picker-options="{
                disabledDate: (time) => {
                  return time.getTime() < Date.now();
                }
              }"
             value-format="yyyy-MM-dd HH:mm:ss"
              type="datetime"
              placeholder="选择日期"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="结束时间：" prop="endDate">
            <el-date-picker
              style="width: 70%"
              v-model="ruleForm.endDate"
              :picker-options="pickerOptionsEnd"
             value-format="yyyy-MM-dd HH:mm:ss"
              type="datetime"
              placeholder="选择日期"
            >
            </el-date-picker>
          </el-form-item>
        </div>
        <el-form-item label="隐患级别：" prop="troubleshootLevel">
          <el-select
            v-model="ruleForm.troubleshootLevel"
            style="width: 70%"
            clearable
          >
            <el-option label="一般隐患" :value="0" />
            <el-option label="重大隐患" :value="1" />
          </el-select>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submit">提 交</el-button>
      </span>
    </el-dialog>
  </el-container>
</template>
<script>
import {
  taskList,
  unitList,
  eventList,
  measureList,
  hazardList,
  delTask,
  saveTask,
  editTask,
  postList,
  lookTask,
} from "@/api/risk/analyse.js";
export default {
  name: "RuoyiAnalyse",

  data() {
    return {
      pickerOptionsEnd: {
        disabledDate: (time) => {
          let beginDateVal = this.ruleForm.startDate;
          if (beginDateVal) {
            return (
              time.getTime() < new Date(beginDateVal).getTime() + 1 * 60 * 1000
            );
          }
        },
      },
      isSearch: false,
      search: {
        hazardId: "",
        riskUnitId: "",
        checkCycleUnit: "",
        riskEventId: "",
        riskMeasureId: "",
        troubleshootContent: "",
        postId: "",
        checkType: "",
        checkCycle: "",
        time: "",
        troubleshootLevel: "",
      },
      // 列表展示的岗位
      checkTaskPostDTOListOne: "",
      // 管控措施分类1
      classifyOptions1: [
        { label: "工程技术", value: "1" },
        { label: "维护保养", value: "2" },
        { label: "操作行为", value: "3" },
        { label: "应急措施", value: "4" },
      ],
      // 管控措施分类2
      classifyOptions2: [],

      // 巡查类型的下拉
      checkCycleOptions: [
        { label: "日常排查", value: 1 },
        { label: "综合排查", value: 2 },
        { label: "专业性排查", value: 3 },
        { label: "季节性排查", value: 4 },
        { label: "重点时段及节假日前排查", value: 5 },
        { label: "事故类比排查", value: 6 },
        { label: "复产复工前排查", value: 7 },
        { label: "外聘专家诊断式排查", value: 8 },
        { label: "管控措施失效", value: 9 },
        { label: "其它", value: 10 },
      ],
      checkCycleUnitOptions: [
        { label: "小时", value: "小时", id: 1 },
        { label: "天", value: "天", id: 2 },
        { label: "月", value: "月", id: 3 },
        { label: "年", value: "年", id: 4 },
      ],

      pageNum: 1,
      pageSize: 10,
      total: 0,
      list: [],
      analysisList: [], // 分析对象的下拉菜单
      cellList: [], // 分析单元的下拉菜单
      cellList1: [], // 分析单元的下拉菜单
      eventList: [], // 风险事件的下拉菜单
      eventList1: [], // 风险事件的下拉菜单
      measureList: [], // 管控项措施的下拉菜单
      measureList1: [], // 管控项措施的下拉菜单
      postList: [], // 岗位的下拉菜单
      multipleSelectionIdList: [],

      dialogVisible: false,
      isEdit: "",
      ruleForm: {
        hazardId: "",
        radio: "单位周期内N次",
        riskUnitId: "",
        checkTypeCount: 1,
        checkCycleUnit: "",
        riskEventId: "",
        riskMeasureId: "",
        troubleshootContent: "",
        postId: "",
        checkType: "",
        checkCycle: "",
        startDate: "",
        endDate: "",
        troubleshootLevel: "",
      },
      rules: {
        hazardId: [
          { required: true, message: "请选择分析对象名称", trigger: "change" },
        ],
        riskUnitId: [
          { required: true, message: "请选择分析单元名称", trigger: "change" },
        ],
        riskEventId: [
          { required: true, message: "请选择风险事件名称", trigger: "change" },
        ],
        riskMeasureId: [
          { required: true, message: "请选择管控项措施", trigger: "change" },
        ],
        troubleshootContent: [
          { required: true, message: "请输入隐患排查内容", trigger: "blur" },
        ],
        postId: [{ required: true, message: "请选择岗位", trigger: "change" }],
        checkType: [
          { required: true, message: "请选择巡查类型", trigger: "change" },
        ],
        checkCycle: [
          { required: true, message: "请输入巡查周期", trigger: "change" },
        ],

        checkCycleUnit: [
          { required: true, message: "请选择巡查周期单位", trigger: "change" },
        ],
        startDate: [
          { required: true, message: "请选择开始时间", trigger: "change" },
        ],
        endDate: [
          { required: true, message: "请选择结束时间", trigger: "change" },
        ],
        troubleshootLevel: [
          { required: true, message: "请选择隐患级别", trigger: "change" },
        ],
        checkTypeCount: [
          { required: true, message: "请选择巡查方式", trigger: "change" },
        ],
      },
    };
  },

  mounted() {
    this.initList();
    this.inithazardListOptions();
    this.initPostOptions();
  },

  methods: {
    async initList() {
      const res = await taskList({
        ...this.search,
        startDate: this.search.time[0] || null,
        endDate: this.search.time[1] || null,
        pageNum: this.pageNum,
        pageSize: this.pageSize,
      });
      this.list = res.rows;
      this.total = res.total;
    },
    // 重置
    reset() {
      this.search.hazardId = "";
      this.search.riskUnitId = "";
      this.search.checkCycleUnit = "";
      this.search.riskEventId = "";
      this.search.riskMeasureId = "";
      this.search.troubleshootContent = "";
      this.search.postId = "";
      this.search.checkType = "";
      this.search.checkCycle = "";
      this.search.time = "";
      this.search.troubleshootLevel = "";
      this.eventList = [], // 风险事件的下拉菜单
      this.eventList1 = [], // 风险事件的下拉菜单
      this.measureList = [], // 管控项措施的下拉菜单
      this.measureList1 = [], // 管控项措施的下拉菜单
      this.cellList = [], // 分析单元的下拉菜单
      this.cellList1 = []
      this.initList();
    },
    initDataSrc(type) {
      if (type === "1") {
        return "自动化管控";
      } else if (type === "2") {
        return "隐患排查";
      }
    },
    initCheckCycle(type) {
      return this.checkCycleOptions.find((item) => item.value == type).label;
    },
    // 岗位的下拉
    initPostOptions() {
      postList().then((res) => {
        if (res.code === 200) {
          this.postList = res.rows;
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    changeMeasureList(type) {
      if (type === 1) {
        this.measureList = []
        this.search.riskMeasureId = "";
      } else if(type === 2){
        this.measureList1 = []
        this.ruleForm.riskMeasureId = ''
      } else {
        this.initMeasureOptions(type);
      }
      if ((this.search.riskEventId && type === 1) || ( this.ruleForm.riskEventId  && type === 2)) {
         this.initMeasureOptions(type);
      }

    },
    // 管控项的下拉菜单
    initMeasureOptions(type) {
      if (type === 1) {
        const obj = {
          item: "",
          dataSrc: "",
          hazardId: "",
          riskUnitId: "",
          riskEventId: this.search.riskEventId,
          pageNum: 1,
          pageSize: 1000,
        };
        measureList(obj).then((res) => {
          if (res.code === 200) {
            this.measureList = res.rows;
          } else {
            this.$message.error(res.msg);
          }
        });
      } else {
        const obj = {
          item: "",
          dataSrc: "",
          hazardId: "",
          riskUnitId: "",
          riskEventId: this.ruleForm.riskEventId,
          pageNum: 1,
          pageSize: 1000,
        };
        measureList(obj).then((res) => {
          if (res.code === 200) {
            this.measureList1 = res.rows;
          } else {
            this.$message.error(res.msg);
          }
        });
      }
    },
    changeEventList(type) {
      if (type === 1) {
        this.search.riskEventId = "";
        this.search.riskMeasureId = "";
        this.eventList = [];
        this.measureList = [];
      } else {
        this.ruleForm.riskEventId = "";
        this.ruleForm.riskMeasureId = "";
        this.eventList1 = [];
        this.measureList1 = [];
      }
      if ((this.search.riskUnitId && type === 1) || (this.ruleForm.riskUnitId && type === 2)) {
        this.initEventListtOptions(type);
      }

    },
    // 风险事件的下拉菜单
    initEventListtOptions(type) {
      if (type === 1) {

        const obj = {
          hazardId: "",
          riskUnitId: this.search.riskUnitId,
          pageNum: 1,
          pageSize: 1000,
        };
        eventList(obj).then((res) => {
          if (res.code === 200) {
            this.eventList = res.rows;
          } else {
            this.$message.error(res.msg);
          }
        });
      } else {
        const obj = {
          hazardId: "",
          riskUnitId: this.ruleForm.riskUnitId,
          pageNum: 1,
          pageSize: 1000,
        };
        eventList(obj).then((res) => {
          if (res.code === 200) {
            this.eventList1 = res.rows;
          } else {
            this.$message.error(res.msg);
          }
        });
      }
    },
    changeCellList(type) {
      console.log(this.search.hazardId)
      if (type === 1) {
        this.search.riskUnitId = "";
        this.search.riskEventId = "";
        this.search.riskMeasureId = "";
        this.cellList = [], // 分析单元的下拉菜单
        this.eventList = [];
        this.measureList = [];
      } else {
        this.ruleForm.riskUnitId = "";
        this.ruleForm.riskEventId = "";
        this.ruleForm.riskMeasureId = "";
        this.cellList1 = [], // 分析单元的下拉菜单
        this.eventList1 = [];
        this.measureList1 = [];
      }
      if ((this.search.hazardId && type === 1) || (this.ruleForm.hazardId && type === 2) ) {
         this.initcellListtOptions(type);
      }

    },
    // 分析单元的下拉菜单
    initcellListtOptions(type) {
      if (type === 1) {
        const obj = {
          hazardId: "",
          riskUnitName: "",
          hazardId: this.search.hazardId,
          pageNum: 1,
          pageSize: 1000,
        };
        unitList(obj).then((res) => {
          if (res.code === 200) {
            this.cellList = res.rows;
          } else {
            this.$message.error(res.msg);
          }
        });
      } else {
        const obj = {
          hazardId: "",
          riskUnitName: "",
          hazardId: this.ruleForm.hazardId,
          pageNum: 1,
          pageSize: 1000,
        };
        unitList(obj).then((res) => {
          if (res.code === 200) {
            this.cellList1 = res.rows;
          } else {
            this.$message.error(res.msg);
          }
        });
      }
    },
    // 分析对象的下拉菜单
    inithazardListOptions() {
      const obj = {
        hazardName: "",
        hazardLevel: "",
        areaId: "",
        pageNum: 1,
        pageSize: 1000,
      };
      hazardList(obj).then((res) => {
        if (res.code === 200) {
          this.analysisList = res.rows;
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    // 全选/反选
    handleSelectionChange(val) {
      this.multipleSelectionIdList = val.map((item) => item.id);
    },
    // 新增
    async doAdd(type, val) {
      if (type === 1) {
        this.isEdit = "新增";
        this.ruleForm.hazardId = "";
        this.ruleForm.checkTypeCount = 1;
        this.ruleForm.riskUnitId = "";
        this.ruleForm.checkCycleUnit = "";
        this.ruleForm.riskEventId = "";
        this.ruleForm.riskMeasureId = "";
        this.ruleForm.troubleshootContent = "";
        this.ruleForm.postId = "";
        this.ruleForm.checkType = "";
        this.ruleForm.checkCycle = "";
        this.ruleForm.startDate = "";
        this.ruleForm.endDate = "";
        this.ruleForm.troubleshootLevel = "";
      } else {
        this.isEdit = "编辑";
        const { data: res } = await lookTask(val.id);
        this.ruleForm = {...res};
        this.initcellListtOptions(2);
        this.initEventListtOptions(2);
        this.changeMeasureList(3);
      }
      this.$nextTick(() => {
        this.dialogVisible = true;
      });
    },
    changeKong() {
      this.ruleForm.checkCycleUnit = "";
      this.ruleForm.checkCycle = "";
      this.ruleForm.startDate = "";
      this.ruleForm.endDate = "";
    },
    submit() {
      this.$refs.ruleFormRef.validate(async (valid) => {
        if (valid) {
          if (this.isEdit === "新增") {
            const res = await saveTask(this.ruleForm);
            if (res.code !== 200) return this.$message.error(res.msg);
          } else {
            const res = await editTask(this.ruleForm);
            if (res.code !== 200) return this.$message.error(res.msg);
          }

          this.initList();
          this.$message.success(`${this.isEdit}成功!`);
          this.ruleForm.hazardId = "";
          this.ruleForm.riskUnitId = "";
          this.ruleForm.checkTypeCount = 1;
          this.ruleForm.checkCycleUnit = "";
          this.ruleForm.riskEventId = "";
          this.ruleForm.riskMeasureId = "";
          this.ruleForm.troubleshootContent = "";
          this.ruleForm.postId = "";
          this.ruleForm.checkType = "";
          this.ruleForm.checkCycle = "";
          this.ruleForm.startDate = "";
          this.ruleForm.endDate = "";
          this.ruleForm.troubleshootLevel = "";

          this.dialogVisible = false;
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    // 删除
    doDelete(type) {
      this.$confirm("是否删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          const res = await delTask(type.id);
          if (res.code !== 200) return this.$message.error(res.msg);
          this.initList();
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message.warning("已取消删除");
        });
    },
    // 批量删除
    doBatchDelete() {
      if (!this.multipleSelectionIdList.length)
        return this.$message.info("请先选择需要删除的选项");
      this.$confirm("是否删除所有选中项?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          const res = await delTask(this.multipleSelectionIdList.join());
          if (res.code !== 200) return this.$message.error(res.msg);
          this.initList();
          this.$message({
            type: "success",
            message: "批量删除成功!",
          });
        })
        .catch(() => {
          this.$message.warning("已取消删除");
        });
    },
  },
};
</script>

<style lang="scss" scoped></style>
