editJob.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <add :after-add="afterAdd" :valid="validate" :isFair="true">
  3. <template #timeline>
  4. <v-timeline-item
  5. dot-color="light-blue darken-1"
  6. icon="mdi-numeric-3"
  7. >
  8. <div>
  9. <h2 class="mt-n1 headline font-weight-regular">{{ t('common.other') }}</h2>
  10. <CtForm ref="formPageRef" class="mt-3" :items="items" style="width: 650px;"></CtForm>
  11. </div>
  12. </v-timeline-item>
  13. </template>
  14. </add>
  15. </template>
  16. <script setup>
  17. defineOptions({ name: 'editJob' })
  18. import { ref } from 'vue'
  19. import { useRoute, useRouter } from 'vue-router'
  20. import CtForm from '@/components/CtForm'
  21. import Add from '@/views/recruit/enterprise/positionManagement/components/add.vue'
  22. import { useI18n } from '@/hooks/web/useI18n'
  23. import { schoolMajorByName, schoolMajorById } from '@/api/recruit/personal/resume'
  24. import {
  25. saveJobAdvertisedExtend,
  26. joinJobFairPosition,
  27. getJobAdvertisedExtend
  28. } from '@/api/recruit/enterprise/jobFair'
  29. import Snackbar from '@/plugins/snackbar'
  30. const { t } = useI18n()
  31. const route = useRoute()
  32. const router = useRouter()
  33. const formPageRef = ref(null)
  34. const items = ref({
  35. options: [
  36. {
  37. type: 'text',
  38. key: 'dept',
  39. value: null,
  40. label: '招聘部门 ',
  41. // rules: [v => !!v || '请选择招聘部门']
  42. },
  43. {
  44. type: 'autocomplete',
  45. key: 'majorId',
  46. search: getMajorList,
  47. value: null,
  48. label: '专业要求 ',
  49. itemText: 'nameCn',
  50. itemValue: 'id',
  51. // rules: [v => !!v || '专业要求'],
  52. noDataText: '请输入检索专业',
  53. items: []
  54. },
  55. {
  56. type: 'autocomplete',
  57. key: 'frequency-dateType',
  58. value: null,
  59. label: '工作频率 ',
  60. col: 6,
  61. // rules: [v => !!v || '请选择工作频率'],
  62. items: [
  63. { label: '每周', value: 'week' },
  64. { label: '每月', value: 'month' },
  65. { label: '每年', value: 'year' },
  66. ]
  67. },
  68. {
  69. type: 'number',
  70. key: 'frequency-day',
  71. value: null,
  72. flexStyle: 'ml-3',
  73. col: 6,
  74. label: '出勤天数 ',
  75. // rules: [v => v > 0 || '请填写正确的出勤天数']
  76. },
  77. {
  78. type: 'ifRadio',
  79. key: 'hot',
  80. value: 1,
  81. label: '热门职位 ',
  82. items: [
  83. { label: '是', value: 1 },
  84. { label: '否', value: 0 },
  85. ],
  86. // rules: [v => !!v || '请选择是否热门']
  87. },
  88. ]
  89. })
  90. // console.log(route)
  91. if (route.query.id) {
  92. // 编辑
  93. initPosition(route.query.id)
  94. }
  95. async function initPosition (jobId) {
  96. const res = await getJobAdvertisedExtend(jobId)
  97. if (!res) return
  98. items.value.options.forEach(e => {
  99. if (e.key.includes('frequency') && res.frequency) {
  100. const keys = e.key.split('-')
  101. e.value = res[keys[0]][keys[1]]
  102. return
  103. }
  104. if (e.key === 'majorId') {
  105. getMajorById(res.majorId)
  106. }
  107. e.value = res[e.key]
  108. })
  109. }
  110. async function getMajorList (name) {
  111. if (!name) {
  112. return
  113. }
  114. const res = await schoolMajorByName({ name })
  115. items.value.options.find(e => e.key === 'majorId').items = res
  116. }
  117. async function getMajorById (id) {
  118. if (!id) return
  119. const res = await schoolMajorById({ id })
  120. items.value.options.find(e => e.key === 'majorId').items = [res]
  121. }
  122. const validate = async () => {
  123. const res = await formPageRef.value.formRef.validate()
  124. return res
  125. }
  126. const afterAdd = async (jobId) => {
  127. try {
  128. const query = items.value.options.reduce((r, v) => {
  129. if (v.key.includes('frequency')) {
  130. const keys = v.key.split('-')
  131. if (!r[keys[0]]) {
  132. r[keys[0]] = {}
  133. }
  134. r[keys[0]][keys[1]] = v.type === 'number' ? +v.value : v.value
  135. return r
  136. }
  137. if (v.key === 'majorId') {
  138. r.major = v.items.find(e => e.id === v.value)?.nameCn || ''
  139. }
  140. r[v.key] = v.type === 'number' ? +v.value : v.value
  141. return r
  142. }, { jobId })
  143. await saveJobAdvertisedExtend(query)
  144. console.log('招聘会职位扩展信息保存成功')
  145. await joinJobFairPosition({
  146. jobFairId: route.params.id,
  147. jobId
  148. })
  149. Snackbar.success(t('common.publishSuccessMsg'))
  150. router.push(`/recruit/enterprise/jobFair/details/${route.params.id}`)
  151. } catch (error) {
  152. console.error(error)
  153. Snackbar.error(error)
  154. }
  155. }
  156. </script>
  157. <style lang="scss" scoped>
  158. </style>