<template>
    <!-- 搜索工作栏 -->
  <ContentWrap>
    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="姓名" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入姓名" clearable @keyup.enter="handleQuery" class="!w-130px" />
      </el-form-item>
      <el-form-item label="联系电话" prop="phone">
        <el-input v-model="queryParams.phone" placeholder="请输入联系电话" clearable @keyup.enter="handleQuery" class="!w-130px" />
      </el-form-item>
      <el-form-item label="性别" prop="sex">
        <el-select v-model="queryParams.sex" placeholder="请选择性别" clearable class="!w-130px">
          <el-option v-for="dict in getIntDictOptions(DICT_TYPE.MENDUNER_SEX)" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="求职状态" prop="jobStatus">
        <el-select v-model="queryParams.jobStatus" placeholder="请选择求职状态" clearable class="!w-130px">
          <el-option v-for="dict in getIntDictOptions(DICT_TYPE.MENDUNER_JOB_SEEK_STATUS)" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="学历" prop="eduType">
        <el-select v-model="queryParams.eduType" placeholder="请选择学历" clearable class="!w-130px">
          <el-option v-for="dict in getIntDictOptions(DICT_TYPE.MENDUNER_EDUCATION_TYPE)" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="工作经验" prop="expType">
        <el-select v-model="queryParams.expType" placeholder="请选择工作经验" clearable class="!w-130px">
          <el-option v-for="dict in getIntDictOptions(DICT_TYPE.MENDUNER_EXP_TYPE)" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery" type="primary"><Icon icon="ep:search" /> 搜索</el-button>
        <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true">
      <!-- <el-table-column label="用户头像" align="center" prop="avatar" width="90px" fixed="left">
        <template #default="scope">
          <el-image v-if="scope.row.person?.avatar" class="h-80px w-80px" :src="scope.row.person?.avatar" lazy preview-teleported :preview-src-list="[scope.row.person?.avatar]" fit="contain" />
        </template>
      </el-table-column> -->
      <el-table-column label="姓名" align="center" prop="person.name" fixed="left" />
      <el-table-column label="联系电话" align="center" prop="user.phone" width="120px" />
      <el-table-column label="求职状态" align="center" prop="person.jobStatus" width="130px">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.MENDUNER_JOB_SEEK_STATUS" :value="scope.row.person?.jobStatus" />
        </template>
      </el-table-column>
      <el-table-column label="学历" align="center" prop="person.eduType">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.MENDUNER_EDUCATION_TYPE" :value="scope.row.person?.eduType" />
        </template>
      </el-table-column>
      <el-table-column label="工作经验" align="center" prop="person.expType">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.MENDUNER_EXP_TYPE" :value="scope.row.person?.expType" />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" fixed="right" min-width="60">
        <template #default="scope">
          <el-button link type="primary" @click="handleDetail(scope.row)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      layout="total, prev, pager, next"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>
</template>

<script setup>
defineOptions({ name: 'TalentMapSearch' })
import { TalentMap } from '@/api/menduner/system/talentMap'
import { PersonInfoApi } from '@/api/menduner/system/person'
import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'

const emit = defineEmits(['detail'])
const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const loading = ref(false) // 列表的加载中
const list = ref([]) // 列表的数据
const total = ref(0) // 列表的总页数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  name: '',
  phone: undefined,
  expType: undefined,
  eduType: undefined,
  jobStatus: undefined
})
const queryFormRef = ref() // 搜索的表单

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await PersonInfoApi.getPersonInfoPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}

const handleDetail = (row) => {
  emit('detail', row.user.id)
}

/** 初始化 **/
onMounted(() => {
  getList()
})
</script>