commodityList.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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="!loginStatus" 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. loginStatus: true,
  71. scrollHeight: '',
  72. commodityList: [],
  73. showLoading: false,
  74. loadingNow: true,
  75. loadingText: '上拉加载更多',
  76. pageSize: 10,
  77. pageNum: 1,
  78. hasNextPage: false,
  79. totalPage: 1,
  80. pullFlag: true,
  81. fromRegularPurchasePage: false,
  82. cartNum: 0,
  83. showRegularBtn: false
  84. }
  85. },
  86. created() {
  87. let self = this;
  88. self.$api.getStorage().then((resolve) =>{
  89. self.userID = resolve.userID
  90. })
  91. self.setScrollHeight();
  92. if(!this.hasLogin){
  93. self.loginStatus = false;
  94. }
  95. },
  96. computed: {
  97. ...mapState(['hasLogin','userInfo'])
  98. },
  99. methods:{
  100. toLoginPage() {
  101. const {lastPageType, lastPageVal} = this.$parent;
  102. uni.navigateTo({
  103. url:`/pages/user-module/login-accont?listType=${lastPageType}&listVal=${lastPageVal}`
  104. })
  105. },
  106. toLower() {
  107. // 第一次加载排除常用商品
  108. if(!this.showRegularBtn) {
  109. if(this.hasNextPage && this.pullFlag) {
  110. this.getListFromServer(true);
  111. }
  112. }
  113. },
  114. setScrollHeight() {
  115. const {windowHeight, pixelRatio} = wx.getSystemInfoSync();
  116. this.windowHeight = windowHeight - 1;
  117. this.scrollHeight = windowHeight - 1;
  118. },
  119. getListFromServer(loadMore) {
  120. let self = this;
  121. const thisServerurl = self.$parent.serverUrl;
  122. self.showLoading = true;
  123. self.loadingNow = true;
  124. self.loadingText = '加载中';
  125. if(loadMore) {
  126. self.pageNum += 1;
  127. }
  128. if(self.$parent.lastPageType === '再次购买') {
  129. self.fromRegularPurchasePage = true;
  130. }
  131. queryGoodslist(thisServerurl,{index:self.pageNum,pageSize:self.pageSize}).then(response=>{
  132. const resData = self.fromRegularPurchasePage ?response.data.page :response.data;
  133. const resList = resData.results,
  134. getCartNum = response.data.count;
  135. this.cartNum = getCartNum > 99 ?'99+' :getCartNum;
  136. if(!loadMore && self.fromRegularPurchasePage && resData.hasNextPage) {
  137. self.showRegularBtn = true;
  138. }
  139. if(resList && resList.length > 0){
  140. self.hasNextPage = resData.hasNextPage;
  141. self.totalPage = resData.totalPage;
  142. if(loadMore) {
  143. self.commodityList = [...self.commodityList,...resList];
  144. self.showRegularBtn = false;
  145. } else {
  146. self.commodityList = [...resList];
  147. self.showSkeleton = false;
  148. }
  149. // 防上拉暴滑
  150. self.pullFlag = false;
  151. setTimeout(()=>{
  152. self.pullFlag = true;
  153. },500)
  154. // 底部提示文案
  155. if(self.hasNextPage) {
  156. self.loadingText = '上拉加载更多';
  157. } else {
  158. self.showLoading = true;
  159. self.loadingNow = false;
  160. }
  161. } else {
  162. if(!loadMore) {
  163. self.showEmpty = true;
  164. }
  165. }
  166. }).catch(response =>{
  167. this.$util.msg(response.msg,3000);
  168. })
  169. },
  170. operationHanld(prop){
  171. this.$emit('operationConfim',prop)
  172. },
  173. navToDetailPage(id) {
  174. this.isModallayer = true;
  175. this.$api.navigateTo(`/pages/goods/product?id=${id}`);
  176. this.isModallayer = false;
  177. },
  178. toCartPage() {
  179. uni.switchTab({
  180. url: '/pages/tabBar/cart/cart'
  181. })
  182. },
  183. toIndexPage() {
  184. uni.switchTab({
  185. url: '/pages/tabBar/home/home'
  186. })
  187. }
  188. }
  189. }
  190. </script>
  191. <style lang="scss">
  192. .commodity-list-wrapper {
  193. scroll-view {
  194. height: 100%;
  195. border-top: 2rpx solid rgba(0,0,0,0.07);
  196. }
  197. .empty-container-image {
  198. margin-top: -300rpx;
  199. }
  200. .toIndexPage {
  201. bottom: 390rpx;
  202. }
  203. .show-more-btn {
  204. width: 276rpx;
  205. height: 52rpx;
  206. line-height: 52rpx;
  207. border: 2rpx solid #D8D8D8;
  208. background: #F7F7F7;
  209. font-size: 26rpx;
  210. margin: 26rpx 0;
  211. position: absolute;
  212. left: 50%;
  213. margin-left: -138rpx;
  214. }
  215. }
  216. .all-type-list-content {
  217. height: 216rpx;
  218. padding: 24rpx;
  219. background: #fff;
  220. margin-bottom: 2rpx;
  221. display: flex;
  222. flex-direction: row;
  223. box-sizing: content-box;
  224. .list-img {
  225. width: 210rpx;
  226. height: 218rpx !important;
  227. margin-right: 26rpx;
  228. border-radius: 10rpx;
  229. border: 2rpx solid #f3f3f3;
  230. }
  231. }
  232. .list-details-info {
  233. width: 466rpx;
  234. display: flex;
  235. flex-direction: column;
  236. font-size: 26rpx;
  237. position: relative;
  238. .list-details-title {
  239. line-height: 38rpx;
  240. text-overflow: ellipsis;
  241. overflow: hidden;
  242. display: -webkit-box;
  243. -webkit-line-clamp: 2;
  244. line-clamp: 2;
  245. -webkit-box-orient: vertical;
  246. }
  247. .list-details-specs {
  248. margin-top: 8rpx;
  249. color: #999999;
  250. }
  251. .list-details-miniQuantity {
  252. margin-top: 7rpx;
  253. }
  254. }
  255. .list-details-price {
  256. width: 100%;
  257. display: flex;
  258. flex-direction: row;
  259. justify-content: space-between;
  260. position: absolute;
  261. bottom: 0;
  262. right: 0;
  263. .price-icon {
  264. width: 22rpx;
  265. height: 28rpx;
  266. vertical-align: middle;
  267. margin-right: 10rpx;
  268. }
  269. .price-icon + text {
  270. font-size: 25rpx;
  271. vertical-align: middle;
  272. }
  273. .list-login-now {
  274. color: #F8C499;
  275. position: absolute;
  276. bottom: 0;
  277. }
  278. .login-now {
  279. padding: 10rpx 10rpx 10rpx 0;
  280. }
  281. .list-price {
  282. color: #FF2A2A;
  283. .price-larger {
  284. font-size: 32rpx;
  285. }
  286. }
  287. .add-cart-btn {
  288. width: 156rpx;
  289. height: 64rpx;
  290. line-height: 64rpx;
  291. border-radius: 32rpx;
  292. color: #fff;
  293. font-size: 26rpx;
  294. margin-right: 0;
  295. background:linear-gradient(45deg,rgba(255,41,41,1) 0%,rgba(255,109,27,1) 100%);
  296. }
  297. }
  298. .cart-icon {
  299. width: 92rpx;
  300. height: 92rpx;
  301. border-radius: 50%;
  302. background: rgba(255, 147, 0, 0.5);
  303. position: fixed;
  304. right: 24rpx;
  305. bottom: 30%;
  306. display: flex;
  307. align-items: center;
  308. justify-content: center;
  309. cursor: pointer;
  310. image {
  311. width: 58rpx;
  312. height: 58rpx;
  313. }
  314. text {
  315. font-size: 28rpx;
  316. position: absolute;
  317. top: -10rpx;
  318. right: 0;
  319. }
  320. }
  321. </style>