活动记录tab切换分页

实现方法:

1.定义 getList 方法,此方法的作用是调用接口获取记录数据,一次获取6条;
当最新获取的记录为空时,将 nextPage 设定为 false

2.在created阶段调用 getList 方法获得默认 tab 的初始数据,在 mounted 阶段初始化默认 tab 的 iscroll
在 onScrollEnd 事件上绑定 getList 方法,触发条件为 nextPage 为 true,目的为当记录已全部加载完后不再调用接口

3.切换 tab 时,销毁另一个 tab 的 iscroll,防止切换 tab 时的弹跳效果;将pageIndex,nextPage,type 等初始化,切换 tab 时重新加载

代码:

data() {
        return {
            discount: [],//优惠券记录
            upload: [],//小票记录
            pageIndex: 0,
            nextPage: true,
            type: 1,
        }
    },
created() {
        this.getList();
    },
    mounted() {
        let that = this;
        this.$nextTick(() => {
            recordScroll = new iScroll('wrapper_record', {
                checkDOMChanges: true,
                vScrollbars: false,
                hScroll: false,
                hideScrollbar: false,
                scrollbarClass: 'none',
                onScrollEnd: function () {//分页
                    if (!that.nextPage) return false;
                    that.getList()
                }
            });
        });
    },
methods: {
        tab(type) {//切换记录框
            let that = this;
            this.pageIndex = 0;
            this.nextPage = true;
            this.discount = [];
            this.upload = [];
            this.type = type;
            this.getList();
            switch (type) {
                case 1:
                    uploadScroll.destroy();
                    this.show = type;
                    this.discountBtn = this.cdnUrl + 'discount_click.png';
                    this.uploadBtn = this.cdnUrl + 'upload_unclick.png';
                    this.$nextTick(() => {
                        recordScroll = new iScroll('wrapper_record', {
                            checkDOMChanges: true,
                            vScrollbars: false,
                            hScroll: false,
                            hideScrollbar: false,
                            scrollbarClass: 'none',
                            onScrollEnd: function () {//分页
                                if (!that.nextPage) return false;
                                that.getList()
                            }
                        });
                        //     YH.iscroll('wrapper_record', 'none');
                    });
                    break;
                case 2:
                    recordScroll.destroy();
                    this.show = type;
                    this.discountBtn = this.cdnUrl + 'discount_unclick.png';
                    this.uploadBtn = this.cdnUrl + 'upload_click.png';
                    this.$nextTick(() => {
                        uploadScroll = new iScroll('wrapper_upload', {
                            checkDOMChanges: true,
                            vScrollbars: false,
                            hScroll: false,
                            hideScrollbar: false,
                            scrollbarClass: 'none',
                            onScrollEnd: function () {//分页
                                if (!that.nextPage) return false;
                                that.getList()
                            }
                        });
                    });
                    break
            }
        },
        async getList() {
            let that = this;
            that.pageIndex += 1;
            let res = await EsHttp.post(Api.Action.GetDrawRecord.url, {
                PageIndex: that.pageIndex,
                PageSize: 6,
                Type: that.type
            });
            console.log('获取记录', res);
            if (res.Success) {
                if (res.Data[0]) {
                    if (that.type == 1) {
                        that.discount = that.discount.concat(res.Data);
                    } else if (that.type == 2) {
                        that.upload = that.upload.concat(res.Data);
                    }
                } else {
                    that.nextPage = false
                }
            }
        },
    },
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值