list.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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="announcement-bar">
  13. <text class="announcement-icon">📢</text>
  14. <text class="announcement-content">红娘特训营报名开始啦!报名得积分,积分兑好礼!</text>
  15. </view>
  16. <!-- 活动分类标签 -->
  17. <view class="activity-tabs">
  18. <view class="tab-item active">全部活动</view>
  19. </view>
  20. <!-- 活动列表 -->
  21. <view class="activity-grid">
  22. <view class="activity-card" v-for="(item, index) in activityList" :key="index"
  23. @click="goToDetail(item.id)">
  24. <image :src="item.cover_image" class="activity-image" mode="aspectFill"></image>
  25. <view class="activity-info">
  26. <view class="activity-name">{{ item.name }}</view>
  27. <view class="activity-meta">
  28. <text class="activity-location">📍 {{ item.location }}</text>
  29. </view>
  30. <view class="activity-footer">
  31. <view class="activity-points">
  32. <text class="points-symbol">💎</text>
  33. <text class="points-value">{{ item.points }}</text>
  34. </view>
  35. <text class="activity-participants">{{ item.participants || 0 }}人参加</text>
  36. </view>
  37. <view class="activity-btn" @click.stop="goToDetail(item.id)">查看详情</view>
  38. </view>
  39. </view>
  40. </view>
  41. <!-- 加载更多 -->
  42. <view class="load-more" v-if="hasMore">
  43. <text class="load-text">{{ loading ? '加载中...' : '上拉加载更多' }}</text>
  44. </view>
  45. <view class="no-more" v-else>
  46. <text class="no-more-text">没有更多了</text>
  47. </view>
  48. </view>
  49. </template>
  50. <script>
  51. import api from '@/utils/api.js'
  52. import { formatTime } from '@/utils/util.js'
  53. import { DEFAULT_IMAGES } from '@/config/index.js'
  54. export default {
  55. data() {
  56. return {
  57. activityList: [],
  58. pageNum: 1,
  59. pageSize: 10,
  60. hasMore: true,
  61. loading: false,
  62. // 模拟数据,当API返回为空时使用
  63. mockActivities: [
  64. {
  65. id: 1,
  66. name: '姻缘一线牵·大型相亲会',
  67. location: '雄安新区',
  68. points: 299,
  69. participants: 18,
  70. cover_image: 'https://images.unsplash.com/photo-1511671782779-c97d3d27a1d4?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60'
  71. },
  72. {
  73. id: 2,
  74. name: '一期一会·红娘心得分享',
  75. location: '北京',
  76. points: 389,
  77. participants: 54,
  78. cover_image: 'https://images.unsplash.com/photo-1464822759023-fed622ff2c3b?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60'
  79. },
  80. {
  81. id: 3,
  82. name: '公园相亲角',
  83. location: '天津',
  84. points: 369,
  85. participants: 16,
  86. cover_image: 'https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60'
  87. },
  88. {
  89. id: 4,
  90. name: '以爱为媒·千里相亲会',
  91. location: '北京',
  92. points: 268,
  93. participants: 25,
  94. cover_image: 'https://images.unsplash.com/photo-1517841905240-472988babdf9?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60'
  95. }
  96. ]
  97. }
  98. },
  99. onLoad() {
  100. this.loadActivityList()
  101. },
  102. onReachBottom() {
  103. if (this.hasMore && !this.loading) {
  104. this.pageNum++
  105. this.loadActivityList()
  106. }
  107. },
  108. methods: {
  109. // 加载活动列表
  110. async loadActivityList() {
  111. if (this.loading) return
  112. this.loading = true
  113. try {
  114. const data = await api.activity.getList({
  115. pageNum: this.pageNum,
  116. pageSize: this.pageSize,
  117. status: 1
  118. })
  119. if (data && data.length > 0) {
  120. this.activityList = [...this.activityList, ...data]
  121. this.hasMore = data.length >= this.pageSize
  122. } else {
  123. // 如果API返回为空,使用模拟数据
  124. this.hasMore = false
  125. if (this.pageNum === 1) {
  126. this.activityList = this.mockActivities
  127. }
  128. }
  129. } catch (error) {
  130. console.error('加载活动列表失败:', error)
  131. // 当API调用失败时,使用模拟数据
  132. if (this.pageNum === 1) {
  133. this.activityList = this.mockActivities
  134. }
  135. this.hasMore = false
  136. } finally {
  137. this.loading = false
  138. }
  139. },
  140. // 格式化时间
  141. formatTime,
  142. // 跳转到详情
  143. goToDetail(id) {
  144. uni.navigateTo({
  145. url: `/pages/activities/detail?id=${id}`
  146. })
  147. },
  148. // 返回
  149. goBack() {
  150. uni.navigateBack()
  151. }
  152. }
  153. }
  154. </script>
  155. <style lang="scss" scoped>
  156. .activities-page {
  157. min-height: 100vh;
  158. background-color: #FFF9F9;
  159. padding-top: 90rpx;
  160. }
  161. /* 自定义导航栏 */
  162. .custom-navbar {
  163. position: fixed;
  164. top: 0;
  165. left: 0;
  166. right: 0;
  167. height: 90rpx;
  168. display: flex;
  169. align-items: center;
  170. justify-content: space-between;
  171. padding: 0 20rpx;
  172. background: linear-gradient(135deg, #FCE4EC 0%, #F8BBD0 100%);
  173. z-index: 999;
  174. .navbar-left,
  175. .navbar-right {
  176. width: 80rpx;
  177. }
  178. .back-icon {
  179. font-size: 40rpx;
  180. color: #333333;
  181. font-weight: bold;
  182. }
  183. .navbar-title {
  184. flex: 1;
  185. text-align: center;
  186. font-size: 32rpx;
  187. font-weight: bold;
  188. color: #333333;
  189. }
  190. }
  191. /* 顶部公告 */
  192. .announcement-bar {
  193. display: flex;
  194. align-items: center;
  195. padding: 15rpx 20rpx;
  196. background-color: #FFF3E0;
  197. margin: 10rpx;
  198. border-radius: 15rpx;
  199. .announcement-icon {
  200. font-size: 28rpx;
  201. margin-right: 15rpx;
  202. }
  203. .announcement-content {
  204. flex: 1;
  205. font-size: 26rpx;
  206. color: #FF6B8A;
  207. line-height: 1.4;
  208. }
  209. }
  210. /* 活动分类标签 */
  211. .activity-tabs {
  212. display: flex;
  213. align-items: center;
  214. padding: 15rpx 20rpx;
  215. background-color: #FFFFFF;
  216. margin: 0 10rpx;
  217. border-radius: 15rpx;
  218. .tab-item {
  219. padding: 10rpx 30rpx;
  220. font-size: 28rpx;
  221. color: #666666;
  222. border-radius: 30rpx;
  223. transition: all 0.3s;
  224. &.active {
  225. background-color: #9C27B0;
  226. color: #FFFFFF;
  227. }
  228. }
  229. }
  230. /* 活动列表 - 两列布局 */
  231. .activity-grid {
  232. display: grid;
  233. grid-template-columns: 1fr 1fr;
  234. gap: 20rpx;
  235. padding: 20rpx;
  236. .activity-card {
  237. position: relative;
  238. background-color: #FFFFFF;
  239. border-radius: 20rpx;
  240. overflow: hidden;
  241. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  242. .activity-image {
  243. width: 100%;
  244. height: 240rpx;
  245. background-color: #F5F5F5;
  246. }
  247. .activity-info {
  248. padding: 20rpx;
  249. .activity-name {
  250. font-size: 28rpx;
  251. font-weight: bold;
  252. color: #333333;
  253. margin-bottom: 10rpx;
  254. display: -webkit-box;
  255. -webkit-box-orient: vertical;
  256. -webkit-line-clamp: 2;
  257. overflow: hidden;
  258. }
  259. .activity-meta {
  260. margin-bottom: 15rpx;
  261. .activity-location {
  262. font-size: 24rpx;
  263. color: #666666;
  264. }
  265. }
  266. .activity-footer {
  267. display: flex;
  268. justify-content: space-between;
  269. align-items: center;
  270. margin-bottom: 15rpx;
  271. .activity-points {
  272. display: flex;
  273. align-items: center;
  274. .points-symbol {
  275. font-size: 24rpx;
  276. margin-right: 5rpx;
  277. }
  278. .points-value {
  279. font-size: 26rpx;
  280. color: #FF6B8A;
  281. font-weight: bold;
  282. }
  283. }
  284. .activity-participants {
  285. font-size: 22rpx;
  286. color: #999999;
  287. }
  288. }
  289. .activity-btn {
  290. width: 100%;
  291. height: 60rpx;
  292. display: flex;
  293. align-items: center;
  294. justify-content: center;
  295. background-color: #9C27B0;
  296. color: #FFFFFF;
  297. border-radius: 30rpx;
  298. font-size: 26rpx;
  299. }
  300. }
  301. }
  302. }
  303. /* 加载更多 */
  304. .load-more,
  305. .no-more {
  306. padding: 30rpx 0;
  307. text-align: center;
  308. .load-text,
  309. .no-more-text {
  310. font-size: 24rpx;
  311. color: #999999;
  312. }
  313. }
  314. </style>