activity-detail.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. <template>
  2. <view class="activity-detail-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-cover">
  13. <image :src="activity.coverImage || activity.cover_image" class="cover-image" mode="aspectFill"></image>
  14. <view class="cover-mask">
  15. <view class="activity-tag" v-if="activity.isRecommended">⭐ 推荐活动</view>
  16. </view>
  17. </view>
  18. <!-- 活动信息 -->
  19. <view class="activity-content">
  20. <view class="activity-title">{{ activity.name }}</view>
  21. <view class="info-section">
  22. <view class="info-item">
  23. <text class="info-icon">⏰</text>
  24. <text class="info-label">活动时间:</text>
  25. <text class="info-value">{{ formatActivityTime(activity.startTime || activity.start_time, activity.endTime || activity.end_time) }}</text>
  26. </view>
  27. <view class="info-item">
  28. <text class="info-icon">📍</text>
  29. <text class="info-label">活动地点:</text>
  30. <text class="info-value">{{ activity.location || '待定' }}</text>
  31. </view>
  32. <view class="info-item">
  33. <text class="info-icon">👥</text>
  34. <text class="info-label">报名人数:</text>
  35. <text class="info-value">{{ activity.participants || 0 }} / {{ activity.capacity || '不限' }}</text>
  36. </view>
  37. <view class="info-item">
  38. <text class="info-icon">💎</text>
  39. <text class="info-label">所需积分:</text>
  40. <text class="info-value points">{{ activity.points || 0 }}</text>
  41. </view>
  42. </view>
  43. <view class="divider"></view>
  44. <view class="description-section">
  45. <view class="section-title">活动介绍</view>
  46. <view class="description-text">{{ activity.description || '暂无介绍' }}</view>
  47. </view>
  48. <view class="divider"></view>
  49. <view class="content-section" v-if="activity.content">
  50. <view class="section-title">活动详情</view>
  51. <view class="content-text">{{ activity.content }}</view>
  52. </view>
  53. </view>
  54. <!-- 底部兑换按钮 -->
  55. <view class="bottom-bar" v-if="!hasExchanged">
  56. <view class="points-info">
  57. <text class="points-label">所需积分</text>
  58. <view class="points-value">
  59. <text class="points-symbol">💎</text>
  60. <text class="points-num">{{ activity.points || 0 }}</text>
  61. </view>
  62. </view>
  63. <view class="exchange-btn"
  64. :class="{ 'btn-disabled': currentPoints < (activity.points || 0) }"
  65. @click="handleExchange">
  66. <text class="btn-text">{{ currentPoints < (activity.points || 0) ? '积分不足' : '积分兑换报名' }}</text>
  67. </view>
  68. </view>
  69. <!-- 已报名状态 -->
  70. <view class="bottom-bar" v-else>
  71. <view class="registered-status">
  72. <text class="status-icon">✓</text>
  73. <text class="status-text">已报名</text>
  74. </view>
  75. </view>
  76. </view>
  77. </template>
  78. <script>
  79. import api from '../../utils/api.js'
  80. export default {
  81. data() {
  82. return {
  83. activityId: null,
  84. activity: {
  85. name: '加载中...',
  86. coverImage: 'https://images.unsplash.com/photo-1511671782779-c97d3d27a1d4?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60',
  87. points: 0
  88. },
  89. currentPoints: 0,
  90. makerId: null,
  91. hasExchanged: false
  92. }
  93. },
  94. onLoad(options) {
  95. if (options.id) {
  96. this.activityId = options.id
  97. this.initData()
  98. }
  99. },
  100. methods: {
  101. // 初始化数据
  102. async initData() {
  103. const userInfo = uni.getStorageSync('userInfo')
  104. // 兼容多种字段名
  105. this.makerId = userInfo && (userInfo.matchmakerId || userInfo.makerId || userInfo.matchmaker_id)
  106. // 如果没有makerId,尝试通过userId获取
  107. if (!this.makerId && userInfo && userInfo.userId) {
  108. try {
  109. const res = await api.matchmaker.getByUserId(userInfo.userId)
  110. let matchmaker = res
  111. if (res && res.data) {
  112. matchmaker = res.data
  113. }
  114. if (matchmaker) {
  115. this.makerId = matchmaker.matchmakerId || matchmaker.matchmaker_id
  116. }
  117. } catch (e) {
  118. console.error('获取红娘信息失败:', e)
  119. }
  120. }
  121. await this.loadMakerInfo()
  122. await this.loadActivityDetail()
  123. await this.checkExchangeStatus()
  124. },
  125. // 加载红娘信息(包括积分)
  126. async loadMakerInfo() {
  127. try {
  128. const res = await api.matchmaker.getDetail(this.makerId)
  129. console.log('红娘信息返回:', res)
  130. // 兼容不同的返回格式
  131. let makerInfo = res
  132. if (res && res.data) {
  133. makerInfo = res.data
  134. }
  135. if (makerInfo) {
  136. // 兼容 snake_case 和 camelCase
  137. this.currentPoints = makerInfo.points ?? makerInfo.total_points ?? 0
  138. console.log('当前积分:', this.currentPoints)
  139. }
  140. } catch (error) {
  141. console.error('加载红娘信息失败:', error)
  142. this.currentPoints = 0
  143. }
  144. },
  145. // 加载活动详情
  146. async loadActivityDetail() {
  147. try {
  148. const data = await api.matchmakerActivity.getDetail(this.activityId)
  149. if (data) {
  150. this.activity = data
  151. }
  152. } catch (error) {
  153. console.error('加载活动详情失败:', error)
  154. uni.showToast({
  155. title: '加载失败',
  156. icon: 'none'
  157. })
  158. }
  159. },
  160. // 检查是否已兑换
  161. async checkExchangeStatus() {
  162. try {
  163. console.log('检查兑换状态, makerId:', this.makerId, 'activityId:', this.activityId)
  164. const res = await api.matchmakerActivity.getPurchasedList(this.makerId)
  165. console.log('已兑换活动列表返回:', res)
  166. // 兼容不同的返回格式
  167. let list = res
  168. if (res && res.data) {
  169. list = res.data
  170. }
  171. if (Array.isArray(list) && list.length > 0) {
  172. this.hasExchanged = list.some(item => {
  173. const itemActivityId = item.activity_id || item.activityId
  174. console.log('比较活动ID:', itemActivityId, '==', this.activityId)
  175. return itemActivityId == this.activityId
  176. })
  177. }
  178. console.log('是否已兑换:', this.hasExchanged)
  179. } catch (error) {
  180. console.error('检查兑换状态失败:', error)
  181. this.hasExchanged = false
  182. }
  183. },
  184. // 格式化活动时间
  185. formatActivityTime(startTime, endTime) {
  186. if (!startTime) return '待定'
  187. const start = new Date(startTime)
  188. const end = endTime ? new Date(endTime) : null
  189. const startStr = start.toLocaleDateString('zh-CN') + ' ' +
  190. start.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' })
  191. if (end) {
  192. // 判断是否同一天
  193. const isSameDay = start.toDateString() === end.toDateString()
  194. let endStr
  195. if (isSameDay) {
  196. // 同一天只显示时间
  197. endStr = end.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' })
  198. } else {
  199. // 不同天显示完整日期时间
  200. endStr = end.toLocaleDateString('zh-CN') + ' ' +
  201. end.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' })
  202. }
  203. return `${startStr} - ${endStr}`
  204. }
  205. return startStr
  206. },
  207. // 处理兑换
  208. async handleExchange() {
  209. if (this.currentPoints < (this.activity.points || 0)) {
  210. uni.showToast({
  211. title: '积分不足',
  212. icon: 'none'
  213. })
  214. return
  215. }
  216. uni.showModal({
  217. title: '确认兑换',
  218. content: `是否用 ${this.activity.points} 积分兑换"${this.activity.name}"活动?`,
  219. confirmText: '确认',
  220. cancelText: '取消',
  221. success: (res) => {
  222. if (res.confirm) {
  223. this.exchangeActivity()
  224. }
  225. }
  226. })
  227. },
  228. // 兑换活动
  229. async exchangeActivity() {
  230. try {
  231. const result = await api.matchmakerActivity.exchange({
  232. makerId: this.makerId,
  233. activityId: this.activityId,
  234. points: this.activity.points
  235. })
  236. if (result) {
  237. uni.showToast({
  238. title: '兑换成功',
  239. icon: 'success'
  240. })
  241. this.currentPoints -= this.activity.points
  242. this.hasExchanged = true
  243. // 更新参与人数
  244. if (this.activity.participants) {
  245. this.activity.participants++
  246. } else {
  247. this.activity.participants = 1
  248. }
  249. }
  250. } catch (error) {
  251. console.error('兑换失败:', error)
  252. uni.showToast({
  253. title: error.message || '兑换失败',
  254. icon: 'none'
  255. })
  256. }
  257. },
  258. // 返回
  259. goBack() {
  260. uni.navigateBack()
  261. }
  262. }
  263. }
  264. </script>
  265. <style lang="scss" scoped>
  266. .activity-detail-page {
  267. min-height: 100vh;
  268. background-color: #FFF9F9;
  269. padding-top: 90rpx;
  270. padding-bottom: 120rpx;
  271. }
  272. /* 自定义导航栏 */
  273. .custom-navbar {
  274. position: fixed;
  275. top: 0;
  276. left: 0;
  277. right: 0;
  278. height: 90rpx;
  279. display: flex;
  280. align-items: center;
  281. justify-content: space-between;
  282. padding: 0 20rpx;
  283. background: linear-gradient(135deg, #FCE4EC 0%, #F8BBD0 100%);
  284. z-index: 999;
  285. .navbar-left,
  286. .navbar-right {
  287. width: 80rpx;
  288. }
  289. .back-icon {
  290. font-size: 40rpx;
  291. color: #333333;
  292. font-weight: bold;
  293. }
  294. .navbar-title {
  295. flex: 1;
  296. text-align: center;
  297. font-size: 32rpx;
  298. font-weight: bold;
  299. color: #333333;
  300. }
  301. }
  302. /* 活动封面 */
  303. .activity-cover {
  304. position: relative;
  305. width: 100%;
  306. height: 400rpx;
  307. overflow: hidden;
  308. .cover-image {
  309. width: 100%;
  310. height: 100%;
  311. background-color: #F5F5F5;
  312. }
  313. .cover-mask {
  314. position: absolute;
  315. top: 0;
  316. left: 0;
  317. right: 0;
  318. bottom: 0;
  319. display: flex;
  320. align-items: flex-start;
  321. justify-content: flex-start;
  322. padding: 20rpx;
  323. background: linear-gradient(180deg, rgba(0, 0, 0, 0.3) 0%, transparent 100%);
  324. .activity-tag {
  325. background-color: rgba(255, 215, 0, 0.9);
  326. color: #333333;
  327. padding: 8rpx 16rpx;
  328. border-radius: 20rpx;
  329. font-size: 24rpx;
  330. font-weight: bold;
  331. }
  332. }
  333. }
  334. /* 活动内容 */
  335. .activity-content {
  336. padding: 30rpx 20rpx;
  337. .activity-title {
  338. font-size: 36rpx;
  339. font-weight: bold;
  340. color: #333333;
  341. margin-bottom: 30rpx;
  342. }
  343. .info-section {
  344. background-color: #FFFFFF;
  345. border-radius: 12rpx;
  346. padding: 20rpx;
  347. margin-bottom: 20rpx;
  348. .info-item {
  349. display: flex;
  350. align-items: flex-start;
  351. margin-bottom: 16rpx;
  352. &:last-child {
  353. margin-bottom: 0;
  354. }
  355. .info-icon {
  356. font-size: 28rpx;
  357. margin-right: 12rpx;
  358. flex-shrink: 0;
  359. }
  360. .info-label {
  361. font-size: 26rpx;
  362. color: #666666;
  363. min-width: 120rpx;
  364. }
  365. .info-value {
  366. font-size: 26rpx;
  367. color: #333333;
  368. flex: 1;
  369. &.points {
  370. color: #FF6B8A;
  371. font-weight: bold;
  372. }
  373. }
  374. }
  375. }
  376. .divider {
  377. height: 1rpx;
  378. background-color: #EEEEEE;
  379. margin: 20rpx 0;
  380. }
  381. .description-section,
  382. .content-section {
  383. background-color: #FFFFFF;
  384. border-radius: 12rpx;
  385. padding: 20rpx;
  386. margin-bottom: 20rpx;
  387. .section-title {
  388. font-size: 28rpx;
  389. font-weight: bold;
  390. color: #333333;
  391. margin-bottom: 16rpx;
  392. }
  393. .description-text,
  394. .content-text {
  395. font-size: 26rpx;
  396. color: #666666;
  397. line-height: 1.6;
  398. white-space: pre-wrap;
  399. word-break: break-word;
  400. }
  401. }
  402. }
  403. /* 底部栏 */
  404. .bottom-bar {
  405. position: fixed;
  406. bottom: 0;
  407. left: 0;
  408. right: 0;
  409. height: 120rpx;
  410. display: flex;
  411. align-items: center;
  412. justify-content: space-between;
  413. padding: 20rpx;
  414. background-color: #FFFFFF;
  415. border-top: 1rpx solid #EEEEEE;
  416. z-index: 100;
  417. .points-info {
  418. display: flex;
  419. flex-direction: column;
  420. align-items: flex-start;
  421. .points-label {
  422. font-size: 24rpx;
  423. color: #999999;
  424. margin-bottom: 8rpx;
  425. }
  426. .points-value {
  427. display: flex;
  428. align-items: center;
  429. gap: 8rpx;
  430. .points-symbol {
  431. font-size: 28rpx;
  432. }
  433. .points-num {
  434. font-size: 32rpx;
  435. color: #FF6B8A;
  436. font-weight: bold;
  437. }
  438. }
  439. }
  440. .exchange-btn {
  441. flex: 1;
  442. height: 80rpx;
  443. display: flex;
  444. align-items: center;
  445. justify-content: center;
  446. background: linear-gradient(135deg, #9C27B0 0%, #7B1FA2 100%);
  447. color: #FFFFFF;
  448. border-radius: 40rpx;
  449. font-size: 28rpx;
  450. font-weight: bold;
  451. margin-left: 20rpx;
  452. transition: all 0.3s ease;
  453. &:active {
  454. transform: scale(0.95);
  455. }
  456. &.btn-disabled {
  457. background: #CCCCCC;
  458. color: #999999;
  459. }
  460. .btn-text {
  461. color: inherit;
  462. }
  463. }
  464. .registered-status {
  465. flex: 1;
  466. height: 80rpx;
  467. display: flex;
  468. align-items: center;
  469. justify-content: center;
  470. background-color: #E8F5E9;
  471. border-radius: 40rpx;
  472. margin-left: 20rpx;
  473. .status-icon {
  474. font-size: 40rpx;
  475. color: #4CAF50;
  476. margin-right: 12rpx;
  477. }
  478. .status-text {
  479. font-size: 28rpx;
  480. color: #4CAF50;
  481. font-weight: bold;
  482. }
  483. }
  484. }
  485. </style>