index.vue 7.1 KB

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