Переглянути джерело

没有加入任何招聘会则不展示招聘会

lifanagju_citu 1 місяць тому
батько
коміт
f70a28c5aa

+ 5 - 4
src/views/recruit/enterprise/positionManagement/components/add.vue

@@ -1,6 +1,6 @@
 <template>
   <div>
-    <v-card class="pa-5">
+    <v-card class="pa-5" v-if="show">
       <v-timeline align="start" side="end">
         <v-timeline-item
           v-for="(val, i) in list"
@@ -281,20 +281,21 @@ const handlePayClose = () => {
   router.push({ path: '/recruit/enterprise/position', query: { key: 0 }})
 }
 
+const show = ref(false)
 // 获取编辑的职位详情
 const getPositionDetail = async (id) => {
   const data = await getJobDetails({ id })
   if (!data && !Object.keys(data).length) return
   itemData.value = {...data, ...dealDictObjData({}, data)}
+  show.value = true
 
   // 招聘类型为实习则获取扩展信息
   if (data.type === '3') initPosition(id)
 }
 
 // 有id为编辑
-if (route.query && route.query.id) {
-  if (route.query.id) getPositionDetail(route.query.id)
-}
+if (route.query?.id) getPositionDetail(route.query.id)
+else show.value = true
 
 // 取消
 const handleCancel = () => {

+ 56 - 49
src/views/recruit/enterprise/positionManagement/components/baseInfo.vue

@@ -64,7 +64,10 @@ import { getJobFairWhiteList } from '@/api/recruit/enterprise/jobFair'
 const { t } = useI18n()
 const props = defineProps({
   itemData: Object,
-  isFair: Boolean
+  isFair: {
+    type: Boolean,
+    default: false
+  }
 })
 
 const getValue = (key) => {
@@ -136,6 +139,55 @@ const items = ref({
   ]
 })
 
+// 获取企业已加入的招聘会列表
+const jobFairLoaded = ref(false)
+const jobFairWhiteList = ref([])
+const getJobFairData = async () => {
+  const data = await getJobFairWhiteList()
+  jobFairWhiteList.value = data?.length ? data : []
+  jobFairLoaded.value = true
+  // 没有加入任何招聘会则不展示招聘会
+  if (!jobFairWhiteList.value?.length) items.value.options = items.value.options.filter(e => e.key !== 'bizId')
+}
+getJobFairData()
+
+const jobFairValid = async () => {
+  if (props.isFair) {
+    // 招聘会内编辑职位,不需要展示选择招聘会
+    items.value.options = items.value.options.filter(e => e.key !== 'bizId')
+    return
+  }
+  // 加载招聘会白名单列表
+  if (!jobFairLoaded.value) await getJobFairData()
+  const bizIdObj = items.value.options.find(e => e.key === 'bizId') // 招聘会下拉框
+  if (!bizIdObj) return
+  bizIdObj.items = jobFairWhiteList.value // 下拉框内容赋值
+  if (bizIdObj.value) {
+    const index = jobFairWhiteList.value.findIndex(e => e.id === props.itemData.bizId)
+    if (index === -1) bizIdObj.value = null // 招聘会已经关闭 或者已被移除招聘会白名单
+    jobFairCheckboxChange(Boolean(bizIdObj.value), bizIdObj) // 招聘会回显
+  }
+}
+jobFairValid()
+
+// 设置为招聘会职位
+const jobFairCheckbox = ref(false)
+const jobFairCheckboxChange = (bool, item) => {
+  item.value = bool ? (item?.value || null) : null
+  jobFairCheckbox.value = bool
+  item.disabled = bool ? false : true
+  item.label = bool ? '招聘会 *' : '招聘会'
+}
+
+// 长期有效
+const soFar = ref(false)
+const handleSoFarChange = (bool, item) => {
+  soFar.value = bool
+  item.value = null
+  item.disabled = bool ? true : false
+  item.label = bool ? '到期时间' : '到期时间 *'
+}
+
 // 编辑回显
 watch(
   () => props.itemData,
@@ -149,32 +201,15 @@ watch(
       }
       if (e.noParam) return
       if (e.key === 'expireTime' && !val[e.key]) return handleSoFarChange(true, e)
-      if (e.key === 'bizId' && val.source === '2') jobFairCheckboxChange(true, e, false) // 招聘会回显
-      if (e.key === 'bizId' && (val.source === '0' || hideJobFairCheckbox.value)) return // 非招聘会职位
+      if (e.key === 'bizId' && val.source === '0') return // 非招聘会职位
       e.value = val[e.key]
     })
-    if (props.isFair) items.value.options = items.value.options.filter(e => e.key !== 'bizId') // 如果为招聘会编辑则不显示
+    // jobFairValid()  // 招聘会回显
   },
   { immediate: true },
   { deep: true }
 )
 
-// 获取企业已加入的招聘会列表
-const hideJobFairCheckbox = ref(false)
-const getJobFairData = async () => {
-  if (props.isFair) return
-  const data = await getJobFairWhiteList()
-  const bizId = items.value.options.find(e => e.key === 'bizId') || {}
-  if (!data?.length) {
-    hideJobFairCheckbox.value = true
-    bizId.value = null
-    return
-  } else{
-    bizId.items = data
-  }
-}
-getJobFairData()
-
 // 职位类型
 const handleJobClickItem = (list, name) => {
   const positionId = getValue('positionId')
@@ -214,32 +249,6 @@ const useJobTemplate = async () => {
   }
 }
 
-const soFar = ref(false)
-// 长期有效
-const handleSoFarChange = (bool, item) => {
-  soFar.value = bool
-  item.value = null
-  item.disabled = bool ? true : false
-  item.label = bool ? '到期时间' : '到期时间 *'
-}
-
-// 设置为招聘会职位
-const jobFairCheckbox = ref(false)
-const jobFairCheckboxChange = (bool, item, isSnackbar = true) => {
-  if (props.isFair) { // 招聘会内职位编辑
-    jobFairCheckbox.value = false
-    return
-  }
-  if (hideJobFairCheckbox.value) {
-    bool = false
-    if (isSnackbar) Snackbar.warning('没有加入任何招聘会')
-  }
-  jobFairCheckbox.value = bool
-  item.value = null
-  item.disabled = bool ? false : true
-  item.label = bool ? '招聘会 *' : '招聘会'
-}
-
 const getQuery = async () => {
   const { valid } = await formPageRef.value.formRef.validate()
   if (!valid) return
@@ -253,7 +262,7 @@ const getQuery = async () => {
     else obj[e.key] = e.value
   })
   
-  if (jobFairCheckbox.value && !obj.bizId) {
+  if (jobFairCheckbox.value && !obj.bizId && jobFairWhiteList.value?.length) {
     Snackbar.warning('请选择招聘会')
     return 'failed'
   }
@@ -277,8 +286,6 @@ const getQuery = async () => {
   if (obj.source === '0')  obj.bizId = null
 
   Object.assign(query, obj)
-  // console.log('obj:', obj)
-  console.log('query:', query)
   return query
 }