commodityList.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <template>
  2. <view class="container commodity-list-wrapper" :style="{'overflow':(showSkeleton? 'hidden' : 'auto'),'height': (showSkeleton? windowHeight + 'px' : 'auto')}">
  3. <list-skeleton v-if="showSkeleton" :listType='0'></list-skeleton>
  4. <scroll-view :style="{'height':scrollHeight+'px'}" @scrolltolower="toLower" scroll-y v-if="commodityList.length > 0">
  5. <view v-for="(item,index) in commodityList" :key="index" :id="item.id" class="all-type-list-content commodity-list" @click.stop="navToDetailPage(item.productID)">
  6. <image mode='widthFix' :src="item.mainImage" class="list-img" alt="list-img"></image>
  7. <view class="list-details-info">
  8. <text class="list-details-title">{{item.name}}</text>
  9. <text class="list-details-specs">规格:{{item.unit}}</text>
  10. <text class="list-details-miniQuantity" v-if="fromRegularPurchasePage">起订量:{{item.minBuyNumber}}</text>
  11. <view class="list-details-price">
  12. <view v-if="!hasLogin" class="list-login-now">
  13. <text class="p-no">价格:</text>
  14. <uni-stars :stars="parseInt(item.price1Grade)" :font-size='36' :width-info="180"></uni-stars>
  15. </view>
  16. <view class="list-price" v-else>
  17. <text>¥<text class="price-larger">{{item.retailPrice.toFixed(2)}}</text></text>
  18. </view>
  19. <button v-if="fromRegularPurchasePage" class="add-cart-btn" @click.stop="operationHanld(item)">选择数量</button>
  20. </view>
  21. </view>
  22. </view>
  23. <button class="show-more-btn" v-if="showRegularBtn" @click="getListFromServer(true)">查看更多</button>
  24. <view v-if="showLoading && commodityList.length > 4 && !showRegularBtn">
  25. <view class="loading-wrapper loading-wrapper-now" v-if="loadingNow">{{loadingText}}<text v-if="loadingText === '已至底部'">‧ ‧ ‧</text></view>
  26. <view class="loading-wrapper loading-wrapper-btm" v-else>———<text class="btm-text">已至底部</text>———</view>
  27. </view>
  28. </scroll-view>
  29. <view class="cart-icon" v-if="fromRegularPurchasePage" @click="toCartPage">
  30. <text v-if="cartNum > 0" class="uni-badge uni-badge-error uni-small uni-badge--small icon-num">
  31. {{cartNum}}
  32. </text>
  33. <image src='../../../static/icon-cart-active@3x.png' mode="widthFix"></image>
  34. </view>
  35. <view class="empty-container" v-if="showEmpty && !fromRegularPurchasePage">
  36. <image class="empty-container-image" src="https://img.caimei365.com/group1/M00/03/71/Cmis2F3wna6AY2ZjAABpmnBICH4247.png"></image>
  37. <text class="error-text">{{emptyText}}</text>
  38. </view>
  39. <view class="empty-container" v-if="showEmpty && fromRegularPurchasePage">
  40. <image class="empty-container-image" src="https://img.caimei365.com/group1/M00/03/71/Cmis2F3wna6AWdWzAAGlgAP0das422.png" mode="aspectFit"></image>
  41. <text class="error-text">您还没有购买过任何商品哟~</text>
  42. <button class="submit-btn toIndexPage" @click="toIndexPage">去逛逛</button>
  43. </view>
  44. <!-- 透明模态层 -->
  45. <modal-layer v-if='isModallayer'></modal-layer>
  46. </view>
  47. </template>
  48. <script>
  49. import listSkeleton from '@/components/module/listTemplate/listSkeleton'
  50. import modalLayer from "@/components/modal-layer"
  51. import uniStars from '@/components/uni-stars/uni-stars.vue'
  52. import { queryGoodslist } from "@/api/product.js"
  53. import { mapState,mapMutations } from 'vuex';
  54. export default{
  55. name:'CommodityList',
  56. components:{
  57. listSkeleton,
  58. modalLayer,
  59. uniStars
  60. },
  61. props: {
  62. emptyText: {
  63. type: String
  64. },
  65. },
  66. data(){
  67. return{
  68. isModallayer:false,
  69. windowHeight: '',
  70. showSkeleton: true,
  71. showEmpty: false,
  72. userID: '',
  73. scrollHeight: '',
  74. commodityList: [],
  75. showLoading: false,
  76. loadingNow: true,
  77. loadingText: '上拉加载更多',
  78. pageSize: 10,
  79. pageNum: 1,
  80. hasNextPage: false,
  81. totalPage: 1,
  82. pullFlag: true,
  83. fromRegularPurchasePage: false,
  84. cartNum: 0,
  85. showRegularBtn: false
  86. }
  87. },
  88. created() {
  89. let self = this;
  90. self.$api.getStorage().then((resolve) =>{
  91. self.userID = resolve.userID
  92. })
  93. self.setScrollHeight();
  94. },
  95. computed: {
  96. ...mapState(['hasLogin','userInfo'])
  97. },
  98. methods:{
  99. toLoginPage() {
  100. const {lastPageType, lastPageVal} = this.$parent;
  101. uni.navigateTo({
  102. url:`/pages/user-module/login-accont?listType=${lastPageType}&listVal=${lastPageVal}`
  103. })
  104. },
  105. toLower() {
  106. // 第一次加载排除常用商品
  107. if(!this.showRegularBtn) {
  108. if(this.hasNextPage && this.pullFlag) {
  109. this.getListFromServer(true);
  110. }
  111. }
  112. },
  113. setScrollHeight() {
  114. const {windowHeight, pixelRatio} = wx.getSystemInfoSync();
  115. this.windowHeight = windowHeight - 1;
  116. this.scrollHeight = windowHeight - 1;
  117. },
  118. getListFromServer(loadMore) {
  119. let self = this;
  120. const thisServerurl = self.$parent.serverUrl;
  121. self.showLoading = true;
  122. self.loadingNow = true;
  123. self.loadingText = '加载中';
  124. if(loadMore) {
  125. self.pageNum += 1;
  126. }
  127. if(self.$parent.lastPageType === '再次购买') {
  128. self.fromRegularPurchasePage = true;
  129. }
  130. queryGoodslist(thisServerurl,{userID:this.userID,pageNum:self.pageNum,pageSize:self.pageSize}).then(response=>{
  131. const resData = self.fromRegularPurchasePage ?response.data.page :response.data;
  132. const resList = resData.results,
  133. getCartNum = response.data.count;
  134. this.cartNum = getCartNum > 99 ?'99+' :getCartNum;
  135. if(!loadMore && self.fromRegularPurchasePage && resData.hasNextPage) {
  136. self.showRegularBtn = true;
  137. }
  138. if(resList && resList.length > 0){
  139. self.hasNextPage = resData.hasNextPage;
  140. self.totalPage = resData.totalPage;
  141. if(loadMore) {
  142. self.commodityList = [...self.commodityList,...resList];
  143. self.showRegularBtn = false;
  144. } else {
  145. self.commodityList = [...resList];
  146. self.showSkeleton = false;
  147. }
  148. // 防上拉暴滑
  149. self.pullFlag = false;
  150. setTimeout(()=>{
  151. self.pullFlag = true;
  152. },500)
  153. // 底部提示文案
  154. if(self.hasNextPage) {
  155. self.loadingText = '上拉加载更多';
  156. } else {
  157. self.showLoading = true;
  158. self.loadingNow = false;
  159. }
  160. } else {
  161. if(!loadMore) {
  162. self.showEmpty = true;
  163. }
  164. }
  165. }).catch(response =>{
  166. this.$util.msg(response.msg,3000);
  167. })
  168. },
  169. operationHanld(prop){
  170. this.$emit('operationConfim',prop)
  171. },
  172. navToDetailPage(id) {
  173. this.isModallayer = true;
  174. this.$api.navigateTo(`/pages/goods/product?id=${id}`);
  175. this.isModallayer = false;
  176. },
  177. toCartPage() {
  178. uni.switchTab({
  179. url: '/pages/tabBar/cart/cart'
  180. })
  181. },
  182. toIndexPage() {
  183. uni.switchTab({
  184. url: '/pages/tabBar/home/home'
  185. })
  186. }
  187. }
  188. }
  189. </script>
  190. <style lang="scss">
  191. .commodity-list-wrapper {
  192. scroll-view {
  193. height: 100%;
  194. border-top: 2rpx solid rgba(0,0,0,0.07);
  195. }
  196. .empty-container-image {
  197. margin-top: -300rpx;
  198. }
  199. .toIndexPage {
  200. bottom: 390rpx;
  201. }
  202. .show-more-btn {
  203. width: 276rpx;
  204. height: 52rpx;
  205. line-height: 52rpx;
  206. border: 2rpx solid #D8D8D8;
  207. background: #F7F7F7;
  208. font-size: 26rpx;
  209. margin: 26rpx 0;
  210. position: absolute;
  211. left: 50%;
  212. margin-left: -138rpx;
  213. }
  214. }
  215. .all-type-list-content {
  216. height: 216rpx;
  217. padding: 24rpx;
  218. background: #fff;
  219. margin-bottom: 2rpx;
  220. display: flex;
  221. flex-direction: row;
  222. box-sizing: content-box;
  223. .list-img {
  224. width: 210rpx;
  225. height: 218rpx !important;
  226. margin-right: 26rpx;
  227. border-radius: 10rpx;
  228. border: 2rpx solid #f3f3f3;
  229. }
  230. }
  231. .list-details-info {
  232. width: 466rpx;
  233. display: flex;
  234. flex-direction: column;
  235. font-size: 26rpx;
  236. position: relative;
  237. .list-details-title {
  238. line-height: 38rpx;
  239. text-overflow: ellipsis;
  240. overflow: hidden;
  241. display: -webkit-box;
  242. -webkit-line-clamp: 2;
  243. line-clamp: 2;
  244. -webkit-box-orient: vertical;
  245. }
  246. .list-details-specs {
  247. margin-top: 8rpx;
  248. color: #999999;
  249. }
  250. .list-details-miniQuantity {
  251. margin-top: 7rpx;
  252. }
  253. }
  254. .list-details-price {
  255. width: 100%;
  256. display: flex;
  257. flex-direction: row;
  258. justify-content: space-between;
  259. position: absolute;
  260. bottom: 0;
  261. right: 0;
  262. .price-icon {
  263. width: 22rpx;
  264. height: 28rpx;
  265. vertical-align: middle;
  266. margin-right: 10rpx;
  267. }
  268. .price-icon + text {
  269. font-size: 25rpx;
  270. vertical-align: middle;
  271. }
  272. .list-login-now {
  273. width: 375rpx;
  274. color: #F8C499;
  275. position: absolute;
  276. bottom: 0;
  277. .p-no{
  278. float: left;
  279. font-size: $font-size-24;
  280. color: $color-system;
  281. margin-right: 10rpx;
  282. }
  283. }
  284. .login-now {
  285. padding: 10rpx 10rpx 10rpx 0;
  286. }
  287. .list-price {
  288. color: #FF2A2A;
  289. .price-larger {
  290. font-size: 32rpx;
  291. }
  292. }
  293. .add-cart-btn {
  294. width: 156rpx;
  295. height: 64rpx;
  296. line-height: 64rpx;
  297. border-radius: 32rpx;
  298. color: #fff;
  299. font-size: 26rpx;
  300. margin-right: 0;
  301. background:linear-gradient(45deg,rgba(255,41,41,1) 0%,rgba(255,109,27,1) 100%);
  302. }
  303. }
  304. .cart-icon {
  305. width: 92rpx;
  306. height: 92rpx;
  307. border-radius: 50%;
  308. background: rgba(255, 147, 0, 0.5);
  309. position: fixed;
  310. right: 24rpx;
  311. bottom: 30%;
  312. display: flex;
  313. align-items: center;
  314. justify-content: center;
  315. cursor: pointer;
  316. image {
  317. width: 58rpx;
  318. height: 58rpx;
  319. }
  320. text {
  321. font-size: 28rpx;
  322. position: absolute;
  323. top: -10rpx;
  324. right: 0;
  325. }
  326. }
  327. </style>