jobIntention.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. const query = {...formData.value, industryIdList: [formData.value.industryIdList], interestedAreaIdList: [formData.value.interestedAreaIdList]}
  69. try {
  70. await saveResumeJobInterested(query)
  71. uni.showToast({
  72. icon: 'success',
  73. title: '保存成功'
  74. })
  75. setTimeout(() => {
  76. editId.value = null
  77. uni.navigateBack({
  78. delta: 1
  79. })
  80. }, 1000)
  81. } catch (err) {
  82. uni.showToast({
  83. icon: 'none',
  84. title: err.msg
  85. })
  86. }
  87. }
  88. // 删除
  89. const handleDelete = async () => {
  90. try {
  91. await deleteResumeJobInterested(editId.value)
  92. uni.showToast({
  93. icon: 'success',
  94. title: '删除成功'
  95. })
  96. setTimeout(() => {
  97. editId.value = null
  98. uni.navigateBack({
  99. delta: 1
  100. })
  101. }, 1000)
  102. } catch (err) {
  103. uni.showToast({
  104. icon: 'none',
  105. title: err.msg
  106. })
  107. }
  108. }
  109. const rules = {
  110. positionId:{
  111. rules: [{required: true, errorMessage: '请选择期望岗位' }]
  112. },
  113. industryIdList:{
  114. rules: [{required: true, errorMessage: '请选择期望行业' }]
  115. },
  116. payFrom:{
  117. rules: [{required: true, errorMessage: '请输入薪资最低要求' }]
  118. },
  119. payTo:{
  120. rules: [{required: true, errorMessage: '请输入薪资最高要求' }]
  121. },
  122. jobType:{
  123. rules: [{required: true, errorMessage: '请选择求职类型' }]
  124. },
  125. workAreaProvinceId:{
  126. rules: [{required: true, errorMessage: '请选择工作城市' }]
  127. },
  128. }
  129. const payToMin = ref(1)
  130. const payChange = (val) => {
  131. payToMin.value = val
  132. if (val > formData.value.payTo) formData.value.payTo = val
  133. }
  134. </script>
  135. <style lang="scss" scoped>
  136. </style>