index.vue 6.5 KB

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