index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <!-- 商品组 -->
  3. <view class="diy-goods" :style="{ background: itemStyle.background }">
  4. <view class="goods-list" :class="[`display__${itemStyle.display}`, `column__${itemStyle.column}`]">
  5. <scroll-view :scroll-x="itemStyle.display === 'slide'">
  6. <view class="goods-item" v-for="(dataItem, index) in dataList" :key="index" @click="onTargetGoods(dataItem.goods_id)">
  7. <!-- 单列商品 -->
  8. <block v-if="itemStyle.column === 1">
  9. <view class="dis-flex">
  10. <!-- 商品图片 -->
  11. <view class="goods-item_left">
  12. <image class="image" :src="dataItem.goods_image"></image>
  13. </view>
  14. <view class="goods-item_right">
  15. <!-- 商品名称 -->
  16. <view v-if="itemStyle.show.includes('goodsName')" class="goods-name twoline-hide">
  17. <text>{{ dataItem.goods_name }}</text>
  18. </view>
  19. <view class="goods-item_desc">
  20. <!-- 商品卖点 -->
  21. <view v-if="itemStyle.show.includes('sellingPoint')" class="desc-selling_point dis-flex">
  22. <text class="oneline-hide">{{ dataItem.selling_point }}</text>
  23. </view>
  24. <!-- 商品销量 -->
  25. <view v-if="itemStyle.show.includes('goodsSales')" class="desc-goods_sales dis-flex">
  26. <text>已售{{ dataItem.goods_sales }}件</text>
  27. </view>
  28. <!-- 商品价格 -->
  29. <view class="desc_footer">
  30. <text v-if="itemStyle.show.includes('goodsPrice')" class="price_x">¥{{ dataItem.goods_price_min }}</text>
  31. <text class="price_y col-9" v-if="itemStyle.show.includes('linePrice') && dataItem.line_price_min > 0">¥{{ dataItem.line_price_min }}</text>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </block>
  37. <!-- 多列商品 -->
  38. <block v-else>
  39. <!-- 商品图片 -->
  40. <view class="goods-image">
  41. <image class="image" mode="aspectFill" :src="dataItem.goods_image"></image>
  42. </view>
  43. <view class="detail">
  44. <!-- 商品标题 -->
  45. <view v-if="itemStyle.show.includes('goodsName')" class="goods-name twoline-hide">
  46. {{ dataItem.goods_name }}
  47. </view>
  48. <!-- 商品价格 -->
  49. <view class="detail-price oneline-hide">
  50. <text v-if="itemStyle.show.includes('goodsPrice')" class="goods-price f-30 col-m">¥{{ dataItem.goods_price_min }}</text>
  51. <text v-if="itemStyle.show.includes('linePrice') && dataItem.line_price_min > 0" class="line-price col-9 f-24">¥{{ dataItem.line_price_min }}</text>
  52. </view>
  53. </view>
  54. </block>
  55. </view>
  56. </scroll-view>
  57. </view>
  58. </view>
  59. </template>
  60. <script>
  61. export default {
  62. name: "Goods",
  63. /**
  64. * 组件的属性列表
  65. * 用于组件自定义设置
  66. */
  67. props: {
  68. itemIndex: String,
  69. itemStyle: Object,
  70. params: Object,
  71. dataList: Array
  72. },
  73. /**
  74. * 组件的方法列表
  75. * 更新属性和数据的方法与更新页面数据的方法类似
  76. */
  77. methods: {
  78. /**
  79. * 跳转商品详情页
  80. */
  81. onTargetGoods(goodsId) {
  82. this.$navTo(`pages/goods/detail`, { goodsId })
  83. }
  84. }
  85. }
  86. </script>
  87. <style lang="scss" scoped>
  88. .diy-goods {
  89. .goods-list {
  90. padding: 4rpx;
  91. box-sizing: border-box;
  92. .goods-item {
  93. box-sizing: border-box;
  94. padding: 6rpx;
  95. .goods-image {
  96. position: relative;
  97. width: 100%;
  98. height: 0;
  99. padding-bottom: 100%;
  100. overflow: hidden;
  101. background: #fff;
  102. &:after {
  103. content: '';
  104. display: block;
  105. margin-top: 100%;
  106. }
  107. .image {
  108. position: absolute;
  109. width: 100%;
  110. height: 100%;
  111. top: 0;
  112. left: 0;
  113. -o-object-fit: cover;
  114. object-fit: cover;
  115. }
  116. }
  117. .detail {
  118. padding: 8rpx;
  119. background: #fff;
  120. .goods-name {
  121. height: 70rpx;
  122. line-height: 1.3;
  123. white-space: normal;
  124. color: #484848;
  125. font-size: 26rpx;
  126. }
  127. .detail-price {
  128. .goods-price {
  129. margin-right: 8rpx;
  130. }
  131. .line-price {
  132. text-decoration: line-through;
  133. }
  134. }
  135. }
  136. }
  137. &.display__slide {
  138. white-space: nowrap;
  139. font-size: 0;
  140. .goods-item {
  141. display: inline-block;
  142. }
  143. }
  144. &.display__list {
  145. .goods-item {
  146. float: left;
  147. }
  148. }
  149. &.column__2 {
  150. .goods-item {
  151. width: 50%;
  152. }
  153. }
  154. &.column__3 {
  155. .goods-item {
  156. width: 33.33333%;
  157. }
  158. }
  159. &.column__1 {
  160. .goods-item {
  161. width: 100%;
  162. height: 280rpx;
  163. margin-bottom: 12rpx;
  164. padding: 20rpx;
  165. box-sizing: border-box;
  166. background: #fff;
  167. line-height: 1.6;
  168. &:last-child {
  169. margin-bottom: 0;
  170. }
  171. }
  172. .goods-item_left {
  173. display: flex;
  174. width: 40%;
  175. background: #fff;
  176. align-items: center;
  177. .image {
  178. display: block;
  179. width: 240rpx;
  180. height: 240rpx;
  181. }
  182. }
  183. .goods-item_right {
  184. position: relative;
  185. width: 60%;
  186. .goods-name {
  187. margin-top: 20rpx;
  188. height: 70rpx;
  189. line-height: 1.3;
  190. white-space: normal;
  191. color: #484848;
  192. font-size: 26rpx;
  193. }
  194. }
  195. .goods-item_desc {
  196. margin-top: 8rpx;
  197. }
  198. .desc-selling_point {
  199. width: 400rpx;
  200. font-size: 24rpx;
  201. color: #e49a3d;
  202. }
  203. .desc-goods_sales {
  204. color: #999;
  205. font-size: 24rpx;
  206. }
  207. .desc_footer {
  208. font-size: 24rpx;
  209. .price_x {
  210. margin-right: 16rpx;
  211. color: #f03c3c;
  212. font-size: 30rpx;
  213. }
  214. .price_y {
  215. text-decoration: line-through;
  216. }
  217. }
  218. }
  219. }
  220. }
  221. </style>