activity-detail.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. <template>
  2. <view class="container">
  3. <!-- 加载状态 -->
  4. <view v-if="loading" class="loading-wrap">
  5. <view class="loading-spinner"></view>
  6. <text class="loading-text">加载中...</text>
  7. </view>
  8. <!-- 错误状态 -->
  9. <view v-else-if="error" class="error-wrap">
  10. <text class="error-icon">📋</text>
  11. <text class="error-text">{{ errorMsg }}</text>
  12. <button class="retry-btn" @click="loadDetail(activityId)">重新加载</button>
  13. </view>
  14. <!-- 活动内容 -->
  15. <scroll-view v-else-if="activity.id" scroll-y class="content">
  16. <!-- 封面图 -->
  17. <image
  18. v-if="activity.coverImage"
  19. class="cover"
  20. :src="activity.coverImage"
  21. mode="widthFix"
  22. />
  23. <image v-else class="cover placeholder-cover" src="/static/default-activity.png" mode="aspectFill" />
  24. <view class="info-section">
  25. <text class="activity-title">{{ activity.title }}</text>
  26. <!-- 活动状态标签 -->
  27. <view class="status-row">
  28. <text class="status-tag" :class="'status-' + (activity.status || 'upcoming')">{{ statusText(activity.status) }}</text>
  29. </view>
  30. <!-- 活动元信息 -->
  31. <view class="meta-list">
  32. <view class="meta-item" v-if="activity.startTime">
  33. <text class="meta-icon">🕐</text>
  34. <text class="meta-text">{{ formatDate(activity.startTime) }}{{ activity.endTime ? ' ~ ' + formatDate(activity.endTime) : '' }}</text>
  35. </view>
  36. <view class="meta-item" v-if="activity.location">
  37. <text class="meta-icon">📍</text>
  38. <text class="meta-text">{{ activity.location }}</text>
  39. </view>
  40. <view class="meta-item" v-if="activity.maxParticipants">
  41. <text class="meta-icon">👥</text>
  42. <text class="meta-text">{{ activity.currentParticipants || 0 }} / {{ activity.maxParticipants }} 人</text>
  43. </view>
  44. <view class="meta-item">
  45. <text class="meta-icon">💰</text>
  46. <text class="meta-text">{{ activity.priceLabel || (activity.price > 0 ? '¥' + activity.price : '免费') }}</text>
  47. </view>
  48. </view>
  49. <!-- 活动简介 -->
  50. <view class="desc-section" v-if="activity.description">
  51. <text class="section-title">活动介绍</text>
  52. <text class="desc-text">{{ activity.description }}</text>
  53. </view>
  54. <!-- 付费不退费说明 -->
  55. <view class="refund-notice" v-if="activity.price > 0">
  56. <text class="refund-notice-icon">⚠️</text>
  57. <text class="refund-notice-text">本活动为付费活动,报名成功后不支持退费</text>
  58. </view>
  59. </view>
  60. <!-- 底部操作栏 -->
  61. <view class="bottom-bar">
  62. <view class="price-info">
  63. <text class="bottom-type">活动</text>
  64. <text class="bottom-vendor" v-if="activity.vendorName">{{ activity.vendorName }}</text>
  65. </view>
  66. <view class="action-btns">
  67. <!-- 报名按钮(仅 requireRegistration=1 时显示) -->
  68. <button
  69. v-if="activity.requireRegistration === 1 && !registrationStatus"
  70. class="btn-register"
  71. :class="{ 'btn-register-loading': registrationLoading || paying }"
  72. :disabled="registrationLoading || paying"
  73. @click="onRegister"
  74. >
  75. <text v-if="registrationLoading">报名中...</text>
  76. <text v-else-if="paying">支付中...</text>
  77. <text v-else-if="activity.price > 0">¥{{ activity.price }} 立即报名</text>
  78. <text v-else>立即报名</text>
  79. </button>
  80. <!-- 已报名待审核 -->
  81. <button
  82. v-if="activity.requireRegistration === 1 && registrationStatus === 'pending'"
  83. class="btn-register-done"
  84. disabled
  85. >
  86. <text>报名待审核</text>
  87. </button>
  88. <!-- 已报名可取消 -->
  89. <button
  90. v-if="activity.requireRegistration === 1 && registrationStatus === 'approved'"
  91. class="btn-cancel"
  92. :disabled="registrationLoading"
  93. @click="onCancelRegistration"
  94. >
  95. <text>取消报名</text>
  96. </button>
  97. <!-- 签到按钮 -->
  98. <button
  99. class="btn-checkin"
  100. :class="{ 'btn-checkin-done': checkinDone, 'btn-checkin-loading': checkinLoading }"
  101. :disabled="checkinLoading || checkinDone"
  102. @click="onCheckin"
  103. >
  104. <text v-if="checkinLoading">签到中...</text>
  105. <text v-else-if="checkinDone">已签到 ✓</text>
  106. <text v-else>签到</text>
  107. </button>
  108. </view>
  109. </view>
  110. <!-- 能量扣减提示弹窗 -->
  111. <modal v-if="showPenaltyModal" class="penalty-modal" :show="showPenaltyModal" @close="showPenaltyModal = false">
  112. <view class="penalty-content">
  113. <text class="penalty-title">签到成功但已扣能量</text>
  114. <text class="penalty-desc">您未报名参加此活动,已被扣除 {{ penaltyAmount }} 点能量值</text>
  115. <button class="penalty-btn" @click="showPenaltyModal = false">我知道了</button>
  116. </view>
  117. </modal>
  118. </scroll-view>
  119. <!-- 空状态 -->
  120. <view v-else class="empty-wrap">
  121. <text class="empty-text">活动不存在或已下架</text>
  122. </view>
  123. </view>
  124. </template>
  125. <script>
  126. import { getActivityDetail, activityCheckin, registerActivity, cancelActivityRegistration, getMyActivityRegistrations } from '@/utils/api.js'
  127. export default {
  128. data() {
  129. return {
  130. activityId: null,
  131. activity: {},
  132. loading: false,
  133. error: false,
  134. errorMsg: '',
  135. checkinLoading: false,
  136. checkinDone: false,
  137. checkinPoints: 0,
  138. registrationStatus: null,
  139. registrationLoading: false,
  140. paying: false,
  141. showPenaltyModal: false,
  142. penaltyAmount: 0
  143. }
  144. },
  145. onLoad: function(options) {
  146. if (options && options.id) {
  147. this.activityId = options.id
  148. this.loadDetail(options.id)
  149. } else {
  150. this.error = true
  151. this.errorMsg = '缺少活动ID'
  152. }
  153. // 检查是否已经签到(从路由参数获取)
  154. if (options && options.checkinDone === '1') {
  155. this.checkinDone = true
  156. }
  157. },
  158. methods: {
  159. // ===== 工具方法 =====
  160. formatDate: function(dateStr) {
  161. if (!dateStr) return ''
  162. var d = new Date(dateStr.replace(/-/g, '/'))
  163. if (isNaN(d.getTime())) return dateStr
  164. var year = d.getFullYear()
  165. var month = d.getMonth() + 1
  166. var day = d.getDate()
  167. var hour = d.getHours()
  168. var minute = d.getMinutes()
  169. var ampm = hour < 12 ? '上午' : '下午'
  170. var h12 = hour % 12
  171. if (h12 === 0) h12 = 12
  172. var minStr = minute < 10 ? '0' + minute : minute
  173. return year + '年' + month + '月' + day + '日 ' + ampm + h12 + ':' + minStr
  174. },
  175. loadDetail: function(id) {
  176. var self = this
  177. self.loading = true
  178. self.error = false
  179. getActivityDetail(id).then(function(res) {
  180. self.loading = false
  181. if (res && res.code === 200 && res.data) {
  182. self.activity = res.data
  183. // Load registration status if logged in and activity requires registration
  184. if (self.activity.requireRegistration === 1) {
  185. var childId = uni.getStorageSync('currentChildId')
  186. if (childId) {
  187. getMyActivityRegistrations({ childId: childId, page: 1, size: 50 }).then(function(regRes) {
  188. if (regRes && regRes.data && regRes.data.records) {
  189. var records = regRes.data.records
  190. for (var i = 0; i < records.length; i++) {
  191. if (records[i].activityId === self.activity.id) {
  192. self.registrationStatus = records[i].status
  193. break
  194. }
  195. }
  196. }
  197. }).catch(function() {})
  198. }
  199. }
  200. } else {
  201. self.error = true
  202. self.errorMsg = (res && res.message) || '加载失败'
  203. }
  204. }).catch(function(err) {
  205. self.loading = false
  206. self.error = true
  207. self.errorMsg = '网络异常,请稍后重试'
  208. })
  209. },
  210. statusText: function(status) {
  211. var map = { draft: '草稿', published: '进行中', ended: '已结束' }
  212. return map[status] || '未知'
  213. },
  214. onCheckin: function() {
  215. var self = this
  216. if (self.checkinLoading || self.checkinDone) return
  217. var childId = uni.getStorageSync('currentChildId')
  218. if (!childId) {
  219. uni.showToast({ title: '请选择孩子身份', icon: 'none' })
  220. return
  221. }
  222. self.checkinLoading = true
  223. activityCheckin({ id: self.activity.id, childId: childId }).then(function(res) {
  224. self.checkinLoading = false
  225. if (res && res.code === 200 && res.data) {
  226. // 检查是否有能量扣减
  227. if (res.data.energyPenalty) {
  228. self.penaltyAmount = res.data.energyPenalty
  229. self.showPenaltyModal = true
  230. self.checkinDone = true
  231. return
  232. }
  233. if (res.data.alreadyCompleted) {
  234. self.checkinDone = true
  235. uni.showToast({ title: '已签到', icon: 'success' })
  236. } else if (res.data.pointsEarned && res.data.pointsEarned > 0) {
  237. self.checkinDone = true
  238. self.checkinPoints = res.data.pointsEarned
  239. uni.showToast({ title: '签到成功 +' + res.data.pointsEarned + '积分', icon: 'success' })
  240. } else {
  241. self.checkinDone = true
  242. uni.showToast({ title: '签到成功', icon: 'success' })
  243. }
  244. } else {
  245. var msg = (res && res.message) || '签到失败'
  246. // 如果是报名待审核,提示用户
  247. if (msg.indexOf('报名') !== -1 || msg.indexOf('审核') !== -1) {
  248. uni.showModal({ title: '提示', content: msg, showCancel: false })
  249. } else {
  250. uni.showToast({ title: msg, icon: 'none' })
  251. }
  252. }
  253. }).catch(function(err) {
  254. self.checkinLoading = false
  255. uni.showToast({ title: '网络异常', icon: 'none' })
  256. })
  257. },
  258. onRegister: function() {
  259. var self = this
  260. var childId = uni.getStorageSync('currentChildId')
  261. if (!childId) {
  262. uni.showToast({ title: '请先选择孩子身份', icon: 'none' })
  263. return
  264. }
  265. // 付费活动 → 先确认支付
  266. if (self.activity && self.activity.price > 0) {
  267. uni.showModal({
  268. title: '确认报名',
  269. content: '该活动需支付 ¥' + self.activity.price + ',报名成功后不支持退费。是否继续?',
  270. confirmText: '确认支付',
  271. cancelText: '再想想',
  272. success: function(confirmRes) {
  273. if (confirmRes.confirm) {
  274. self.doRegister(childId)
  275. }
  276. }
  277. })
  278. } else {
  279. self.doRegister(childId)
  280. }
  281. },
  282. doRegister: function(childId) {
  283. var self = this
  284. self.registrationLoading = true
  285. if (self.activity && self.activity.price > 0) {
  286. self.paying = true
  287. }
  288. registerActivity({ id: self.activity.id, childId: childId }).then(function(res) {
  289. self.registrationLoading = false
  290. self.paying = false
  291. if (res && res.code === 200) {
  292. self.registrationStatus = 'pending'
  293. uni.showToast({ title: '报名成功,请等待审核', icon: 'success' })
  294. } else {
  295. uni.showToast({ title: (res && res.message) || '报名失败', icon: 'none' })
  296. }
  297. }).catch(function(err) {
  298. self.registrationLoading = false
  299. self.paying = false
  300. uni.showToast({ title: '网络异常', icon: 'none' })
  301. })
  302. },
  303. onCancelRegistration: function() {
  304. var self = this
  305. uni.showModal({
  306. title: '提示',
  307. content: '确定要取消报名吗?',
  308. success: function(res) {
  309. if (res.confirm) {
  310. var childId = uni.getStorageSync('currentChildId')
  311. self.registrationLoading = true
  312. cancelActivityRegistration({ id: self.activity.id, childId: childId }).then(function(res) {
  313. self.registrationLoading = false
  314. if (res && res.code === 200) {
  315. self.registrationStatus = null
  316. uni.showToast({ title: '已取消报名', icon: 'success' })
  317. } else {
  318. uni.showToast({ title: (res && res.message) || '取消失败', icon: 'none' })
  319. }
  320. }).catch(function() {
  321. self.registrationLoading = false
  322. uni.showToast({ title: '网络异常', icon: 'none' })
  323. })
  324. }
  325. }
  326. })
  327. }
  328. }
  329. }
  330. </script>
  331. <style scoped>
  332. .container {
  333. min-height: 100vh;
  334. background: #FFF7ED;
  335. }
  336. /* 加载 / 错误 / 空状态 */
  337. .loading-wrap,
  338. .error-wrap,
  339. .empty-wrap {
  340. display: flex;
  341. flex-direction: column;
  342. align-items: center;
  343. justify-content: center;
  344. padding: 120rpx 40rpx;
  345. }
  346. .loading-spinner {
  347. width: 60rpx;
  348. height: 60rpx;
  349. border: 4rpx solid #FDE68A;
  350. border-top-color: #F97316;
  351. border-radius: 50%;
  352. animation: spin 0.8s linear infinite;
  353. margin-bottom: 20rpx;
  354. }
  355. @keyframes spin {
  356. to { transform: rotate(360deg); }
  357. }
  358. .loading-text,
  359. .error-text,
  360. .empty-text {
  361. font-size: 28rpx;
  362. color: #999;
  363. margin-bottom: 20rpx;
  364. }
  365. .error-icon {
  366. font-size: 60rpx;
  367. margin-bottom: 16rpx;
  368. }
  369. .retry-btn {
  370. background: #F97316;
  371. color: #fff;
  372. border: none;
  373. border-radius: 40rpx;
  374. padding: 12rpx 40rpx;
  375. font-size: 26rpx;
  376. line-height: 1.5;
  377. }
  378. /* 内容区 */
  379. .content {
  380. height: 100vh;
  381. padding-bottom: 120rpx;
  382. }
  383. .cover {
  384. width: 100%;
  385. display: block;
  386. }
  387. .placeholder-cover {
  388. height: 400rpx;
  389. background: #f0f0f0;
  390. }
  391. /* 信息区 */
  392. .info-section {
  393. padding: 30rpx;
  394. }
  395. .activity-title {
  396. font-size: 36rpx;
  397. font-weight: bold;
  398. color: #1f2937;
  399. line-height: 1.4;
  400. }
  401. .status-row {
  402. margin-top: 16rpx;
  403. }
  404. .status-tag {
  405. display: inline-block;
  406. font-size: 22rpx;
  407. padding: 4rpx 16rpx;
  408. border-radius: 8rpx;
  409. }
  410. .status-draft { background: #F5F5F5; color: #999; }
  411. .status-published { background: #F0FDF4; color: #22C55E; }
  412. .status-ended { background: #F5F5F5; color: #999; }
  413. .status-upcoming { background: #FFF7ED; color: #F97316; }
  414. /* 元信息列表 */
  415. .meta-list {
  416. margin-top: 24rpx;
  417. background: #fff;
  418. border-radius: 16rpx;
  419. padding: 24rpx;
  420. }
  421. .meta-item {
  422. display: flex;
  423. flex-direction: row;
  424. align-items: center;
  425. margin-bottom: 16rpx;
  426. }
  427. .meta-item:last-child {
  428. margin-bottom: 0;
  429. }
  430. .meta-icon {
  431. font-size: 28rpx;
  432. margin-right: 12rpx;
  433. width: 32rpx;
  434. text-align: center;
  435. }
  436. .meta-text {
  437. font-size: 26rpx;
  438. color: #4b5563;
  439. flex: 1;
  440. line-height: 1.4;
  441. }
  442. /* 活动介绍 */
  443. .desc-section {
  444. margin-top: 30rpx;
  445. background: #fff;
  446. border-radius: 16rpx;
  447. padding: 24rpx;
  448. }
  449. .section-title {
  450. font-size: 28rpx;
  451. font-weight: 600;
  452. color: #1f2937;
  453. display: block;
  454. margin-bottom: 12rpx;
  455. }
  456. .desc-text {
  457. font-size: 26rpx;
  458. color: #4b5563;
  459. line-height: 1.6;
  460. }
  461. /* 付费不退费说明 */
  462. .refund-notice {
  463. margin-top: 20rpx;
  464. margin-left: 30rpx;
  465. margin-right: 30rpx;
  466. margin-bottom: 10rpx;
  467. background: #FEF2F2;
  468. border: 2rpx solid #FECACA;
  469. border-radius: 12rpx;
  470. padding: 16rpx 20rpx;
  471. display: flex;
  472. flex-direction: row;
  473. align-items: center;
  474. }
  475. .refund-notice-icon {
  476. font-size: 24rpx;
  477. margin-right: 10rpx;
  478. flex-shrink: 0;
  479. }
  480. .refund-notice-text {
  481. font-size: 24rpx;
  482. color: #DC2626;
  483. line-height: 1.4;
  484. }
  485. /* 底部操作栏 */
  486. .bottom-bar {
  487. position: fixed;
  488. left: 0;
  489. right: 0;
  490. bottom: 0;
  491. background: #fff;
  492. padding: 20rpx 30rpx;
  493. padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
  494. display: flex;
  495. flex-direction: row;
  496. align-items: center;
  497. justify-content: space-between;
  498. box-shadow: 0 -2rpx 12rpx rgba(0,0,0,0.06);
  499. }
  500. .price-info {
  501. display: flex;
  502. flex-direction: column;
  503. }
  504. .bottom-type {
  505. font-size: 22rpx;
  506. color: #999;
  507. }
  508. .bottom-vendor {
  509. font-size: 22rpx;
  510. color: #999;
  511. margin-top: 4rpx;
  512. }
  513. .action-btns {
  514. display: flex;
  515. flex-direction: row;
  516. gap: 16rpx;
  517. }
  518. .btn-checkin {
  519. background: linear-gradient(135deg, #F97316, #FB923C);
  520. color: #fff;
  521. border: none;
  522. border-radius: 40rpx;
  523. padding: 16rpx 48rpx;
  524. font-size: 28rpx;
  525. font-weight: 600;
  526. line-height: 1.5;
  527. min-width: 160rpx;
  528. text-align: center;
  529. }
  530. .btn-checkin:active {
  531. opacity: 0.85;
  532. }
  533. .btn-checkin-done {
  534. background: #22C55E;
  535. }
  536. .btn-checkin-loading {
  537. opacity: 0.7;
  538. }
  539. /* 报名按钮 */
  540. .btn-register {
  541. background: linear-gradient(135deg, #10B981, #34D399);
  542. color: #fff;
  543. border: none;
  544. border-radius: 40rpx;
  545. padding: 16rpx 32rpx;
  546. font-size: 26rpx;
  547. font-weight: 600;
  548. line-height: 1.5;
  549. min-width: 140rpx;
  550. text-align: center;
  551. }
  552. .btn-register:active { opacity: 0.85; }
  553. .btn-register-loading { opacity: 0.7; }
  554. .btn-register-done {
  555. background: #F5F5F5;
  556. color: #999;
  557. border: none;
  558. border-radius: 40rpx;
  559. padding: 16rpx 32rpx;
  560. font-size: 26rpx;
  561. line-height: 1.5;
  562. min-width: 140rpx;
  563. text-align: center;
  564. }
  565. .btn-cancel {
  566. background: #fff;
  567. color: #999;
  568. border: 2rpx solid #ddd;
  569. border-radius: 40rpx;
  570. padding: 14rpx 28rpx;
  571. font-size: 24rpx;
  572. line-height: 1.5;
  573. min-width: 120rpx;
  574. text-align: center;
  575. }
  576. .btn-cancel:active { opacity: 0.7; }
  577. /* 能量扣减弹窗 */
  578. .penalty-modal {
  579. position: fixed;
  580. top: 0;
  581. left: 0;
  582. right: 0;
  583. bottom: 0;
  584. background: rgba(0,0,0,0.5);
  585. display: flex;
  586. align-items: center;
  587. justify-content: center;
  588. z-index: 999;
  589. }
  590. .penalty-content {
  591. background: #fff;
  592. border-radius: 24rpx;
  593. padding: 48rpx 40rpx;
  594. width: 560rpx;
  595. text-align: center;
  596. }
  597. .penalty-title {
  598. font-size: 32rpx;
  599. font-weight: bold;
  600. color: #EF4444;
  601. display: block;
  602. margin-bottom: 20rpx;
  603. }
  604. .penalty-desc {
  605. font-size: 26rpx;
  606. color: #666;
  607. display: block;
  608. margin-bottom: 40rpx;
  609. line-height: 1.6;
  610. }
  611. .penalty-btn {
  612. background: #F97316;
  613. color: #fff;
  614. border: none;
  615. border-radius: 40rpx;
  616. padding: 16rpx 60rpx;
  617. font-size: 28rpx;
  618. }
  619. </style>