<template>
  <div>
    <el-card>
      <el-form
        :model="searchForm"
        label-width="130px"
        @submit.prevent="fnResetPaginationTransfer"
      >
        <el-row>
          <el-col :span="6">
            <el-form-item label="证书名称/证书编号" prop="KEYWORDS">
              <el-input
                v-model="searchForm.KEYWORDS"
                placeholder="请输入关键字"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="证书有效期" prop="dates">
              <el-date-picker
                v-model="searchForm.dates"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                format="YYYY-MM-DD"
                value-format="YYYY-MM-DD"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label-width="10px">
              <el-button type="primary" native-type="submit">搜索</el-button>
              <el-button native-type="reset" @click="fnResetPagination">
                重置
              </el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <layout-card>
      <layout-table
        v-model:pagination="pagination"
        :data="list"
        @get-data="fnGetDataTransfer"
      >
        <el-table-column label="序号" width="70">
          <template #default="{ $index }">
            {{ serialNumber(pagination, $index) }}
          </template>
        </el-table-column>
        <el-table-column label="证书名称" prop="NAME" />
        <el-table-column label="证书有效期" prop="VALIDITYTIME" />
        <el-table-column label="证书编号" prop="NUMBER" />
        <el-table-column label="照片">
          <template #default="{ row }">
            <layout-tooltip-img :imgs="row.imgs" />
          </template>
        </el-table-column>
        <el-table-column label="操作" width="150">
          <template #default="{ row }">
            <el-button
              type="primary"
              text
              link
              @click="
                router.push({
                  path: '/enterprise_management/information/industry_qualifications/view',
                  query: { QUALIFICATIONS_ID: row.QUALIFICATIONS_ID },
                })
              "
            >
              查看
            </el-button>
            <el-button
              type="primary"
              text
              link
              @click="
                router.push({
                  path: '/enterprise_management/information/industry_qualifications/update',
                  query: { QUALIFICATIONS_ID: row.QUALIFICATIONS_ID },
                })
              "
            >
              修改
            </el-button>
            <el-button
              type="primary"
              text
              link
              @click="fnDelete(row.QUALIFICATIONS_ID)"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
        <template #button>
          <el-button
            type="primary"
            @click="
              router.push({
                path: '/enterprise_management/information/industry_qualifications/add',
              })
            "
          >
            新增
          </el-button>
        </template>
      </layout-table>
    </layout-card>
  </div>
</template>

<script setup>
import { serialNumber } from "@/assets/js/utils.js";
import { debounce } from "throttle-debounce";
import { ElMessage, ElMessageBox } from "element-plus";
import {
  getIndustryQualificationsList,
  setIndustryQualificationsDelete,
} from "@/request/enterprise_management.js";
import { useRouter } from "vue-router";
import useListData from "@/assets/js/useListData.js";
import LayoutTooltipImg from "@/components/tooltip_img/index.vue";

const router = useRouter();
const { list, pagination, searchForm, fnGetData, fnResetPagination } =
  useListData(getIndustryQualificationsList);
const fnGetDataTransfer = () => {
  fnGetData({
    STARTTIME: searchForm.value.dates?.[0],
    ENDTIME: searchForm.value.dates?.[1],
  });
};
const fnResetPaginationTransfer = () => {
  fnResetPagination({
    STARTTIME: searchForm.value.dates?.[0],
    ENDTIME: searchForm.value.dates?.[1],
  });
};
const fnDelete = debounce(
  1000,
  async (QUALIFICATIONS_ID) => {
    await ElMessageBox.confirm("确定要删除吗？", { type: "warning" });
    await setIndustryQualificationsDelete({ QUALIFICATIONS_ID });
    ElMessage.success("删除成功");
    fnResetPaginationTransfer();
  },
  { atBegin: true }
);
</script>

<style scoped></style>
