<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch">
        <el-form-item label="姓名" prop="name">
          <el-input
              v-model="queryParams.name"
              clearable
              style="width: 300px"
              @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="证件号码" prop="id_no">
          <el-input
              v-model="queryParams.id_no"
              clearable
              style="width: 300px"
              @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="状态" prop="state">
          <el-select
              v-model="queryParams.state"
              placeholder="请选择"
              style="width: 300px"
          >
            <el-option value="entry" label="在职" />
            <el-option value="quit" label="离职" />
          </el-select>
        </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="list">
        <el-table-column label="证件号码" align="left" prop="id_no" />
        <el-table-column label="姓名" align="left" prop="name"  >
          <template #default="{row}">
            <el-button link type="primary" @click="handleDetail(row)">{{row.name}}</el-button>
          </template>
        </el-table-column>
        <el-table-column label="性别" align="center" prop="sex" />
        <el-table-column label="年龄" align="center" prop="age" />
        <el-table-column label="籍贯" align="center" prop="register" />
        <el-table-column label="状态" align="left" prop="state"  />
        <el-table-column label="入库时间" align="left" prop="create_time" />
        <el-table-column label="更新时间" align="left" prop="update_time" />
      </el-table>
  
      <pagination
          v-show="total > 0"
          :total="total"
          v-model:page="queryParams.page"
          v-model:limit="queryParams.limit"
          @pagination="getList"
      />

    </div>
  </template>
  
<script setup>

  
  import {personL} from "@/api/personArchives.js";

  const { proxy } = getCurrentInstance();
  
  const list = ref([]);
  const loading = ref(true);
  const showSearch = ref(true);
  const total = ref(0);


  const data = reactive({
    queryParams: {
      page: 1,
      limit: 10,
    },
  });
  
  const { queryParams } = toRefs(data);


  /** 查询列表 */
  function getList() {
    loading.value = true;
    personL(queryParams.value).then(response => {
      list.value = response.data.data;
      total.value = response.data.count;
      loading.value = false;
    });
  }
  
  /** 搜索按钮操作 */
  function handleQuery() {
    queryParams.value.page = 1;
    queryParams.value.limit = 10;
    getList();
  }
  /** 重置按钮操作 */
  function resetQuery() {
    proxy.resetForm("queryRef");
    handleQuery();
  }

  function handleDetail(row) {
    proxy.$router.push('/person/archives/details?id='+row.id)
  }


  getList();

  </script>
  