<!-- 分享职位 -->
<template>
  <div style="background-color: #f0f0f0;" :style="{'padding': isMobile ? '0' : '10px'}">
    <v-card
      class="py-3 px-5"
      style="min-height: calc(100vh - 20px); box-sizing: border-box; margin: 0 auto;"
      :style="{'width': isMobile ? '100%' : '750px'}"
    >
      <div v-if="!Object.keys(info).length">加载失败</div>
      <div v-else>
        <div class="d-flex justify-space-between">
          <h2 class="JobName ellipsis">{{ info.name }}</h2>
          <span class="salary">{{ info.payFrom }}-{{ info.payTo }}/{{ positionInfo.payName }}</span>
        </div>
        <div class="d-flex justify-space-between mt-4">
          <div>
            <div class="banner-tags">
              <div v-for="k in desc" :key="k.mdi" class="mr-3">
                <v-icon color="var(--color-666)" size="20">{{ k.mdi }}</v-icon>
                <span class="f-w-600 ml-1">{{ positionInfo[k.value] }}</span>
              </div>
            </div>
            <div class="mt-4" v-if="info?.tagList">
              <v-chip size="small" class="mr-1 mb-1" color="primary" label v-for="(k, i) in info.tagList" :key="i">{{ k }}</v-chip>
            </div>
          </div>
          <v-btn
            class="button-item radius"
            color="warning" 
            variant="outlined" 
            prepend-icon="mdi-heart-outline"
            @click="null"
          >{{ $t('position.collection') }}</v-btn>
        </div>
        <v-divider class="mt-3"></v-divider>
        <div class="mt-3 mb-1 f-w-600">{{ $t('position.jobResponsibilities') }}</div>
        <div class="requirement" v-html="info.content?.replace(/\n/g, '</br>')"></div>
        <div class="mt-3 mb-1 f-w-600">{{ $t('position.jobRequirements') }}</div>
        <div class="requirement" v-html="info.requirement?.replace(/\n/g, '</br>')"></div>
        <v-divider class="my-3"></v-divider>
        <div class="contact">
          <div class="float-left d-flex align-center">
            <v-img :src="info.contact?.avatar || 'https://minio.citupro.com/dev/menduner/7.png'" :width="45" style="height: 45px;"></v-img>
            <div class="ml-2">
              <div class="contact-name">{{ info.contact?.name }}</div>
              <div class="contact-info">{{ info.enterprise?.name }} · {{ info.contact?.postNameCn }}</div>
            </div>
          </div>
        </div>
        <v-divider class="my-3"></v-divider>
        <div>
          <h4>{{ $t('position.address') }}</h4>
          <div class="mt-1">
            <v-icon size="25" color="primary">mdi-map-marker</v-icon>
            <span style="color: var(--color-666);font-size: 15px;">{{ info.address }}</span>
          </div>
        </div>
        <div class="mb-5 text-center" style="height: 80px; line-height: 80px;">
          <!-- <v-btn class="mr-2 radius button-item" color="success" variant="outlined">{{ $t('position.communicate') }}</v-btn> -->
          <v-btn class="mr-2 radius button-item" color="success" variant="outlined" target="_blank" to="/recruit/personal/position">{{ $t('position.moreBtn') }}</v-btn>
          <v-btn class="radius button-item" color="primary" @click="handleDelivery">{{ $t('position.submitResume') }}</v-btn>
        </div>
      </div>
    </v-card>
  </div>

  <CtDialog :visible="showResume" :widthType="2" titleClass="text-h6" title="简历投递" @close="handleClose" @submit="handleSubmit">
    <DeliveryForm ref="deliveryForm"></DeliveryForm>
  </CtDialog>

</template>

<script setup>
defineOptions({name: 'recruit-personal-shareJob-index'})
import { onMounted, ref } from 'vue';
import { getPositionDetails } from '@/api/position'
import { dealDictObjData } from '@/utils/position'
import DeliveryForm from './components/deliveryForm.vue'

// 组件挂载后添加事件监听器  
const isMobile = ref(false)
onMounted(() => {
  const userAgent = navigator.userAgent
  isMobile.value = /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i.test(userAgent)
})
// 获取路由参数
const queryParams = new URLSearchParams(window.location.search)
const jobId = queryParams.get('jobId') || ''
const sharedById = queryParams.get('sharedById') || ''
const sharedByName = queryParams.get('sharedByName') || ''
const sharedByPhone = queryParams.get('sharedByPhone') || ''
const file = queryParams.get('file') || ''
console.log(jobId, sharedById, sharedByName, sharedByPhone, file)

// 职位详情
const info = ref({})
const positionInfo = ref({})
const getPositionDetail = async () => {
  const data = await getPositionDetails({ id: jobId })
  info.value = data
  positionInfo.value = { ...dealDictObjData({}, info.value), ...info.value }
}
getPositionDetail()

const desc = [
  { mdi: 'mdi-map-marker-outline', value: 'areaName' },
  { mdi: 'mdi-school-outline', value: 'eduName' },
  { mdi: 'mdi-clock-time-ten-outline', value: 'expName' }
]

// 简历投递
const deliveryForm = ref()
const showResume = ref(false)
const handleDelivery = () => {
  showResume.value = true
}

const handleClose = () => {
  showResume.value = false
}
const handleSubmit = async () => {
  console.log(await deliveryForm.value.getQuery(), 'handleSubmit')
}
</script>

<style lang="scss" scoped>
.f-w-600 { font-weight: 600; }
.radius { border-radius: 8px; }
.salary {
  color: var(--v-error-base);
  line-height: 41px;
  font-weight: 600;
  height: auto;
  display: inline-block;
  vertical-align: sub;
}
.JobName {
  color: #37576c;
  font-size: 28px;
  margin-right: 30px;
  margin-top: 1px;
  // max-width: 45%;
  vertical-align: middle;
  flex: 1;
}
.banner-tags { display: flex; flex-wrap: wrap; }
.requirement {
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 28px;
  color: var(--color-333);
  font-size: 15px;
  text-align: justify;
  letter-spacing: 0;
}
.contact {
  height: 60px;
  line-height: 60px;
  padding: 0 10px;
}
.contact-name {
  font-size: 20px;
  font-weight: 500;
  color: var(--color-222);
  line-height: 28px;
}
.contact-info {
  font-size: 15px;
  color: var(--color-666);
  line-height: 21px;
  margin-top: 8px;
}
.button-item {
  min-width: 110px;
  height: 36px
}
</style>
