baseInfo.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <view class="f-straight wrapper">
  3. <uni-forms ref="form" :modelValue="formData" :rules="rules" validateTrigger="bind" label-width="90px" label-align="right">
  4. <template v-if="!props.isFair && jobFairLIst?.length">
  5. <!-- 设置为招聘会职位 -->
  6. <uni-forms-item label="招聘会" name="bizId" >
  7. <uni-data-picker class="picker" popup-title="请选择招聘会" v-model="formData.bizId" :localdata="jobFairLIst" :clear-icon="false" :map="{ text: 'title', value: 'id'}"></uni-data-picker>
  8. <view style="color: #777; font-size: 12px;" class="ss-m-t-8 ss-m-l-10">职位会在对应的招聘会显示</view>
  9. </uni-forms-item>
  10. </template>
  11. <uni-forms-item label="职位类型" name="positionId" required>
  12. <view class="positionTemplate">
  13. <uni-data-picker class="picker" popup-title="请选择职位类型" v-model="formData.positionId" :localdata="dictObj?.positionTreeData || []" :clear-icon="false" :map="{ text: 'nameCn', value: 'id'}"></uni-data-picker>
  14. <button v-if="formData.positionId" class="btn" type="primary" size="mini" @click="useJobTemplate">职位模板</button>
  15. </view>
  16. </uni-forms-item>
  17. <uni-forms-item required label="职位名称" name="name">
  18. <uni-easyinput v-model="formData.name" placeholder="请填写职位名称"></uni-easyinput>
  19. </uni-forms-item>
  20. <uni-forms-item label="到期时间" name="expireTime" required>
  21. <view class="d-flex">
  22. <picker mode="date" :value="formData.expireTime" :disabled="expireTimeDisabled" :start="startDate" @change="expireTimeChange">
  23. <view class="uni-input ss-m-t-20" :style="{'opacity': expireTimeDisabled ? '0.5' : '1'}">{{ formData.expireTime }}</view>
  24. </picker>
  25. <uni-data-checkbox selectedColor="#00B760" class="ss-m-l-50 ss-m-t-14" multiple v-model="soFar" :localdata="[{ text: '长期有效', value: 1 }]" @change="handleChangeSofar"></uni-data-checkbox>
  26. </view>
  27. </uni-forms-item>
  28. <uni-forms-item label="岗位职责" name="content" required>
  29. <RichEditor ref="contentRef" :richValue="formData.content" @blur="val => editorBlur('content', val)" :max="5000" />
  30. </uni-forms-item>
  31. <uni-forms-item label="岗位要求 " name="requirement" required>
  32. <RichEditor ref="requirementRef" :richValue="formData.requirement" @blur="val => editorBlur('requirement', val)" :max="5000" />
  33. </uni-forms-item>
  34. </uni-forms>
  35. <!-- 确认框 -->
  36. <uni-popup ref="confirm" type="dialog">
  37. <uni-popup-dialog
  38. type="warn"
  39. cancelText="取消"
  40. confirmText="确认"
  41. title="系统提示"
  42. content="您确定要放弃目前岗位描述的内容吗?"
  43. @confirm="handleConfirm"
  44. @close="handleClose"
  45. ></uni-popup-dialog>
  46. </uni-popup>
  47. </view>
  48. </template>
  49. <script setup>
  50. import { ref, unref } from 'vue'
  51. import { dictObj } from '@/utils/position.js'
  52. import { getNextDate } from '@/utils/date'
  53. import { getRecruitPositionDetails } from '@/api/new/position'
  54. import { dateToTimestamp } from '@/utils/date.js'
  55. import { getJobFairWhiteList } from '@/api/jobFair'
  56. import RichEditor from '@/components/RichEditor'
  57. const props = defineProps({
  58. data: {
  59. type: Object,
  60. default: () => {}
  61. },
  62. isFair: {
  63. type: Boolean,
  64. default: false
  65. }
  66. })
  67. const formData = ref({
  68. bizId: props.data?.bizId || '',
  69. positionId: props.data?.positionId || '',
  70. name: props.data?.name || '', // + new Date().getTime().toString()
  71. expireTime: props.data?.expireTime || getNextDate(15, 'YYYY-MM-DD', 'day'),
  72. content: props.data?.content || '',
  73. requirement: props.data?.requirement || ''
  74. })
  75. const startDate = new Date().getFullYear() + '-' + (new Date().getMonth() + 1) // 不可选时间
  76. const expireTimeDisabled = ref(props.data?.expireTime === null ? true : false)
  77. // 至今
  78. const handleChangeSofar = (e) => {
  79. const value = e.detail.value.length ? e.detail.value[0] : ''
  80. expireTimeDisabled.value = value ? true : false
  81. }
  82. const expireTimeChange = (e) => {
  83. formData.value.expireTime = e?.detail?.value
  84. }
  85. const rules = {
  86. positionId:{
  87. rules: [{required: true, errorMessage: '请选择职位类型' }]
  88. },
  89. positionId:{
  90. rules: [{required: true, errorMessage: '请选择职位类型' }]
  91. },
  92. name:{
  93. rules: [{required: true, errorMessage: '请填写职位名称' }]
  94. },
  95. expireTime:{
  96. rules: [{required: true, errorMessage: '请选择职位到期时间' }]
  97. },
  98. content:{
  99. rules: [{required: true, errorMessage: '请填写岗位职责' }]
  100. },
  101. requirement:{
  102. rules: [{required: true, errorMessage: '请填写岗位要求' }]
  103. },
  104. }
  105. const editorBlur = (key, val) => {
  106. formData.value[key] = val || ''
  107. }
  108. // 获取企业已加入的招聘会列表
  109. const jobFairLIst = ref(false)
  110. const getJobFairData = async () => {
  111. if (props.isFair) return
  112. const res = await getJobFairWhiteList()
  113. jobFairLIst.value = res?.data || []
  114. }
  115. getJobFairData()
  116. const pushTemplate = () => {
  117. formData.value.content = jobTemplateRes.value.content
  118. formData.value.requirement = jobTemplateRes.value.requirement
  119. uni.showToast({ title: '模板填充完成!', icon: 'success' })
  120. }
  121. const confirm = ref()
  122. const handleClose = () => {
  123. confirm.value.close()
  124. }
  125. const handleConfirm = () => {
  126. try {
  127. uni.showLoading({ title: '替换中...', mask: true })
  128. pushTemplate()
  129. } catch (error) {
  130. uni.showToast({ title: '替换失败', icon: 'error' })
  131. console.log(error)
  132. } finally {
  133. uni.hideLoading()
  134. }
  135. }
  136. const jobTemplateRes = ref({})
  137. const useJobTemplate = async () => {
  138. if (!formData.value.positionId) return Snackbar.warning('请先选择职位类型')
  139. // 获取职位模板内容-赋值
  140. const res = await getRecruitPositionDetails(formData.value.positionId)
  141. if (!res?.data || !res.data .content || !res.data.requirement) {
  142. uni.showToast({ title: '此职位类型没有可使用的模板!', icon: 'none', duration: 2000 })
  143. return
  144. }
  145. jobTemplateRes.value = res.data
  146. if (formData.value?.content || formData.value?.requirement) {
  147. // 弹窗提示
  148. confirm.value.open()
  149. } else {
  150. // 无内容点击默认填充
  151. pushTemplate()
  152. }
  153. }
  154. const form = ref()
  155. const contentRef = ref()
  156. const requirementRef = ref()
  157. const soFar = ref(props.data?.expireTime === null ? [1] : [])
  158. const getQuery = async () => {
  159. const valid = await unref(form).validate()
  160. if (!valid) return
  161. const obj = {
  162. hirePrice: 0,
  163. soFar: Boolean(soFar.value?.length),
  164. hire: false,
  165. ...formData.value
  166. }
  167. obj.source = obj.bizId ? '2' : '0' // 职位来源(0职位管理|1众聘职位|2招聘会)
  168. obj.expireTime = obj.soFar ? null : dateToTimestamp(obj.expireTime)
  169. obj && Object.keys(obj).length && Object.keys(obj).forEach(key => { if (['areaId', 'eduType', 'expType'].includes(key) && obj[key] === -1) obj[key] = null })
  170. return obj
  171. }
  172. defineExpose({
  173. getQuery
  174. })
  175. </script>
  176. <style lang="scss" scoped>
  177. .positionTemplate {
  178. text-align: left;
  179. .btn {
  180. width: 90px;
  181. line-height: 34px;
  182. margin-top: 10px;
  183. }
  184. }
  185. :deep(.uni-forms-item__content) {
  186. width: 100% !important;
  187. overflow: hidden !important;
  188. }
  189. </style>