const util = require("../../../utils/util.js"); const config = require("../../../config/config.js"); const Http = require("../../../utils/HttpBasics"); Page({ data: { tabs: [ { key: 0, name: "未使用" }, { key: 1, name: "已使用" }, { key: 2, name: "已过期" }, { key: 3, name: "已退款" } ], list: [], current: "0", current_scroll: "0", page: 1, allow_load: true, loading: true, //"上拉加载"的变量,默认false,隐藏 content: "" }, onLoad() { this.getList(0, 0); }, //点击跳转到券详情页面 gotouse: function(e) { console.log(e.currentTarget.dataset.quancode); console.log("点击跳转到券详情"); wx.navigateTo({ url: `/pages/couponorder/detail/index?quancode=${ e.currentTarget.dataset.quancode }` }); }, getList(key, pageNum) { var that = this; console.log(key); console.log(pageNum); if (that.data.allow_load) { that.setData({ loading: true, content: "小主,我在玩命加载中..." }); Http.get({ url: config.api.couponOrderList, data: { pageNum: pageNum, pageSize: 6, couponOrderStatus: key } }).then(res => { console.log(res); res.data.list.map(file => { file.expiredTime = util.fmtDate(file.expiredTime); }); setTimeout(function() { that.setData({ loading: false }); }, 1400); if (pageNum >= res.data.pages) { that.setData({ allow_load: false }); setTimeout(function() { that.setData({ loading: false }); }, 1400); } /** * 先赋值后渲染页面 * concat 不会改变原数组值 * push 会改变原数组值,但不会一条一条插入,而是整个数组插入 */ that.data.list = that.data.list.concat(res.data.list); that.setData({ list: that.data.list }); }); } else { console.log("加载完成allow_load设置成false"); that.setData({ loading: true, content: "^_^再拉裤子就掉啦ʅ(´◔౪◔)ʃ" }); setTimeout(function() { that.setData({ loading: false }); }, 1400); } }, handleChange({ detail }) { console.log(detail); this.setData({ current: detail.key }); }, handleChangeScroll({ detail }) { this.setData({ list: [], allow_load: true, current_scroll: detail.key }); this.getList(detail.key, 1); this.setData({ current_scroll: detail.key }); }, onReachBottom: function() { var that = this; console.log(that.data.page); that.data.page++; console.log(that.data.page); that.setData({ page: that.data.page }); console.info("after++ " + that.data.page); that.getList(that.data.current_scroll, that.data.page); } });