<!-- @format -->

<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryRef"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="卡片编号" prop="cardNumber">
        <el-input
          v-model="queryParams.cardNumber"
          placeholder="请输入卡片编号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>

      <el-form-item label="姓名" prop="chineseName">
        <el-input
          v-model="queryParams.chineseName"
          placeholder="请输入中文名称"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>

      <el-form-item label="证件号" prop="idNum">
        <el-input
          v-model="queryParams.idNum"
          placeholder="请输入证件号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>

      <el-form-item label="制卡类型" prop="zhiKaType">
        <el-select
          v-model="queryParams.zhiKaType"
          placeholder="请选择制卡类型"
          clearable
        >
          <el-option
            v-for="dict in zhi_ka_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="制卡状态" prop="zhiKaState">
        <el-select
          v-model="queryParams.zhiKaState"
          placeholder="请选择制卡状态"
          clearable
        >
          <el-option
            v-for="dict in zhi_ka_state"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <!--
      <el-form-item label="复核日期">
        <el-date-picker
          v-model="value1"
          type="daterange"
          range-separator="To"
          start-placeholder="Start date"
          end-placeholder="End date"
          :size="size"
        />
      </el-form-item> -->

      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          @click="handleAdd"
          v-hasPermi="['talent:list:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['talent:list:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['talent:list:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['talent:list:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        v-model:showSearch="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="listData"
      @selection-change="handleSelectionChange"
    >
      <el-table-column label="卡片编号" align="center" prop="cardNumber" />
      <el-table-column
        width="150"
        label="姓名"
        align="center"
        prop="chineseName"
      />

      <el-table-column width="150" label="性别" align="center" prop="gender">
        <template #default="scope">
          <dict-tag :options="sys_user_sex" :value="scope.row.gender" />
        </template>
      </el-table-column>

      <el-table-column
        width="150"
        label="证件类型"
        align="center"
        prop="zhengJianType"
      >
        <template #default="scope">
          <dict-tag
            :options="zheng_jian_type"
            :value="scope.row.zhengJianType"
          />
        </template>
      </el-table-column>
      <el-table-column width="200" label="证件号" align="center" prop="idNum" />
      <el-table-column
        width="200"
        label="手机号码"
        align="center"
        prop="shouJiNum"
      />

      <el-table-column
        width="200"
        label="工作单位"
        align="center"
        prop="yrdwName"
      />

      <el-table-column
        label="制卡类型"
        width="150"
        align="center"
        prop="zhiKaType"
      >
        <template #default="scope">
          <dict-tag :options="zhi_ka_type" :value="scope.row.zhiKaType" />
        </template>
      </el-table-column>
      <el-table-column
        label="制卡状态"
        width="150"
        align="center"
        prop="zhiKaState"
      >
        <template #default="scope">
          <dict-tag :options="zhi_ka_state" :value="scope.row.zhiKaState" />
        </template>
      </el-table-column>
      <el-table-column
        label="制卡时间"
        align="center"
        prop="zhiKaDate"
        width="180"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.zhiKaDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="出卡时间"
        align="center"
        prop="chuKaDate"
        width="180"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.chuKaDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="复核截止日期"
        align="center"
        prop="fuheJiezhiDate"
        width="200"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.fuheJiezhiDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="是否超过复核截止日期"
        align="center"
        prop="fuheJiezhiDate"
        width="200"
      >
        <template #default="scope">
          <el-tag
            :type="
              fuheJiezhiDate(
                parseTime(scope.row.fuheJiezhiDate, '{y}-{m}-{d}')
              ) > 0
                ? 'danger'
                : 'primary'
            "
            >{{
              fuheJiezhiDate(
                parseTime(scope.row.fuheJiezhiDate, "{y}-{m}-{d}")
              ) > 0
                ? "是"
                : "否"
            }}</el-tag
          >
        </template>
      </el-table-column>
      <el-table-column
        label="英才卡有效日期"
        align="center"
        prop="cardYouxiaoDate"
        width="200"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.cardYouxiaoDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="是否超过英才卡有效日期"
        align="center"
        prop="fuheJiezhiDate"
        width="200"
      >
        <template #default="scope">
          <el-tag
            :type="
              cardYouxiaoDate(
                parseTime(scope.row.cardYouxiaoDate, '{y}-{m}-{d}')
              ) > 0
                ? 'danger'
                : 'primary'
            "
            >{{
              cardYouxiaoDate(
                parseTime(scope.row.cardYouxiaoDate, "{y}-{m}-{d}")
              ) > 0
                ? "是"
                : "否"
            }}</el-tag
          >
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="150"
      >
        <template #default="scope">
          <el-button
            link
            type="primary"
            icon="Edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['talent:list:edit']"
            >修改</el-button
          >
          <el-button
            link
            type="primary"
            icon="Delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['talent:list:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script setup name="List">
