<template>
  <div>
    <el-card>
      <el-form
        :model="searchForm"
        label-width="60px"
        @submit.prevent="fnGetData"
      >
        <el-row>
          <el-col :span="6">
            <el-form-item label="年份" prop="YEAR">
              <el-select v-model="searchForm.YEAR" @change="fnGetData">
                <el-option
                  v-for="item in yearList"
                  :key="item"
                  :label="item"
                  :value="item"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <layout-card>
      <h3 class="tc mb-10">{{ searchForm.YEAR }}年隐患排查计划</h3>
      <layout-table :data="list" :show-pagination="false">
        <el-table-column
          prop="type_name"
          label="检查类型【清单类型】"
          width="150"
        />
        <el-table-column prop="level_name" label="排查级别" width="100" />
        <el-table-column
          prop="period_name"
          label="排查频次【排查周期】"
          width="150"
        />
        <el-table-column label="隐患排查要求">
          <template v-slot="{ row }">
            {{ dictionary[row.type_name].require }}
          </template>
        </el-table-column>
        <el-table-column prop="check_count" label="排查任务数" width="100" />
        <el-table-column prop="list_count" label="涉及排查清单数" width="120" />
        <el-table-column prop="dept_count" label="涉及部门数" width="100" />
        <el-table-column label="排查目的">
          <template v-slot="{ row }">
            {{ dictionary[row.type_name].purpose }}
          </template>
        </el-table-column>
      </layout-table>
    </layout-card>
  </div>
</template>

<script setup>
import useListData from "@/assets/js/useListData.js";
import { getTroubleshootingPlanList } from "@/request/hazard_investigation.js";
import dayjs from "dayjs";
import { ref } from "vue";

const year = dayjs().year();
const dictionary = {
  节假日: {
    require: "按节假日检查表内容实施检查，保存检查记录、隐患通知及整改记录",
    purpose: "保证节日期间各种应急物资及备用设施充足相关事项明确落实。",
  },
  综合: {
    require: "按综合性检查表内容实施检查。保存检查记录、隐患通知及整改记录",
    purpose: "以检查各级人员安全责任的落实情况为重点",
  },
  专业: {
    require:
      "按各专业性检查表内容实施检查，有问题向领导汇报。保存检查记录、隐患通知及整改记录",
    purpose: "主要排查各专业正常运行情况",
  },
  季节性: {
    require: "按各季节性检查表检查",
    purpose: "根据季节特点进行预防性检查",
  },
  日常: {
    require:
      "检查人员按各自负责部门进行检查，保存检查记录、隐患通知及整改记录。",
    purpose: "履行本身安全工作职责，及时发现三违行为",
  },
};
const yearList = ref([]);
const fnInitYearList = () => {
  for (let i = 2021; i <= year; i++) {
    yearList.value.push(i);
  }
};
fnInitYearList();
const { list, searchForm, fnGetData } = useListData(
  getTroubleshootingPlanList,
  {
    usePagination: false,
    defaultSearchForm: {
      YEAR: year,
    },
    key: "planList",
    callbackFn: (list) => {
      for (let i = 0; i < list.length; i++) {
        if (
          list[i].check_count === 0 ||
          list[i].list_count === 0 ||
          list[i].dept_count === 0
        ) {
          list.splice(i, 1);
          i--;
        }
      }
    },
  }
);
</script>

<style scoped></style>
