var config = require("../../config/config.js"); const Http = require("../../utils/HttpBasics"); const imgurl = require("../../utils/imgurl"); Page({ /** * 页面的初始数据 */ data: { bannerUrl: imgurl.banner.url, loadingUrl: imgurl.loading.url, nodata: imgurl.nodata.url, wangmeimeicredit: imgurl.wangmeimeicredit.url, list: [], lists: [], myLists: [], page: 1, // 设置加载的第几次,默认是第一次 pageSize: 10, //返回数据的个数 searchLoadingComplete: false, //“没有数据”的变量,默认false,隐藏 allow_load: true, // 是否允许继续加载标识 默认 true 允许,false 加载完成 myorder: false, actUrl: imgurl.act.url, loading: true, content: '数据正在加载中', reloadIf: false, creditAmount: 0 }, onLoad: function (options) { let that = this; var todayDate = new Date().getTime(); that.getPoints(); that.setData({ optionsData: options, todayDate: todayDate }) if (options && options.from == 'myhtml') { that.getmyList(); } else { that.getList(1); that.setData({ lists: null }) } }, onShow() { let that = this; if (this.data.reloadIf) { wx.setNavigationBarTitle({ title: '积分商城' }) that.getList(1); that.setData({ lists: null }) } }, // 获得积分,渲染页面 getPoints(){ let that = this; Http.get({ url: config.api.integralList, data: { pageNum: 1, pageSize: 1, } }).then(res => { wx.stopPullDownRefresh(); that.setData({ creditAmount: res.data.list[0].creditAmount }); }) .catch(err => { wx.stopPullDownRefresh(); wx.showToast({ title: err.errMsg, icon: 'none', duration: 2000, mask: false }); }) }, gotojifen(){ wx.navigateTo({ url: '/pages/integralmall/integraHistory/index', }) }, getList(pageNum) { var that = this; console.log(pageNum) if (that.data.allow_load) { that.setData({ loading: true, content: '小主,我在玩命加载中...' }) var param = {}; var param = { pageNum: pageNum, pageSize: 10, targetAd: 50 }; var url = config.api.couponChannelList; // 请求接口 Http.get({ url: url, data: param }).then(res => { console.log(res) /** * 加载完成 */ if (pageNum >= res.data.pages) { if (res.data.pages == 0 || res.data.pages == 1) { that.setData({ allow_load: true, loading: false, content: "" }); } else { that.setData({ allow_load: false, loading: true, content: "——— 再拉裤子就掉了啦 ———", }); } } if (pageNum == 1) { that.setData({ lists: [], }) } var tmpArr = that.data.lists; tmpArr.push.apply(tmpArr, res.data.list); that.setData({ lists: tmpArr }) wx.stopPullDownRefresh(); }) .catch(err => { wx.stopPullDownRefresh(); wx.showToast({ title: err.message, icon: 'none', duration: 2000, mask: false }); }) setTimeout(function () { that.setData({ loading: false, }) }, 1400); } else { that.setData({ loading: true, content: "——— 再拉裤子就掉了啦 ———" }) setTimeout(function () { that.setData({ loading: false, }) }, 1400) } }, /** * * @param goto拼团券详情 */ invite: function (e) { let couponChannelId = e.currentTarget.dataset.id; let couponId = e.currentTarget.dataset.couponid; if (couponChannelId && couponId) { wx.navigateTo({ url: `/pages/integralmall/integcoupondetail/index?couponChannelId=${couponChannelId}&couponId=${couponId}` }) } }, //加载更多 onReachBottom: function () { let that = this; that.data.page++; that.setData({ page: that.data.page }); that.getList(that.data.page, that.data.flag); }, /** * 刷新 */ onPullDownRefresh: function (e) { let that = this; that.getList(1); that.getPoints(); } })