jobFair.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <layout-page>
  3. <view style="padding-bottom: 30px; ">
  4. <view v-if="items.length">
  5. <uni-card v-for="val in items" :key="val.id" @tap="handleToJobFairEnterprises(val)">
  6. <image v-if="val?.previewImg" class="ss-m-t-10" :src="val.previewImg" mode="widthFix" style="width: 100%; height: auto; border-radius: 6px;"></image>
  7. <view class="ss-m-t-20">活动时间:{{ timesTampChange(val.startTime, 'Y-M-D') }}至{{ timesTampChange(val.endTime, 'Y-M-D') }}</view>
  8. <button class="ss-m-t-20 ss-m-b-10" style="background-color: #00B760; color: #fff;" type="primary">立即加入</button>
  9. </uni-card>
  10. </view>
  11. <view v-else class="nodata-img-parent">
  12. <image src="https://minio.citupro.com/dev/static/nodata.png" mode="widthFix" style="width: 100vw;height: 100vh;"></image>
  13. </view>
  14. </view>
  15. <payPopup ref="payRef" @paySuccess="paySuccess"></payPopup>
  16. </layout-page>
  17. </template>
  18. <script setup>
  19. import layoutPage from '@/layout'
  20. import { ref, watch } from 'vue'
  21. import { onShow } from '@dcloudio/uni-app'
  22. import { getAccessToken } from '@/utils/request'
  23. import { showAuthModal } from '@/hooks/useModal'
  24. import { getJobFairList, checkJobFairPermission } from '@/api/jobFair'
  25. import { timesTampChange } from '@/utils/date'
  26. import { userStore } from '@/store/user'
  27. import payPopup from '@/components/payPopup'
  28. const useUserStore = userStore()
  29. const items = ref([])
  30. // 获得招聘会列表
  31. const getList = async () => {
  32. const res = await getJobFairList()
  33. items.value = res?.data || []
  34. }
  35. watch(() => useUserStore.refreshToken, () => {
  36. if (!useUserStore.refreshToken) return items.value = []
  37. getList()
  38. })
  39. onShow(() => {
  40. // 设置自定义tabbar选中值
  41. const currentPage = getCurrentPages()[0] // 获取当前页面实例
  42. const currentTabBar = currentPage?.getTabBar?.()
  43. // 设置当前tab页的下标index
  44. currentTabBar?.setData({ selected: 3 })
  45. if (!getAccessToken()) return showAuthModal()
  46. getList()
  47. })
  48. //跳转招聘会详情
  49. const payRef = ref()
  50. const itemData = ref({})
  51. const handleToJobFairEnterprises = async (val) => {
  52. itemData.value = val
  53. if (!val?.id) {
  54. uni.showToast({ title: '资源获取失败,请稍后重试', icon: 'none' })
  55. }
  56. uni.showLoading({ title: '加载中' })
  57. try {
  58. const { data } = await checkJobFairPermission(val.id)
  59. uni.hideLoading()
  60. if (data) {
  61. uni.navigateTo({
  62. url: '/pagesB/jobFair/details?id=' + val.id
  63. })
  64. }
  65. } catch (error) {
  66. uni.hideLoading()
  67. // 权限被禁用
  68. if (error?.code === 1100056008) {
  69. uni.showToast({ title: error.msg, icon: 'none', duration: 2000 })
  70. return
  71. }
  72. // 没有权限参加招聘会,购买门票
  73. if (error?.code === 1100056005) {
  74. // 没有设置门票金额则提示无权限参加
  75. if (!val?.admissionPrice || val?.admissionPrice <= 0) {
  76. uni.showToast({ title: error.msg, icon: 'none', duration: 2000 })
  77. return
  78. }
  79. // 设置门票金额则提示购买门票
  80. uni.showToast({ title: '您暂时无法参加该招聘会,请先购买门票', icon: 'none', duration: 2000 })
  81. payRef.value && payRef.value.handleOpen({ spuId: val?.id || '', spuName: val?.title || '', price: val.admissionPrice, type: 5 })
  82. }
  83. }
  84. }
  85. // 支付成功
  86. const paySuccess = () => {
  87. uni.showToast({ title: '支付成功', icon: 'success', duration: 2000 })
  88. handleToJobFairEnterprises(itemData.value)
  89. }
  90. </script>
  91. <style scoped lang="scss">
  92. </style>