s-goods-shelves.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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="productFields"
  23. :tagStyle="tagStyle"
  24. :data="item"
  25. :titleColor="productFields.title?.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="productFields"
  53. :tagStyle="tagStyle"
  54. :data="item"
  55. :titleColor="productFields.title?.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="productFields"
  76. :tagStyle="tagStyle"
  77. :data="item"
  78. :titleColor="productFields.title?.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, tagStyle, 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. // 商品字段配置,todo @owen 字段名称与服务端对齐,这里先转换,后期重构时再修改
  115. const productFields = computed(() => {
  116. return {
  117. title: props.data.fields.name,
  118. subtitle: props.data.fields.introduction,
  119. price: props.data.fields.price,
  120. original_price: props.data.fields.marketPrice,
  121. stock: props.data.fields.stock,
  122. salesCount: props.data.fields.salesCount,
  123. }
  124. })
  125. // 角标,todo @owen 规范命名,这里先转换,后期重构时再修改
  126. const badge = computed(() => {
  127. return {
  128. show: props.data.badge.show,
  129. src: props.data.badge.imgUrl,
  130. }
  131. })
  132. </script>
  133. <style lang="scss" scoped>
  134. .goods-xs-box {
  135. // margin: 0 auto;
  136. width: 100%;
  137. .goods-xs-list {
  138. box-sizing: border-box;
  139. flex-shrink: 0;
  140. overflow: hidden;
  141. width: 50%;
  142. }
  143. }
  144. .goods-sm-box {
  145. margin: 0 auto;
  146. box-sizing: border-box;
  147. .goods-card-box {
  148. flex-shrink: 0;
  149. overflow: hidden;
  150. width: 33.3%;
  151. box-sizing: border-box;
  152. }
  153. }
  154. .goods-scroll-box {
  155. margin: 0 auto;
  156. width: 100%;
  157. box-sizing: border-box;
  158. }
  159. </style>