<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 label="姓名">
        <el-input placeholder="请输入" v-model="queryParams.personName" />
      </el-form-item>
      <el-form-item label="身份证号">
        <el-input placeholder="请输入" v-model="queryParams.personIdno" />
      </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="rtTime">
        <template #default="{row}">
          {{ row.rtTime || row.createTime}}
        </template>
      </el-table-column>
      <el-table-column label="报名企业" prop="orgName" />
      <el-table-column label="报名职位" prop="name" />
      <el-table-column label="姓名">
        <template #default="{row}">
          {{ row.person && row.person.name}}
        </template>
      </el-table-column>
      <el-table-column label="联系电话">
        <template #default="{row}">
          {{ row.person && row.person.phoneNumber}}
        </template>
      </el-table-column>
      <el-table-column label="性别" prop="sex">
        <template #default="{row}">
          {{ row.person && row.person.sex ? '男' : '女' }}
        </template>
      </el-table-column>
      <el-table-column label="身份证号">
        <template #default="{row}">
          {{ row.person && row.person.idNo}}
        </template>
      </el-table-column>
      <el-table-column label="状态" width="160" align="center">
        <template #default="{row}">
          {{ row.recordState == 'INTERVIEW' ? '面试中' : '' }}
          {{ row.recordState == 'APPLY_FAILED' ? '未录取' : '' }}
          {{ row.recordState == 'APPLY_SUCCESS' ? '已录取' : '' }}
          {{ row.recordState == 'ON_BOARDING' ? '已入职' : '' }}
          {{ row.recordState == 'INVITING_INTERVIEW' ? '邀请面试' : '' }}
          {{ row.recordState == 'APPLYING' ? '提交简历' : '' }}
        </template>
      </el-table-column>
      <el-table-column label="操作" width="200" align="center">
        <template #default="{row}">
          <el-button link type="primary" icon="View" @click="look(row)">简历查看</el-button>
          <el-button link type="primary" icon="Edit" @click="edit(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" class="jltc">
      <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>
    <el-dialog title="修改状态" v-model="open" width="400px" append-to-body>
        <el-form ref="postRef" label-width="80px">
          <el-form-item label="状态" prop="state">
            <el-select clearable v-model="state" placeholder="请选择" style="width: 100%;">
              <el-option label="面试中" value="INTERVIEW" />
              <el-option label="未录取" value="APPLY_FAILED" />
              <el-option label="已录取" value="APPLY_SUCCESS" />
              <el-option label="已入职" value="ON_BOARDING" />
              <el-option label="邀请面试" value="INVITING_INTERVIEW" />
            </el-select>
          </el-form-item>
        </el-form>
        <template #footer>
          <div class="dialog-footer">
            <el-button type="primary" @click="submitForm">提 交</el-button>
            <el-button @click="open = false">取 消</el-button>
          </div>
        </template>
      </el-dialog>
  </div>
</template>

<script setup>

import { signRecordList,workExperienceList,personEducational,objectiveIndustry, updateState } from "@/api/personnel";
import { ref } from "vue";
const { proxy } = getCurrentInstance();
const list = ref([]);
const loading = ref(false);
const total = ref(0);
const state = ref(''); // 修改状态
const open = ref(false);
const rowInfo = ref({});
const lookInfo = ref({
  userInfo: {}, // 基本信息
  careerObjective: [], // 求职意向
  workExperience: [], // 工作经历
  educationalBackground: [], // 教育经历
});
const lookShow = ref(false);
const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
})
function look(row) {
  lookShow.value = true
  lookInfo.value = {
    userInfo: row.person,
    careerObjective: [],
    workExperience: [],
    educationalBackground: [],
  }
  workExperienceList({ personId: row.person.id }).then(res => {
    lookInfo.value.workExperience = res.data.list
  })
  personEducational({ personId: row.person.id }).then(res => {
    lookInfo.value.educationalBackground = res.data.list
  })
  objectiveIndustry({ personId: row.person.id }).then(res => {
    lookInfo.value.careerObjective = res.data.list
  })
}
function edit(row) {
  open.value = true;
  debugger
  rowInfo.value = row;
}
function submitForm() {
  if (!state.value) {
    return proxy.$modal.msgError('请选择状态');
  }
  debugger
  updateState({
    state: state.value,
    openId: rowInfo.value.person.openId,
    recruitId: rowInfo.value.id,
    recordId: rowInfo.value.recordId,
    // id: rowInfo.value.id,
  }).then(res => {
    getList();
    proxy.$modal.msgSuccess('修改成功');
    open.value = false;
  })
}
/** 查询列表 */
function getList() {
  const form = { ...queryParams.value }
  loading.value = true;
  signRecordList(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>
<style lang="scss">
.jltc {
  .el-descriptions{
    border-bottom: 1px solid #eee;
  }
  .el-descriptions:last-child{
    border-bottom: none;
  }
}
</style>