list.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <template>
  2. <view class="activities-page">
  3. <!-- 自定义导航栏 -->
  4. <view class="custom-navbar">
  5. <view class="navbar-left" @click="goBack">
  6. <text class="back-icon">←</text>
  7. </view>
  8. <view class="navbar-title">活动列表</view>
  9. <view class="navbar-right"></view>
  10. </view>
  11. <!-- 活动列表 -->
  12. <view class="activity-list">
  13. <view class="activity-card" v-for="(item, index) in activityList" :key="index"
  14. @click="goToDetail(item.id)">
  15. <image :src="item.cover_image" class="activity-image" mode="aspectFill"></image>
  16. <view class="activity-info">
  17. <view class="activity-name">{{ item.name }}</view>
  18. <view class="activity-meta">
  19. <text class="activity-time">⏰ {{ formatTime(item.start_time) }}</text>
  20. <text class="activity-location">📍 {{ item.location }}</text>
  21. </view>
  22. <view class="activity-footer">
  23. <view class="activity-price">
  24. <text class="price-symbol">¥</text>
  25. <text class="price-value">{{ item.price }}</text>
  26. </view>
  27. <view class="activity-btn">立即报名</view>
  28. </view>
  29. </view>
  30. <view class="hot-tag" v-if="item.is_hot">HOT</view>
  31. </view>
  32. </view>
  33. <!-- 加载更多 -->
  34. <view class="load-more" v-if="hasMore">
  35. <text class="load-text">{{ loading ? '加载中...' : '上拉加载更多' }}</text>
  36. </view>
  37. <view class="no-more" v-else>
  38. <text class="no-more-text">没有更多了</text>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. import api from '@/utils/api.js'
  44. import { formatTime } from '@/utils/util.js'
  45. import { DEFAULT_IMAGES } from '@/config/index.js'
  46. export default {
  47. data() {
  48. return {
  49. activityList: [],
  50. pageNum: 1,
  51. pageSize: 10,
  52. hasMore: true,
  53. loading: false
  54. }
  55. },
  56. onLoad() {
  57. this.loadActivityList()
  58. },
  59. onReachBottom() {
  60. if (this.hasMore && !this.loading) {
  61. this.pageNum++
  62. this.loadActivityList()
  63. }
  64. },
  65. methods: {
  66. // 加载活动列表
  67. async loadActivityList() {
  68. if (this.loading) return
  69. this.loading = true
  70. try {
  71. const data = await api.activity.getList({
  72. pageNum: this.pageNum,
  73. pageSize: this.pageSize,
  74. status: 1
  75. })
  76. if (data && data.length > 0) {
  77. this.activityList = [...this.activityList, ...data]
  78. this.hasMore = data.length >= this.pageSize
  79. } else {
  80. this.hasMore = false
  81. }
  82. } catch (error) {
  83. console.error('加载活动列表失败:', error)
  84. uni.showToast({
  85. title: '加载失败',
  86. icon: 'none'
  87. })
  88. } finally {
  89. this.loading = false
  90. }
  91. },
  92. // 格式化时间
  93. formatTime,
  94. // 跳转到详情
  95. goToDetail(id) {
  96. uni.navigateTo({
  97. url: `/pages/activities/detail?id=${id}`
  98. })
  99. },
  100. // 返回
  101. goBack() {
  102. uni.navigateBack()
  103. }
  104. }
  105. }
  106. </script>
  107. <style lang="scss" scoped>
  108. .activities-page {
  109. min-height: 100vh;
  110. background-color: #FFF9F9;
  111. padding-top: 90rpx;
  112. }
  113. /* 自定义导航栏 */
  114. .custom-navbar {
  115. position: fixed;
  116. top: 0;
  117. left: 0;
  118. right: 0;
  119. height: 90rpx;
  120. display: flex;
  121. align-items: center;
  122. justify-content: space-between;
  123. padding: 0 20rpx;
  124. background-color: #E91E63;
  125. z-index: 999;
  126. .navbar-left,
  127. .navbar-right {
  128. width: 80rpx;
  129. }
  130. .back-icon {
  131. font-size: 40rpx;
  132. color: #FFFFFF;
  133. font-weight: bold;
  134. }
  135. .navbar-title {
  136. flex: 1;
  137. text-align: center;
  138. font-size: 32rpx;
  139. font-weight: bold;
  140. color: #FFFFFF;
  141. }
  142. }
  143. /* 活动列表 */
  144. .activity-list {
  145. padding: 20rpx 30rpx;
  146. .activity-card {
  147. position: relative;
  148. display: flex;
  149. margin-bottom: 20rpx;
  150. background-color: #FFFFFF;
  151. border-radius: 20rpx;
  152. overflow: hidden;
  153. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  154. .activity-image {
  155. width: 260rpx;
  156. height: 260rpx;
  157. background-color: #F5F5F5;
  158. }
  159. .activity-info {
  160. flex: 1;
  161. padding: 20rpx;
  162. display: flex;
  163. flex-direction: column;
  164. justify-content: space-between;
  165. .activity-name {
  166. font-size: 30rpx;
  167. font-weight: bold;
  168. color: #333333;
  169. margin-bottom: 10rpx;
  170. display: -webkit-box;
  171. -webkit-box-orient: vertical;
  172. -webkit-line-clamp: 2;
  173. overflow: hidden;
  174. }
  175. .activity-meta {
  176. display: flex;
  177. flex-direction: column;
  178. gap: 8rpx;
  179. font-size: 24rpx;
  180. color: #666666;
  181. .activity-location {
  182. color: #999999;
  183. }
  184. }
  185. .activity-footer {
  186. display: flex;
  187. justify-content: space-between;
  188. align-items: center;
  189. margin-top: 10rpx;
  190. .activity-price {
  191. color: #E91E63;
  192. font-weight: bold;
  193. .price-symbol {
  194. font-size: 24rpx;
  195. }
  196. .price-value {
  197. font-size: 36rpx;
  198. }
  199. }
  200. .activity-btn {
  201. padding: 10rpx 30rpx;
  202. background-color: #E91E63;
  203. color: #FFFFFF;
  204. text-align: center;
  205. border-radius: 30rpx;
  206. font-size: 24rpx;
  207. }
  208. }
  209. }
  210. .hot-tag {
  211. position: absolute;
  212. top: 10rpx;
  213. left: 10rpx;
  214. padding: 5rpx 15rpx;
  215. background: linear-gradient(135deg, #FF6B6B 0%, #FF9800 100%);
  216. color: #FFFFFF;
  217. font-size: 20rpx;
  218. font-weight: bold;
  219. border-radius: 10rpx;
  220. }
  221. }
  222. }
  223. /* 加载更多 */
  224. .load-more,
  225. .no-more {
  226. padding: 30rpx 0;
  227. text-align: center;
  228. .load-text,
  229. .no-more-text {
  230. font-size: 24rpx;
  231. color: #999999;
  232. }
  233. }
  234. </style>