jobFair.vue 5.6 KB

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