<template>
  <!-- 搜索工作栏 -->
  <ContentWrap>
    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="40px"
    >
      <el-form-item label="状态" prop="task_status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择状态"
          clearable
          class="!w-200px"
          @change="handleQuery"
        >
          <el-option v-for="(val, index) in ['待审核', '已入库']" :label="val" :value="val" :key="index" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery"><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="name_zh" />
      <el-table-column label="职位" align="center" prop="title_zh" />
      <el-table-column label="酒店" align="center" prop="hotel_zh" />
      <!-- <el-table-column label="手机号码" align="center" prop="mobile" /> -->
      <el-table-column label="来源" align="center" prop="task_type" />
      <el-table-column label="任务ID" align="center" prop="task_id" />
      <el-table-column label="状态" align="center" prop="status">
        <template #default="{ row }">
          <el-tag :type="typeObj[row.status]">{{ row.status }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="created_at" :formatter="dateFormatter" />
      <!-- <el-table-column label="更新时间" align="center" prop="updated_at" :formatter="dateFormatter" /> -->
      <el-table-column label="操作" align="center" fixed="right" min-width="110">
        <template #default="scope">
          <el-button
            v-if="scope.row.status === '待审核'"
            link
            type="success"
            @click="handleStore(scope.row)"
          >审核入库</el-button>
          <el-button link type="primary" @click="handleStore(scope.row, true)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.page"
      v-model:limit="queryParams.per_page"
      @pagination="getList"
    />
  </ContentWrap>

	<!-- 入库 -->
  <StorePage ref="StorePageRef" @refresh="handleQuery" />
</template>

<script setup>
defineOptions({ name: 'TalentMapMaintenanceExamineIndex' })
import { dateFormatter } from '@/utils/formatTime'
import StorePage from '@/views/menduner/system/talentMap/maintenance/examine/store.vue'
import { talentExamineApi } from '@/api/menduner/system/talentMap/examine'

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const loading = ref(false) // 列表的加载中
const list = ref([]) // 列表的数据
const total = ref(0) // 列表的总页数
const queryParams = reactive({
  // page: 1,
  // per_page: 10,
  // task_status: undefined // 来源
  status: null
})
const queryFormRef = ref() // 搜索的表单
const taskType = [
  { label: '名片', value: '名片' },
  { label: '简历', value: '简历' },
  { label: '门墩儿新任命', value: '新任命' },
  { label: '门墩儿招聘', value: '招聘' },
  { label: '杂项', value: '杂项' }
]
const typeObj = {
  '待审核': 'primary',
  '已入库': 'success',
  '已拒绝': 'danger'
}

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    list.value = []
    const data = await talentExamineApi.getExamineList(queryParams)
    list.value = data || []
    // list.value = data.tasks ?? []
    // total.value = data.pagination.total ?? 0
  } finally {
    loading.value = false
  }
}

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

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

// 入库
const StorePageRef = ref(null)
const handleStore = (row, isDetail = false) => {
  StorePageRef.value.open(row.task_type, [row], row.task_id, isDetail)
}

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

</script>

<style lang="scss" scoped>
</style>