<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>
        <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>

  <div v-if="paramsVerify && !list?.length" class="tip">
    <div>{{ tipContent }}</div>
  </div>
  <!-- 列表 -->
  <ContentWrap>
    <div class="listBox" v-loading="loading">
      <personCard
        v-for="item of list"
        :key="item.id"
        :data="item"
        class="item"
        @detail="detail"
      />
    </div>
  </ContentWrap>

  <ContentWrap>
    <!-- <el-table v-loading="loading" :data="list" :stripe="true">
      <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 v-if="scope.row.person?.jobStatus" :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 v-if="scope.row.person?.eduType" :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 v-if="scope.row.person?.expType" :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)">{{ detailButTxt || '详情'}}</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'
import personCard from './personCard.vue'

const emit = defineEmits(['detail'])
const props = defineProps({
  detailButTxt: String,
  paramsVerify: Boolean,
  searchName: String
})
const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

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

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await PersonInfoApi.getPersonInfoPage(queryParams)
    list.value = data?.list.map(e => {
      return {
        ...e.person,
        // Boolean(exp.year) || Boolean(exp.enterpriseName) || Boolean(exp.positionName)
        workExpList: e.work ? [e.work] : []
      }
    }) || []
    total.value = data?.total || 0
  } finally {
    loading.value = false
  }
}

const tipContent = '输入人才姓名、电话查询后可使用门墩儿人才库数据填充表单！'
/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  if (props.paramsVerify && !queryParams.name && !queryParams.phone) {
    message.warning('请输入后查询 ！')
    return
  }
  getList()
}

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

const detail = (row) => {
  emit('detail', { id: row.id, userId: row.userId })
}

/** 初始化 **/
// onMounted(async () => {
//   if (props.paramsVerify) return
//   setTimeout(() => {
//     if (props.searchName) {
//       queryParams.name = props.searchName
//     }
//   }, 1000)
//   getList()
// })

if (!props.paramsVerify) getList()
</script>

<style lang="scss" scoped>
.tip {
  text-align: center;
  margin-bottom: 10px;
  color: #e6a23c;
}
.listBox {
  min-height: 200px;
  max-height: calc(100vh - 400px);
  overflow-y: auto;
  padding: 10px;
  .item {
    margin-bottom: 10px;
  }
}
</style>