s-groupon-block.vue 3.6 KB

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