index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <view v-if="show" class="ss-m-x-20 ss-p-b-100">
  3. <uni-section class="ss-m-y-20" title="职位基本信息">
  4. <template v-slot:decoration>
  5. <view class="decoration decoration1">1</view>
  6. </template>
  7. <!-- 基本信息 -->
  8. <baseInfo ref="baseInfoRef" :isFair="Boolean(fairId)" :data="itemData"></baseInfo>
  9. </uni-section>
  10. <uni-section class="ss-m-y-20" title="岗位要求">
  11. <template v-slot:decoration>
  12. <view class="decoration decoration2">2</view>
  13. </template>
  14. <!-- 岗位要求 -->
  15. <requirement ref="requirementRef" :data="itemData"></requirement>
  16. </uni-section>
  17. <!-- <template v-if="isStudent">
  18. <uni-section class="ss-m-y-20" title="其他">
  19. <template v-slot:decoration>
  20. <view class="decoration decoration3">3</view>
  21. </template>
  22. <extendInfo ref="extendRef" :data="extendData"></extendInfo>
  23. </uni-section>
  24. </template> -->
  25. <view class="f-horizon-center">
  26. <button type="primary" size="default" class="send-button" @click="getSubmitParams">提 交</button>
  27. </view>
  28. <!-- 支付 -->
  29. <payPopup ref="payRef" :tabBar="false" @paySuccess="paySuccess" @close="payClose"></payPopup>
  30. </view>
  31. </template>
  32. <script setup>
  33. import baseInfo from './components/baseInfo.vue'
  34. import requirement from './components/requirement.vue'
  35. import extendInfo from './components/extend.vue'
  36. import { ref, nextTick } from 'vue'
  37. import { onLoad } from '@dcloudio/uni-app'
  38. import payPopup from '@/components/payPopup'
  39. import { dealDictObjData } from '@/utils/position'
  40. import {
  41. saveJobAdvertised,
  42. saveJobAdvertisedExtend,
  43. getJobDetails,
  44. getJobAdvertisedExtend,
  45. } from '@/api/new/position'
  46. const props = defineProps({
  47. jobId: String,
  48. fairId: String,
  49. })
  50. const jobId = ref('')
  51. const fairId = ref('')
  52. onLoad((options) => {
  53. jobId.value = options?.jobId || props.jobId || ''
  54. fairId.value = options?.fairId || props.fairId || ''
  55. if (jobId.value) getPositionDetail(jobId.value)
  56. else {
  57. show.value = true
  58. }
  59. })
  60. // 获取编辑的职位详情
  61. const show = ref(false)
  62. const itemData = ref({})
  63. const getPositionDetail = async (id) => {
  64. try {
  65. uni.showLoading({ title: '加载中...', mask: true })
  66. const res = await getJobDetails({ id })
  67. if (!res?.data || !Object.keys(res.data).length) return
  68. itemData.value = {...res.data, ...dealDictObjData({}, res.data)}
  69. // itemData.value.name = new Date().getTime().toString() + '测试小程序发布职位'
  70. // if (itemData.value?.type === '3') {
  71. // await getPositionExtendDetail(id)
  72. // }
  73. show.value = true
  74. } finally {
  75. uni.hideLoading()
  76. }
  77. }
  78. // // 测试数据
  79. // setTimeout(async() => {
  80. // show.value = false
  81. // await getPositionDetail('1904786675108691969')
  82. // }, 2000)
  83. // 获取实习扩展信息
  84. // const extendData = ref({})
  85. // const getPositionExtendDetail = async (id) => {
  86. // try {
  87. // const res = await getJobAdvertisedExtend(id)
  88. // extendData.value = res?.data || {}
  89. // isStudent.value = true
  90. // } catch (error) {
  91. // }
  92. // }
  93. const baseInfoRef = ref(null)
  94. const requirementRef = ref(null)
  95. // const extendRef = ref(null)
  96. let submitParams = null
  97. const getSubmitParams = async() => {
  98. const baseInfo = await baseInfoRef.value.getQuery()
  99. const requirement = await requirementRef.value.getQuery()
  100. if (!baseInfo || !requirement) return
  101. // if (cleanedHtml(baseInfo.content)?.length > 5000) return uni.showToast({ title: '岗位职责字数超出限制', icon: 'none', duration: 2000 })
  102. // if (cleanedHtml(baseInfo.requirement)?.length > 5000) return uni.showToast({ title: '岗位要求字数超出限制', icon: 'none', duration: 2000 })
  103. submitParams = {
  104. ...baseInfo,
  105. ...requirement,
  106. fair: Boolean(fairId.value), // fair:是否为招聘会职位编辑-必填
  107. currency_type: 0, // currency_type: 写死0(人民币)
  108. source: fairId.value || baseInfo.bizId ? '2' : '0', // source: 0职位管理|1招聘会
  109. bizId: fairId.value || baseInfo.bizId || null,
  110. }
  111. if (!submitParams.salary) {
  112. if (!submitParams.payFrom) return uni.showToast({ title: '请填写最低薪资', icon: 'none', duration: 2000 })
  113. if (!submitParams.payTo) return uni.showToast({ title: '请填写最高薪资', icon: 'none', duration: 2000 })
  114. }
  115. if (jobId.value) submitParams.id = jobId.value // 有id则为编辑
  116. saveEmit()
  117. }
  118. //
  119. const price = 39900 // 39900 职位价格,传递单位:分
  120. // const isStudent = ref(false)
  121. let _jobId = ''
  122. const saveEmit = async (retry) => {
  123. try {
  124. uni.showLoading({ title: '操作中...', mask: true })
  125. const res = await saveJobAdvertised(submitParams)
  126. _jobId = res?.data || res || ''
  127. // if (isStudent.value) handleSaveExtend() // 保存扩展信息
  128. // status:99为待支付职位,弹窗支付
  129. if (submitParams?.status && submitParams?.status === '99') {
  130. uni.showToast({ title: '当前可发布职位额度不足,请支付', icon: 'none', duration: 2000 })
  131. nextTick(() => {
  132. // 金额*100,页面展示/100
  133. payRef.value && payRef.value.handleOpen({ spuId: _jobId||'', spuName: submitParams?.name||'', price, type: 1 })
  134. })
  135. return
  136. }
  137. uni.switchTab({ url: '/pages/index/position' })
  138. // const title = itemData.value?.status === '99' '编辑成功,请前往支付' : jobId.value ? '编辑成功' : '发布成功'
  139. setTimeout(() => { uni.showToast({ title: jobId.value ? '编辑成功' : '发布成功', icon: 'success' }) }, 1000)
  140. } catch (error) {
  141. console.log('error:', error)
  142. // 可发布职位额度不足时,将status设为99重新提交
  143. if (error?.msg === '企业额度已超过') {
  144. submitParams.status = '99'
  145. setTimeout(() => {
  146. if (!retry) saveEmit(true) // true:重新提交避免死循环
  147. }, 1000)
  148. }
  149. // else if (error?.msg === '招聘会时间已过,暂停招聘') {
  150. // uni.showToast({ title: error.msg, icon: 'none', duration: 2000 })
  151. // }
  152. } finally {
  153. uni.hideLoading()
  154. }
  155. }
  156. const payRef = ref(null)
  157. const paySuccess = () => {
  158. uni.switchTab({ url: '/pages/index/position' })
  159. setTimeout(() => { uni.showToast({ title: '发布成功', icon: 'success', duration: 2000 }) }, 1000)
  160. }
  161. const payClose = () => {
  162. setTimeout(() => { uni.showToast({ title: '您已取消支付,请前往待发布查看!', icon: 'none', duration: 3000 }) }, 500)
  163. uni.switchTab({ url: '/pages/index/position' }) // 不支持传参
  164. }
  165. // 保存扩展信息
  166. // const handleSaveExtend = async () => {
  167. // if (!_jobId) return
  168. // try {
  169. // const extend = await extendRef.value && extendRef.value.getQuery() || null
  170. // if (!extend) return
  171. // await saveJobAdvertisedExtend({ ...extend, jobId: _jobId })
  172. // } catch (error) {
  173. // console.error('保存扩展信息失败', error)
  174. // }
  175. // }
  176. </script>
  177. <style scoped lang="scss">
  178. .decoration {
  179. color: #fff;
  180. border-radius: 50%;
  181. width: 15px;
  182. height: 15px;
  183. line-height: 15px;
  184. font-size: 10px;
  185. text-align: center;
  186. margin-right: 4px;
  187. }
  188. .decoration1 {
  189. background-color: #00b760;
  190. }
  191. .decoration2 {
  192. background-color: #7a87c9;
  193. }
  194. .decoration3 {
  195. background-color: #1caaf2;
  196. }
  197. </style>