s-seckill-block.vue 4.1 KB

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