<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="idNo" />
      <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="View" @click="look(row)">简历查看</el-button>
          <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" />
      <el-dialog title="简历" v-model="lookShow" width="1000px" append-to-body :close-on-click-modal="false">
      <el-descriptions title="基本信息">
        <el-descriptions-item label="姓名">{{ lookInfo.userInfo.name }}</el-descriptions-item>
        <el-descriptions-item label="性别">{{ lookInfo.userInfo.sex ? '男' : '女' }}</el-descriptions-item>
        <el-descriptions-item label="手机号码">{{ lookInfo.userInfo.phoneNumber }}</el-descriptions-item>
        <el-descriptions-item label="身份证号">{{ lookInfo.userInfo.idNo }}</el-descriptions-item>
      </el-descriptions>
      <el-descriptions :title="`求职意向${index + 1}`" v-for="(item,index) in lookInfo.careerObjective">
        <el-descriptions-item label="期望职位">{{ item.industryName }}</el-descriptions-item>
        <el-descriptions-item label="工作城市">{{ item.province }}{{ item.city }}{{ item.region }}</el-descriptions-item>
        <el-descriptions-item label="薪资要求">{{ item.salaryMin }}-{{ item.salaryMax }}</el-descriptions-item>
        <el-descriptions-item label="工作性质">{{ item.workType }}</el-descriptions-item>
      </el-descriptions>
      <el-descriptions :title="`工作经历${index + 1}`" v-for="(item,index) in lookInfo.workExperience">
          <el-descriptions-item label="公司名称">{{ item.orgName }}</el-descriptions-item>
          <el-descriptions-item label="职位名称">{{ item.job }}</el-descriptions-item>
          <el-descriptions-item label="在职时间">{{ item.startTime }} ~ {{ item.endTime }}</el-descriptions-item>
          <el-descriptions-item label="所属行业">{{ item.industryName }}</el-descriptions-item>
          <el-descriptions-item label="月薪">{{ item.money }}</el-descriptions-item>
          <el-descriptions-item></el-descriptions-item>
          <el-descriptions-item label="工作描述">{{ item.descr }}</el-descriptions-item>
      </el-descriptions>
      <el-descriptions :title="`教育经历${index + 1}`" v-for="(item,index) in lookInfo.educationalBackground">
          <el-descriptions-item label="最高学历">{{ item.qualification }}</el-descriptions-item>
          <el-descriptions-item label="学校名称">{{ item.school }}</el-descriptions-item>
          <el-descriptions-item label="所学专业">{{ item.major }}</el-descriptions-item>
          <el-descriptions-item label="在校时间">{{ item.startTime }} ~ {{ item.endTime }}</el-descriptions-item>
      </el-descriptions>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="lookShow = false">关 闭</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import { personList,personDel,workExperienceList,personEducational,objectiveIndustry } 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,
})
const lookShow = ref(false);
const lookInfo = ref({
  userInfo: {}, // 基本信息
  careerObjective: [], // 求职意向
  workExperience: [], // 工作经历
  educationalBackground: [], // 教育经历
});
function look(row) {
  lookShow.value = true
  lookInfo.value = {
    userInfo: row,
    careerObjective: [],
    workExperience: [],
    educationalBackground: [],
  }
  workExperienceList({ personId: row.id }).then(res => {
    lookInfo.value.workExperience = res.data.list
  })
  personEducational({ personId: row.id }).then(res => {
    lookInfo.value.educationalBackground = res.data.list
  })
  objectiveIndustry({ personId: row.id }).then(res => {
    lookInfo.value.careerObjective = res.data.list
  })
}
/** 查询列表 */
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>