jobFair.vue 4.2 KB

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