s-groupon-block.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <!-- 装修组件 - 拼团 -->
  2. <template>
  3. <view>
  4. <view v-if="layoutType === 'threeCol'" class="goods-sm-box ss-flex ss-flex-wrap" :style="[{ margin: '-' + data.space + 'rpx' }]">
  5. <view v-for="product in productList" class="goods-card-box" :key="product.id" :style="[{padding: data.space + 'rpx',},]">
  6. <s-goods-column
  7. class="goods-card"
  8. 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/groupon', { id: props.data.activityId, })">
  16. </s-goods-column>
  17. </view>
  18. </view>
  19. <!-- 样式2 一行一个 图片左 文案右 -->
  20. <view class="goods-box" v-if="layoutType === 'oneCol'">
  21. <view class="goods-list" v-for="(product, index) in productList" :key="index" :style="[{ marginBottom: space + 'px' }]">
  22. <s-goods-column
  23. class="goods-card" size="lg"
  24. :grouponTag="true"
  25. :goodsFields="goodsFields"
  26. :tagStyle="badge"
  27. :data="product"
  28. :titleColor="data.fields.name?.color"
  29. :subTitleColor="data.fields.introduction?.color"
  30. :topRadius="data.borderRadiusTop"
  31. :bottomRadius="data.borderRadiusBottom"
  32. @click="sheep.$router.go('/pages/goods/groupon', { id: props.data.activityId, })">
  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. import {
  48. computed,
  49. onMounted,
  50. reactive,
  51. ref
  52. } from 'vue';
  53. import sheep from '@/sheep';
  54. import SpuApi from "@/sheep/api/product/spu";
  55. import CombinationApi from "@/sheep/api/promotion/combination";
  56. // 接收参数
  57. const props = defineProps({
  58. // 装修数据
  59. data: {
  60. type: Object,
  61. default: () => ({}),
  62. },
  63. // 装修样式
  64. styles: {
  65. type: Object,
  66. default: () => ({}),
  67. },
  68. });
  69. // 设置相关信息是否显示
  70. const goodsFields = reactive({
  71. // 商品价格
  72. price: { show: true },
  73. // 库存
  74. stock: { show: true },
  75. // 商品名称
  76. name: { show: true },
  77. // 商品介绍
  78. introduction: { show: true },
  79. // 市场价
  80. marketPrice: { show: true },
  81. // 销量
  82. salesCount: { show: true },
  83. });
  84. let {
  85. layoutType,
  86. badge,
  87. btnBuy,
  88. space,
  89. } = props.data;
  90. let {
  91. marginLeft,
  92. marginRight
  93. } = 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. const productList = ref([]);
  112. onMounted(async () => {
  113. // todo:@owen 与Yudao结构不一致,待重构
  114. const {
  115. data: activity
  116. } = await CombinationApi.getCombinationActivity(props.data.activityId);
  117. const {
  118. data: spu
  119. } = await SpuApi.getSpuDetail(activity.spuId)
  120. // 循环活动信息,赋值拼团最低价格
  121. activity.products.forEach((product) => {
  122. spu.price = Math.min(spu.price, product.combinationPrice); // 设置 SPU 的最低价格
  123. });
  124. productList.value = [spu];
  125. });
  126. </script>
  127. <style lang="scss" scoped>
  128. .goods-list {
  129. position: relative;
  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. background: linear-gradient(90deg, #ff6600 0%, #fe832a 100%);
  142. }
  143. }
  144. .goods-list {
  145. &:nth-last-of-type(1) {
  146. margin-bottom: 0 !important;
  147. }
  148. }
  149. .goods-sm-box {
  150. margin: 0 auto;
  151. box-sizing: border-box;
  152. .goods-card-box {
  153. flex-shrink: 0;
  154. overflow: hidden;
  155. width: 33.3%;
  156. box-sizing: border-box;
  157. }
  158. }
  159. </style>