s-groupon-block.vue 3.9 KB

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