jufubao-food 1.0.12-beta8 → 1.0.12-beta9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jufubao-food",
3
- "version": "1.0.12-beta8",
3
+ "version": "1.0.12-beta9",
4
4
  "private": false,
5
5
  "description": "聚福宝业务组件餐饮插件包",
6
6
  "main": "index.js",
@@ -200,6 +200,7 @@
200
200
  prodScrollIntoView: "",
201
201
  prodScrollTop: 0,
202
202
  scrollUpTimer: null,
203
+ scrollTimer: null,
203
204
 
204
205
  scrollBoxHeight: 0, // 商品滚动盒子高度
205
206
  triggerHeight: 100, // 触发加载更多高度
@@ -392,49 +393,81 @@
392
393
  }
393
394
  })
394
395
  },
396
+ getList(options = {}){
397
+ return new Promise((resolve, reject) => {
398
+ jfbRootExec("getFoodProductList", {
399
+ vm: this,
400
+ data: {
401
+ xnamespace: this.xnamespace,
402
+ shop_id: this.shopInfo.shop_id,
403
+ consume_mode: this.consume_mode,
404
+ page_token: options.page_token || 1,
405
+ page_size: this.page_size,
406
+ category_id: options.category_id,
407
+ ...options,
408
+ }
409
+ }).then(res => {
410
+ let productList = res.lists;
411
+ this.categoryList = this.categoryList.map((item, index) => {
412
+ if(item.category_id === options.category_id){
413
+ let prodList = [];
414
+ if(item.productList && item.productList.length){
415
+ prodList = item.productList.concat(productList);
416
+ }else{
417
+ prodList = productList;
418
+ }
419
+ prodList = prodList.map(prod => {
420
+ prod.key = `${item.category_id}_${prod.product_id}`;
421
+ return prod;
422
+ })
423
+ prodList = prodList.reduce((pre, cur) => {
424
+ if(!pre[cur.key]){
425
+ pre[cur.key] = cur;
426
+ }
427
+ return pre;
428
+ }, {});
429
+ item.productList = Object.values(prodList);
430
+ item.total_size = res.total_size;
431
+ item.next_page_token = res.next_page_token;
432
+ }
433
+ return item;
434
+ })
435
+ resolve(res);
436
+ }).catch(err => {
437
+ reject(err);
438
+ })
439
+ })
440
+ },
395
441
  //获取门店商品列表
