baseInfo.vue 5.9 KB

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