activity-detail.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  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. }
  119. }
  120. await this.loadMakerInfo()
  121. await this.loadActivityDetail()
  122. await this.checkExchangeStatus()
  123. },
  124. // 加载红娘信息(包括积分)
  125. async loadMakerInfo() {
  126. try {
  127. const res = await api.matchmaker.getDetail(this.makerId)
  128. // 兼容不同的返回格式
  129. let makerInfo = res
  130. if (res && res.data) {
  131. makerInfo = res.data
  132. }
  133. if (makerInfo) {
  134. // 兼容 snake_case 和 camelCase
  135. this.currentPoints = makerInfo.points ?? makerInfo.total_points ?? 0
  136. }
  137. } catch (error) {
  138. this.currentPoints = 0
  139. }
  140. },
  141. // 加载活动详情
  142. async loadActivityDetail() {
  143. try {
  144. const data = await api.matchmakerActivity.getDetail(this.activityId)
  145. if (data) {
  146. this.activity = data
  147. }
  148. } catch (error) {
  149. uni.showToast({
  150. title: '加载失败',
  151. icon: 'none'
  152. })
  153. }
  154. },
  155. // 检查是否已兑换
  156. async checkExchangeStatus() {
  157. try {
  158. const res = await api.matchmakerActivity.getPurchasedList(this.makerId)
  159. let list = res
  160. if (res && res.data) {
  161. list = res.data
  162. }
  163. if (Array.isArray(list) && list.length > 0) {
  164. this.hasExchanged = list.some(item => {
  165. const itemActivityId = item.activity_id || item.activityId
  166. return itemActivityId == this.activityId
  167. })
  168. }
  169. } catch (error) {
  170. this.hasExchanged = false
  171. }
  172. },
  173. // 格式化活动时间
  174. formatActivityTime(startTime, endTime) {
  175. if (!startTime) return '待定'
  176. const start = new Date(startTime)
  177. const end = endTime ? new Date(endTime) : null
  178. const startStr = start.toLocaleDateString('zh-CN') + ' ' +
  179. start.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' })
  180. if (end) {
  181. // 判断是否同一天
  182. const isSameDay = start.toDateString() === end.toDateString()
  183. let endStr
  184. if (isSameDay) {
  185. // 同一天只显示时间
  186. endStr = end.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' })
  187. } else {
  188. // 不同天显示完整日期时间
  189. endStr = end.toLocaleDateString('zh-CN') + ' ' +
  190. end.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' })
  191. }
  192. return `${startStr} - ${endStr}`
  193. }
  194. return startStr
  195. },
  196. // 处理兑换
  197. async handleExchange() {
  198. if (this.currentPoints < (this.activity.points || 0)) {
  199. uni.showToast({
  200. title: '积分不足',
  201. icon: 'none'
  202. })
  203. return
  204. }
  205. uni.showModal({
  206. title: '确认兑换',
  207. content: `是否用 ${this.activity.points} 积分兑换"${this.activity.name}"活动?`,
  208. confirmText: '确认',
  209. cancelText: '取消',
  210. success: (res) => {
  211. if (res.confirm) {
  212. this.exchangeActivity()
  213. }
  214. }
  215. })
  216. },
  217. // 兑换活动
  218. async exchangeActivity() {
  219. try {
  220. const result = await api.matchmakerActivity.exchange({
  221. makerId: this.makerId,
  222. activityId: this.activityId,
  223. points: this.activity.points
  224. })
  225. if (result) {
  226. uni.showToast({
  227. title: '兑换成功',
  228. icon: 'success'
  229. })
  230. this.currentPoints -= this.activity.points
  231. this.hasExchanged = true
  232. // 更新参与人数
  233. if (this.activity.participants) {
  234. this.activity.participants++
  235. } else {
  236. this.activity.participants = 1
  237. }
  238. }
  239. } catch (error) {
  240. uni.showToast({
  241. title: error.message || '兑换失败',
  242. icon: 'none'
  243. })
  244. }
  245. },
  246. // 返回
  247. goBack() {
  248. uni.navigateBack()
  249. }
  250. }
  251. }
  252. </script>
  253. <style lang="scss" scoped>
  254. .activity-detail-page {
  255. min-height: 100vh;
  256. background-color: #FFF9F9;
  257. padding-top: 90rpx;
  258. padding-bottom: 120rpx;
  259. }
  260. /* 自定义导航栏 */
  261. .custom-navbar {
  262. position: fixed;
  263. top: 0;
  264. left: 0;
  265. right: 0;
  266. height: 90rpx;
  267. display: flex;
  268. align-items: center;
  269. justify-content: space-between;
  270. padding: 0 20rpx;
  271. background: linear-gradient(135deg, #FCE4EC 0%, #F8BBD0 100%);
  272. z-index: 999;
  273. .navbar-left,
  274. .navbar-right {
  275. width: 80rpx;
  276. }
  277. .back-icon {
  278. font-size: 40rpx;
  279. color: #333333;
  280. font-weight: bold;
  281. }
  282. .navbar-title {
  283. flex: 1;
  284. text-align: center;
  285. font-size: 32rpx;
  286. font-weight: bold;
  287. color: #333333;
  288. }
  289. }
  290. /* 活动封面 */
  291. .activity-cover {
  292. position: relative;
  293. width: 100%;
  294. height: 400rpx;
  295. overflow: hidden;
  296. .cover-image {
  297. width: 100%;
  298. height: 100%;
  299. background-color: #F5F5F5;
  300. }
  301. .cover-mask {
  302. position: absolute;
  303. top: 0;
  304. left: 0;
  305. right: 0;
  306. bottom: 0;
  307. display: flex;
  308. align-items: flex-start;
  309. justify-content: flex-start;
  310. padding: 20rpx;
  311. background: linear-gradient(180deg, rgba(0, 0, 0, 0.3) 0%, transparent 100%);
  312. .activity-tag {
  313. background-color: rgba(255, 215, 0, 0.9);
  314. color: #333333;
  315. padding: 8rpx 16rpx;
  316. border-radius: 20rpx;
  317. font-size: 24rpx;
  318. font-weight: bold;
  319. }
  320. }
  321. }
  322. /* 活动内容 */
  323. .activity-content {
  324. padding: 30rpx 20rpx;
  325. .activity-title {
  326. font-size: 36rpx;
  327. font-weight: bold;
  328. color: #333333;
  329. margin-bottom: 30rpx;
  330. }
  331. .info-section {
  332. background-color: #FFFFFF;
  333. border-radius: 12rpx;
  334. padding: 20rpx;
  335. margin-bottom: 20rpx;
  336. .info-item {
  337. display: flex;
  338. align-items: flex-start;
  339. margin-bottom: 16rpx;
  340. &:last-child {
  341. margin-bottom: 0;
  342. }
  343. .info-icon {
  344. font-size: 28rpx;
  345. margin-right: 12rpx;
  346. flex-shrink: 0;
  347. }
  348. .info-label {
  349. font-size: 26rpx;
  350. color: #666666;
  351. min-width: 120rpx;
  352. }
  353. .info-value {
  354. font-size: 26rpx;
  355. color: #333333;
  356. flex: 1;
  357. &.points {
  358. color: #FF6B8A;
  359. font-weight: bold;
  360. }
  361. }
  362. }
  363. }
  364. .divider {
  365. height: 1rpx;
  366. background-color: #EEEEEE;
  367. margin: 20rpx 0;
  368. }
  369. .description-section,
  370. .content-section {
  371. background-color: #FFFFFF;
  372. border-radius: 12rpx;
  373. padding: 20rpx;
  374. margin-bottom: 20rpx;
  375. .section-title {
  376. font-size: 28rpx;
  377. font-weight: bold;
  378. color: #333333;
  379. margin-bottom: 16rpx;
  380. }
  381. .description-text,
  382. .content-text {
  383. font-size: 26rpx;
  384. color: #666666;
  385. line-height: 1.6;
  386. white-space: pre-wrap;
  387. word-break: break-word;
  388. }
  389. }
  390. }
  391. /* 底部栏 */
  392. .bottom-bar {
  393. position: fixed;
  394. bottom: 0;
  395. left: 0;
  396. right: 0;
  397. height: 120rpx;
  398. display: flex;
  399. align-items: center;
  400. justify-content: space-between;
  401. padding: 20rpx;
  402. background-color: #FFFFFF;
  403. border-top: 1rpx solid #EEEEEE;
  404. z-index: 100;
  405. .points-info {
  406. display: flex;
  407. flex-direction: column;
  408. align-items: flex-start;
  409. .points-label {
  410. font-size: 24rpx;
  411. color: #999999;
  412. margin-bottom: 8rpx;
  413. }
  414. .points-value {
  415. display: flex;
  416. align-items: center;
  417. gap: 8rpx;
  418. .points-symbol {
  419. font-size: 28rpx;
  420. }
  421. .points-num {
  422. font-size: 32rpx;
  423. color: #FF6B8A;
  424. font-weight: bold;
  425. }
  426. }
  427. }
  428. .exchange-btn {
  429. flex: 1;
  430. height: 80rpx;
  431. display: flex;
  432. align-items: center;
  433. justify-content: center;
  434. background: linear-gradient(135deg, #9C27B0 0%, #7B1FA2 100%);
  435. color: #FFFFFF;
  436. border-radius: 40rpx;
  437. font-size: 28rpx;
  438. font-weight: bold;
  439. margin-left: 20rpx;
  440. transition: all 0.3s ease;
  441. &:active {
  442. transform: scale(0.95);
  443. }
  444. &.btn-disabled {
  445. background: #CCCCCC;
  446. color: #999999;
  447. }
  448. .btn-text {
  449. color: inherit;
  450. }
  451. }
  452. .registered-status {
  453. flex: 1;
  454. height: 80rpx;
  455. display: flex;
  456. align-items: center;
  457. justify-content: center;
  458. background-color: #E8F5E9;
  459. border-radius: 40rpx;
  460. margin-left: 20rpx;
  461. .status-icon {
  462. font-size: 40rpx;
  463. color: #4CAF50;
  464. margin-right: 12rpx;
  465. }
  466. .status-text {
  467. font-size: 28rpx;
  468. color: #4CAF50;
  469. font-weight: bold;
  470. }
  471. }
  472. }
  473. </style>