396
442
  p_getFoodProductList(){
397
443
  let curLoadCate = this.categoryList[this.loadCateIndex];
398
- if(!curLoadCate) return;
444
+ if(!curLoadCate) return Promise.resolve();
399
445
  this.$xdShowLoading({});
400
- jfbRootExec("getFoodProductList", {
401
- vm: this,
402
- data: {
403
- xnamespace: this.xnamespace,
404
- shop_id: this.shopInfo.shop_id,
405
- consume_mode: this.consume_mode,
406
- page_token: curLoadCate.next_page_token || 1,
407
- page_size: this.page_size,
408
- category_id: curLoadCate.category_id,
409
- }
410
- }).then(res => {
411
- // this.productList = res.lists;
412
- this.$xdHideLoading();
413
- let productList = res.lists;
414
- this.categoryList = this.categoryList.map((item, index) => {
415
- if(index === this.loadCateIndex){
416
- if(item.productList && item.productList.length){
417
- item.productList = item.productList.concat(productList);
418
- }else{
419
- item.productList = productList;
420
- }
421
- item.productList = item.productList.map(prod => {
422
- prod.key = `${item.category_id}_${prod.product_id}`;
423
- return prod;
424
- })
425
- item.total_size = res.total_size;
426
- item.next_page_token = res.next_page_token;
446
+ let options = {
447
+ page_token: curLoadCate.next_page_token || 1,
448
+ category_id: curLoadCate.category_id,
449
+ };
450
+ return new Promise((resolve,reject) => {
451
+ this.getList(options).then(async res => {
452
+ this.$xdHideLoading();
453
+ if(res.total_size < 3){
454
+ await this.loadNextCateProduct(this.loadCateIndex)
427
455
  }
428
- return item;
429
- })
430
- this.$nextTick(() => {
431
- this.setCategoryRect();
432
- this.isLoading = false;
456
+ this.$nextTick(() => {
457
+ setTimeout(() => {
458
+ this.setCategoryRect();
459
+ this.isLoading = false;
460
+ }, 300)
461
+ });
462
+ resolve(res);
463
+ }).catch(err => {
464
+ this.$xdHideLoading();
465
+ reject(err);
433
466
  })
434
- console.log(this.categoryList, 'categoryList')
435
467
  })
436
468
  },
437
469
  setCategoryRect(){
470
+ console.log("setCategoryRect")
438
471
  const query = uni.createSelectorQuery().in(this);
439
472
  this.categoryList = this.categoryList.map(cate => {
440
473
  let id = this.getID(cate);
@@ -458,12 +491,16 @@
458
491
  getID(cate) {
459
492
  return `category_${cate.category_id}`;
460
493
  },
461
- switchCate(index){
494
+ async switchCate(index){
462
495
  this.pointerScroll = false;
463
496
  this.cateIndex = index;
464
497
  this.loadCateIndex = index;
465
498
  let curCate = this.categoryList[this.cateIndex];
466
499
  this.prodScrollIntoView = this.getID(curCate);
500
+ //是否最后一个分类
501
+ if(this.cateIndex === this.categoryList.length - 1){
502
+ await this.loadPreCateProduct(index);
503
+ }
467
504
  if(curCate.productList && curCate.productList.length===0){
468
505
  this.p_getFoodProductList();
469
506
  }
@@ -488,8 +525,23 @@
488
525
  this.handleCurCate(e);
489
526
  }
490
527
  this.lastScrollTop = scrollTop;
491
-
528
+
529
+ //滚动结束后,触发纠错机制
530
+ if(this.scrollTimer) clearTimeout(this.scrollTimer);
531
+ this.scrollTimer = setTimeout(() => {
532
+ this.getProductIsEmpty();
533
+ }, 200)
492
534
  },
535
+ //滚动过快,当前项未加载
536
+ getProductIsEmpty(){
537
+ let curCate = this.categoryList[this.cateIndex];
538
+ if(!curCate) return;
539
+ if(curCate.productList && curCate.productList.length===0){
540
+ console.log("当前分类商品列表为空,重新加载数据");
541
+ this.switchCate(this.cateIndex);
542
+ }
543
+ },
544
+
493
545
  productBoxScrollUp(e){
494
546
  let scrollTop = e.detail.scrollTop
495
547
  let curIndex = this.categoryList.findIndex(item => {
@@ -545,10 +597,11 @@
545
597
  this.isLoading = true;
546
598
  //判断是否需要加载更多, 继续加载当前分类,还是加载下一个分类
547
599
  if(curCate.productList && curCate.productList.length < curCate.total_size){
600
+ console.log("继续加载当前分类商品 categoryList")
548
601
  this.loadCateIndex = curIndex;
549
602
  this.p_getFoodProductList();
550
603
  }else{
551
- // console.log("加载下一个分类商品 categoryList")
604
+ console.log("加载下一个分类商品 categoryList")
552
605
  this.loadCateIndex = curIndex + 1;
553
606
  let nextCate = this.categoryList[this.loadCateIndex];
554
607
  if(nextCate && nextCate.productList && nextCate.productList.length < nextCate.total_size){
@@ -560,6 +613,46 @@
560
613
  return;
561
614
  }
562
615
  },
616
+ loadPreCateProduct(curCateIndex){
617
+ let preCateIndex = curCateIndex - 1;
618
+ let preCate = this.categoryList[preCateIndex];
619
+ if(!preCate) return Promise.resolve();
620
+ if(preCate.productList && preCate.productList.length === 0){
621
+ let options = {
622
+ page_token: 1,
623
+ category_id: preCate.category_id,
624
+ }
625
+ return new Promise((resolve, reject) => {
626
+ this.getList(options).then(async res => {
627
+ if(res.lists.length < 3 ) {
628
+ await this.loadPreCateProduct(preCateIndex)
629
+ }
630
+ resolve();
631
+ }).catch(err => {
632
+ reject(err);
633
+ })
634
+ })
635
+ }
636
+ return Promise.resolve();
637
+ },
638
+ loadNextCateProduct(curCateIndex){
639
+ console.log("loadNextCateProduct")
640
+ let nextCateIndex = curCateIndex + 1;
641
+ let nextCate = this.categoryList[nextCateIndex];
642
+ if(!nextCate) return Promise.resolve();
643
+ if(nextCate.productList && nextCate.productList.length === 0){
644
+ let options = {
645
+ page_token: 1,
646
+ category_id: nextCate.category_id,
647
+ }
648
+ this.getList(options).then(async res => {
649
+ if(res.lists.length < 3 ) {
650
+ await this.loadNextCateProduct(nextCateIndex)
651
+ }
652
+ })
653
+ }
654
+ return Promise.resolve();
655
+ },
563
656
 
564
657
  toProductDetail(product){
565
658
  if(product.has_choose){