ActivityBanner.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <template>
  2. <view class="activity-banner" v-if="list && list.length > 0">
  3. <swiper class="activity-swiper" :style="{height: swiperHeight}" circular autoplay interval="5000" duration="500">
  4. <swiper-item v-for="(item, index) in list" :key="item.activityId">
  5. <view class="activity-card type-reduction" >
  6. <view class="card-left">
  7. <view class="type-badge">{{ item.tierTypeLabel }}</view>
  8. <view class="activity-title">{{ item.title }}</view>
  9. <view class="rule-summary">{{ item.ruleSummary }}</view>
  10. <view class="scope-info">
  11. <u-icon name="tags" size="12" color="inherit"></u-icon>
  12. <text class="scope-text">{{ item.scopeSummary }}</text>
  13. </view>
  14. </view>
  15. <view class="card-right">
  16. <view class="stack-info">{{ item.stackableText }}</view>
  17. <view class="limit-info">{{ item.limitPerUserText }}</view>
  18. <view class="end-time">至{{ formatDate(item.endTime) }}</view>
  19. </view>
  20. <!-- 装饰背景 -->
  21. <view class="decoration-circle"></view>
  22. </view>
  23. </swiper-item>
  24. </swiper>
  25. </view>
  26. </template>
  27. <script>
  28. export default {
  29. props: {
  30. list: {
  31. type: Array,
  32. default: () => []
  33. }
  34. },
  35. data() {
  36. return {
  37. swiperHeight: '160rpx'
  38. }
  39. },
  40. watch: {
  41. list: {
  42. handler(val) {
  43. if (val && val.length > 0) {
  44. this.updateHeight();
  45. }
  46. },
  47. immediate: true
  48. }
  49. },
  50. methods: {
  51. updateHeight() {
  52. this.$nextTick(() => {
  53. setTimeout(() => {
  54. const query = uni.createSelectorQuery().in(this);
  55. query.selectAll('.activity-card').boundingClientRect(data => {
  56. if (data && data.length > 0) {
  57. // 取所有卡片中的最大高度
  58. let maxHeight = 0;
  59. data.forEach(item => {
  60. if (item.height > maxHeight) maxHeight = item.height;
  61. });
  62. if (maxHeight > 0) {
  63. this.swiperHeight = maxHeight + 'px';
  64. this.$emit('heightChange');
  65. }
  66. }
  67. }).exec();
  68. }, 200);
  69. });
  70. },
  71. formatDate(dateStr) {
  72. if (!dateStr) return '';
  73. // 简单的日期格式化,只保留月日
  74. const date = new Date(dateStr.replace(/-/g, '/'));
  75. if (isNaN(date.getTime())) return dateStr;
  76. const month = (date.getMonth() + 1).toString().padStart(2, '0');
  77. const day = date.getDate().toString().padStart(2, '0');
  78. return `${month}-${day}`;
  79. }
  80. }
  81. }
  82. </script>
  83. <style lang="scss" scoped>
  84. .activity-banner {
  85. padding: 20rpx 32rpx;
  86. background: #fff;
  87. }
  88. .activity-swiper {
  89. min-height: 160rpx;
  90. }
  91. .activity-card {
  92. min-height: 160rpx;
  93. height: auto;
  94. border-radius: 16rpx;
  95. padding: 20rpx 24rpx;
  96. display: flex;
  97. justify-content: space-between;
  98. position: relative;
  99. overflow: hidden;
  100. color: #fff;
  101. &.type-reduction {
  102. background: linear-gradient(135deg, #FF7E5F 0%, #FF5C03 100%);
  103. }
  104. &.type-discount {
  105. background: linear-gradient(135deg, #66b2ef 0%, #2583EB 100%);
  106. }
  107. .card-left {
  108. flex: 1;
  109. display: flex;
  110. flex-direction: column;
  111. justify-content: space-between;
  112. z-index: 1;
  113. overflow: hidden;
  114. .type-badge {
  115. display: inline-block;
  116. align-self: flex-start;
  117. font-size: 18rpx;
  118. padding: 2rpx 12rpx;
  119. background: rgba(255, 255, 255, 0.2);
  120. border: 1rpx solid rgba(255, 255, 255, 0.4);
  121. border-radius: 20rpx;
  122. margin-bottom: 8rpx;
  123. }
  124. .activity-title {
  125. font-size: 28rpx;
  126. font-weight: bold;
  127. line-height: 1.2;
  128. margin-bottom: 4rpx;
  129. }
  130. .rule-summary {
  131. font-size: 24rpx;
  132. font-weight: 500;
  133. margin-bottom: 8rpx;
  134. }
  135. .scope-info {
  136. display: flex;
  137. align-items: center;
  138. font-size: 20rpx;
  139. opacity: 0.9;
  140. .scope-text {
  141. margin-left: 6rpx;
  142. }
  143. }
  144. }
  145. .card-right {
  146. width: 200rpx;
  147. display: flex;
  148. flex-direction: column;
  149. justify-content: center;
  150. align-items: flex-end;
  151. text-align: right;
  152. z-index: 1;
  153. border-left: 1rpx dashed rgba(255, 255, 255, 0.4);
  154. padding-left: 16rpx;
  155. .stack-info, .limit-info {
  156. font-size: 20rpx;
  157. margin-bottom: 4rpx;
  158. }
  159. .end-time {
  160. font-size: 18rpx;
  161. opacity: 0.8;
  162. margin-top: 8rpx;
  163. }
  164. }
  165. .decoration-circle {
  166. position: absolute;
  167. right: -40rpx;
  168. bottom: -40rpx;
  169. width: 120rpx;
  170. height: 120rpx;
  171. background: rgba(255, 255, 255, 0.1);
  172. border-radius: 50%;
  173. z-index: 0;
  174. }
  175. }
  176. </style>