jobIntention.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. formData.value.interestedAreaIdList = obj.interestedAreaIdList.length ? Number(obj.interestedAreaIdList[0]) : ''
  52. }
  53. onLoad((options) => {
  54. if (options.id) {
  55. editId.value = options.id
  56. getJobInterested(options.id)
  57. }
  58. })
  59. // 提交
  60. const submit = async () => {
  61. const valid = await unref(form).validate()
  62. if (!valid) return
  63. // 后续做多选
  64. formData.value.industryIdList = [formData.value.industryIdList]
  65. formData.value.interestedAreaIdList = [formData.value.interestedAreaIdList]
  66. try {
  67. await saveResumeJobInterested(formData.value)
  68. uni.showToast({
  69. icon: 'success',
  70. title: '保存成功'
  71. })
  72. setTimeout(() => {
  73. editId.value = null
  74. uni.navigateBack({
  75. delta: 1
  76. })
  77. }, 1000)
  78. } catch (err) {
  79. uni.showToast({
  80. icon: 'none',
  81. title: err.msg
  82. })
  83. }
  84. }
  85. // 删除
  86. const handleDelete = async () => {
  87. try {
  88. await deleteResumeJobInterested(editId.value)
  89. uni.showToast({
  90. icon: 'success',
  91. title: '删除成功'
  92. })
  93. setTimeout(() => {
  94. editId.value = null
  95. uni.navigateBack({
  96. delta: 1
  97. })
  98. }, 1000)
  99. } catch (err) {
  100. uni.showToast({
  101. icon: 'none',
  102. title: err.msg
  103. })
  104. }
  105. }
  106. const rules = {
  107. positionId:{
  108. rules: [{required: true, errorMessage: '请选择期望岗位' }]
  109. },
  110. industryIdList:{
  111. rules: [{required: true, errorMessage: '请选择期望行业' }]
  112. },
  113. payFrom:{
  114. rules: [{required: true, errorMessage: '请输入薪资最低要求' }]
  115. },
  116. payTo:{
  117. rules: [{required: true, errorMessage: '请输入薪资最高要求' }]
  118. },
  119. jobType:{
  120. rules: [{required: true, errorMessage: '请选择求职类型' }]
  121. },
  122. workAreaProvinceId:{
  123. rules: [{required: true, errorMessage: '请选择工作城市' }]
  124. },
  125. }
  126. const payToMin = ref(1)
  127. const payChange = (val) => {
  128. payToMin.value = val
  129. if (val > formData.value.payTo) formData.value.payTo = val
  130. }
  131. </script>
  132. <style lang="scss" scoped>
  133. </style>