<template>
  <!-- 搜索工作栏 -->
  <ContentWrap>
    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="40px"
    >
			<el-form-item label="状态" prop="status">
        <el-select
          v-model="queryParams.status"
          class="!w-240px"
          clearable
          placeholder="请选择状态"
        >
          <el-option
            v-for="dict in statusOptions"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</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" row-key="id">
      <el-table-column label="姓名" align="center" prop="main_card.name_zh" />
      <el-table-column label="酒店" align="center" prop="main_card.hotel_zh" :show-overflow-tooltip="true" />
      <el-table-column label="职位" align="center" prop="main_card.title_zh" :show-overflow-tooltip="true" />
      <el-table-column label="手机号" align="center" prop="main_card.mobile" :show-overflow-tooltip="true" />
      <el-table-column label="原因" align="center" prop="duplicate_reason" :show-overflow-tooltip="true" />
      <el-table-column label="状态" align="center" prop="processing_status">
        <template #default="scope">
          <el-tag :type="statusOptions.find(item => item.value === scope.row.processing_status)?.color">
						{{ statusOptions.find(item => item.value === scope.row.processing_status)?.label }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="created_at" width="160" />
      <el-table-column label="操作" align="center">
        <template #default="scope">
          <el-button
            v-if="scope.row.processing_status === 'pending'"
            link
            type="success"
            @click="openForm(scope.row.main_card_id)"
          >处理</el-button>
          <el-button type="primary" link @click="openForm(scope.row.main_card_id, true)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>
  </ContentWrap>

  <MergePage ref="mergePageRef" @refresh="getList" />
</template>

<script setup name="TalentMapDuplicate">
import { talentDuplicateApi } from '@/api/menduner/system/talentMap/duplicate'
import MergePage from './merge.vue'

const loading = ref(false)
const list = ref([])
const mergePageRef = ref()
const queryParams = reactive({
	status: ''
})
const queryFormRef = ref() // 搜索的表单
const statusOptions = [
	{ label: '待处理', value: 'pending', color: 'warning' },
	{ label: '已处理', value: 'processed', color: 'success' },
	// { label: '已忽略', value: 'ignored', color: 'info' }
]

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await talentDuplicateApi.getDuplicateList(queryParams)
    list.value = data || []
  } finally {
    loading.value = false
  }
}

/** 添加/修改操作 */
const openForm = async (id, isDetail = false) => {
  mergePageRef.value.open(id, isDetail)
}

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

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

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