s-seckill-block.vue 4.0 KB

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