<!-- @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" prop="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-tag type="success">审批通过</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center">
        <template #default="scope">
          <el-button type="text" icon="Edit" @click="handleView(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"
    />

    <el-dialog
      v-model="viewDia"
      title="查看详情"
      width="80%"
      :before-close="
        () => {
          viewDia = false;
        }
      "
    >
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="viewDia = false">关闭</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import { listForm, delForm } from "@/api/talentApplication/draftBox";
import { useRouter } from "vue-router";
import AmatterClass from "@/components/AmatterClass/index";
import materialTable from "@/components/materialTable/index";
import useUserStore from "@/store/modules/user";

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

const viewDia = ref(false);
const formList = ref([]);
const loading = ref(true);
const showSearch = ref(true);
const total = ref(0);

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    cardType: null,
    shenqingState: "sptg",
    chineseName: null,
    sehnqingrenId: userStore.id,
  },
});

const { queryParams } = toRefs(data);

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

//查看正在预审的详情材料
const handleView = (row) => {
  console.log(row);
  viewDia.value = true;
};

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

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

getList();
</script>
