jobFair.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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' ? checkActivityTime(val.startTime, val.endTime) ? '筹备中' : '进行中' : '已结束' }}
  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. function checkActivityTime(startTimeStamp) {
  85. const now = new Date()
  86. const currentTime = now.getTime()
  87. const startDate = new Date(startTimeStamp)
  88. const startOfDay = new Date(
  89. startDate.getFullYear(),
  90. startDate.getMonth(),
  91. startDate.getDate(),
  92. 0, 0, 0, 0
  93. )
  94. const adjustedStartTime = startOfDay.getTime()
  95. // 判断时间关系
  96. if (currentTime < adjustedStartTime) return true // 活动未开始
  97. }
  98. // 加载更多
  99. const loadingMore = () => {
  100. if (more.value === 'noMore') return
  101. more.value = 'loading'
  102. query.value.pageNo++
  103. getList()
  104. }
  105. watch(() => useUserStore.refreshToken, () => {
  106. if (!useUserStore.refreshToken) return items.value = []
  107. getList()
  108. })
  109. onShow(() => {
  110. // 设置自定义tabbar选中值
  111. const currentPage = getCurrentPages()[0] // 获取当前页面实例
  112. const currentTabBar = currentPage?.getTabBar?.()
  113. // 设置当前tab页的下标index
  114. currentTabBar?.setData({ selected: 3 })
  115. if (!getAccessToken()) return showAuthModal()
  116. getList()
  117. })
  118. //跳转招聘会详情
  119. const payRef = ref()
  120. const itemData = ref({})
  121. const handleToJobFairEnterprises = async (val) => {
  122. itemData.value = val
  123. if (!val?.id) {
  124. uni.showToast({ title: '资源获取失败,请稍后重试', icon: 'none' })
  125. }
  126. uni.showLoading({ title: '加载中' })
  127. try {
  128. const { data } = await checkJobFairPermission(val.id)
  129. uni.hideLoading()
  130. if (data) {
  131. uni.navigateTo({
  132. url: '/pagesB/jobFair/details?id=' + val.id
  133. })
  134. }
  135. } catch (error) {
  136. uni.hideLoading()
  137. // 权限被禁用
  138. if (error?.code === 1100056008) {
  139. uni.showToast({ title: error.msg, icon: 'none', duration: 2000 })
  140. return
  141. }
  142. // 没有权限参加招聘会,购买门票
  143. if (error?.code === 1100056005) {
  144. // 没有设置门票金额则提示无权限参加
  145. if (!val?.admissionPrice || val?.admissionPrice <= 0) {
  146. const title = val?.status === '1' ? '您没有参加该招聘会,暂无详情查看' : error.msg
  147. uni.showToast({ title, icon: 'none', duration: 2000 })
  148. return
  149. }
  150. // 设置门票金额则提示购买门票
  151. uni.showToast({ title: '您暂时无法参加该招聘会,请先购买门票', icon: 'none', duration: 2000 })
  152. payRef.value && payRef.value.handleOpen({ spuId: val?.id || '', spuName: val?.title || '', price: val.admissionPrice, type: 5 })
  153. }
  154. }
  155. }
  156. // 支付成功
  157. const paySuccess = () => {
  158. uni.showToast({ title: '支付成功', icon: 'success', duration: 2000 })
  159. handleToJobFairEnterprises(itemData.value)
  160. }
  161. </script>
  162. <style scoped lang="scss">
  163. .scrollBox {
  164. height: 100vh;
  165. box-sizing: border-box;
  166. padding-bottom: 100px;
  167. }
  168. .list-item {
  169. margin: 0 30rpx 30rpx 30rpx;
  170. border-radius: 20rpx;
  171. padding: 30rpx;
  172. position: relative;
  173. background-color: #fbfbfb;
  174. box-shadow: 1px 2px 12px rgba(0, 0, 0, 0.17);
  175. view {
  176. font-size: 28rpx;
  177. color: #666;
  178. }
  179. }
  180. </style>