index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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)" 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)" 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. this.$navTo(`pages/goods/detail`, { goodsId })
  117. },
  118. // 点击加入购物车
  119. handleAddCart(item) {
  120. this.$refs.AddCartPopup.handle(item)
  121. },
  122. // 更新购物车角标
  123. onAddCart(total) {
  124. setCartTabBadge()
  125. }
  126. }
  127. }
  128. </script>
  129. <style lang="scss" scoped>
  130. .diy-goods {
  131. // 解决 margin-bottom: -10px 导致的容器异常
  132. display: flex;
  133. flex-direction: column;
  134. // overflow: hidden; // 会导致横向无法滑动
  135. .goods-list {
  136. margin-bottom: -10px;
  137. // 横向滑动
  138. &.display-slide {
  139. display: flex;
  140. width: max-content;
  141. .goods-item {
  142. flex-shrink: 1;
  143. margin-right: 20rpx !important;
  144. &:last-child {
  145. margin-right: 0 !important;
  146. }
  147. }
  148. // 双列
  149. &.column-2 {
  150. .goods-item {
  151. width: 160px;
  152. }
  153. }
  154. // 3列
  155. &.column-3 {
  156. .goods-item {
  157. width: 220px;
  158. }
  159. }
  160. }
  161. // 列表平铺
  162. &.display-list {
  163. display: flex;
  164. flex-wrap: wrap;
  165. }
  166. // 单列
  167. &.column-1 {
  168. margin-bottom: 0;
  169. .goods-item {
  170. margin-bottom: 12rpx;
  171. padding: 20rpx;
  172. box-sizing: border-box;
  173. background: #fff;
  174. flex-basis: 100%;
  175. margin-right: 0;
  176. &:last-child {
  177. margin-bottom: 0 !important;
  178. }
  179. .goods-info {
  180. padding: 0;
  181. .goods-name {
  182. font-size: 27rpx;
  183. }
  184. .footer {
  185. position: absolute;
  186. bottom: 16rpx;
  187. width: 100%;
  188. }
  189. }
  190. }
  191. // 商品图片
  192. .goods-item-left {
  193. background: #fff;
  194. margin-right: 20rpx;
  195. .image {
  196. display: block;
  197. width: 240rpx;
  198. height: 240rpx;
  199. }
  200. }
  201. .goods-item-right {
  202. position: relative;
  203. flex: 1;
  204. width: 0; // 解决文字超出无法隐藏
  205. }
  206. }
  207. // 2列
  208. &.column-2 {
  209. .goods-item {
  210. flex-basis: 48.6%;
  211. &:nth-child(2n) {
  212. margin-right: 0;
  213. }
  214. }
  215. }
  216. // 3列
  217. &.column-3 {
  218. .goods-item {
  219. flex-basis: 31.46666%;
  220. &:nth-child(3n) {
  221. margin-right: 0;
  222. }
  223. }
  224. }
  225. // 商品内容
  226. .goods-item {
  227. flex-shrink: 0;
  228. background-color: #fff;
  229. flex: 0 1 48.6%;
  230. margin-right: 2.8%;
  231. border-radius: 16rpx;
  232. overflow: hidden;
  233. margin-bottom: 20rpx;
  234. &.display-card {
  235. box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.07);
  236. }
  237. .goods-image {
  238. position: relative;
  239. width: 100%;
  240. height: 0;
  241. padding-bottom: 100%;
  242. overflow: hidden;
  243. &:after {
  244. content: '';
  245. display: block;
  246. margin-top: 100%;
  247. }
  248. .image {
  249. position: absolute;
  250. top: 0;
  251. left: 0;
  252. display: block;
  253. width: 100%;
  254. height: 100%;
  255. object-fit: cover;
  256. }
  257. }
  258. .goods-info {
  259. padding: 20rpx;
  260. .goods-name {
  261. font-size: 26rpx;
  262. color: #000;
  263. margin-bottom: 8rpx;
  264. line-height: 1.3; // 用户端
  265. &.row-two {
  266. min-height: 68rpx; // 用户端
  267. }
  268. }
  269. .goods-selling {
  270. display: flex; // 解决文字超出无法隐藏
  271. font-size: 24rpx;
  272. margin-bottom: 8rpx;
  273. height: 38rpx;
  274. }
  275. .goods-sales {
  276. font-size: 24rpx;
  277. color: #959595;
  278. margin-bottom: 8rpx;
  279. .line {
  280. margin: 0 8rpx;
  281. }
  282. }
  283. }
  284. .footer {
  285. display: flex;
  286. justify-content: space-between;
  287. align-items: center;
  288. .goods-price {
  289. position: relative;
  290. color: #ff1051;
  291. .unit {
  292. font-size: 20rpx;
  293. }
  294. .value {
  295. font-size: 30rpx;
  296. }
  297. .unit2 {
  298. margin-left: 4rpx;
  299. font-size: 22rpx;
  300. }
  301. .line-price {
  302. margin-left: 6rpx;
  303. color: #959595;
  304. .unit {
  305. text-decoration: line-through;
  306. font-size: 22rpx;
  307. }
  308. .value {
  309. text-decoration: line-through;
  310. font-size: 22rpx;
  311. }
  312. }
  313. }
  314. .action {
  315. .btn-cart {
  316. text-align: center;
  317. .cart-icon {
  318. font-size: 36rpx;
  319. }
  320. }
  321. }
  322. }
  323. }
  324. }
  325. }
  326. </style>