s-groupon-block.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <!-- 装修组件 - 拼团 -->
  2. <template>
  3. <view>
  4. <view
  5. v-if="layoutType === 'threeCol'"
  6. class="goods-sm-box ss-flex ss-flex-wrap"
  7. :style="[{ margin: '-' + data.space + 'rpx' }]"
  8. >
  9. <view
  10. v-for="product in productList"
  11. :key="product.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="data.fields"
  23. :tagStyle="tagStyle"
  24. :data="product"
  25. :titleColor="data.fields.name?.color"
  26. :topRadius="data.borderRadiusTop"
  27. :bottomRadius="data.borderRadiusBottom"
  28. @click="
  29. sheep.$router.go('/pages/goods/groupon', {
  30. id: product.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="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/groupon', {
  57. id: product.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. {{ btnBuy?.type === 'text' ? btnBuy.text : '' }}
  65. </button>
  66. </template>
  67. </s-goods-column>
  68. </view>
  69. </view>
  70. </view>
  71. </template>
  72. <script setup>
  73. /**
  74. * 拼团
  75. */
  76. import { computed, onMounted, ref } from 'vue';
  77. import sheep from '@/sheep';
  78. import SpuApi from "@/sheep/api/product/spu";
  79. import CombinationApi from "@/sheep/api/promotion/combination";
  80. // 接收参数
  81. const props = defineProps({
  82. data: {
  83. type: Object,
  84. default() {},
  85. },
  86. styles: {
  87. type: Object,
  88. default() {},
  89. },
  90. });
  91. let { layoutType, tagStyle, btnBuy, space } = props.data;
  92. let { marginLeft, marginRight } = props.styles;
  93. // 购买按钮样式
  94. const buyStyle = computed(() => {
  95. let btnBuy = props.data.btnBuy;
  96. if (btnBuy?.type === 'text') {
  97. return {
  98. background: `linear-gradient(to right, ${btnBuy.bgBeginColor}, ${btnBuy.bgEndColor})`,
  99. };
  100. }
  101. if (btnBuy?.type === 'img') {
  102. return {
  103. width: '54rpx',
  104. height: '54rpx',
  105. background: `url(${sheep.$url.cdn(btnBuy.imgUrl)}) no-repeat`,
  106. backgroundSize: '100% 100%',
  107. };
  108. }
  109. });
  110. const productList = ref([]);
  111. onMounted(async () => {
  112. // todo:@owen 与Yudao结构不一致,待重构
  113. const { data: activity } = await CombinationApi.getCombinationActivity(props.data.activityId);
  114. const { data: spu } = await SpuApi.getSpuDetail(activity.spuId)
  115. productList.value = [spu];
  116. });
  117. </script>
  118. <style lang="scss" scoped>
  119. .goods-list {
  120. position: relative;
  121. .cart-btn {
  122. position: absolute;
  123. bottom: 10rpx;
  124. right: 20rpx;
  125. z-index: 11;
  126. height: 50rpx;
  127. line-height: 50rpx;
  128. padding: 0 20rpx;
  129. border-radius: 25rpx;
  130. font-size: 24rpx;
  131. color: #fff;
  132. }
  133. }
  134. .goods-list {
  135. &:nth-last-of-type(1) {
  136. margin-bottom: 0 !important;
  137. }
  138. }
  139. .goods-sm-box {
  140. margin: 0 auto;
  141. box-sizing: border-box;
  142. .goods-card-box {
  143. flex-shrink: 0;
  144. overflow: hidden;
  145. width: 33.3%;
  146. box-sizing: border-box;
  147. }
  148. }
  149. </style>