s-goods-shelves.vue 3.8 KB

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