<!-- @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="cardType">
        <el-select
          v-model="queryParams.cardType"
          placeholder="请选择卡片类型"
          clearable
        >
          <el-option
            v-for="dict in card_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="申请人" prop="chineseName">
        <el-input
          v-model="queryParams.chineseName"
          placeholder="请选择卡片类型"
        >
        </el-input>
      </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-table v-loading="loading" :data="formList">
      <el-table-column
        label="序号"
        width="100"
        align="center"
        type="index"
      ></el-table-column>
      <el-table-column
        label="申请人"
        align="center"
        prop="chineseName"
      ></el-table-column>
      <el-table-column label="证件类型" align="center">
        <template #default="scope">
          <dict-tag
            :options="zheng_jian_type"
            :value="scope.row.zhengJianType"
          />
        </template>
      </el-table-column>
      <el-table-column label="证件号" align="center" p rop="idNum">
        <template #default="scope">
          <span
            >{{ maskIdNumber(scope.row.idNum, scope.row.isIdView) }}
            <el-icon
              style="cursor: pointer"
              @click="scope.row.isIdView = true"
              v-if="!scope.row.isIdView"
              ><View />
            </el-icon>
            <el-icon
              style="cursor: pointer"
              @click="scope.row.isIdView = false"
              v-else
              ><Hide
            /></el-icon>
          </span>
        </template>
      </el-table-column>
      <el-table-column label="类型" align="center">
        <template #default="scope">
          <dict-tag :options="card_type" :value="scope.row.cardType" />
        </template>
      </el-table-column>
      <el-table-column label="申请编号" align="center" prop="sehnqingNumber" />

      <el-table-column
        label="申请时间"
        align="center"
        prop="createTime"
        width="180"
      >
      </el-table-column>

      <el-table-column label="操作" align="center">
        <template #default="scope">
          <el-button type="text" icon="Edit" @click="handleUpdate(scope.row)"
            >编辑</el-button
          >
          <el-button type="text" icon="Delete" @click="handleDelete(scope.row)"
            >删除</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="Form">
import { listForm, delForm } from "@/api/talentApplication/draftBox";
import { useRouter } from "vue-router";

import useUserStore from "@/store/modules/user.js";

const userStore = useUserStore();

const router = useRouter();
const { proxy } = getCurrentInstance();
const { card_type, zheng_jian_type } = proxy.useDict(
  "card_type",
  "yjrc_type",
  "politics_status",
  "zheng_jian_type"
);

const formList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const total = ref(0);
const title = ref("");
const isIdView = ref(false);

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    cardType: null,
    shenqingState: "cg",
    chineseName: null,
  },
});

const { queryParams } = toRefs(data);

/** 查询人才绿卡申请列表 */
function getList() {
  loading.value = true;
  listForm({ ...queryParams.value, sehnqingrenId: userStore.id }).then(
    (response) => {
      formList.value = response.rows;
      total.value = response.total;
      loading.value = false;
    }
  );
}

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

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

/** 修改按钮操作 */
function handleUpdate(row) {
  router.push({
    path: "/materialApplication",
    query: {
      materialCalssId: row.id,
      type: row.cardType,
    },
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal
    .confirm("是否确认删除选中的数据项？")
    .then(function () {
      return delForm(_ids);
    })
    .then(() => {
      getList();
      proxy.$modal.msgSuccess("删除成功");
    })
    .catch(() => {});
}

getList();
</script>
