index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. else {
  58. show.value = showExtend.value = true
  59. }
  60. })
  61. // 获取编辑的职位详情
  62. const show = ref(false)
  63. const itemData = ref({})
  64. const getPositionDetail = async (id) => {
  65. const res = await getJobDetails({ id })
  66. if (!res?.data && !Object.keys(res.data).length) return
  67. itemData.value = {...res.data, ...dealDictObjData({}, res.data)}
  68. show.value = true
  69. console.log('itemData:', itemData.value)
  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 (jobId) => {
  80. const res = await getJobAdvertisedExtend(jobId)
  81. extendData.value = res?.data || {}
  82. showExtend.value = true
  83. console.log('extendData:', extendData.value)
  84. }
  85. const baseInfoRef = ref(null)
  86. const requirementRef = ref(null)
  87. const extendRef = ref(null)
  88. let submitParams = null
  89. const getSubmitParams = async() => {
  90. const baseInfo = await baseInfoRef.value.getQuery()
  91. const requirement = await requirementRef.value.getQuery()
  92. if (!baseInfo || !requirement) return
  93. submitParams = {
  94. ...baseInfo,
  95. ...requirement,
  96. fair: Boolean(fairId), // fair:是否为招聘会职位编辑-必填
  97. currency_type: 0, // currency_type: 写死0(人民币)
  98. source: fairId ? '2' : '0', // source: 0职位管理|1招聘会
  99. bizId: fairId ? fairId : null,
  100. }
  101. if (jobId) submitParams.id = jobId // 有id则为编辑
  102. saveEmit()
  103. }
  104. //
  105. const price = 1 // 39900
  106. const isStudent = ref(false)
  107. let _jobId = ''
  108. const saveEmit = async (retry) => {
  109. try {
  110. uni.showLoading({ title: '操作中...', mask: true })
  111. const res = await saveJobAdvertised(submitParams)
  112. _jobId = res?.data || res || ''
  113. if (isStudent.value) handleSaveExtend() // 保存扩展信息
  114. // status:99为待支付职位,弹窗支付
  115. if (submitParams?.status && submitParams?.status === '99') {
  116. showPay.value = true
  117. console.log('1payRef:', payRef.value)
  118. uni.showToast({ title: '当前可发布职位额度不足,请支付', icon: 'none', duration: 2000 })
  119. nextTick(() => {
  120. // 金额*100,页面展示/100
  121. console.log('2payRef:', payRef.value?.handleOpen)
  122. payRef.value && payRef.value.handleOpen({ spuId: _jobId||'', spuName: submitParams?.name||'', price, type: 1 })
  123. })
  124. return
  125. }
  126. uni.switchTab({ url: '/pages/index/position' })
  127. setTimeout(() => { uni.showToast({ title: '发布成功', 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>