commodityList.vue 8.9 KB

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