Commit ecacaa8712e7e7e5dcaffffcf2b3a48ca7722a9d
1 parent
7afe40e3
分类下滑,清空上一个定时器
Showing
2 changed files
with
120 additions
and
93 deletions
packageC/pages/goods/distributionCategoryList/index.js
1 | const { app } = require("../../../../utils/common"); | 1 | const { app } = require("../../../../utils/common"); |
2 | let startY = 0; | 2 | let startY = 0; |
3 | let endY = 0; | 3 | let endY = 0; |
4 | -let scrolltop = 0; | 4 | +let isReachBt = 0; |
5 | let moveDistance = 0; | 5 | let moveDistance = 0; |
6 | const t = getApp(), e = t.request, oo = t.globalData.setting; | 6 | const t = getApp(), e = t.request, oo = t.globalData.setting; |
7 | var i = function (i) { | 7 | var i = function (i) { |
@@ -449,6 +449,9 @@ Page({ | @@ -449,6 +449,9 @@ Page({ | ||
449 | }, | 449 | }, |
450 | 450 | ||
451 | async click_classify(e) { | 451 | async click_classify(e) { |
452 | + | ||
453 | + clearInterval(this.data.timer); | ||
454 | + | ||
452 | let { cid, current } = e.currentTarget.dataset; | 455 | let { cid, current } = e.currentTarget.dataset; |
453 | this.setData({ | 456 | this.setData({ |
454 | select_classify_on: current, | 457 | select_classify_on: current, |
@@ -495,71 +498,87 @@ Page({ | @@ -495,71 +498,87 @@ Page({ | ||
495 | }) | 498 | }) |
496 | } | 499 | } |
497 | }, */ | 500 | }, */ |
498 | - async requestGoodsList() { | ||
499 | - console.log('hanshu'); | ||
500 | - if (this.data.isLoading) return false; | ||
501 | - // if(this.data.is_no_more)return | ||
502 | - if (this.data.is_no_more && this.data.is_up) return false; | 501 | + |
502 | + requestGoodsList() { | ||
503 | + if(this.data.isLoading) return false; | ||
504 | + if(this.data.is_no_more) return false | ||
503 | this.data.isLoading = 1; | 505 | this.data.isLoading = 1; |
506 | + var th=this; | ||
507 | + | ||
504 | let { currentData } = this.data; | 508 | let { currentData } = this.data; |
505 | currentData.cat_id = this.data.cat_id; | 509 | currentData.cat_id = this.data.cat_id; |
506 | currentData.page = this.data.stylePage; | 510 | currentData.page = this.data.stylePage; |
507 | - // console.log(data); | ||
508 | - let url = `/api/weshop/users/distribut/pagemyshop`; | ||
509 | - const { data: res } = await e.promiseGet(url, { | 511 | + |
512 | + let url = '/api/weshop/users/distribut/pagemyshop'; | ||
513 | + getApp().promiseGet(url, { | ||
510 | isShowLoading: true, | 514 | isShowLoading: true, |
511 | data: currentData, | 515 | data: currentData, |
512 | - }); | ||
513 | - console.log(res); | ||
514 | - | ||
515 | - let index = this.getCurrentIndex(); | ||
516 | - let next_classify_name = this.data.catelist[index].name; | ||
517 | - this.setData({ | ||
518 | - isLoading: 0, | ||
519 | - is_no_more: 0, | ||
520 | - is_get: 1, | ||
521 | - select_classify_on: index, | ||
522 | - classify_name: next_classify_name, | ||
523 | - next_classify_name, | ||
524 | - }); | ||
525 | - if (res.code == 0 && res.data.pageData.length > 0) { | ||
526 | - // if(res.data.pageData.length<res.data.pageSize){ | ||
527 | - // this.setData({ | ||
528 | - // is_no_more:1, | ||
529 | - // }) | ||
530 | - // } | ||
531 | - if (res.data.page > 1) { | ||
532 | - this.setData({ | ||
533 | - requestData: this.data.requestData.concat(res.data.pageData), | 516 | + }).then(res=>{ |
517 | + var res=res.data; | ||
518 | + let index = this.getCurrentIndex(); | ||
519 | + let next_classify_name = this.data.catelist[index].name; | ||
520 | + th.setData({ | ||
521 | + isLoading: 0, | ||
522 | + is_get: 1, | ||
523 | + select_classify_on: index, | ||
524 | + classify_name: next_classify_name, | ||
525 | + next_classify_name, | ||
534 | }); | 526 | }); |
535 | - } else { | ||
536 | - this.setData({ | ||
537 | - requestData: res.data.pageData, | ||
538 | - }); | ||
539 | - } | ||
540 | 527 | ||
541 | - } else { | ||
542 | - //上拉加载 | ||
543 | - if (res.data.page > 1) { | ||
544 | - this.setData({ | ||
545 | - is_no_more: 1, | ||
546 | - }) | ||
547 | - } else { | ||
548 | - this.setData({ | ||
549 | - requestData: [], | ||
550 | - }); | ||
551 | - //如果类目为空则3秒后加载下一类目 | ||
552 | - this.data.timer = setInterval(() => { | ||
553 | - this.setData({ | ||
554 | - countDownNum: this.data.countDownNum - 1, | ||
555 | - }); | ||
556 | - if (this.data.countDownNum == 0) { | ||
557 | - clearInterval(this.data.timer); | ||
558 | - this.get_next_cate(index); | ||
559 | - } | ||
560 | - }, 1000); | ||
561 | - } | ||
562 | - } | 528 | + if (res.code == 0 && res.data.pageData.length > 0) { |
529 | + if (res.data.page > 1) { | ||
530 | + th.setData({ | ||
531 | + requestData: th.data.requestData.concat(res.data.pageData), | ||
532 | + }); | ||
533 | + } else { | ||
534 | + th.setData({ | ||
535 | + requestData: res.data.pageData, | ||
536 | + }); | ||
537 | + } | ||
538 | + isReachBt = 0; | ||
539 | + | ||
540 | + if(res.data.pageData.length<10){ | ||
541 | + this.setData({ | ||
542 | + is_no_more: 1, | ||
543 | + }) | ||
544 | + } | ||
545 | + | ||
546 | + } else { | ||
547 | + //上拉加载 | ||
548 | + if (res.data.page > 1) { | ||
549 | + th.setData({ | ||
550 | + is_no_more: 1, | ||
551 | + }) | ||
552 | + } else { | ||
553 | + th.setData({ | ||
554 | + requestData: [], | ||
555 | + }); | ||
556 | + | ||
557 | + //如果类目为空则3秒后加载下一类目 | ||
558 | + if(th.data.timer) { | ||
559 | + th.data.timer=clearInterval(th.data.timer); | ||
560 | + th.data.timer=0; | ||
561 | + } | ||
562 | + th.data.timer = setInterval(() => { | ||
563 | + if(th.data.countDownNum<0){ | ||
564 | + clearInterval(th.data.timer); | ||
565 | + return false; | ||
566 | + } | ||
567 | + | ||
568 | + th.setData({ | ||
569 | + countDownNum: this.data.countDownNum - 1, | ||
570 | + }); | ||
571 | + if (th.data.countDownNum <= 0) { | ||
572 | + clearInterval(th.data.timer); | ||
573 | + th.get_next_cate(index); | ||
574 | + return false; | ||
575 | + } | ||
576 | + }, 1000); | ||
577 | + } | ||
578 | + } | ||
579 | + }) | ||
580 | + | ||
581 | + | ||
563 | }, | 582 | }, |
564 | 583 | ||
565 | //查找当前类目在 catelist的下标 为后面下一个类目使用 | 584 | //查找当前类目在 catelist的下标 为后面下一个类目使用 |
@@ -577,23 +596,22 @@ Page({ | @@ -577,23 +596,22 @@ Page({ | ||
577 | return index; | 596 | return index; |
578 | }, | 597 | }, |
579 | 598 | ||
580 | - | ||
581 | get_next_cate(index) { | 599 | get_next_cate(index) { |
582 | - console.log('get_next_cate'); | 600 | + if(this.data.isLoading) return false; |
583 | index = index + 1; | 601 | index = index + 1; |
584 | let nex_cat_id = this.data.catelist[index].id; | 602 | let nex_cat_id = this.data.catelist[index].id; |
585 | this.setData({ | 603 | this.setData({ |
586 | cat_id: nex_cat_id, | 604 | cat_id: nex_cat_id, |
587 | stylePage: 1, | 605 | stylePage: 1, |
588 | is_get: 0, | 606 | is_get: 0, |
607 | + is_no_more:0, | ||
589 | next_classify_name: this.data.catelist[index].name, | 608 | next_classify_name: this.data.catelist[index].name, |
590 | }); | 609 | }); |
591 | - this.data.is_up = 0; | 610 | + this.data.car_scroll=0; |
611 | + isReachBt = 0; | ||
592 | this.requestGoodsList(); | 612 | this.requestGoodsList(); |
593 | }, | 613 | }, |
594 | - onReachBottom: function () { | ||
595 | 614 | ||
596 | - }, | ||
597 | //选择更多 | 615 | //选择更多 |
598 | select_more: function (e) { | 616 | select_more: function (e) { |
599 | var cid = e.currentTarget.dataset.cid; | 617 | var cid = e.currentTarget.dataset.cid; |
@@ -624,41 +642,45 @@ Page({ | @@ -624,41 +642,45 @@ Page({ | ||
624 | 642 | ||
625 | }, | 643 | }, |
626 | touchstart(e) { | 644 | touchstart(e) { |
627 | - // if (!this.data.is_no_more) return false; | ||
628 | - // if(this.data.is_next){ | ||
629 | - // this.setData({ | ||
630 | - // is_no_more:0, | ||
631 | - // }) | ||
632 | - // } | ||
633 | - // this.data.is_next=0; | 645 | + startY=0; |
646 | + if (!this.data.is_no_more) return false; | ||
647 | + if(isReachBt<=0) return false; | ||
634 | startY = e.changedTouches[0].clientY; | 648 | startY = e.changedTouches[0].clientY; |
635 | - console.log('gdsg'); | 649 | + |
636 | }, | 650 | }, |
637 | touchend(e) { | 651 | touchend(e) { |
652 | + var th=this; | ||
653 | + setTimeout(function () { | ||
654 | + if(!th.data.car_scroll){ | ||
655 | + clearInterval(th.data.timer); | ||
656 | + th.get_next_cate(th.data.select_classify_on); | ||
657 | + return false; | ||
658 | + } | ||
638 | 659 | ||
639 | - endY = e.changedTouches[0].clientY; | ||
640 | - moveDistance = startY - endY; | ||
641 | - if(moveDistance<0){ | ||
642 | - scrolltop=0 | ||
643 | - } | ||
644 | - console.log(scrolltop); | ||
645 | - if (this.data.is_no_more && !this.data.is_up) { | ||
646 | - this.data.is_up = 1; | ||
647 | - return false; | ||
648 | - } | 660 | + if(!startY) return false; |
661 | + endY = e.changedTouches[0].clientY; | ||
662 | + moveDistance = startY - endY; | ||
663 | + if(moveDistance<0){ | ||
664 | + isReachBt=0; | ||
665 | + return false; | ||
666 | + } | ||
667 | + if (th.data.is_no_more && moveDistance >= 10 && isReachBt > 0) { | ||
668 | + clearInterval(th.data.timer); | ||
669 | + th.get_next_cate(th.data.select_classify_on); | ||
670 | + } | ||
671 | + },50) | ||
649 | 672 | ||
650 | - if (this.data.is_no_more && moveDistance >= 300 && scrolltop > 0) { | ||
651 | - this.data.is_up = 0; | ||
652 | - this.get_next_cate(this.data.select_classify_on); | ||
653 | - } | ||
654 | 673 | ||
655 | }, | 674 | }, |
656 | // 左侧更新 | 675 | // 左侧更新 |
657 | scrollLower: function () { | 676 | scrollLower: function () { |
658 | - scrolltop = 1; | ||
659 | - if (this.data.isLoading) return false; | ||
660 | - if (this.data.is_no_more) return false; | ||
661 | 677 | ||
678 | + console.log("low111"); | ||
679 | + if (this.data.isLoading) return false; | ||
680 | + if (this.data.is_no_more) { | ||
681 | + isReachBt = 1; | ||
682 | + return false; | ||
683 | + } | ||
662 | 684 | ||
663 | this.setData({ | 685 | this.setData({ |
664 | stylePage: this.data.stylePage + 1, | 686 | stylePage: this.data.stylePage + 1, |
@@ -666,7 +688,6 @@ Page({ | @@ -666,7 +688,6 @@ Page({ | ||
666 | }); | 688 | }); |
667 | !this.data.is_none && this.requestGoodsList(); | 689 | !this.data.is_none && this.requestGoodsList(); |
668 | 690 | ||
669 | - | ||
670 | }, | 691 | }, |
671 | 692 | ||
672 | //--- 获取卡类列表 --- | 693 | //--- 获取卡类列表 --- |
@@ -693,4 +714,8 @@ Page({ | @@ -693,4 +714,8 @@ Page({ | ||
693 | }) | 714 | }) |
694 | }, | 715 | }, |
695 | 716 | ||
717 | + bd_scroll:function (e) { | ||
718 | + this.data.car_scroll=1; | ||
719 | + } | ||
720 | + | ||
696 | }); | 721 | }); |
697 | \ No newline at end of file | 722 | \ No newline at end of file |
packageC/pages/goods/distributionCategoryList/index.wxml
@@ -95,8 +95,10 @@ | @@ -95,8 +95,10 @@ | ||
95 | <!-- 显示商品列表开始 --> | 95 | <!-- 显示商品列表开始 --> |
96 | <!-- <view class="classify_content-frame flex-wrap" style="width:100%;overflow:hidden;heigth:100%;"> --> | 96 | <!-- <view class="classify_content-frame flex-wrap" style="width:100%;overflow:hidden;heigth:100%;"> --> |
97 | <!-- <view class="null" style="width:100%;margin-top:70rpx;"></view> --> | 97 | <!-- <view class="null" style="width:100%;margin-top:70rpx;"></view> --> |
98 | - <scroll-view wx:if="{{is_get}}" scroll-y scroll-top="{{scrollTop}}" bindtouchstart="touchstart" bindtouchend="touchend" bindscrolltolower='scrollLower' lower-threshold="200" style="height:{{windowHeight}};position:absolute;margin-top:70rpx;top:140rpx;bottom:0;rigth:0;left:26%;width:73%;"> | ||
99 | - <view class="null" style="width:100%;height:1px;"></view> | 98 | + <scroll-view wx:if="{{is_get}}" scroll-y scroll-top="{{scrollTop}}" |
99 | + bindscroll="bd_scroll" | ||
100 | + bindtouchstart="touchstart" bindtouchend="touchend" bindscrolltolower='scrollLower' lower-threshold="200" style="height:{{windowHeight}};position:absolute;margin-top:70rpx;top:140rpx;bottom:0;rigth:0;left:26%;width:73%;"> | ||
101 | + <!--<view class="null" style="width:100%;height:1px;"></view>--> | ||
100 | <!-- goodslist --> | 102 | <!-- goodslist --> |
101 | <view class="choice_list" style="height:{{requestData.length?'100%':''}}"> | 103 | <view class="choice_list" style="height:{{requestData.length?'100%':''}}"> |
102 | <navigator class="choice_item" style="margin-bottom:{{dataLength -1 == index?'100px':'0'}}" url="/pages/goods/goodsInfo/goodsInfo?goods_id={{item.goods_id}}" wx:for="{{requestData}}" data-id="{{item.id}}"> | 104 | <navigator class="choice_item" style="margin-bottom:{{dataLength -1 == index?'100px':'0'}}" url="/pages/goods/goodsInfo/goodsInfo?goods_id={{item.goods_id}}" wx:for="{{requestData}}" data-id="{{item.id}}"> |
@@ -204,9 +206,9 @@ | @@ -204,9 +206,9 @@ | ||
204 | </view> | 206 | </view> |
205 | </navigator> | 207 | </navigator> |
206 | <!-- 暂无更多 --> | 208 | <!-- 暂无更多 --> |
207 | - <view wx:if="{{is_no_more&&!is_none&&requestData.length}}" style="color:c-red; height: 200rpx;line-height: 30rpx;margin-top: 20rpx;font-size: 25rpx; text-align: center;"> | 209 | + <view id="morelb" wx:if="{{is_no_more&&!is_none&&requestData.length}}" style="color:c-red; height: 60rpx;line-height: 30rpx;margin-top: 20rpx;font-size: 25rpx; text-align: center;"> |
208 | <text style="font-size:32rpx;color:red;margin-right:10rpx" class="iconfont icon-arrowup"></text> | 210 | <text style="font-size:32rpx;color:red;margin-right:10rpx" class="iconfont icon-arrowup"></text> |
209 | - <text style="color:#999">向上拉继续浏览{{next_classify_name}}</text> | 211 | + <text style="color:#999">向上拉继续浏览下一个类别</text> |
210 | </view> | 212 | </view> |
211 | </view> | 213 | </view> |
212 | <view class="no-data" wx:if="{{requestData.length==0}}"> | 214 | <view class="no-data" wx:if="{{requestData.length==0}}"> |