<template>
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true">
      <el-table-column label="投递岗位" align="center" prop="job.name">
        <template #default="scope">{{ formatName(scope.row.job.name) }}</template>
      </el-table-column>
      <el-table-column label="岗位薪资" align="center" prop="job.payFrom">
        <template #default="{ row }">
          {{ !row.job.payFrom && !row.job.payTo ? '面议' : `${row.job.payFrom}-${row.job.payTo}/${payUnit.find(e => e.value === Number(row.job.payUnit))?.label}` }}
        </template>
      </el-table-column>
      <el-table-column label="发布企业" align="center" prop="enterprise.name">
        <template #default="{ row }">{{ formatName(row.enterprise.anotherName || row.enterprise.name) }}</template>
      </el-table-column>
      <el-table-column label="面试时间" align="center" prop="time">
        <template #default="{ row }">{{ timesTampChange(row.time, 'Y-M-D h:m') }}</template>
      </el-table-column>
      <el-table-column label="面试地点" align="center" prop="address" />
      <el-table-column label="联系人" align="center" prop="contact.name" />
      <el-table-column label="联系电话" align="center" prop="phone" />
      <el-table-column label="状态" align="center" prop="status">
        <template #default="{ row }">
          <dict-tag :type="DICT_TYPE.MENDUNER_INTERVIEW_INVITE_STATUS" :value="row.status" />
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>
</template>

<script lang="ts" setup>
import { timesTampChange } from '@/utils/transform/date'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { PersonInfoApi } from '@/api/menduner/system/person'
import { formatName } from '@/utils'
defineOptions({ name: 'PersonInterviewInvite' })

const props = defineProps({
  userId: String
})

const loading = ref(true) // 列表的加载中
const total = ref(0) // 列表的总页数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  userId: props.userId
})

const payUnit = getIntDictOptions(DICT_TYPE.MENDUNER_PAY_UNIT)
const list = ref([]) // 列表的数据
const getList = async () => {
  loading.value = true
  try {
    const data = await PersonInfoApi.getInterviewInvitePage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

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