DimensionActivities.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <template>
  2. <view class="section">
  3. <view class="section-header">
  4. <text class="section-title">🔥 推荐活动</text>
  5. <text class="section-more" @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.stop="$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="weight-badges" v-if="act._badges && act._badges.length">
  16. <text class="weight-badge" v-for="badge in act._badges" :key="badge.name" :style="{ background: badge.color + '20', color: badge.color }">{{ badge.name }}{{ badge.weight }}%</text>
  17. </view>
  18. <view class="activity-meta">
  19. <text class="activity-time">{{ act.startTime }}</text>
  20. </view>
  21. <view class="activity-bottom">
  22. <text class="activity-status" :class="'status-' + (act.status || 'upcoming')">{{ statusText(act.status) }}</text>
  23. <text class="activity-fee" v-if="act.priceLabel">{{ act.priceLabel }}</text>
  24. <text class="activity-fee" v-else-if="act.price && act.price > 0">{{ formatPriceWithSymbol(act.price) }}</text>
  25. <text class="activity-fee fee-free" v-else>免费</text>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. var DIMENSION_MAP = {
  34. body: { name: '身', color: '#FF8C42' },
  35. mind: { name: '心', color: '#FF6B9D' },
  36. wisdom: { name: '智', color: '#6366F1' },
  37. action: { name: '行', color: '#10B981' },
  38. wealth: { name: '富', color: '#F59E0B' }
  39. }
  40. export default {
  41. props: {
  42. dimensionCode: { type: String, required: true },
  43. activities: { type: Array, default: function() { return [] } },
  44. isLoggedIn: { type: Boolean, default: false }
  45. },
  46. data: function() {
  47. return {
  48. }
  49. },
  50. computed: {
  51. displayActivities: function() {
  52. var self = this
  53. return (this.activities || []).slice(0, 3).map(function(item) {
  54. item._badges = self.parseWeights(item.dimensionWeights)
  55. return item
  56. })
  57. }
  58. },
  59. methods: {
  60. parseWeights: function(str) {
  61. if (!str) return []
  62. try {
  63. var obj = JSON.parse(str)
  64. var result = []
  65. for (var key in obj) {
  66. if (obj[key] > 0 && DIMENSION_MAP[key]) {
  67. result.push({ name: DIMENSION_MAP[key].name, color: DIMENSION_MAP[key].color, weight: obj[key] })
  68. }
  69. }
  70. return result
  71. } catch (e) {
  72. return []
  73. }
  74. },
  75. statusText: function(status) {
  76. var map = { upcoming: '即将开始', ongoing: '进行中', ended: '已结束', cancelled: '已取消' }
  77. return map[status] || '即将开始'
  78. }
  79. }
  80. }
  81. </script>
  82. <style scoped>
  83. .section {
  84. margin: 20rpx 20rpx;
  85. }
  86. .section-header {
  87. display: flex;
  88. justify-content: space-between;
  89. align-items: center;
  90. margin-bottom: 20rpx;
  91. }
  92. .section-title {
  93. font-size: 30rpx;
  94. font-weight: bold;
  95. color: #333;
  96. }
  97. .section-more {
  98. font-size: 24rpx;
  99. color: #999;
  100. }
  101. .activity-list {
  102. display: flex;
  103. flex-direction: column;
  104. }
  105. .activity-card {
  106. display: flex;
  107. flex-direction: row;
  108. background: #fff;
  109. border-radius: 16rpx;
  110. overflow: hidden;
  111. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  112. margin-bottom: 20rpx;
  113. }
  114. .activity-card:active { opacity: 0.8; }
  115. .activity-cover {
  116. width: 220rpx;
  117. height: 200rpx;
  118. flex-shrink: 0;
  119. background: #f0f0f0;
  120. }
  121. .activity-info {
  122. flex: 1;
  123. padding: 16rpx 20rpx;
  124. display: flex;
  125. flex-direction: column;
  126. justify-content: space-between;
  127. }
  128. .activity-name {
  129. font-size: 28rpx;
  130. color: #333;
  131. font-weight: 500;
  132. }
  133. .weight-badges {
  134. display: flex;
  135. flex-direction: row;
  136. flex-wrap: wrap;
  137. gap: 6rpx;
  138. margin-top: 6rpx;
  139. }
  140. .weight-badge {
  141. font-size: 18rpx;
  142. padding: 2rpx 10rpx;
  143. border-radius: 8rpx;
  144. font-weight: 500;
  145. }
  146. .activity-meta {
  147. margin-top: 8rpx;
  148. }
  149. .activity-time {
  150. font-size: 24rpx;
  151. color: #999;
  152. }
  153. .activity-bottom {
  154. display: flex;
  155. flex-direction: row;
  156. justify-content: space-between;
  157. align-items: center;
  158. margin-top: 12rpx;
  159. }
  160. .activity-status {
  161. font-size: 22rpx;
  162. padding: 4rpx 12rpx;
  163. border-radius: 8rpx;
  164. }
  165. .status-upcoming { background: #FFF7ED; color: #F97316; }
  166. .status-ongoing { background: #F0FDF4; color: #22C55E; }
  167. .status-ended { background: #F5F5F5; color: #999; }
  168. .status-cancelled { background: #FEE2E2; color: #EF4444; }
  169. .activity-fee {
  170. font-size: 24rpx;
  171. color: #F97316;
  172. font-weight: 500;
  173. }
  174. .fee-free {
  175. color: #22C55E;
  176. }
  177. .empty-state {
  178. display: flex;
  179. justify-content: center;
  180. padding: 40rpx 0;
  181. }
  182. .empty-tip {
  183. font-size: 24rpx;
  184. color: #999;
  185. }
  186. .line-clamp-1 {
  187. overflow: hidden;
  188. text-overflow: ellipsis;
  189. white-space: nowrap;
  190. }
  191. </style>