index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. <template>
  2. <!-- 商品组 -->
  3. <scroll-view class="scroll-view" :scroll-x="itemStyle.display === 'slide'" :style="{ background: itemStyle.background }">
  4. <view class="diy-goods">
  5. <view class="goods-list" :class="[`display-${itemStyle.display}`, `column-${itemStyle.column}`]"
  6. :style="{ padding: `${itemStyle.paddingY * 2}rpx ${itemStyle.paddingX * 2}rpx` }">
  7. <view class="goods-item" v-for="(dataItm, dataIdx) in dataList" :key="dataIdx" :class="[`display-${itemStyle.cardType}`]"
  8. :style="{ marginBottom: `${itemStyle.itemMargin * 2}rpx`, borderRadius: `${itemStyle.borderRadius * 2}rpx` }"
  9. @click="handleGoodsItem(dataItm.goods_id)">
  10. <!-- 单列商品 -->
  11. <template v-if="itemStyle.column === 1">
  12. <view class="flex">
  13. <view class="goods-item-left">
  14. <image class="image" :src="dataItm.goods_image"></image>
  15. </view>
  16. <view class="goods-item-right">
  17. <view class="goods-info">
  18. <view v-if="inArray('goodsName', itemStyle.show)" class="goods-name"
  19. :class="[ itemStyle.goodsNameRows == 'two' ? 'twoline-hide' : 'oneline-hide', `row-${itemStyle.goodsNameRows}` ]">
  20. {{ dataItm.goods_name }}
  21. </view>
  22. <view v-if="inArray('sellingPoint', itemStyle.show)" class="goods-selling">
  23. <text class="selling oneline-hide" :style="{ color: itemStyle.sellingColor }">{{ dataItm.selling_point }}</text>
  24. </view>
  25. <view v-if="inArray('goodsSales', itemStyle.show)" class="goods-sales oneline-hide">
  26. <text class="sales">已售{{ dataItm.goods_sales }}</text>
  27. <!-- <text class="line">|</text>
  28. <text>惊艳度100%</text>-->
  29. </view>
  30. <view class="footer">
  31. <view class="goods-price oneline-hide" :style="{ color: itemStyle.priceColor }">
  32. <template v-if="inArray('goodsPrice', itemStyle.show)">
  33. <text class="unit">¥</text>
  34. <text class="value">{{ dataItm.goods_price_min }}</text>
  35. <!-- <text class="unit2">到手价</text> -->
  36. </template>
  37. <text v-if="inArray('linePrice', itemStyle.show) && dataItm.line_price_min > 0" class="line-price">
  38. <text class="unit">¥</text>
  39. <text class="value">{{ dataItm.line_price_min }}</text>
  40. </text>
  41. </view>
  42. <view v-show="inArray('cartBtn', itemStyle.show) && itemStyle.column < 3" class="action">
  43. <view class="btn-cart" :style="{ color: itemStyle.btnCartColor }" @click.stop="handleAddCart(dataItm)">
  44. <text class="cart-icon iconfont" :class="[`icon-jiagou${itemStyle.btnCartStyle}`]"></text>
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. </template>
  52. <!-- 两列/三列 -->
  53. <template v-else>
  54. <view class="goods-image">
  55. <image class="image" mode="aspectFill" :src="dataItm.goods_image"></image>
  56. </view>
  57. <view class="goods-info">
  58. <view v-if="inArray('goodsName', itemStyle.show)" class="goods-name"
  59. :class="[ itemStyle.goodsNameRows == 'two' ? 'twoline-hide' : 'oneline-hide', `row-${itemStyle.goodsNameRows}` ]">
  60. {{ dataItm.goods_name }}
  61. </view>
  62. <view v-if="inArray('sellingPoint', itemStyle.show)" class="goods-selling">
  63. <text class="selling oneline-hide" :style="{ color: itemStyle.sellingColor }">{{ dataItm.selling_point }}</text>
  64. </view>
  65. <view v-if="inArray('goodsSales', itemStyle.show)" class="goods-sales oneline-hide">
  66. <text class="sales">已售{{ dataItm.goods_sales }}</text>
  67. <!-- <text class="line">|</text>
  68. <text>惊艳度100%</text>-->
  69. </view>
  70. <view class="footer">
  71. <view v-if="inArray('goodsPrice', itemStyle.show)" class="goods-price oneline-hide"
  72. :style="{ color: itemStyle.priceColor }">
  73. <text class="unit">¥</text>
  74. <text class="value">{{ dataItm.goods_price_min }}</text>
  75. <!-- <text class="unit2">到手价</text> -->
  76. <text v-if="inArray('linePrice', itemStyle.show) && dataItm.line_price_min > 0" class="line-price">
  77. <text class="unit">¥</text>
  78. <text class="value">{{ dataItm.line_price_min }}</text>
  79. </text>
  80. </view>
  81. <view v-show="inArray('cartBtn', itemStyle.show) && itemStyle.column < 3" class="action">
  82. <view class="btn-cart" :style="{ color: itemStyle.btnCartColor }" @click.stop="handleAddCart(dataItm)">
  83. <text class="cart-icon iconfont" :class="[`icon-jiagou${itemStyle.btnCartStyle}`]"></text>
  84. </view>
  85. </view>
  86. </view>
  87. </view>
  88. </template>
  89. </view>
  90. </view>
  91. </view>
  92. <!-- 加入购物车组件 -->
  93. <AddCartPopup ref="AddCartPopup" @addCart="onAddCart" />
  94. </scroll-view>
  95. </template>
  96. <script>
  97. import { inArray } from '@/utils/util'
  98. import { setCartTabBadge } from '@/core/app'
  99. import AddCartPopup from '@/components/add-cart-popup'
  100. export default {
  101. components: {
  102. AddCartPopup
  103. },
  104. props: {
  105. itemIndex: String,
  106. itemStyle: Object,
  107. params: Object,
  108. dataList: Array
  109. },
  110. data() {
  111. return { inArray }
  112. },
  113. methods: {
  114. // 跳转商品详情页
  115. handleGoodsItem(goodsId) {
  116. if (goodsId !== undefined) {
  117. this.$navTo(`pages/goods/detail`, { goodsId })
  118. }
  119. },
  120. // 点击加入购物车
  121. handleAddCart(item) {
  122. this.$refs.AddCartPopup.handle(item)
  123. },
  124. // 更新购物车角标
  125. onAddCart(total) {
  126. setCartTabBadge()
  127. }
  128. }
  129. }
  130. </script>
  131. <style lang="scss" scoped>
  132. .diy-goods {
  133. // 解决 margin-bottom: -10px 导致的容器异常
  134. display: flex;
  135. flex-direction: column;
  136. // overflow: hidden; // 会导致横向无法滑动
  137. .goods-list {
  138. margin-bottom: -10px;
  139. // 横向滑动
  140. &.display-slide {
  141. display: flex;
  142. width: max-content;
  143. .goods-item {
  144. flex-shrink: 1;
  145. margin-right: 20rpx !important;
  146. &:last-child {
  147. margin-right: 0 !important;
  148. }
  149. }
  150. // 双列
  151. &.column-2 {
  152. .goods-item {
  153. width: 160px;
  154. }
  155. }
  156. // 3列
  157. &.column-3 {
  158. .goods-item {
  159. width: 220px;
  160. }
  161. }
  162. }
  163. // 列表平铺
  164. &.display-list {
  165. display: flex;
  166. flex-wrap: wrap;
  167. }
  168. // 单列
  169. &.column-1 {
  170. margin-bottom: 0;
  171. .goods-item {
  172. margin-bottom: 12rpx;
  173. padding: 20rpx;
  174. box-sizing: border-box;
  175. background: #fff;
  176. flex-basis: 100%;
  177. margin-right: 0;
  178. &:last-child {
  179. margin-bottom: 0 !important;
  180. }
  181. .goods-info {
  182. padding: 0;
  183. .footer {
  184. position: absolute;
  185. bottom: 16rpx;
  186. width: 100%;
  187. }
  188. }
  189. }
  190. // 商品图片
  191. .goods-item-left {
  192. background: #fff;
  193. margin-right: 20rpx;
  194. .image {
  195. display: block;
  196. width: 240rpx;
  197. height: 240rpx;
  198. }
  199. }
  200. .goods-item-right {
  201. position: relative;
  202. flex: 1;
  203. width: 0; // 解决文字超出无法隐藏
  204. }
  205. }
  206. // 2列
  207. &.column-2 {
  208. .goods-item {
  209. flex-basis: 48.6%;
  210. &:nth-child(2n) {
  211. margin-right: 0;
  212. }
  213. }
  214. }
  215. // 3列
  216. &.column-3 {
  217. .goods-item {
  218. flex-basis: 31.46666%;
  219. &:nth-child(3n) {
  220. margin-right: 0;
  221. }
  222. }
  223. .goods-name {
  224. font-size: 26rpx !important;
  225. }
  226. }
  227. // 商品内容
  228. .goods-item {
  229. flex-shrink: 0;
  230. background-color: #fff;
  231. flex: 0 1 48.6%;
  232. margin-right: 2.8%;
  233. border-radius: 16rpx;
  234. overflow: hidden;
  235. margin-bottom: 20rpx;
  236. &.display-card {
  237. box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.07);
  238. }
  239. .goods-image {
  240. position: relative;
  241. width: 100%;
  242. height: 0;
  243. padding-bottom: 100%;
  244. overflow: hidden;
  245. &:after {
  246. content: '';
  247. display: block;
  248. margin-top: 100%;
  249. }
  250. .image {
  251. position: absolute;
  252. top: 0;
  253. left: 0;
  254. display: block;
  255. width: 100%;
  256. height: 100%;
  257. object-fit: cover;
  258. }
  259. }
  260. .goods-info {
  261. padding: 20rpx;
  262. .goods-name {
  263. font-size: 27rpx;
  264. color: #000;
  265. margin-bottom: 8rpx;
  266. // line-height: 1.3; // 用户端
  267. &.row-two {
  268. // min-height: 68rpx; // 用户端
  269. }
  270. }
  271. .goods-selling {
  272. display: flex; // 解决文字超出无法隐藏
  273. font-size: 24rpx;
  274. margin-bottom: 8rpx;
  275. min-height: 38rpx;
  276. }
  277. .goods-sales {
  278. font-size: 24rpx;
  279. color: #959595;
  280. margin-bottom: 8rpx;
  281. .line {
  282. margin: 0 8rpx;
  283. }
  284. }
  285. }
  286. .footer {
  287. display: flex;
  288. justify-content: space-between;
  289. align-items: center;
  290. .goods-price {
  291. position: relative;
  292. color: #ff1051;
  293. .unit {
  294. font-size: 20rpx;
  295. }
  296. .value {
  297. font-size: 30rpx;
  298. }
  299. .unit2 {
  300. margin-left: 4rpx;
  301. font-size: 22rpx;
  302. }
  303. .line-price {
  304. margin-left: 6rpx;
  305. color: #959595;
  306. .unit {
  307. text-decoration: line-through;
  308. font-size: 22rpx;
  309. }
  310. .value {
  311. text-decoration: line-through;
  312. font-size: 22rpx;
  313. }
  314. }
  315. }
  316. .action {
  317. .btn-cart {
  318. text-align: center;
  319. .cart-icon {
  320. font-size: 36rpx;
  321. }
  322. }
  323. }
  324. }
  325. }
  326. }
  327. }
  328. </style>