commodityList.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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.id)">
  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="addCartNow(item.id, item.minBuyNumber)">加入购物车</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. export default{
  51. name:'CommodityList',
  52. components:{
  53. listSkeleton,
  54. modalLayer
  55. },
  56. props: {
  57. emptyText: {
  58. type: String
  59. },
  60. },
  61. data(){
  62. return{
  63. isModallayer:false,
  64. windowHeight: '',
  65. showSkeleton: true,
  66. showEmpty: false,
  67. userID: '',
  68. loginStatus: true,
  69. scrollHeight: '',
  70. commodityList: [],
  71. showLoading: false,
  72. loadingNow: true,
  73. loadingText: '上拉加载更多',
  74. pageSize: 10,
  75. pageNum: 1,
  76. hasNextPage: false,
  77. totalPage: 1,
  78. pullFlag: true,
  79. fromRegularPurchasePage: false,
  80. cartNum: 0,
  81. showRegularBtn: false
  82. }
  83. },
  84. created() {
  85. let self = this;
  86. self.$api.getStorage().then((resolve) =>{
  87. self.userID = resolve.userID
  88. })
  89. self.setScrollHeight();
  90. self.$api.loginStatus().then((resolveData) => {
  91. self.loginStatus = resolveData;
  92. });
  93. },
  94. methods:{
  95. toLoginPage() {
  96. const {lastPageType, lastPageVal} = this.$parent;
  97. uni.navigateTo({
  98. url:`/pages/user-module/login?listType=${lastPageType}&listVal=${lastPageVal}`
  99. })
  100. },
  101. toLower() {
  102. // 第一次加载排除常用商品
  103. if(!this.showRegularBtn) {
  104. if(this.hasNextPage && this.pullFlag) {
  105. this.getListFromServer(true);
  106. }
  107. }
  108. },
  109. setScrollHeight() {
  110. const {windowHeight, pixelRatio} = wx.getSystemInfoSync();
  111. this.windowHeight = windowHeight - 1;
  112. this.scrollHeight = windowHeight - 1;
  113. },
  114. getListFromServer(loadMore) {
  115. let self = this;
  116. const thisServerurl = self.$parent.serverUrl;
  117. self.showLoading = true;
  118. self.loadingNow = true;
  119. self.loadingText = '加载中';
  120. if(loadMore) {
  121. self.pageNum += 1;
  122. }
  123. if(self.$parent.lastPageType === '再次购买') {
  124. self.fromRegularPurchasePage = true;
  125. }
  126. self.$api.get(thisServerurl,{index:self.pageNum,pageSize:self.pageSize,
  127. organizeID:self.userOrganizeID},
  128. response => {
  129. const code = response.code;
  130. if(code == 1) {
  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. } else {
  166. this.$util.msg(response.msg,3000);
  167. }
  168. }
  169. )
  170. },
  171. addCartNow(productID, miniQuantity) {
  172. this.$api.post('/details/addCart',
  173. {
  174. productID: productID,
  175. userID: this.userID,
  176. productCount: miniQuantity,
  177. organizeID: this.userOrganizeID
  178. },
  179. response => {
  180. if (response.code == "1") {
  181. this.$util.msg(response.msg,1500,true,'success');
  182. this.cartNum = response.data;
  183. }else{
  184. this.$util.msg(response.msg,2000);
  185. }
  186. }
  187. )
  188. },
  189. navToDetailPage(id) {
  190. this.isModallayer = true;
  191. this.$api.navigateTo(`/pages/goods/product?id=${id}`);
  192. this.isModallayer = false;
  193. },
  194. toCartPage() {
  195. uni.switchTab({
  196. url: '/pages/tabBar/cart/cart'
  197. })
  198. },
  199. toIndexPage() {
  200. uni.switchTab({
  201. url: '/pages/tabBar/home/home'
  202. })
  203. }
  204. }
  205. }
  206. </script>
  207. <style lang="scss">
  208. .commodity-list-wrapper {
  209. scroll-view {
  210. height: 100%;
  211. border-top: 2rpx solid rgba(0,0,0,0.07);
  212. }
  213. .empty-container-image {
  214. margin-top: -300rpx;
  215. }
  216. .toIndexPage {
  217. bottom: 390rpx;
  218. }
  219. .show-more-btn {
  220. width: 276rpx;
  221. height: 52rpx;
  222. line-height: 52rpx;
  223. border: 2rpx solid #D8D8D8;
  224. background: #F7F7F7;
  225. font-size: 26rpx;
  226. margin: 26rpx 0;
  227. position: absolute;
  228. left: 50%;
  229. margin-left: -138rpx;
  230. }
  231. }
  232. .all-type-list-content {
  233. height: 216rpx;
  234. padding: 24rpx;
  235. background: #fff;
  236. margin-bottom: 2rpx;
  237. display: flex;
  238. flex-direction: row;
  239. box-sizing: content-box;
  240. .list-img {
  241. width: 210rpx;
  242. height: 218rpx !important;
  243. margin-right: 26rpx;
  244. border-radius: 10rpx;
  245. border: 2rpx solid #f3f3f3;
  246. }
  247. }
  248. .list-details-info {
  249. width: 466rpx;
  250. display: flex;
  251. flex-direction: column;
  252. font-size: 26rpx;
  253. position: relative;
  254. .list-details-title {
  255. line-height: 38rpx;
  256. text-overflow: ellipsis;
  257. overflow: hidden;
  258. display: -webkit-box;
  259. -webkit-line-clamp: 2;
  260. line-clamp: 2;
  261. -webkit-box-orient: vertical;
  262. }
  263. .list-details-specs {
  264. margin-top: 8rpx;
  265. color: #999999;
  266. }
  267. .list-details-miniQuantity {
  268. margin-top: 7rpx;
  269. }
  270. }
  271. .list-details-price {
  272. width: 100%;
  273. display: flex;
  274. flex-direction: row;
  275. justify-content: space-between;
  276. position: absolute;
  277. bottom: 0;
  278. right: 0;
  279. .price-icon {
  280. width: 22rpx;
  281. height: 28rpx;
  282. vertical-align: middle;
  283. margin-right: 10rpx;
  284. }
  285. .price-icon + text {
  286. font-size: 25rpx;
  287. vertical-align: middle;
  288. }
  289. .list-login-now {
  290. color: #F8C499;
  291. position: absolute;
  292. bottom: 0;
  293. }
  294. .login-now {
  295. padding: 10rpx 10rpx 10rpx 0;
  296. }
  297. .list-price {
  298. color: #FF2A2A;
  299. .price-larger {
  300. font-size: 32rpx;
  301. }
  302. }
  303. .add-cart-btn {
  304. width: 144rpx;
  305. height: 56rpx;
  306. line-height: 56rpx;
  307. color: #fff;
  308. font-size: 24rpx;
  309. margin-right: 0;
  310. background:linear-gradient(45deg,rgba(255,41,41,1) 0%,rgba(255,109,27,1) 100%);
  311. }
  312. }
  313. .cart-icon {
  314. width: 92rpx;
  315. height: 92rpx;
  316. border-radius: 50%;
  317. background: #E2E2E2;
  318. position: fixed;
  319. right: 24rpx;
  320. bottom: 186rpx;
  321. display: flex;
  322. align-items: center;
  323. justify-content: center;
  324. cursor: pointer;
  325. image {
  326. width: 58rpx;
  327. height: 58rpx;
  328. }
  329. text {
  330. font-size: 28rpx;
  331. position: absolute;
  332. top: -10rpx;
  333. right: 0;
  334. }
  335. }
  336. </style>