<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="exactParams.name"
              clearable
              style="width: 300px"
              @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="证件号码" prop="id_no">
          <el-input
              v-model="exactParams.id_no"
              clearable
              style="width: 300px"
              @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="账号" prop="account">
          <el-input
              v-model="exactParams.account"
              clearable
              style="width: 300px"
              @keyup.enter="handleQuery"
          />
        </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="center" prop="name" />
        <el-table-column label="证件号码" align="left" prop="id_no"  />
        <el-table-column label="账号" align="left" prop="account" />
        <el-table-column label="创建时间" align="left" prop="create_time" />
        <el-table-column label="更新时间" align="left" prop="update_time" />
<!--        <el-table-column label="操作" width="280" align="center" class-name="small-padding fixed-width" fixed="right">-->
<!--          <template #default="{row}">-->
<!--            <el-button link type="primary"  @click="handleResetPwd(row)" icon="Refresh">重置密码</el-button>-->
<!--          </template>-->
<!--        </el-table-column>-->
      </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, resetPwd} from "@/api/person";

  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,
      query:'exact',
      vague:'',
      accurate:''
    },
    exactParams:{
    }
  });
  
  const { queryParams, exactParams } = toRefs(data);

  /** 查询列表 */
  function getList() {
    loading.value = true;
    personL(queryParams.value).then(response => {
      list.value = response.data;
      total.value = response.count;
      loading.value = false;
    });
  }

  /** 重置密码按钮操作 */
  function handleResetPwd(row) {
    proxy.$modal.confirm('您确定要重置密码吗？').then(function() {
      return resetPwd({
        id: row.id,
      });
    }).then((res) => {
      getList();
      proxy.$modal.msgSuccess(res.code);
    }).catch(() => {});
  }


  /** 搜索按钮操作 */
  function handleQuery() {
    queryParams.value.page = 1;
    queryParams.value.limit = 10;
    queryParams.value.accurate = JSON.stringify(exactParams.value);
    getList();
  }
  /** 重置按钮操作 */
  function resetQuery() {
    proxy.resetForm("queryRef");
    exactParams.value={};
    handleQuery();
  }


  getList();

  </script>
  