jobIntention.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <!-- -->
  2. <template>
  3. <view class="ss-m-x-30 ss-m-y-30">
  4. <uni-forms ref="form" :modelValue="formData" :rules="rules" validateTrigger="bind" label-width="90px">
  5. <uni-forms-item label="期望岗位" name="positionId" required>
  6. <uni-data-picker popup-title="请选择期望岗位" v-model="formData.positionId" :localdata="dictObj?.positionTreeData || []" :clear-icon="false" :map="{ text: 'nameCn', value: 'id'}"></uni-data-picker>
  7. </uni-forms-item>
  8. <uni-forms-item label="期望行业" name="industryIdList" required>
  9. <uni-data-picker popup-title="请选择期望行业" v-model="formData.industryIdList" :localdata="dictObj?.industryTreeData || []" :clear-icon="false" :map="{ text: 'nameCn', value: 'id'}"></uni-data-picker>
  10. </uni-forms-item>
  11. <uni-forms-item label="最低薪资" name="payFrom" required>
  12. <uni-number-box v-model="formData.payFrom" :min="1" :max="999999999" :step="1000" :width="150" @change="payChange"></uni-number-box>
  13. </uni-forms-item>
  14. <uni-forms-item label="最高薪资" name="payTo" required>
  15. <uni-number-box v-model="formData.payTo" :min="payToMin" :max="999999999" :step="1000" :width="150"></uni-number-box>
  16. </uni-forms-item>
  17. <uni-forms-item label="求职类型" name="jobType" required>
  18. <uni-data-picker popup-title="请选择求职类型" v-model="formData.jobType" :localdata="dictObj?.jobType || []" :clear-icon="false" :map="{ text: 'label', value: 'value'}"></uni-data-picker>
  19. </uni-forms-item>
  20. <uni-forms-item label="工作城市" name="workAreaId" required>
  21. <uni-data-picker popup-title="请选择工作城市" v-model="formData.workAreaId" :localdata="dictObj?.areaTreeData || []" :clear-icon="false" :map="{ text: 'name', value: 'id'}"></uni-data-picker>
  22. </uni-forms-item>
  23. <uni-forms-item label="其它感兴趣的城市" name="interestedAreaIdList">
  24. <uni-data-picker popup-title="其它感兴趣的城市" v-model="formData.interestedAreaIdList" :localdata="dictObj?.areaTreeData || []" :clear-icon="false" :map="{ text: 'name', value: 'id'}"></uni-data-picker>
  25. </uni-forms-item>
  26. </uni-forms>
  27. <view class="f-horizon-center">
  28. <button v-if="editId" size="default" class="delete-button commonBtnStyle" @click="handleDelete">删 除</button>
  29. <button size="default" :class="{'save-button': editId, 'commonBtnStyle': editId, 'send-button': !editId}" @click="submit">保 存</button>
  30. </view>
  31. </view>
  32. </template>
  33. <script setup>
  34. import { ref, unref } from 'vue'
  35. import { dictObj } from '@/utils/position.js'
  36. import { saveResumeJobInterested, getResumeJobInterested, deleteResumeJobInterested } from '@/api/resume.js'
  37. import { onLoad } from '@dcloudio/uni-app'
  38. import { cloneDeep } from 'lodash-es'
  39. let formData = ref({ positionId: '', payFrom: 0, payTo: 0 })
  40. const form = ref()
  41. const editId = ref(null)
  42. // 获取求职意向
  43. async function getJobInterested (id) {
  44. const { data } = await getResumeJobInterested()
  45. if (!data || !data.length) {
  46. return
  47. }
  48. const obj = data.find(k => k.id === id)
  49. formData.value = cloneDeep(obj)
  50. formData.value.industryIdList = obj.industryIdList.length ? obj.industryIdList[0] : ''
  51. if (dictObj && dictObj?.areaTreeData) {
  52. const type = typeof dictObj.areaTreeData[0].id
  53. formData.value.workAreaId = type === 'string' ? obj.workAreaId.toString() : Number(obj.workAreaId)
  54. formData.value.interestedAreaIdList = type === 'string' && obj.interestedAreaIdList.length ? obj.interestedAreaIdList[0].toString() : Number(obj.interestedAreaIdList[0])
  55. }
  56. }
  57. onLoad((options) => {
  58. if (options.id) {
  59. editId.value = options.id
  60. getJobInterested(options.id)
  61. }
  62. })
  63. // 提交
  64. const submit = async () => {
  65. const valid = await unref(form).validate()
  66. if (!valid) return
  67. // 后续做多选
  68. formData.value.industryIdList = [formData.value.industryIdList]
  69. formData.value.interestedAreaIdList = [formData.value.interestedAreaIdList]
  70. try {
  71. await saveResumeJobInterested(formData.value)
  72. uni.showToast({
  73. icon: 'success',
  74. title: '保存成功'
  75. })
  76. setTimeout(() => {
  77. editId.value = null
  78. uni.navigateBack({
  79. delta: 1
  80. })
  81. }, 1000)
  82. } catch (err) {
  83. uni.showToast({
  84. icon: 'none',
  85. title: err.msg
  86. })
  87. }
  88. }
  89. // 删除
  90. const handleDelete = async () => {
  91. try {
  92. await deleteResumeJobInterested(editId.value)
  93. uni.showToast({
  94. icon: 'success',
  95. title: '删除成功'
  96. })
  97. setTimeout(() => {
  98. editId.value = null
  99. uni.navigateBack({
  100. delta: 1
  101. })
  102. }, 1000)
  103. } catch (err) {
  104. uni.showToast({
  105. icon: 'none',
  106. title: err.msg
  107. })
  108. }
  109. }
  110. const rules = {
  111. positionId:{
  112. rules: [{required: true, errorMessage: '请选择期望岗位' }]
  113. },
  114. industryIdList:{
  115. rules: [{required: true, errorMessage: '请选择期望行业' }]
  116. },
  117. payFrom:{
  118. rules: [{required: true, errorMessage: '请输入薪资最低要求' }]
  119. },
  120. payTo:{
  121. rules: [{required: true, errorMessage: '请输入薪资最高要求' }]
  122. },
  123. jobType:{
  124. rules: [{required: true, errorMessage: '请选择求职类型' }]
  125. },
  126. workAreaProvinceId:{
  127. rules: [{required: true, errorMessage: '请选择工作城市' }]
  128. },
  129. }
  130. const payToMin = ref(1)
  131. const payChange = (val) => {
  132. payToMin.value = val
  133. if (val > formData.value.payTo) formData.value.payTo = val
  134. }
  135. </script>
  136. <style lang="scss" scoped>
  137. </style>