detail.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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" class="cover-image" mode="aspectFill"></image>
  14. <view class="cover-mask">
  15. <view class="activity-tag" v-if="activity.isHot">🔥 热门活动</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">{{ formatTime(activity.startTime) }}</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.actualParticipants || 0 }} / {{ activity.maxParticipants || '不限' }}</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 price">¥{{ activity.price || 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="notes-section">
  50. <view class="section-title">注意事项</view>
  51. <view class="notes-text">{{ activity.notes || '请准时参加活动' }}</view>
  52. </view>
  53. </view>
  54. <!-- 底部报名按钮 -->
  55. <view class="bottom-bar">
  56. <view class="price-info">
  57. <text class="price-label">活动费用</text>
  58. <view class="price-value">
  59. <text class="price-symbol">¥</text>
  60. <text class="price-num">{{ activity.price || 0 }}</text>
  61. </view>
  62. </view>
  63. <view class="register-btn" @click="handleRegister">
  64. <text class="btn-text">立即报名</text>
  65. </view>
  66. </view>
  67. </view>
  68. </template>
  69. <script>
  70. import api from '@/utils/api.js'
  71. import { formatTime } from '@/utils/util.js'
  72. import { DEFAULT_IMAGES } from '@/config/index.js'
  73. import userAuth from '@/utils/userAuth.js'
  74. export default {
  75. data() {
  76. return {
  77. activityId: null,
  78. activity: {
  79. name: '加载中...',
  80. coverImage: DEFAULT_IMAGES.activity,
  81. price: 0
  82. }
  83. }
  84. },
  85. onLoad(options) {
  86. if (options.id) {
  87. this.activityId = options.id
  88. this.loadActivityDetail()
  89. }
  90. },
  91. methods: {
  92. // 加载活动详情
  93. async loadActivityDetail() {
  94. try {
  95. const data = await api.activity.getDetail(this.activityId)
  96. if (data) {
  97. this.activity = data
  98. }
  99. } catch (error) {
  100. console.error('加载活动详情失败:', error)
  101. uni.showToast({
  102. title: '加载失败',
  103. icon: 'none'
  104. })
  105. }
  106. },
  107. // 格式化时间
  108. formatTime,
  109. // 处理报名
  110. handleRegister() {
  111. // 获取当前用户ID
  112. const userId = userAuth.getUserId()
  113. if (!userId) {
  114. uni.showModal({
  115. title: '需要登录',
  116. content: '请先登录后再报名活动',
  117. showCancel: false,
  118. success: () => {
  119. uni.navigateTo({
  120. url: '/pages/page3/page3'
  121. })
  122. }
  123. })
  124. return
  125. }
  126. // 检查人数限制(前端预检查,提供更好的用户体验)
  127. if (this.activity.maxParticipants &&
  128. this.activity.actualParticipants >= this.activity.maxParticipants) {
  129. uni.showModal({
  130. title: '报名已满',
  131. content: '当前活动报名人数已达上限,感谢您的关注,敬请期待后续活动~',
  132. showCancel: false
  133. })
  134. return
  135. }
  136. uni.showModal({
  137. title: '确认报名',
  138. content: `确认报名参加"${this.activity.name}"吗?`,
  139. success: async (res) => {
  140. if (res.confirm) {
  141. try {
  142. await api.activity.register(this.activityId, userId)
  143. uni.showModal({
  144. title: '报名成功',
  145. content: '恭喜您报名成功!',
  146. showCancel: false,
  147. success: () => {
  148. this.loadActivityDetail()
  149. }
  150. })
  151. } catch (error) {
  152. console.error('报名失败:', error)
  153. // 后端会返回友好的错误信息(通过Result类的message字段)
  154. const errorMsg = error.message || '报名失败,请稍后重试'
  155. uni.showModal({
  156. title: '提示',
  157. content: errorMsg,
  158. showCancel: false
  159. })
  160. }
  161. }
  162. }
  163. })
  164. },
  165. // 返回
  166. goBack() {
  167. uni.navigateBack()
  168. }
  169. }
  170. }
  171. </script>
  172. <style lang="scss" scoped>
  173. .activity-detail-page {
  174. min-height: 100vh;
  175. background-color: #FFF9F9;
  176. padding-top: 90rpx;
  177. padding-bottom: 120rpx;
  178. }
  179. /* 自定义导航栏 */
  180. .custom-navbar {
  181. position: fixed;
  182. top: 0;
  183. left: 0;
  184. right: 0;
  185. height: 90rpx;
  186. display: flex;
  187. align-items: center;
  188. justify-content: space-between;
  189. padding: 0 20rpx;
  190. background-color: #E91E63;
  191. z-index: 999;
  192. .navbar-left,
  193. .navbar-right {
  194. width: 80rpx;
  195. }
  196. .back-icon {
  197. font-size: 40rpx;
  198. color: #FFFFFF;
  199. font-weight: bold;
  200. }
  201. .navbar-title {
  202. flex: 1;
  203. text-align: center;
  204. font-size: 32rpx;
  205. font-weight: bold;
  206. color: #FFFFFF;
  207. }
  208. }
  209. /* 活动封面 */
  210. .activity-cover {
  211. position: relative;
  212. width: 100%;
  213. height: 500rpx;
  214. .cover-image {
  215. width: 100%;
  216. height: 100%;
  217. }
  218. .cover-mask {
  219. position: absolute;
  220. top: 0;
  221. left: 0;
  222. right: 0;
  223. bottom: 0;
  224. background: linear-gradient(to bottom, rgba(0, 0, 0, 0.3), transparent);
  225. padding: 30rpx;
  226. .activity-tag {
  227. display: inline-block;
  228. padding: 10rpx 20rpx;
  229. background: linear-gradient(135deg, #FF6B6B 0%, #FF9800 100%);
  230. color: #FFFFFF;
  231. font-size: 24rpx;
  232. font-weight: bold;
  233. border-radius: 30rpx;
  234. }
  235. }
  236. }
  237. /* 活动内容 */
  238. .activity-content {
  239. padding: 30rpx;
  240. background-color: #FFFFFF;
  241. margin: 20rpx;
  242. border-radius: 20rpx;
  243. .activity-title {
  244. font-size: 36rpx;
  245. font-weight: bold;
  246. color: #333333;
  247. margin-bottom: 30rpx;
  248. line-height: 1.5;
  249. }
  250. .info-section {
  251. .info-item {
  252. display: flex;
  253. align-items: center;
  254. margin-bottom: 20rpx;
  255. font-size: 28rpx;
  256. .info-icon {
  257. font-size: 32rpx;
  258. margin-right: 10rpx;
  259. }
  260. .info-label {
  261. color: #666666;
  262. }
  263. .info-value {
  264. color: #333333;
  265. flex: 1;
  266. &.price {
  267. color: #E91E63;
  268. font-weight: bold;
  269. font-size: 32rpx;
  270. }
  271. }
  272. }
  273. }
  274. .divider {
  275. height: 1rpx;
  276. background-color: #F0F0F0;
  277. margin: 30rpx 0;
  278. }
  279. .section-title {
  280. font-size: 30rpx;
  281. font-weight: bold;
  282. color: #333333;
  283. margin-bottom: 20rpx;
  284. }
  285. .description-text,
  286. .notes-text {
  287. font-size: 28rpx;
  288. color: #666666;
  289. line-height: 1.8;
  290. white-space: pre-wrap;
  291. }
  292. }
  293. /* 底部报名按钮 */
  294. .bottom-bar {
  295. position: fixed;
  296. bottom: 0;
  297. left: 0;
  298. right: 0;
  299. display: flex;
  300. align-items: center;
  301. justify-content: space-between;
  302. padding: 20rpx 30rpx;
  303. background-color: #FFFFFF;
  304. border-top: 1rpx solid #F0F0F0;
  305. z-index: 999;
  306. .price-info {
  307. flex: 1;
  308. .price-label {
  309. display: block;
  310. font-size: 24rpx;
  311. color: #999999;
  312. margin-bottom: 5rpx;
  313. }
  314. .price-value {
  315. color: #E91E63;
  316. font-weight: bold;
  317. .price-symbol {
  318. font-size: 28rpx;
  319. }
  320. .price-num {
  321. font-size: 40rpx;
  322. }
  323. }
  324. }
  325. .register-btn {
  326. padding: 20rpx 60rpx;
  327. background: linear-gradient(135deg, #E91E63 0%, #FF6B6B 100%);
  328. border-radius: 50rpx;
  329. box-shadow: 0 8rpx 16rpx rgba(233, 30, 99, 0.3);
  330. .btn-text {
  331. font-size: 32rpx;
  332. font-weight: bold;
  333. color: #FFFFFF;
  334. }
  335. }
  336. }
  337. </style>