index.vue 6.4 KB

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