s-seckill-block.vue 3.7 KB

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