list.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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. if (this.pageNum === 1) {
  131. this.activityList = this.mockActivities
  132. }
  133. this.hasMore = false
  134. } finally {
  135. this.loading = false
  136. }
  137. },
  138. // 格式化时间
  139. formatTime,
  140. // 跳转到详情
  141. goToDetail(id) {
  142. uni.navigateTo({
  143. url: `/pages/activities/detail?id=${id}`
  144. })
  145. },
  146. // 返回
  147. goBack() {
  148. uni.navigateBack()
  149. }
  150. }
  151. }
  152. </script>
  153. <style lang="scss" scoped>
  154. .activities-page {
  155. min-height: 100vh;
  156. background-color: #FFF9F9;
  157. padding-top: 90rpx;
  158. }
  159. /* 自定义导航栏 */
  160. .custom-navbar {
  161. position: fixed;
  162. top: 0;
  163. left: 0;
  164. right: 0;
  165. height: 90rpx;
  166. display: flex;
  167. align-items: center;
  168. justify-content: space-between;
  169. padding: 0 20rpx;
  170. background: linear-gradient(135deg, #FCE4EC 0%, #F8BBD0 100%);
  171. z-index: 999;
  172. .navbar-left,
  173. .navbar-right {
  174. width: 80rpx;
  175. }
  176. .back-icon {
  177. font-size: 40rpx;
  178. color: #333333;
  179. font-weight: bold;
  180. }
  181. .navbar-title {
  182. flex: 1;
  183. text-align: center;
  184. font-size: 32rpx;
  185. font-weight: bold;
  186. color: #333333;
  187. }
  188. }
  189. /* 顶部公告 */
  190. .announcement-bar {
  191. display: flex;
  192. align-items: center;
  193. padding: 15rpx 20rpx;
  194. background-color: #FFF3E0;
  195. margin: 10rpx;
  196. border-radius: 15rpx;
  197. .announcement-icon {
  198. font-size: 28rpx;
  199. margin-right: 15rpx;
  200. }
  201. .announcement-content {
  202. flex: 1;
  203. font-size: 26rpx;
  204. color: #FF6B8A;
  205. line-height: 1.4;
  206. }
  207. }
  208. /* 活动分类标签 */
  209. .activity-tabs {
  210. display: flex;
  211. align-items: center;
  212. padding: 15rpx 20rpx;
  213. background-color: #FFFFFF;
  214. margin: 0 10rpx;
  215. border-radius: 15rpx;
  216. .tab-item {
  217. padding: 10rpx 30rpx;
  218. font-size: 28rpx;
  219. color: #666666;
  220. border-radius: 30rpx;
  221. transition: all 0.3s;
  222. &.active {
  223. background-color: #9C27B0;
  224. color: #FFFFFF;
  225. }
  226. }
  227. }
  228. /* 活动列表 - 两列布局 */
  229. .activity-grid {
  230. display: grid;
  231. grid-template-columns: 1fr 1fr;
  232. gap: 20rpx;
  233. padding: 20rpx;
  234. .activity-card {
  235. position: relative;
  236. background-color: #FFFFFF;
  237. border-radius: 20rpx;
  238. overflow: hidden;
  239. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  240. .activity-image {
  241. width: 100%;
  242. height: 240rpx;
  243. background-color: #F5F5F5;
  244. }
  245. .activity-info {
  246. padding: 20rpx;
  247. .activity-name {
  248. font-size: 28rpx;
  249. font-weight: bold;
  250. color: #333333;
  251. margin-bottom: 10rpx;
  252. display: -webkit-box;
  253. -webkit-box-orient: vertical;
  254. -webkit-line-clamp: 2;
  255. overflow: hidden;
  256. }
  257. .activity-meta {
  258. margin-bottom: 15rpx;
  259. .activity-location {
  260. font-size: 24rpx;
  261. color: #666666;
  262. }
  263. }
  264. .activity-footer {
  265. display: flex;
  266. justify-content: space-between;
  267. align-items: center;
  268. margin-bottom: 15rpx;
  269. .activity-points {
  270. display: flex;
  271. align-items: center;
  272. .points-symbol {
  273. font-size: 24rpx;
  274. margin-right: 5rpx;
  275. }
  276. .points-value {
  277. font-size: 26rpx;
  278. color: #FF6B8A;
  279. font-weight: bold;
  280. }
  281. }
  282. .activity-participants {
  283. font-size: 22rpx;
  284. color: #999999;
  285. }
  286. }
  287. .activity-btn {
  288. width: 100%;
  289. height: 60rpx;
  290. display: flex;
  291. align-items: center;
  292. justify-content: center;
  293. background-color: #9C27B0;
  294. color: #FFFFFF;
  295. border-radius: 30rpx;
  296. font-size: 26rpx;
  297. }
  298. }
  299. }
  300. }
  301. /* 加载更多 */
  302. .load-more,
  303. .no-more {
  304. padding: 30rpx 0;
  305. text-align: center;
  306. .load-text,
  307. .no-more-text {
  308. font-size: 24rpx;
  309. color: #999999;
  310. }
  311. }
  312. </style>