<!-- 人才库 - 人才详情 -->
<template>
  <div v-if="Object.keys(cvData).length" class="d-flex justify-center mb-8">
    <div style="width: 940px;background: #fff;" class="px-8 pb-12 pt-3 my-n3 mr-3">
      <!-- 基本信息 -->
      <baseInfo class="mt-5" :data="cvData.person"></baseInfo>
      <!-- 个人优势 -->
      <div class="d-flex mt-8">
        <span class="mr-6">{{ $t('resume.personalAdvantages') }}</span>
        <div style="flex: 1; white-space: pre-line; font-size: 15px;" v-if="cvData?.person?.advantage" v-html="cvData.person.advantage"></div>
      </div>
      <!-- 职业技能 -->
      <div class="d-flex mt-8">
        <span class="mr-6">{{ $t('resume.vocationalSkills') }}</span>
        <vocationalSkills style="flex: 1;" :data="cvData.skillList"></vocationalSkills>
      </div>
      <!-- 求职意向 -->
      <div class="d-flex mt-8">
        <span class="mr-6">{{ $t('resume.jobIntention') }}</span>
        <jobIntention style="flex: 1;" :data="cvData.interestedList"></jobIntention>
      </div>
      <!-- 工作经历 -->
      <div class="d-flex mt-8">
        <span class="mr-6">{{ $t('resume.workExperience') }}</span>
        <workExperience style="flex: 1;" :data="cvData.workList"></workExperience>
      </div>
      <!-- 项目经历 -->
      <!-- <div class="d-flex mt-8">
        <span class="mr-6">{{ $t('resume.projectExperience') }}</span>
        <projectExperience style="flex: 1;" :data="cvData.projectList"></projectExperience>
      </div> -->
      <!-- 培训经历 -->
      <div class="d-flex mt-8">
        <span class="mr-6">{{ $t('resume.trainingExperience') }}</span>
        <trainingExperience style="flex: 1;" :data="cvData.trainList"></trainingExperience>
      </div>
      <!-- 教育经历 -->
      <div class="d-flex mt-8">
        <span class="mr-6">{{ $t('resume.educationExp') }}</span>
        <educationExp style="flex: 1;" :data="cvData.eduList"></educationExp>
      </div>
    </div>
    <div class="operate pa-3">
      <v-list>
        <v-list-subheader class="title">操作</v-list-subheader>
        <v-list-item
          v-for="(item, i) in operateItems" :key="'操作' + i"
          color="primary"
          :prepend-icon="item.icon"
          :title="item.text"
          @click="handleCommunicate(item)"
        >
        </v-list-item>
      </v-list>
    </div>
  </div>
  <Loading :visible="loading"></Loading>
</template>

<script setup>
defineOptions({name: 'enterprise-talentPool-details'})
import baseInfo from './details/baseInfo.vue'
import vocationalSkills from './details/vocationalSkills.vue'
import jobIntention from './details/jobIntention.vue'
import workExperience from './details/workExperience.vue'
// import projectExperience from './details/projectExperience.vue'
import trainingExperience from './details/trainingExperience.vue'
import educationExp from './details/educationExp.vue'
// import attachmentResume from './details/attachmentResume.vue'
import { getPersonCvDetail } from '@/api/enterprise'
import { ref } from 'vue'
import { talkToUser, defaultTextEnt } from '@/hooks/web/useIM'
import { useRouter, useRoute } from 'vue-router'
import { getJobAdvertisedList } from '@/api/position'
import Snackbar from '@/plugins/snackbar'

const route = useRoute()
const router = useRouter()
const operateItems = [
  // { text: '邀请面试', icon: 'mdi-account-check' },
  // { text: '不合适', icon: 'mdi-close-circle-outline' },
  { text: '立即沟通', icon: 'mdi-chat-processing-outline' },
  // { text: '加入人才库', icon: 'mdi-tab-plus' },
  // { text: '操作记录', icon: 'mdi-clock-edit-outline' },
]

// 获取人才详情
const cvData = ref({})
const loading = ref(false)
const getCvDetail = async () => {
  const { id } = route.params
  if (!id) {
    Snackbar.warning('缺少简历id')
    setTimeout(() => {
      window.close()
    }, 2000)
    return
  }
  loading.value = true
  const data = await getPersonCvDetail(id)
  cvData.value = data
  loading.value = false
}
getCvDetail()

// 职位列表
const jobNum = ref(0)
const getJobList = async () => {
  const { total } = await getJobAdvertisedList({ pageNo: 1, pageSize: 10, hasExpiredData: false, status: 0 })
  jobNum.value = total
}
getJobList()

// 立即沟通
const handleCommunicate = async (item) => {
  if (item.text !== '立即沟通') return
  // 企业必须有招聘中的职位才能发起沟通
  if (jobNum.value === 0) return Snackbar.warning('请先发布职位')
  const userId = cvData.value.person.userId
  if (!userId) return
  await talkToUser({userId, text: defaultTextEnt})
  let url = `/recruit/enterprise/invite/chatTools?id=${userId}`
  router.push(url)
}

</script>
<style lang="scss" scoped>
.operate {
  width: 240px;
  height: 500px; // 272px
  position: sticky;
  top: 60px;
}
</style>
