commodityList.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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="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. 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. operationHanld(prop){
  172. this.$emit('operationConfim',prop)
  173. },
  174. addCartNow(productID, miniQuantity) {
  175. this.$api.post('/details/addCart',
  176. {
  177. productID: productID,
  178. userID: this.userID,
  179. productCount: miniQuantity,
  180. organizeID: this.userOrganizeID
  181. },
  182. response => {
  183. if (response.code == "1") {
  184. this.$util.msg(response.msg,1500,true,'success');
  185. this.cartNum = response.data;
  186. }else{
  187. this.$util.msg(response.msg,2000);
  188. }
  189. }
  190. )
  191. },
  192. navToDetailPage(id) {
  193. this.isModallayer = true;
  194. this.$api.navigateTo(`/pages/goods/product?id=${id}`);
  195. this.isModallayer = false;
  196. },
  197. toCartPage() {
  198. uni.switchTab({
  199. url: '/pages/tabBar/cart/cart'
  200. })
  201. },
  202. toIndexPage() {
  203. uni.switchTab({
  204. url: '/pages/tabBar/home/home'
  205. })
  206. }
  207. }
  208. }
  209. </script>
  210. <style lang="scss">
  211. .commodity-list-wrapper {
  212. scroll-view {
  213. height: 100%;
  214. border-top: 2rpx solid rgba(0,0,0,0.07);
  215. }
  216. .empty-container-image {
  217. margin-top: -300rpx;
  218. }
  219. .toIndexPage {
  220. bottom: 390rpx;
  221. }
  222. .show-more-btn {
  223. width: 276rpx;
  224. height: 52rpx;
  225. line-height: 52rpx;
  226. border: 2rpx solid #D8D8D8;
  227. background: #F7F7F7;
  228. font-size: 26rpx;
  229. margin: 26rpx 0;
  230. position: absolute;
  231. left: 50%;
  232. margin-left: -138rpx;
  233. }
  234. }
  235. .all-type-list-content {
  236. height: 216rpx;
  237. padding: 24rpx;
  238. background: #fff;
  239. margin-bottom: 2rpx;
  240. display: flex;
  241. flex-direction: row;
  242. box-sizing: content-box;
  243. .list-img {
  244. width: 210rpx;
  245. height: 218rpx !important;
  246. margin-right: 26rpx;
  247. border-radius: 10rpx;
  248. border: 2rpx solid #f3f3f3;
  249. }
  250. }
  251. .list-details-info {
  252. width: 466rpx;
  253. display: flex;
  254. flex-direction: column;
  255. font-size: 26rpx;
  256. position: relative;
  257. .list-details-title {
  258. line-height: 38rpx;
  259. text-overflow: ellipsis;
  260. overflow: hidden;
  261. display: -webkit-box;
  262. -webkit-line-clamp: 2;
  263. line-clamp: 2;
  264. -webkit-box-orient: vertical;
  265. }
  266. .list-details-specs {
  267. margin-top: 8rpx;
  268. color: #999999;
  269. }
  270. .list-details-miniQuantity {
  271. margin-top: 7rpx;
  272. }
  273. }
  274. .list-details-price {
  275. width: 100%;
  276. display: flex;
  277. flex-direction: row;
  278. justify-content: space-between;
  279. position: absolute;
  280. bottom: 0;
  281. right: 0;
  282. .price-icon {
  283. width: 22rpx;
  284. height: 28rpx;
  285. vertical-align: middle;
  286. margin-right: 10rpx;
  287. }
  288. .price-icon + text {
  289. font-size: 25rpx;
  290. vertical-align: middle;
  291. }
  292. .list-login-now {
  293. color: #F8C499;
  294. position: absolute;
  295. bottom: 0;
  296. }
  297. .login-now {
  298. padding: 10rpx 10rpx 10rpx 0;
  299. }
  300. .list-price {
  301. color: #FF2A2A;
  302. .price-larger {
  303. font-size: 32rpx;
  304. }
  305. }
  306. .add-cart-btn {
  307. width: 156rpx;
  308. height: 64rpx;
  309. line-height: 64rpx;
  310. border-radius: 32rpx;
  311. color: #fff;
  312. font-size: 26rpx;
  313. margin-right: 0;
  314. background:linear-gradient(45deg,rgba(255,41,41,1) 0%,rgba(255,109,27,1) 100%);
  315. }
  316. }
  317. .cart-icon {
  318. width: 92rpx;
  319. height: 92rpx;
  320. border-radius: 50%;
  321. background: rgba(255, 147, 0, 0.5);
  322. position: fixed;
  323. right: 24rpx;
  324. bottom: 30%;
  325. display: flex;
  326. align-items: center;
  327. justify-content: center;
  328. cursor: pointer;
  329. image {
  330. width: 58rpx;
  331. height: 58rpx;
  332. }
  333. text {
  334. font-size: 28rpx;
  335. position: absolute;
  336. top: -10rpx;
  337. right: 0;
  338. }
  339. }
  340. </style>