baseInfo.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <div>
  3. <CtForm ref="formPageRef" :items="items" style="width: 650px;">
  4. <template #bizId="{ item }">
  5. <div>
  6. <v-checkbox-btn
  7. v-model="jobFairCheckbox"
  8. color="primary"
  9. label="设置为招聘会职位"
  10. class="ml-2"
  11. :disabled="false"
  12. :style="`line-height: ${item.dense === 'default' ? 56 : item.dense === 'comfortable' ? 48 : 40 }px;`"
  13. style="width: 174px;"
  14. hide-details
  15. @update:modelValue="v => jobFairCheckboxChange(v, item)"
  16. ></v-checkbox-btn>
  17. </div>
  18. </template>
  19. <template #positionId="{ item }">
  20. <v-menu :close-delay="1" :open-delay="0" v-bind="$attrs">
  21. <template v-slot:activator="{ props }">
  22. <textUI
  23. :modelValue="item.value"
  24. :item="item"
  25. v-bind="props"
  26. style="position: relative;"
  27. ></textUI>
  28. </template>
  29. <jobTypeCard class="jobTypeCardBox" :select="[query.positionId].filter(Boolean)" :isSingle="true" @handleJobClick="handleJobClickItem"></jobTypeCard>
  30. </v-menu>
  31. <v-btn v-if="showTemplateBtn" class="ml-3 half-button" color="primary" style="margin-top: 2px;" @click="useJobTemplate(item)">职位模板</v-btn>
  32. </template>
  33. <template #expireTime="{ item }">
  34. <div>
  35. <v-checkbox-btn
  36. v-model="soFar"
  37. color="primary"
  38. label="长期有效"
  39. class="ml-2"
  40. :disabled="false"
  41. :style="`line-height: ${item.dense === 'default' ? 56 : item.dense === 'comfortable' ? 48 : 40 }px;`"
  42. style="width: 110px;"
  43. hide-details
  44. @update:modelValue="v => handleSoFarChange(v, item)"
  45. ></v-checkbox-btn>
  46. </div>
  47. </template>
  48. </CtForm>
  49. </div>
  50. </template>
  51. <script setup>
  52. defineOptions({ name: 'position-add-baseInfo'})
  53. import CtForm from '@/components/CtForm'
  54. import { reactive, ref, watch } from 'vue'
  55. import textUI from '@/components/FormUI/TextInput'
  56. import jobTypeCard from '@/components/jobTypeCard'
  57. import { getRecruitPositionDetails } from '@/api/recruit/enterprise/position'
  58. import Confirm from '@/plugins/confirm'
  59. import Snackbar from '@/plugins/snackbar'
  60. import { useI18n } from '@/hooks/web/useI18n';
  61. import { getJobFairList } from '@/api/recruit/enterprise/jobFair'
  62. const { t } = useI18n()
  63. const props = defineProps({
  64. itemData: Object
  65. })
  66. const getValue = (key) => {
  67. return items.value.options.find(e => e.key === key)
  68. }
  69. const showTemplateBtn = ref(true)
  70. const formPageRef = ref()
  71. let query = reactive({})
  72. const items = ref({
  73. options: [
  74. {
  75. slotName: 'bizId',
  76. type: 'autocomplete',
  77. key: 'bizId',
  78. value: null,
  79. label: '招聘会',
  80. itemText: 'title',
  81. itemValue: 'id',
  82. disabled: true,
  83. items: [],
  84. },
  85. {
  86. slotName: 'positionId',
  87. key: 'positionId',
  88. value: '',
  89. flexStyle: 'mt-5',
  90. labelKey: 'positionName',
  91. label: '职位类型 *',
  92. noParam: true,
  93. readonly: true,
  94. rules: [v => !!v || '请选择职位类型']
  95. },
  96. {
  97. type: 'text',
  98. key: 'name',
  99. value: '',
  100. label: '职位名称 *',
  101. rules: [v => !!v || '请填写职位名称']
  102. },
  103. {
  104. type: 'datePicker',
  105. key: 'expireTime',
  106. value: null,
  107. format: 'YYYY-MM-DD',
  108. label: '到期时间 *',
  109. disabledDate: true,
  110. dayAfter: true,
  111. labelWidth: 120,
  112. slotName: 'expireTime',
  113. },
  114. {
  115. type: 'wangEditor',
  116. key: 'content',
  117. value: '',
  118. label: '岗位职责 *',
  119. maxLength: 5000,
  120. rules: '请填写岗位职责'
  121. },
  122. {
  123. type: 'wangEditor',
  124. key: 'requirement',
  125. value: '',
  126. label: '岗位要求 *',
  127. maxLength: 5000,
  128. rules: '请填写岗位要求'
  129. }
  130. ]
  131. })
  132. // 编辑回显
  133. watch(
  134. () => props.itemData,
  135. (val) => {
  136. if (!Object.keys(val).length) return
  137. items.value.options.forEach(e => {
  138. if (e.labelKey) {
  139. query[e.key] = val[e.key]
  140. e.value = val[e.labelKey]
  141. return
  142. }
  143. if (e.noParam) return
  144. if (e.key === 'expireTime' && !val[e.key]) return handleSoFarChange(true, e)
  145. if (e.key === 'bizId' && val.source === '2') jobFairCheckboxChange(true, e) // 招聘会回显
  146. if (e.key === 'bizId' && val.source === '0') val[e.key] = null // 非招聘会职位
  147. e.value = val[e.key]
  148. })
  149. },
  150. { immediate: true },
  151. { deep: true }
  152. )
  153. // 职位类型
  154. const handleJobClickItem = (list, name) => {
  155. const positionId = getValue('positionId')
  156. if (!list.length) {
  157. delete query.positionId
  158. positionId.value = ''
  159. return
  160. }
  161. showTemplateBtn.value = true
  162. query.positionId = list[0]
  163. positionId.value = name
  164. }
  165. const useJobTemplate = async () => {
  166. if (!query.positionId) return Snackbar.warning('请先选择职位类型')
  167. // 获取职位模板内容-赋值
  168. const res = await getRecruitPositionDetails(query.positionId)
  169. if (!res || !res.content || !res.requirement) {
  170. Snackbar.warning('此职位类型没有可使用的模板!')
  171. showTemplateBtn.value = false
  172. return
  173. }
  174. const content = items.value.options.find(e => e.key === 'content')
  175. const requirement = items.value.options.find(e => e.key === 'requirement')
  176. if ((content && content.value) || (requirement && requirement.value)) {
  177. // 弹窗提示
  178. Confirm(t('common.confirmTitle'), '您确定要放弃目前岗位描述的内容吗?').then(() => {
  179. content.value = res.content
  180. requirement.value = res.requirement
  181. Snackbar.success('模板填充完成!')
  182. })
  183. } else {
  184. // 无内容点击默认填充
  185. if (content) content.value = res.content
  186. if (requirement) requirement.value = res.requirement
  187. Snackbar.success('模板填充完成!')
  188. }
  189. }
  190. const soFar = ref(false)
  191. // 长期有效
  192. const handleSoFarChange = (bool, item) => {
  193. soFar.value = bool
  194. item.value = null
  195. item.disabled = bool ? true : false
  196. item.label = bool ? '到期时间' : '到期时间 *'
  197. }
  198. // 设置为招聘会职位
  199. const jobFairCheckbox = ref(false)
  200. const jobFairCheckboxChange = (bool, item) => {
  201. jobFairCheckbox.value = bool
  202. item.value = null
  203. item.disabled = bool ? false : true
  204. item.label = bool ? '招聘会 *' : '招聘会'
  205. }
  206. const getJobFairData = async () => {
  207. const data = await getJobFairList()
  208. const bizId = items.value.options.find(e => e.key === 'bizId')
  209. if (!bizId) return
  210. bizId.items = data
  211. }
  212. getJobFairData()
  213. const getQuery = async () => {
  214. const { valid } = await formPageRef.value.formRef.validate()
  215. if (!valid) return
  216. const obj = {
  217. hirePrice: 0,
  218. soFar: soFar.value,
  219. hire: false
  220. }
  221. items.value.options.forEach(e => {
  222. if (e.noParam || e.value === null) return
  223. else obj[e.key] = e.value
  224. })
  225. if (jobFairCheckbox.value && !obj.bizId) {
  226. Snackbar.warning('请选择招聘会')
  227. return 'failed'
  228. }
  229. if (!obj.content) {
  230. Snackbar.warning('请填写岗位职责')
  231. return 'failed'
  232. }
  233. if (!obj.requirement) {
  234. Snackbar.warning('请填写岗位要求')
  235. return 'failed'
  236. }
  237. if (!obj.expireTime && !soFar.value) {
  238. Snackbar.warning('请填写到期时间')
  239. return 'failed'
  240. }
  241. obj.source = jobFairCheckbox.value ? '2' : '0' // 职位来源(0职位管理|1众聘职位|2招聘会)
  242. if (obj.source === '0') obj.bizId = null
  243. Object.assign(query, obj)
  244. // console.log('obj:', obj)
  245. console.log('query:', query)
  246. return query
  247. }
  248. defineExpose({
  249. formPageRef,
  250. getQuery
  251. })
  252. </script>
  253. <style scoped lang="scss">
  254. .jobTypeCardBox {
  255. position: absolute;
  256. top: -22px;
  257. left: 0;
  258. }
  259. .calculation {
  260. display: block;
  261. width: 120px;
  262. }
  263. </style>