s-goods-shelves.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <!-- 装修商品组件:商品栏 -->
  2. <template>
  3. <view>
  4. <!-- 布局1. 两列商品,图片左文案右 -->
  5. <view
  6. v-if="layoutType === 'twoCol'"
  7. class="goods-xs-box ss-flex ss-flex-wrap"
  8. :style="[{ margin: '-' + data.space + 'rpx' }]"
  9. >
  10. <view
  11. class="goods-xs-list"
  12. v-for="item in goodsList"
  13. :key="item.id"
  14. :style="[
  15. {
  16. padding: data.space + 'rpx',
  17. },
  18. ]"
  19. >
  20. <s-goods-column
  21. class="goods-card"
  22. size="xs"
  23. :goodsFields="data.fields"
  24. :tagStyle="data.badge"
  25. :data="item"
  26. :titleColor="data.fields.name?.color"
  27. :topRadius="data.borderRadiusTop"
  28. :bottomRadius="data.borderRadiusBottom"
  29. :titleWidth="(454 - marginRight * 2 - data.space * 2 - marginLeft * 2) / 2"
  30. @click="sheep.$router.go('/pages/goods/index', { id: item.id })"
  31. />
  32. </view>
  33. </view>
  34. <!-- 布局. 三列商品:图片上文案下 -->
  35. <view
  36. v-if="layoutType === 'threeCol'"
  37. class="goods-sm-box ss-flex ss-flex-wrap"
  38. :style="[{ margin: '-' + data.space + 'rpx' }]"
  39. >
  40. <view
  41. v-for="item in goodsList"
  42. :key="item.id"
  43. class="goods-card-box"
  44. :style="[
  45. {
  46. padding: data.space + 'rpx',
  47. },
  48. ]"
  49. >
  50. <s-goods-column
  51. class="goods-card"
  52. size="sm"
  53. :goodsFields="data.fields"
  54. :tagStyle="data.badge"
  55. :data="item"
  56. :titleColor="data.fields.name?.color"
  57. :topRadius="data.borderRadiusTop"
  58. :bottomRadius="data.borderRadiusBottom"
  59. @click="sheep.$router.go('/pages/goods/index', { id: item.id })"
  60. />
  61. </view>
  62. </view>
  63. <!-- 布局3. 一行商品,水平滑动 -->
  64. <view v-if="layoutType === 'horizSwiper'" class="">
  65. <scroll-view class="scroll-box goods-scroll-box" scroll-x scroll-anchoring>
  66. <view class="goods-box ss-flex">
  67. <view
  68. class="goods-card-box"
  69. v-for="item in goodsList"
  70. :key="item.id"
  71. :style="[{ marginRight: data.space * 2 + 'rpx' }]"
  72. >
  73. <s-goods-column
  74. class="goods-card"
  75. size="sm"
  76. :goodsFields="data.fields"
  77. :tagStyle="data.badge"
  78. :data="item"
  79. :titleColor="data.fields.name?.color"
  80. :titleWidth="(750 - marginRight * 2 - data.space * 4 - marginLeft * 2) / 3"
  81. @click="sheep.$router.go('/pages/goods/index', { id: item.id })"
  82. />
  83. </view>
  84. </view>
  85. </scroll-view>
  86. </view>
  87. </view>
  88. </template>
  89. <script setup>
  90. /**
  91. * 商品栏
  92. */
  93. import { onMounted, ref, computed } from 'vue';
  94. import sheep from '@/sheep';
  95. import SpuApi from "@/sheep/api/product/spu";
  96. const props = defineProps({
  97. data: {
  98. type: Object,
  99. default() {},
  100. },
  101. styles: {
  102. type: Object,
  103. default() {},
  104. },
  105. });
  106. const { layoutType, spuIds } = props.data;
  107. let { marginLeft, marginRight } = props.styles;
  108. const goodsList = ref([]);
  109. onMounted(async () => {
  110. if (spuIds.length > 0) {
  111. let { data } = await SpuApi.getSpuListByIds(spuIds.join(','));
  112. goodsList.value = data;
  113. }
  114. });
  115. </script>
  116. <style lang="scss" scoped>
  117. .goods-xs-box {
  118. // margin: 0 auto;
  119. width: 100%;
  120. .goods-xs-list {
  121. box-sizing: border-box;
  122. flex-shrink: 0;
  123. overflow: hidden;
  124. width: 50%;
  125. }
  126. }
  127. .goods-sm-box {
  128. margin: 0 auto;
  129. box-sizing: border-box;
  130. .goods-card-box {
  131. flex-shrink: 0;
  132. overflow: hidden;
  133. width: 33.3%;
  134. box-sizing: border-box;
  135. }
  136. }
  137. .goods-scroll-box {
  138. margin: 0 auto;
  139. width: 100%;
  140. box-sizing: border-box;
  141. }
  142. </style>