jobFair.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. <scroll-view class="scrollBox" :scroll-y="true" @scrolltolower="loadingMore" style="position:relative;">
  9. <view v-for="val in items" :key="val.id" @tap="handleToJobFairEnterprises(val)" class="list-item default-border">
  10. <image v-if="val?.previewImg" class="ss-m-t-10" :src="val.previewImg" mode="widthFix" style="width: 100%; height: auto; border-radius: 6px;"></image>
  11. <view class="ss-m-t-20">活动主题:{{ val.title }}</view>
  12. <view class="ss-m-t-20 ss-m-b-10">
  13. 活动状态:
  14. <span class="font-weight-bold" :style="{'color': val.status === '0' ? '#00b760' : '#ff5252'}">
  15. {{ val.status === '0' ? '进行中' : '已结束' }}
  16. </span>
  17. </view>
  18. <view>活动时间:{{ timesTampChange(val.startTime, 'Y-M-D') }}至{{ timesTampChange(val.endTime, 'Y-M-D') }}</view>
  19. <button class="ss-m-t-20 ss-m-b-10" style="background-color: #00B760; color: #fff;" type="primary">
  20. {{ val.status === '0' ? '立即加入' : '查看详情' }}
  21. </button>
  22. </view>
  23. <uni-load-more :status="more" />
  24. </scroll-view>
  25. </view>
  26. <view v-else>
  27. <view class="commonBackground"></view>
  28. <view class="nodata-img-parent" :style="{'height': `calc(100vh - ${(navbarHeight + 100)}px)`}">
  29. <image src="https://minio.menduner.com/dev/bb43df1dc91945e05ee93da76e49b34f87b0d10203eb76c20e2d4999a13b9a0a.png" mode="widthFix" style="width: 100vw;height: 100vh;"></image>
  30. </view>
  31. </view>
  32. </view>
  33. <payPopup ref="payRef" @paySuccess="paySuccess"></payPopup>
  34. </layout-page>
  35. </view>
  36. </template>
  37. <script setup>
  38. import { ref, watch } from 'vue'
  39. import layoutPage from '@/layout'
  40. import Navbar from '@/components/Navbar'
  41. import { onShow } from '@dcloudio/uni-app'
  42. import { getAccessToken } from '@/utils/request'
  43. import { showAuthModal } from '@/hooks/useModal'
  44. import { getJobFairList, checkJobFairPermission } from '@/api/jobFair'
  45. import { timesTampChange } from '@/utils/date'
  46. import { userStore } from '@/store/user'
  47. import payPopup from '@/components/payPopup'
  48. const useUserStore = userStore()
  49. const items = ref([])
  50. const navbarHeight = ref(uni.getStorageSync('navbarHeight'))
  51. const total = ref(0)
  52. const query = ref({
  53. pageNo: 1,
  54. pageSize: 20
  55. })
  56. const more = ref('more')
  57. // 获得招聘会列表
  58. const getList = async () => {
  59. if (query.value.pageNo < 1) return
  60. if (query.value.pageNo === 1) items.value = []
  61. try {
  62. more.value = 'loading'
  63. uni.showLoading({ title: '加载中' })
  64. const res = await getJobFairList(query.value)
  65. const list = res?.data?.list || []
  66. if (!list?.length) {
  67. more.value = 'noMore'
  68. return
  69. }
  70. items.value = items.value.concat(...list)
  71. total.value = res.data.total
  72. more.value = 'more'
  73. if (items.value.length === +total.value) {
  74. more.value = 'noMore'
  75. return
  76. }
  77. } catch (error) {
  78. query.value.pageNo--
  79. more.value = 'more'
  80. } finally {
  81. uni.hideLoading()
  82. }
  83. }
  84. // 加载更多
  85. const loadingMore = () => {
  86. if (more.value === 'noMore') return
  87. more.value = 'loading'
  88. query.value.pageNo++
  89. getList()
  90. }
  91. watch(() => useUserStore.refreshToken, () => {
  92. if (!useUserStore.refreshToken) return items.value = []
  93. getList()
  94. })
  95. onShow(() => {
  96. // 设置自定义tabbar选中值
  97. const currentPage = getCurrentPages()[0] // 获取当前页面实例
  98. const currentTabBar = currentPage?.getTabBar?.()
  99. // 设置当前tab页的下标index
  100. currentTabBar?.setData({ selected: 3 })
  101. if (!getAccessToken()) return showAuthModal()
  102. getList()
  103. })
  104. //跳转招聘会详情
  105. const payRef = ref()
  106. const itemData = ref({})
  107. const handleToJobFairEnterprises = async (val) => {
  108. itemData.value = val
  109. if (!val?.id) {
  110. uni.showToast({ title: '资源获取失败,请稍后重试', icon: 'none' })
  111. }
  112. uni.showLoading({ title: '加载中' })
  113. try {
  114. const { data } = await checkJobFairPermission(val.id)
  115. uni.hideLoading()
  116. if (data) {
  117. uni.navigateTo({
  118. url: '/pagesB/jobFair/details?id=' + val.id
  119. })
  120. }
  121. } catch (error) {
  122. uni.hideLoading()
  123. // 权限被禁用
  124. if (error?.code === 1100056008) {
  125. uni.showToast({ title: error.msg, icon: 'none', duration: 2000 })
  126. return
  127. }
  128. // 没有权限参加招聘会,购买门票
  129. if (error?.code === 1100056005) {
  130. // 没有设置门票金额则提示无权限参加
  131. if (!val?.admissionPrice || val?.admissionPrice <= 0) {
  132. const title = val?.status === '1' ? '您没有参加该招聘会,暂无详情查看' : error.msg
  133. uni.showToast({ title, icon: 'none', duration: 2000 })
  134. return
  135. }
  136. // 设置门票金额则提示购买门票
  137. uni.showToast({ title: '您暂时无法参加该招聘会,请先购买门票', icon: 'none', duration: 2000 })
  138. payRef.value && payRef.value.handleOpen({ spuId: val?.id || '', spuName: val?.title || '', price: val.admissionPrice, type: 5 })
  139. }
  140. }
  141. }
  142. // 支付成功
  143. const paySuccess = () => {
  144. uni.showToast({ title: '支付成功', icon: 'success', duration: 2000 })
  145. handleToJobFairEnterprises(itemData.value)
  146. }
  147. </script>
  148. <style scoped lang="scss">
  149. .scrollBox {
  150. height: 100vh;
  151. box-sizing: border-box;
  152. padding-bottom: 100px;
  153. }
  154. .list-item {
  155. margin: 0 30rpx 30rpx 30rpx;
  156. border-radius: 20rpx;
  157. padding: 30rpx;
  158. position: relative;
  159. background-color: #fbfbfb;
  160. box-shadow: 1px 2px 12px rgba(0, 0, 0, 0.17);
  161. view {
  162. font-size: 28rpx;
  163. color: #666;
  164. }
  165. }
  166. </style>