DimensionActivities.vue 3.9 KB

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