categoryShow.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <template>
  2. <view class="goodRecommend">
  3. <ProductSkeleton :loading="loading" :is-first="isFirst" />
  4. <template v-if="!isFirst">
  5. <view class="product-list">
  6. <view class="product-list-box">
  7. <view v-for="(item, index) in productList" :key="index" class="product-list-item-warp">
  8. <view class="product-list-item">
  9. <view class="product-list-img" @click="handleJumpProductDetail(item)">
  10. <img v-show="item.image" class="img" :src="item.image">
  11. </view>
  12. <view class="product-list-info u-skeleton-fillet">
  13. <view class="product-name">{{ item.productName }}</view>
  14. <view class="flex">
  15. <view class="shop-box" @click.stop="handleJumpStore(item)">
  16. <view class="shop-name" @click="handleJumpProductDetail(item)">
  17. {{ item.shopName }}
  18. </view>
  19. <view class="shop-logo">
  20. <img :src="item.shopLogo">
  21. </view>
  22. </view>
  23. <view class="buy-count">{{ item.users ? item.users : 0 }}人付款</view>
  24. </view>
  25. <div class="price-warp">
  26. <image class="iconImg" :src="getPriceActivity(item.activityType)" />
  27. <div class="price">
  28. ¥ {{ item.price }}
  29. </div>
  30. <div class="original-price">
  31. ¥ {{ item.originalPrice }}
  32. </div>
  33. </div>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. <!-- 空状态 -->
  40. <Empty
  41. background="#fff" :show="!loading && productList.length < 0"
  42. src="../../static/images/origin/bgnull.png"
  43. >
  44. 这里空空如也
  45. </Empty>
  46. <!-- 底部提示 -->
  47. <ListBottomTips
  48. v-show="loading || total !== 0 && total === productList.length" :loading="loading"
  49. :type="productList.length < total ? 1 : 0"
  50. />
  51. </template>
  52. </view>
  53. </template>
  54. <script>
  55. import Empty from '@/components/Empty'
  56. import ProductSkeleton from './components/ProductSkeleton'
  57. import ListBottomTips from '@/components/ListBottomTips'
  58. const NET = require('@/utils/request')
  59. const API = require('@/config/api')
  60. export default {
  61. name: 'CategoryShow',
  62. components: {
  63. Empty,
  64. ListBottomTips,
  65. ProductSkeleton
  66. },
  67. props: {
  68. classifyId: {
  69. type: Number,
  70. default: 0
  71. }
  72. },
  73. data() {
  74. return {
  75. page: 1,
  76. pageSize: 10,
  77. total: 0,
  78. productList: [],
  79. isFirst: true,
  80. loading: true // 是否正在请求
  81. }
  82. },
  83. computed: {
  84. // 获取活动小图标
  85. getPriceActivity() {
  86. return (activityType) => {
  87. switch (activityType) {
  88. case 1:
  89. return require('../canvasShow/static/images/groupBuyIcon.png')
  90. case 2:
  91. return require('../canvasShow/static/images/spikeIcon.png')
  92. case 3:
  93. return require('../canvasShow/static/images/discountListIcon.png')
  94. case 4:
  95. return require('../canvasShow/static/images/spikeIcon.png')
  96. case 5:
  97. return require('../canvasShow/static/images/discountListIcon.png')
  98. case 8:
  99. return require('../canvasShow/static/images/memberCenterIcon.png')
  100. }
  101. }
  102. }
  103. },
  104. watch: {
  105. 'classifyId': {
  106. handler() {
  107. this.handleResetList()
  108. this.handleResetPage()
  109. this.handleGetProductData()
  110. },
  111. deep: true
  112. }
  113. },
  114. mounted() {
  115. this.handleResetList()
  116. this.handleResetPage()
  117. this.handleGetProductData()
  118. },
  119. methods: {
  120. // 重设苏族
  121. handleResetList() {
  122. uni.pageScrollTo({
  123. scrollTop: 0,
  124. duration: 0
  125. })
  126. this.isFirst = true
  127. this.productList = []
  128. },
  129. handleResetPage() {
  130. this.total = 0
  131. this.page = 1
  132. },
  133. // 获取商品数据
  134. handleGetProductData() {
  135. if (this.total !== 0 && this.productList.length >= this.total) {
  136. return
  137. }
  138. this.loading = true
  139. NET.request(API.getProductsV2, {
  140. classifyId: this.classifyId,
  141. page: this.page,
  142. pageSize: this.pageSize
  143. }, 'GET').then((res) => {
  144. this.productList = [...this.productList, ...res.data.list]
  145. this.total = res.data.total
  146. })
  147. .catch((err) => {
  148. throw Error(err)
  149. })
  150. .finally(() => {
  151. this.loading = false
  152. this.isFirst = false
  153. })
  154. },
  155. // 跳转到店铺主页
  156. handleJumpStore(item) {
  157. uni.navigateTo({
  158. url: `/pages_category_page1/store/index?storeId=${item.shopId}`
  159. })
  160. },
  161. // 跳转到商品详情
  162. handleJumpProductDetail(item) {
  163. uni.navigateTo({
  164. url: '/pages_category_page1/goodsModule/goodsDetails?shopId=' + item.shopId + '&productId=' + item.productId + '&skuId=' + item
  165. .skuId
  166. })
  167. }
  168. }
  169. }
  170. </script>
  171. <style
  172. lang="scss"
  173. scoped
  174. >
  175. .goodRecommend {
  176. padding-top: 20rpx;
  177. .product-list {
  178. position: relative;
  179. padding: 0 13upx;
  180. width: 100%;
  181. //min-height: 60vh;
  182. &-box {
  183. display: flex;
  184. flex-wrap: wrap;
  185. flex-direction: row;
  186. &.swiper {
  187. height: 620upx;
  188. }
  189. }
  190. &.product-swiper .product-list-box {
  191. padding-left: 0;
  192. }
  193. &-item-warp {
  194. margin: 0 0 20upx 0;
  195. }
  196. &-item {
  197. width: 348upx;
  198. padding: 0 7upx;
  199. box-sizing: content-box;
  200. }
  201. &-img {
  202. width: 348upx;
  203. height: 348upx;
  204. background-color: #d0d0d0;
  205. border-radius: 10upx 10upx 0 0;
  206. .img {
  207. width: 100%;
  208. height: 100%;
  209. object-fit: contain;
  210. }
  211. }
  212. &-info {
  213. background-color: #FFFFFF;
  214. //box-shadow: 0px 0px 15px 0px rgba(52, 52, 52, 0.15);
  215. border-radius: 0 0 10upx 10upx;
  216. padding: 20upx;
  217. label {
  218. font-weight: normal;
  219. }
  220. .product-name {
  221. font-size: 28upx;
  222. color: #333;
  223. display: block;
  224. overflow: hidden;
  225. text-overflow: ellipsis;
  226. white-space: nowrap;
  227. margin-bottom: 18upx;
  228. line-height: 40upx;
  229. }
  230. .flex {
  231. display: flex;
  232. align-items: center;
  233. }
  234. .shop-box {
  235. background-color: #333333;
  236. border-radius: 0upx 20upx 20upx 0upx;
  237. line-height: 40upx;
  238. display: flex;
  239. align-items: center;
  240. height: 40upx;
  241. margin-right: 10upx;
  242. float: left;
  243. .shop-name {
  244. font-size: 20upx;
  245. color: #FFEBC4;
  246. padding: 0 8upx 0 12upx;
  247. line-height: 40upx;
  248. display: inline-block;
  249. float: left;
  250. max-width: 170rpx;
  251. white-space: nowrap;
  252. overflow: hidden;
  253. text-overflow: ellipsis;
  254. }
  255. .shop-logo {
  256. border: 2upx solid #707070;
  257. border-radius: 50%;
  258. overflow: hidden;
  259. float: right;
  260. img {
  261. width: 34upx;
  262. height: 34upx;
  263. display: block;
  264. }
  265. }
  266. }
  267. .buy-count {
  268. color: #C5AA7B;
  269. font-size: 20upx;
  270. border: 2upx solid #E4E5E6;
  271. line-height: 36upx;
  272. padding: 0 5upx;
  273. }
  274. .price-warp {
  275. display: flex;
  276. align-items: baseline;
  277. line-height: 56upx;
  278. .iconImg {
  279. width: 58rpx;
  280. height: 36rpx;
  281. margin-right: 10rpx;
  282. }
  283. .price {
  284. color: #C83732;
  285. font-size: 40upx;
  286. margin-right: 20upx;
  287. }
  288. .original-price {
  289. font-size: 24upx;
  290. color: #ccc;
  291. text-decoration: line-through;
  292. }
  293. }
  294. }
  295. }
  296. .emptyCart-box {
  297. margin-top: 70rpx;
  298. .emptyCart-img {
  299. width: 216rpx;
  300. height: 156rpx;
  301. }
  302. }
  303. }
  304. </style>