index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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" :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. })
  50. let jobId = ''
  51. let fairId = ''
  52. onLoad((options) => {
  53. jobId = options?.jobId || props.jobId || ''
  54. fairId = options?.fairId || ''
  55. console.log('jobId:', jobId); console.log('fairId:', fairId)
  56. if (jobId) getPositionDetail(jobId)
  57. })
  58. // 获取编辑的职位详情
  59. const show = ref(false)
  60. const itemData = ref({})
  61. const getPositionDetail = async (id) => {
  62. const res = await getJobDetails({ id })
  63. if (!res?.data && !Object.keys(res.data).length) return
  64. itemData.value = {...res.data, ...dealDictObjData({}, res.data)}
  65. show.value = true
  66. console.log('itemData:', itemData.value)
  67. if (itemData.value?.type === '3') {
  68. isStudent.value = true
  69. getPositionExtendDetail(id)
  70. }
  71. }
  72. // getPositionDetail('1904154452278009858')
  73. // 获取编辑的职位详情
  74. const showExtend = ref(false)
  75. const extendData = ref({})
  76. const getPositionExtendDetail = async (jobId) => {
  77. const res = await getJobAdvertisedExtend(jobId)
  78. extendData.value = res?.data || {}
  79. showExtend.value = true
  80. console.log('extendData:', extendData.value)
  81. }
  82. const baseInfoRef = ref(null)
  83. const requirementRef = ref(null)
  84. const extendRef = ref(null)
  85. let submitParams = null
  86. const getSubmitParams = async() => {
  87. const baseInfo = await baseInfoRef.value.getQuery()
  88. const requirement = await requirementRef.value.getQuery()
  89. if (!baseInfo || !requirement) return
  90. submitParams = {
  91. ...baseInfo,
  92. ...requirement,
  93. fair: Boolean(fairId), // fair:是否为招聘会职位编辑-必填
  94. currency_type: 0, // currency_type: 写死0(人民币)
  95. source: fairId ? '2' : '0', // source: 0职位管理|1招聘会
  96. bizId: fairId ? fairId : null,
  97. }
  98. if (jobId) submitParams.id = jobId // 有id则为编辑
  99. saveEmit()
  100. }
  101. //
  102. const price = 1 // 39900
  103. const isStudent = ref(false)
  104. let _jobId = ''
  105. const saveEmit = async (retry) => {
  106. try {
  107. uni.showLoading({ title: '操作中...', mask: true })
  108. const res = await saveJobAdvertised(submitParams)
  109. _jobId = res?.data || res || ''
  110. if (isStudent.value) handleSaveExtend() // 保存扩展信息
  111. // status:99为待支付职位,弹窗支付
  112. if (submitParams?.status && submitParams?.status === '99') {
  113. showPay.value = true
  114. console.log('1payRef:', payRef.value)
  115. uni.showToast({ title: '当前可发布职位额度不足,请支付', icon: 'none', duration: 2000 })
  116. nextTick(() => {
  117. // 金额*100,页面展示/100
  118. console.log('2payRef:', payRef.value?.handleOpen)
  119. payRef.value && payRef.value.handleOpen({ spuId: _jobId||'', spuName: submitParams?.name||'', price, type: 1 })
  120. })
  121. return
  122. }
  123. uni.switchTab({ url: '/pages/index/position' })
  124. setTimeout(() => { uni.showToast({ title: '发布成功', icon: 'success' }) }, 1000)
  125. } catch (error) {
  126. console.log('error:', error)
  127. // 可发布职位额度不足时,将status设为99重新提交
  128. if (error?.msg === '企业额度已超过') {
  129. showPay.value = true
  130. submitParams.status = '99'
  131. setTimeout(() => {
  132. if (!retry) saveEmit(true) // true:重新提交避免死循环
  133. }, 1000)
  134. }
  135. } finally {
  136. uni.hideLoading()
  137. }
  138. }
  139. const payRef = ref(null)
  140. const showPay = ref(false)
  141. const paySuccess = () => {
  142. uni.switchTab({ url: '/pages/index/position' })
  143. setTimeout(() => { uni.showToast({ title: '发布成功', icon: 'success' }) }, 1000)
  144. }
  145. const payClose = () => {
  146. uni.switchTab({ url: '/pages/index/position' }) // 不支持传参
  147. }
  148. // 保存扩展信息
  149. const handleSaveExtend = async () => {
  150. if (!_jobId) return
  151. try {
  152. const extend = await extendRef.value && extendRef.value.getQuery() || null
  153. if (!extend) return
  154. await saveJobAdvertisedExtend({ ...extend, jobId: _jobId })
  155. } catch (error) {
  156. console.error('保存扩展信息失败', error)
  157. }
  158. }
  159. </script>
  160. <style scoped lang="scss">
  161. .decoration {
  162. color: #fff;
  163. border-radius: 50%;
  164. width: 15px;
  165. height: 15px;
  166. line-height: 15px;
  167. font-size: 10px;
  168. text-align: center;
  169. margin-right: 4px;
  170. }
  171. .decoration1 {
  172. background-color: #00b760;
  173. }
  174. .decoration2 {
  175. background-color: #7a87c9;
  176. }
  177. .decoration3 {
  178. background-color: #1caaf2;
  179. }
  180. </style>