|
- // pages/index/sw/index.js
- let config = require("../../config/config.js");
- let Http = require("../../utils/HttpBasics");
- const app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- list: [],
- page: 2,
- allow_load: true
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function(options) {},
- //列表
- getList: function(page) {
- let that = this;
-
-
- app.couponChannelListCallback = token => {
- Http.setToken(token);
- /**
- * 判断用户是否加载完成
- */
- if (that.data.allow_load) {
- wx.showLoading({
- title: "加载中"
- });
-
- setTimeout(function() {
- wx.hideLoading();
- }, 1200);
- Http.get({
- url: config.api.couponChannelList,
- data: {
- pageNum: page,
- pageSize: 5,
- targetAd: 2
- }
- }).then(res => {
- console.log(res);
- if (page >= res.data.pages) {
- wx.showToast({
- title: "加载完成喽",
- icon: "success"
- });
- that.setData({
- allow_load: false
- });
- }
- that.data.list = that.data.list.concat(res.data.list);
- that.setData({
- list: that.data.list
- });
- });
- } else {
- console.info("allow_load==false 已禁止加载");
- }
- };
- if (app.globalData.token && app.globalData.token != null) {
- console.log("couponChannelList init 1");
- app.couponChannelListCallback(app.globalData.token);
- }
- },
- onReady: function() {
- let that = this;
- that.setData({
- list: []
- });
- that.getList(2);
- },
- //限时抢购的强请页面
- gotodetail: function(e) {
- console.log(e);
- console.log("姐姐在测试");
- console.log(e.currentTarget.dataset.couponid);
- console.log(e.currentTarget.dataset.targetad);
- wx.navigateTo({
- url: `/pages/coupon/detail/index?id=${
- e.currentTarget.dataset.couponid
- }&targetAd=${e.currentTarget.dataset.targetad}`,
- success: function(res) {
- // success
- },
- fail: function() {
- // fail
- },
- complete: function() {
- // complete
- }
- });
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function() {},
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function() {
- let that = this;
- that.data.page++;
- console.log(that.data.page);
- that.getList(that.data.page);
- console.log("这是第:" + that.data.page);
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function() {}
- });
|