import {
  listList,
  getListData,
  delList,
  addList,
  updateList,
} from "@/api/talentManagement/category";
import { computed } from "vue";
import {useRouter} from "vue-router";
const router = useRouter();
const { proxy } = getCurrentInstance();
const {
  zhi_ka_type,
  is_zhuxiao,
  zhi_ka_state,
  card_type,
  yjrc_type,
  politics_status,
  zheng_jian_type,
  sys_user_sex,
} = proxy.useDict(
  "sys_user_sex",
  "zhi_ka_type",
  "is_zhuxiao",
  "zhi_ka_state",
  "card_type",
  "yjrc_type",
  "politics_status",
  "zheng_jian_type"
);

const listData = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    sehnqingrenId: null,
    cardType: "B",
    cardNumber: null,
    sehnqingNumber: null,
  },
  rules: {},
});

const { queryParams, form, rules } = toRefs(data);

/** 查询人才库列列表 */
function getList() {
  loading.value = true;
  listList(queryParams.value).then((response) => {
    listData.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    sehnqingrenId: null,
    cardType: "B",
    cardNumber: null,
    sehnqingNumber: null,
    chineseName: null,
    englishName: null,
    photoPath: null,
    politicsStatus: null,
    gender: null,
    minZu: null,
    chuShengDate: null,
    jiGuan: null,
    juZhuDi: null,
    xueLi: null,
    school: null,
    specialty: null,
    isHaiwai: null,
    zaiZhiJiaoYu: null,
    zaiZhiZhuanYe: null,
    zhengShuNum: null,
    renCaiType: null,
    renCaiChengHao: null,
    getDate: null,
    zhengJianType: null,
    idNum: null,
    phoneNum: null,
    shouJiNum: null,
    eMail: null,
    yjrcYuanDanWeiZhiWu: null,
    yjrcXianDanWeiZhiWu: null,
    yjrcType: null,
    yjrcQianyueDate: null,
    zzpyZhiWu: null,
    byuanDanWei: null,
    byuanDanWeiZhiwu: null,
    byuanDanWeiZhicheng: null,
    bxianDanWei: null,
    bxianDanWeiZhiwu: null,
    bxianDanWeiZhicheng: null,
    yrdwName: null,
    yrdwAddressArea: null,
    yrdwAddress: null,
    yrdwXingZhi: null,
    yrdwIndustryInvolved: null,
    yrdwFaRen: null,
    yrdwLianxiRen: null,
    yrdwPhone: null,
    jingLi: null,
    huojiangCondition: null,
    zhiKaState: null,
    zhiKaType: null,
    zhiKaDate: null,
    chuKaDate: null,
    fuheJiezhiDate: null,
    cardYouxiaoDate: null,
    isZhuxiao: null,
    zhuxiaoReason: null,
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null,
    remark: null,
  };
  proxy.resetForm("listRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

//是否超过复核日期
const fuheJiezhiDate = computed(() => {
  return (date) => {
    return new Date().getTime() - new Date(date).getTime();
  };
});

//是否超过英才卡有效日期
const cardYouxiaoDate = computed(() => {
  return (date) => {
    return new Date().getTime() - new Date(date).getTime();
  };
});

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map((item) => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

// /** 新增按钮操作 */
// function handleAdd() {
//   reset();
//   open.value = true;
//   title.value = "添加人才库列";
// }

/** 新增按钮操作 */
function handleAdd() {
  router.push({
    path: "/materialApplication/indexb",
    query: {
      methodType: "post",
    },
  });
}



/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const _id = row.id || ids.value;
  getListData(_id).then((response) => {
    form.value = response.data;
    open.value = true;
    title.value = "修改人才库列";
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["listRef"].validate((valid) => {
    if (valid) {
      if (form.value.id != null) {
        updateList(form.value).then((response) => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addList(form.value).then((response) => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal
    .confirm('是否确认删除人才库列编号为"' + _ids + '"的数据项？')
    .then(function () {
      return delList(_ids);
    })
    .then(() => {
      getList();
      proxy.$modal.msgSuccess("删除成功");
    })
    .catch(() => {});
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download(
    "talent/list/export",
    {
      ...queryParams.value,
    },
    `list_${new Date().getTime()}.xlsx`
  );
}

getList();
</script>
