<template>
  <layout-card>
    <el-divider content-position="left">隐患排查清单信息</el-divider>
    <el-descriptions :column="2" border>
      <el-descriptions-item label="清单名称">
        {{ info.NAME }}
      </el-descriptions-item>
      <el-descriptions-item label="排查清单类型">
        {{ info.SCREENTYPENAME }}
      </el-descriptions-item>
      <el-descriptions-item label="包保责任人部门">
        {{ info.DEPARTMENT_NAME }}
      </el-descriptions-item>
      <el-descriptions-item label="包保责任人岗位">
        {{ info.POST_NAME }}
      </el-descriptions-item>
      <el-descriptions-item label="排查周期">
        {{ info.PERIODNAME }}
      </el-descriptions-item>
      <el-descriptions-item label="清单类型">
        {{ info.TYPENAME }}
      </el-descriptions-item>
      <el-descriptions-item label="包保责任人">
        {{ info.USER_NAME }}
      </el-descriptions-item>
    </el-descriptions>
    <el-divider content-position="left">检查内容</el-divider>
    <layout-table :data="list" :show-pagination="false">
      <el-table-column type="index" label="序号" width="55" />
      <el-table-column
        prop="CHECK_CATEGORY_NAME"
        label="检查类别"
        width="120"
      />
      <el-table-column prop="CHECK_ITEM_NAME" label="检查项目" width="120" />
      <el-table-column prop="CHECK_CONTENT" label="检查内容" width="200" />
      <el-table-column prop="CHECK_STANDARD" label="检查标准" width="200" />
      <el-table-column prop="REFERENCE_BASIS" label="参考依据" width="200" />
      <el-table-column prop="CHECK_QUALIFIED" label="检查合格项" width="150" />
      <el-table-column
        prop="CHECK_UNQUALIFIED"
        label="检查不合格项"
        width="150"
      />
      <el-table-column label="操作类型" width="100">
        <template #default="{ row }">
          <span v-if="row.OPERATION_TYPE === 1">选择</span>
          <span v-if="row.OPERATION_TYPE === 2">填写</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="BAO_BAO_NUM_NAME"
        label="包保任务对应项"
        width="150"
      />
      <el-table-column label="操作">
        <template #default="{ row, $index }">
          <el-button type="primary" text link @click="fnSelect(row, $index)">
            选择
          </el-button>
        </template>
      </el-table-column>
    </layout-table>
    <div class="tc mt-10">
      <el-button type="primary" @click="fnSubmit">保存</el-button>
    </div>
    <insurance-coverage-select-custom
      v-model:visible="data.selectDialog.visible"
      :info="data.selectDialog.info"
      @check="fnCheck"
    />
  </layout-card>
</template>

<script setup>
import {
  getCheckStandardManagementView,
  setCustomInsuranceCoverageSave,
} from "@/request/hazard_investigation.js";
import { useRoute, useRouter } from "vue-router";
import { reactive, ref } from "vue";
import { debounce } from "throttle-debounce";
import { ElMessage } from "element-plus";
import InsuranceCoverageSelectCustom from "./components/insurance_coverage_select_custom.vue";
import useListData from "@/assets/js/useListData.js";

const route = useRoute();
const router = useRouter();
const { ID } = route.query;
const info = ref({});
const data = reactive({
  selectDialog: {
    visible: false,
    info: {},
    index: 111,
  },
});
const { list } = useListData(getCheckStandardManagementView, {
  otherParams: { ID },
  usePagination: false,
  callbackFn: (list, resData) => {
    info.value = resData.pd;
  },
});
const fnSelect = (row, index) => {
  data.selectDialog.visible = true;
  data.selectDialog.info = row;
  data.selectDialog.index = index;
};
const fnCheck = (row) => {
  list.value[data.selectDialog.index].BAO_BAO_NUM_NAME = row.TERM_DESCRIBE;
  list.value[data.selectDialog.index].BAO_BAO_NUM = row.TASK_NUM;
};
const fnSubmit = debounce(
  1000,
  async () => {
    await setCustomInsuranceCoverageSave({
      list: JSON.stringify(list.value),
    });
    ElMessage.success("保存成功");
    router.back();
  },
  { atBegin: true }
);
</script>

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