s-seckill-block.vue 3.7 KB

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