<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true">
      <el-form-item label="姓名">
        <el-input placeholder="请输入" v-model="queryParams.name" />
      </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" show-overflow-tooltip>
      <el-table-column label="姓名" prop="name" />
      <el-table-column label="手机号" prop="phoneNumber" />
      <el-table-column label="年龄" prop="age" align="center"  />
      <el-table-column label="性别" prop="sex">
        <template #default="{row}">
          {{ row.sex ? '男' : '女' }}
        </template>
      </el-table-column>
      <el-table-column label="民族" prop="nation" />
      <el-table-column label="创建时间" prop="createTime" align="center"/>
      <el-table-column label="操作" width="160" align="center">
        <template #default="{row}">
          <el-button link type="primary" icon="Delete" @click="del(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>
import { personList,personDel } from "@/api/personnel";
import { ref } from "vue";
const { proxy } = getCurrentInstance();
const list = ref([]);
const loading = ref(false);
const total = ref(0);
const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
})
/** 查询列表 */
function getList() {
  const form = { ...queryParams.value }
  loading.value = true;
  personList(form).then(res => {
    list.value = res.data.list;
    total.value = res.data.total;
    loading.value = false;
  });
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  queryParams.value.pageSize = 10;
  getList();
}
/** 重置按钮操作 */
function resetQuery() {
  queryParams.value = {
    pageNum: 1,
    pageSize: 10,
  }
  handleQuery();
}
function del(row) {
    proxy.$modal.confirm('您确定要删除吗？').then(function() {
      return personDel({
        id: row.id,
      });
    }).then((res) => {
      getList();
      proxy.$modal.msgSuccess('删除成功');
    }).catch(() => {});
}
getList();
</script>
<style lang="scss" scoped>
.el-dialog .el-dialog__body {
  max-height: 650px;
}
</style>