index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. watch:{
  76. dataList:{
  77. immediate:true,
  78. handler(newData){
  79. newData.map((item) => {
  80. item.goods_image = item.goods_image.replace('http://www.ccsckj.com','https://www.ccsckj.com')
  81. })
  82. }
  83. }
  84. },
  85. /**
  86. * 组件的方法列表
  87. * 更新属性和数据的方法与更新页面数据的方法类似
  88. */
  89. methods: {
  90. /**
  91. * 跳转商品详情页
  92. */
  93. onTargetGoods(goodsId) {
  94. this.$navTo(`pages/goods/detail`, { goodsId })
  95. }
  96. }
  97. }
  98. </script>
  99. <style lang="scss" scoped>
  100. .diy-goods {
  101. .goods-list {
  102. padding: 4rpx;
  103. box-sizing: border-box;
  104. .goods-item {
  105. box-sizing: border-box;
  106. padding: 6rpx;
  107. .goods-image {
  108. position: relative;
  109. width: 100%;
  110. height: 0;
  111. padding-bottom: 100%;
  112. overflow: hidden;
  113. background: #fff;
  114. &:after {
  115. content: '';
  116. display: block;
  117. margin-top: 100%;
  118. }
  119. .image {
  120. position: absolute;
  121. width: 100%;
  122. height: 100%;
  123. top: 0;
  124. left: 0;
  125. -o-object-fit: cover;
  126. object-fit: cover;
  127. }
  128. }
  129. .detail {
  130. padding: 8rpx;
  131. background: #fff;
  132. .goods-name {
  133. min-height: 68rpx;
  134. line-height: 1.3;
  135. white-space: normal;
  136. color: #484848;
  137. font-size: 26rpx;
  138. }
  139. .detail-price {
  140. .goods-price {
  141. margin-right: 8rpx;
  142. }
  143. .line-price {
  144. text-decoration: line-through;
  145. }
  146. }
  147. }
  148. }
  149. &.display__slide {
  150. white-space: nowrap;
  151. font-size: 0;
  152. .goods-item {
  153. display: inline-block;
  154. }
  155. }
  156. &.display__list {
  157. .goods-item {
  158. float: left;
  159. }
  160. }
  161. &.column__2 {
  162. .goods-item {
  163. width: 50%;
  164. }
  165. }
  166. &.column__3 {
  167. .goods-item {
  168. width: 33.33333%;
  169. }
  170. }
  171. &.column__1 {
  172. .goods-item {
  173. width: 100%;
  174. height: 280rpx;
  175. margin-bottom: 12rpx;
  176. padding: 20rpx;
  177. box-sizing: border-box;
  178. background: #fff;
  179. line-height: 1.6;
  180. &:last-child {
  181. margin-bottom: 0;
  182. }
  183. }
  184. .goods-item_left {
  185. display: flex;
  186. width: 40%;
  187. background: #fff;
  188. align-items: center;
  189. .image {
  190. display: block;
  191. width: 240rpx;
  192. height: 240rpx;
  193. }
  194. }
  195. .goods-item_right {
  196. position: relative;
  197. width: 60%;
  198. .goods-name {
  199. margin-top: 20rpx;
  200. min-height: 68rpx;
  201. line-height: 1.3;
  202. white-space: normal;
  203. color: #484848;
  204. font-size: 26rpx;
  205. }
  206. }
  207. .goods-item_desc {
  208. margin-top: 8rpx;
  209. }
  210. .desc-selling_point {
  211. width: 400rpx;
  212. font-size: 24rpx;
  213. color: #e49a3d;
  214. }
  215. .desc-goods_sales {
  216. color: #999;
  217. font-size: 24rpx;
  218. }
  219. .desc_footer {
  220. font-size: 24rpx;
  221. .price_x {
  222. margin-right: 16rpx;
  223. color: #f03c3c;
  224. font-size: 30rpx;
  225. }
  226. .price_y {
  227. text-decoration: line-through;
  228. }
  229. }
  230. }
  231. }
  232. }
  233. </style>