activities.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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">
  10. <view class="points-display">
  11. <text class="points-label">积分</text>
  12. <text class="points-value">{{ currentPoints }}</text>
  13. </view>
  14. </view>
  15. </view>
  16. <!-- 顶部公告 -->
  17. <view class="announcement-bar">
  18. <text class="announcement-icon">📢</text>
  19. <text class="announcement-content">红娘活动报名开始啦!用积分兑换活动名额,积分兑好礼!</text>
  20. </view>
  21. <!-- 活动分类标签 - 横向滚动 -->
  22. <scroll-view scroll-x class="category-scroll" show-scrollbar="false">
  23. <view class="category-list">
  24. <view
  25. v-for="(tab, index) in tabs"
  26. :key="index"
  27. class="category-item"
  28. :class="{ active: activeTab === tab.type }"
  29. @click="switchTab(tab.type)"
  30. >
  31. {{ tab.name }}
  32. </view>
  33. </view>
  34. </scroll-view>
  35. <!-- 活动列表 -->
  36. <view class="activity-grid">
  37. <view class="activity-card" v-for="(item, index) in activityList" :key="index" @click="goToDetail(item)">
  38. <image :src="item.coverImage || item.cover_image" class="activity-image" mode="aspectFill"></image>
  39. <view class="activity-info">
  40. <view class="activity-name">{{ item.name }}</view>
  41. <view class="activity-meta">
  42. <text class="activity-location">📍 {{ item.location }}</text>
  43. </view>
  44. <view class="activity-footer">
  45. <view class="activity-points">
  46. <text class="points-symbol">💎</text>
  47. <text class="points-value">{{ item.points }}</text>
  48. </view>
  49. <text class="activity-participants">{{ item.participants || 0 }}人参加</text>
  50. </view>
  51. <view class="activity-btn"
  52. :class="{ 'btn-disabled': hasExchanged(item.id) }"
  53. @click.stop="handleActivityAction(item)">
  54. {{ hasExchanged(item.id) ? '已报名' : '积分兑换' }}
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. <!-- 空状态 -->
  60. <view class="empty-state" v-if="activityList.length === 0 && !loading">
  61. <image src="https://img.icons8.com/color/96/000000/calendar--v1.png" class="empty-icon"></image>
  62. <text class="empty-text">暂无活动</text>
  63. <text class="empty-subtext">敬请期待更多精彩活动</text>
  64. </view>
  65. <!-- 加载更多 -->
  66. <view class="load-more" v-if="hasMore && activityList.length > 0">
  67. <text class="load-text">{{ loading ? '加载中...' : '上拉加载更多' }}</text>
  68. </view>
  69. <view class="no-more" v-else-if="activityList.length > 0">
  70. <text class="no-more-text">没有更多了</text>
  71. </view>
  72. </view>
  73. </template>
  74. <script>
  75. import api from '../../utils/api.js'
  76. export default {
  77. data() {
  78. return {
  79. activityList: [],
  80. pageNum: 1,
  81. pageSize: 10,
  82. hasMore: true,
  83. loading: false,
  84. currentPoints: 0,
  85. makerId: null,
  86. exchangedActivities: [],
  87. tabs: [
  88. { name: '全部活动', type: 'all' },
  89. { name: '推荐活动', type: 'premium' }
  90. ],
  91. activeTab: 'all'
  92. }
  93. },
  94. onLoad() {
  95. this.initData()
  96. },
  97. onReachBottom() {
  98. if (this.hasMore && !this.loading) {
  99. this.pageNum++
  100. this.loadActivityList()
  101. }
  102. },
  103. methods: {
  104. // 初始化数据
  105. async initData() {
  106. const userInfo = uni.getStorageSync('userInfo')
  107. // 兼容多种字段名
  108. this.makerId = userInfo && (userInfo.matchmakerId || userInfo.makerId || userInfo.matchmaker_id)
  109. // 如果没有makerId,尝试通过userId获取
  110. if (!this.makerId && userInfo && userInfo.userId) {
  111. try {
  112. const res = await api.matchmaker.getByUserId(userInfo.userId)
  113. let matchmaker = res
  114. if (res && res.data) {
  115. matchmaker = res.data
  116. }
  117. if (matchmaker) {
  118. this.makerId = matchmaker.matchmakerId || matchmaker.matchmaker_id
  119. }
  120. } catch (e) {
  121. }
  122. }
  123. if (!this.makerId) {
  124. uni.showToast({
  125. title: '请先登录红娘账号',
  126. icon: 'none'
  127. })
  128. return
  129. }
  130. await this.loadMakerInfo()
  131. await this.loadExchangedActivities()
  132. await this.loadActivityList()
  133. },
  134. // 加载红娘信息(包括积分)
  135. async loadMakerInfo() {
  136. try {
  137. const res = await api.matchmaker.getDetail(this.makerId)
  138. // 兼容不同的返回格式
  139. const makerInfo = res && res.data ? res.data : res
  140. if (makerInfo) {
  141. this.currentPoints = makerInfo.points || makerInfo.point || 0
  142. }
  143. } catch (error) {
  144. this.currentPoints = 0
  145. }
  146. },
  147. // 加载已兑换的活动列表
  148. async loadExchangedActivities() {
  149. try {
  150. const list = await api.matchmakerActivity.getPurchasedList(this.makerId)
  151. if (list && list.length > 0) {
  152. this.exchangedActivities = list.map(item => item.activity_id || item.activityId)
  153. }
  154. } catch (error) {
  155. this.exchangedActivities = []
  156. }
  157. },
  158. // 加载活动列表
  159. async loadActivityList() {
  160. if (this.loading) return
  161. this.loading = true
  162. try {
  163. const params = {
  164. categoryType: this.activeTab
  165. }
  166. const data = await api.matchmakerActivity.getList(params)
  167. if (data && data.length > 0) {
  168. this.activityList = [...this.activityList, ...data]
  169. this.hasMore = data.length >= this.pageSize
  170. } else {
  171. this.hasMore = false
  172. }
  173. } catch (error) {
  174. this.hasMore = false
  175. } finally {
  176. this.loading = false
  177. }
  178. },
  179. // 切换分类标签
  180. switchTab(type) {
  181. if (this.activeTab === type) return
  182. this.activeTab = type
  183. this.pageNum = 1
  184. this.activityList = []
  185. this.loadActivityList()
  186. },
  187. // 检查是否已兑换
  188. hasExchanged(activityId) {
  189. return this.exchangedActivities.includes(activityId)
  190. },
  191. // 处理活动操作(兑换或查看详情)
  192. async handleActivityAction(item) {
  193. if (this.hasExchanged(item.id)) {
  194. // 已兑换,跳转到详情页
  195. uni.navigateTo({
  196. url: `/pages/matchmaker-workbench/activity-detail?id=${item.id}`
  197. })
  198. } else {
  199. // 未兑换,显示兑换确认
  200. uni.showModal({
  201. title: '确认兑换',
  202. content: `是否用 ${item.points} 积分兑换"${item.name}"活动?`,
  203. confirmText: '确认',
  204. cancelText: '取消',
  205. success: (res) => {
  206. if (res.confirm) {
  207. this.exchangeActivity(item)
  208. }
  209. }
  210. })
  211. }
  212. },
  213. // 兑换活动
  214. async exchangeActivity(item) {
  215. const pointsNeeded = item.points || 0
  216. if (this.currentPoints < pointsNeeded) {
  217. uni.showToast({
  218. title: '积分不足',
  219. icon: 'none'
  220. })
  221. return
  222. }
  223. try {
  224. const result = await api.matchmakerActivity.exchange({
  225. makerId: this.makerId,
  226. activityId: item.id,
  227. points: pointsNeeded
  228. })
  229. // API请求成功(request函数已处理code=200的情况,能走到这里说明已成功)
  230. uni.showToast({
  231. title: '兑换成功',
  232. icon: 'success'
  233. })
  234. this.currentPoints -= pointsNeeded
  235. this.exchangedActivities.push(item.id)
  236. // 跳转到详情页
  237. setTimeout(() => {
  238. uni.navigateTo({
  239. url: `/pages/matchmaker-workbench/activity-detail?id=${item.id}`
  240. })
  241. }, 500)
  242. } catch (error) {
  243. uni.showToast({
  244. title: error.message || '兑换失败',
  245. icon: 'none'
  246. })
  247. }
  248. },
  249. // 跳转到活动详情
  250. goToDetail(item) {
  251. uni.navigateTo({
  252. url: `/pages/matchmaker-workbench/activity-detail?id=${item.id}`
  253. })
  254. },
  255. // 返回
  256. goBack() {
  257. uni.navigateBack()
  258. }
  259. }
  260. }
  261. </script>
  262. <style lang="scss" scoped>
  263. .activities-page {
  264. min-height: 100vh;
  265. background-color: #FFF9F9;
  266. padding-top: 90rpx;
  267. }
  268. /* 自定义导航栏 */
  269. .custom-navbar {
  270. position: fixed;
  271. top: 0;
  272. left: 0;
  273. right: 0;
  274. height: 90rpx;
  275. display: flex;
  276. align-items: center;
  277. justify-content: space-between;
  278. padding: 0 20rpx;
  279. background: linear-gradient(135deg, #FCE4EC 0%, #F8BBD0 100%);
  280. z-index: 999;
  281. .navbar-left,
  282. .navbar-right {
  283. width: 80rpx;
  284. }
  285. .back-icon {
  286. font-size: 40rpx;
  287. color: #333333;
  288. font-weight: bold;
  289. }
  290. .navbar-title {
  291. flex: 1;
  292. text-align: center;
  293. font-size: 32rpx;
  294. font-weight: bold;
  295. color: #333333;
  296. }
  297. .points-display {
  298. display: flex;
  299. align-items: center;
  300. gap: 8rpx;
  301. background-color: rgba(255, 255, 255, 0.8);
  302. padding: 8rpx 16rpx;
  303. border-radius: 20rpx;
  304. .points-label {
  305. font-size: 24rpx;
  306. color: #666666;
  307. }
  308. .points-value {
  309. font-size: 28rpx;
  310. color: #FF6B8A;
  311. font-weight: bold;
  312. }
  313. }
  314. }
  315. /* 公告栏 */
  316. .announcement-bar {
  317. display: flex;
  318. align-items: center;
  319. gap: 12rpx;
  320. padding: 16rpx 20rpx;
  321. background-color: #FFF3E0;
  322. margin: 10rpx 0;
  323. .announcement-icon {
  324. font-size: 28rpx;
  325. flex-shrink: 0;
  326. }
  327. .announcement-content {
  328. font-size: 24rpx;
  329. color: #E65100;
  330. flex: 1;
  331. }
  332. }
  333. /* 分类标签 - 横向滚动 */
  334. .category-scroll {
  335. white-space: nowrap;
  336. padding: 0 20rpx;
  337. margin: 10rpx 0;
  338. }
  339. .category-list {
  340. display: flex;
  341. gap: 12rpx;
  342. }
  343. .category-item {
  344. display: inline-block;
  345. padding: 12rpx 24rpx;
  346. background-color: #FFFFFF;
  347. border-radius: 30rpx;
  348. font-size: 26rpx;
  349. color: #666666;
  350. border: 2rpx solid #EEEEEE;
  351. transition: all 0.3s ease;
  352. &.active {
  353. background-color: #9C27B0;
  354. color: #FFFFFF;
  355. border-color: #9C27B0;
  356. }
  357. }
  358. /* 活动列表 - 两列布局 */
  359. .activity-grid {
  360. display: grid;
  361. grid-template-columns: 1fr 1fr;
  362. gap: 20rpx;
  363. padding: 20rpx;
  364. .activity-card {
  365. position: relative;
  366. background-color: #FFFFFF;
  367. border-radius: 20rpx;
  368. overflow: hidden;
  369. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  370. .activity-image {
  371. width: 100%;
  372. height: 240rpx;
  373. background-color: #F5F5F5;
  374. }
  375. .activity-info {
  376. padding: 20rpx;
  377. .activity-name {
  378. font-size: 28rpx;
  379. font-weight: bold;
  380. color: #333333;
  381. margin-bottom: 10rpx;
  382. display: -webkit-box;
  383. -webkit-box-orient: vertical;
  384. -webkit-line-clamp: 2;
  385. overflow: hidden;
  386. }
  387. .activity-meta {
  388. margin-bottom: 15rpx;
  389. .activity-location {
  390. font-size: 24rpx;
  391. color: #666666;
  392. }
  393. }
  394. .activity-footer {
  395. display: flex;
  396. justify-content: space-between;
  397. align-items: center;
  398. margin-bottom: 15rpx;
  399. .activity-points {
  400. display: flex;
  401. align-items: center;
  402. .points-symbol {
  403. font-size: 24rpx;
  404. margin-right: 5rpx;
  405. }
  406. .points-value {
  407. font-size: 26rpx;
  408. color: #FF6B8A;
  409. font-weight: bold;
  410. }
  411. }
  412. .activity-participants {
  413. font-size: 22rpx;
  414. color: #999999;
  415. }
  416. }
  417. .activity-btn {
  418. width: 100%;
  419. height: 60rpx;
  420. display: flex;
  421. align-items: center;
  422. justify-content: center;
  423. background-color: #9C27B0;
  424. color: #FFFFFF;
  425. border-radius: 30rpx;
  426. font-size: 26rpx;
  427. transition: all 0.3s ease;
  428. &:active {
  429. background-color: #7B1FA2;
  430. }
  431. &.btn-disabled {
  432. background-color: #CCCCCC;
  433. color: #999999;
  434. }
  435. }
  436. }
  437. }
  438. }
  439. /* 空状态 */
  440. .empty-state {
  441. display: flex;
  442. flex-direction: column;
  443. align-items: center;
  444. justify-content: center;
  445. padding: 100rpx 0;
  446. .empty-icon {
  447. width: 120rpx;
  448. height: 120rpx;
  449. opacity: 0.5;
  450. margin-bottom: 20rpx;
  451. }
  452. .empty-text {
  453. font-size: 32rpx;
  454. color: #666666;
  455. margin-bottom: 10rpx;
  456. }
  457. .empty-subtext {
  458. font-size: 26rpx;
  459. color: #999999;
  460. }
  461. }
  462. /* 加载更多 */
  463. .load-more,
  464. .no-more {
  465. padding: 30rpx 0;
  466. text-align: center;
  467. .load-text,
  468. .no-more-text {
  469. font-size: 24rpx;
  470. color: #999999;
  471. }
  472. }
  473. </style>