s-seckill-block.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <!-- 装修组件 - 秒杀 -->
  2. <template>
  3. <view>
  4. <!-- 样式一:三列 - 上图下文 -->
  5. <view v-if="layoutType === 'threeCol'" class="goods-sm-box ss-flex ss-flex-wrap" :style="[{ margin: '-' + data.space + 'rpx' }]">
  6. <view v-for="product in productList" :key="product.id" class="goods-card-box" :style="[{padding: data.space + 'rpx',},]">
  7. <s-goods-column
  8. class="goods-card" size="sm"
  9. :goodsFields="goodsFields"
  10. :tagStyle="badge"
  11. :data="product"
  12. :titleColor="data.fields.name?.color"
  13. :topRadius="data.borderRadiusTop"
  14. :bottomRadius="data.borderRadiusBottom"
  15. @click="sheep.$router.go('/pages/goods/seckill', { id: props.data.activityId, })">
  16. </s-goods-column>
  17. </view>
  18. </view>
  19. <!-- 样式二:一列 - 左图右文 -->
  20. <view class="goods-box" v-if="layoutType === 'oneCol'">
  21. <view class="goods-list" v-for="(product, index) in productList" :key="index"
  22. :style="[{ marginBottom: space + 'px' }]">
  23. <s-goods-column
  24. class="goods-card"
  25. size="lg"
  26. :goodsFields="goodsFields"
  27. :seckillTag="true"
  28. :tagStyle="badge"
  29. :data="product"
  30. :titleColor="data.fields.name?.color"
  31. :subTitleColor="data.fields.introduction?.color"
  32. :topRadius="data.borderRadiusTop"
  33. :bottomRadius="data.borderRadiusBottom"
  34. @click="sheep.$router.go('/pages/goods/seckill', { id: props.data.activityId, })">
  35. <template v-slot:cart>
  36. <button class="ss-reset-button cart-btn" :style="[buyStyle]">
  37. {{ btnBuy?.type === 'text' ? btnBuy.text : '立即秒杀' }}
  38. </button>
  39. </template>
  40. </s-goods-column>
  41. </view>
  42. </view>
  43. </view>
  44. </template>
  45. <script setup>
  46. /**
  47. * 秒杀商品列表
  48. *
  49. * @property {Array} list 商品列表
  50. */
  51. import {
  52. computed,
  53. onMounted,
  54. reactive,
  55. ref
  56. } from 'vue';
  57. import sheep from '@/sheep';
  58. import SeckillApi from "@/sheep/api/promotion/seckill";
  59. import SpuApi from "@/sheep/api/product/spu";
  60. // 接收参数
  61. const props = defineProps({
  62. // 装修数据
  63. data: {
  64. type: Object,
  65. default: () => ({}),
  66. },
  67. // 装修样式
  68. styles: {
  69. type: Object,
  70. default: () => ({}),
  71. },
  72. });
  73. // 设置相关信息是否显示
  74. const goodsFields = reactive({
  75. // 商品价格
  76. price: { show: true },
  77. // 库存
  78. stock: { show: true },
  79. // 商品名称
  80. name: { show: true },
  81. // 商品介绍
  82. introduction: { show: true },
  83. // 市场价
  84. marketPrice: { show: true },
  85. // 销量
  86. salesCount: { show: true },
  87. });
  88. let {
  89. layoutType,
  90. badge,
  91. btnBuy,
  92. space,
  93. } = props.data;
  94. let {
  95. marginLeft,
  96. marginRight
  97. } = props.styles;
  98. // 购买按钮样式
  99. const buyStyle = computed(() => {
  100. let btnBuy = props.data.btnBuy;
  101. if (btnBuy?.type === 'text') {
  102. return {
  103. background: `linear-gradient(to right, ${btnBuy.bgBeginColor}, ${btnBuy.bgEndColor})`,
  104. };
  105. }
  106. if (btnBuy?.type === 'img') {
  107. return {
  108. width: '54rpx',
  109. height: '54rpx',
  110. background: `url(${sheep.$url.cdn(btnBuy.imgUrl)}) no-repeat`,
  111. backgroundSize: '100% 100%',
  112. };
  113. }
  114. });
  115. // 商品列表
  116. const productList = ref([]);
  117. // 查询秒杀活动商品
  118. onMounted(async () => {
  119. // todo:@owen 与Yudao结构不一致,待重构
  120. const {
  121. data: activity
  122. } = await SeckillApi.getSeckillActivity(props.data.activityId);
  123. const {
  124. data: spu
  125. } = await SpuApi.getSpuDetail(activity.spuId)
  126. // 循环活动信息,赋值秒杀最低价格
  127. activity.products.forEach((product) => {
  128. spu.price = Math.min(spu.price, product.seckillPrice); // 设置 SPU 的最低价格
  129. });
  130. // 将活动库存赋值给商品库存
  131. spu.stock = activity.stock
  132. // 活动总库存 - 活动库存 = 销量
  133. spu.salesCount = activity.totalStock - activity.stock
  134. productList.value = [spu];
  135. });
  136. </script>
  137. <style lang="scss" scoped>
  138. .header-box {
  139. height: 100rpx;
  140. }
  141. .goods-list {
  142. position: relative;
  143. &:nth-last-child(1) {
  144. margin-bottom: 0 !important;
  145. }
  146. .cart-btn {
  147. position: absolute;
  148. bottom: 10rpx;
  149. right: 20rpx;
  150. z-index: 11;
  151. height: 50rpx;
  152. line-height: 50rpx;
  153. padding: 0 20rpx;
  154. border-radius: 25rpx;
  155. font-size: 24rpx;
  156. color: #fff;
  157. background: linear-gradient(90deg, #ff6600 0%, #fe832a 100%);
  158. }
  159. }
  160. .goods-sm-box {
  161. margin: 0 auto;
  162. box-sizing: border-box;
  163. .goods-card-box {
  164. flex-shrink: 0;
  165. overflow: hidden;
  166. width: 33.3%;
  167. box-sizing: border-box;
  168. }
  169. }
  170. </style>