DimensionActivities.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <view class="section">
  3. <view class="section-header">
  4. <text class="section-title">🔥 相关活动</text>
  5. <text class="section-more" v-if="displayActivities && displayActivities.length > 0" @click="$emit('moreActivities')">更多 ›</text>
  6. </view>
  7. <view v-if="!displayActivities || displayActivities.length === 0" class="empty-state">
  8. <text class="empty-tip">{{ isLoggedIn ? '暂无相关活动' : '登录后查看更多活动' }}</text>
  9. </view>
  10. <view class="activity-list" v-if="displayActivities && displayActivities.length > 0">
  11. <view class="activity-card" v-for="act in displayActivities" :key="act.id" @click="$emit('activityClick', act)">
  12. <image class="activity-cover" :src="act.coverImage || '/static/default-activity.png'" mode="aspectFill" />
  13. <view class="activity-info">
  14. <text class="activity-name line-clamp-1">{{ act.title }}</text>
  15. <view class="activity-meta">
  16. <text class="activity-time">{{ act.startTime }}</text>
  17. </view>
  18. <view class="activity-bottom">
  19. <text class="activity-status" :class="'status-' + (act.status || 'upcoming')">{{ statusText(act.status) }}</text>
  20. <text class="activity-fee" v-if="act.priceLabel">{{ act.priceLabel }}</text>
  21. <text class="activity-fee" v-else-if="act.price && act.price > 0">{{ formatPriceWithSymbol(act.price) }}</text>
  22. <text class="activity-fee fee-free" v-else>免费</text>
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. export default {
  31. props: {
  32. dimensionCode: { type: String, required: true },
  33. activities: { type: Array, default: function() { return [] } },
  34. isLoggedIn: { type: Boolean, default: false }
  35. },
  36. data: function() {
  37. return {
  38. activitiesData: []
  39. }
  40. },
  41. computed: {
  42. displayActivities: function() {
  43. return this.activitiesData.length > 0 ? this.activitiesData : this.activities
  44. }
  45. },
  46. created: function() {
  47. this.loadActivities()
  48. },
  49. methods: {
  50. statusText: function(status) {
  51. var map = { upcoming: '即将开始', ongoing: '进行中', ended: '已结束', cancelled: '已取消' }
  52. return map[status] || '即将开始'
  53. },
  54. loadActivities: function() {
  55. var self = this
  56. import('@/utils/api.js').then(function(api) {
  57. api.getActivityList({ dimensionCode: self.dimensionCode, page: 1, size: 6 }).then(function(res) {
  58. var records = (res.data && res.data.records) ? res.data.records : []
  59. self.activitiesData = records
  60. }).catch(function() {
  61. // silently fail
  62. })
  63. })
  64. }
  65. }
  66. }
  67. </script>
  68. <style scoped>
  69. .section {
  70. margin: 20rpx 20rpx;
  71. }
  72. .section-header {
  73. display: flex;
  74. justify-content: space-between;
  75. align-items: center;
  76. margin-bottom: 20rpx;
  77. }
  78. .section-title {
  79. font-size: 30rpx;
  80. font-weight: bold;
  81. color: #333;
  82. }
  83. .section-more {
  84. font-size: 24rpx;
  85. color: #999;
  86. }
  87. .activity-list {
  88. display: flex;
  89. flex-direction: column;
  90. }
  91. .activity-card {
  92. display: flex;
  93. flex-direction: row;
  94. background: #fff;
  95. border-radius: 16rpx;
  96. overflow: hidden;
  97. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  98. margin-bottom: 20rpx;
  99. }
  100. .activity-card:active { opacity: 0.8; }
  101. .activity-cover {
  102. width: 220rpx;
  103. height: 200rpx;
  104. flex-shrink: 0;
  105. background: #f0f0f0;
  106. }
  107. .activity-info {
  108. flex: 1;
  109. padding: 16rpx 20rpx;
  110. display: flex;
  111. flex-direction: column;
  112. justify-content: space-between;
  113. }
  114. .activity-name {
  115. font-size: 28rpx;
  116. color: #333;
  117. font-weight: 500;
  118. }
  119. .activity-meta {
  120. margin-top: 8rpx;
  121. }
  122. .activity-time {
  123. font-size: 24rpx;
  124. color: #999;
  125. }
  126. .activity-bottom {
  127. display: flex;
  128. flex-direction: row;
  129. justify-content: space-between;
  130. align-items: center;
  131. margin-top: 12rpx;
  132. }
  133. .activity-status {
  134. font-size: 22rpx;
  135. padding: 4rpx 12rpx;
  136. border-radius: 8rpx;
  137. }
  138. .status-upcoming { background: #FFF7ED; color: #F97316; }
  139. .status-ongoing { background: #F0FDF4; color: #22C55E; }
  140. .status-ended { background: #F5F5F5; color: #999; }
  141. .status-cancelled { background: #FEE2E2; color: #EF4444; }
  142. .activity-fee {
  143. font-size: 24rpx;
  144. color: #F97316;
  145. font-weight: 500;
  146. }
  147. .fee-free {
  148. color: #22C55E;
  149. }
  150. .empty-state {
  151. display: flex;
  152. justify-content: center;
  153. padding: 40rpx 0;
  154. }
  155. .empty-tip {
  156. font-size: 24rpx;
  157. color: #999;
  158. }
  159. .line-clamp-1 {
  160. overflow: hidden;
  161. text-overflow: ellipsis;
  162. white-space: nowrap;
  163. }
  164. </style>