|
- let config = require("../../config/config.js");
- let Http = require("../../utils/HttpBasics");
- const util = require("../../utils/util");
- const app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- list: [],
- page: 2,
- allow_load: true,
- day: "",
- hour: "",
- minute: "",
- loading: true, //"上拉加载"的变量,默认false,隐藏
- content:"",
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function(options) {},
- //列表
- getList: function(page) {
- let that = this;
-
- app.couponChannelListCallback = token => {
- Http.setToken(token);
- /**
- * 判断用户是否加载完成
- */
- if (that.data.allow_load) {
- // wx.showLoading({
- // title: "加载中"
- // });
- that.setData({
- loading:true,
- content:'小主,我在玩命加载中...'
- })
-
- // 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) {
- that.setData({
- allow_load: false
- });
- setTimeout(function() {
- that.setData({
- loading:false,
- })
- }, 1400);
- } else {
- setTimeout(function() {
- that.setData({
- loading:false,
- })
- }, 1400);
- /**
- * 页面上显示的时间
- */
- console.log(that.data.list);
- that.data.list = that.data.list.concat(res.data.list);
- that.setData({
- list: that.data.list
- });
- console.log(that.data.list);
- for (let i = 0; i < that.data.list.length; i++) {
- var startTime = util.fmtDate(that.data.list[i].endTime);
- util.timechuo(startTime);
- console.log(util.timechuo(startTime));
- /**
- * 修改list的endtime
- * 渲染到页面
- */
- var endtime = 'list[' + i + '].endtime'
- that.setData({
- [endtime]: util.timechuo(startTime)
- });
- }
- }
- });
- } else {
- console.info("allow_load==false 已禁止加载");
- that.setData({
- loading:true,
- content: "——— 在拉裤子就掉了啦 ———"
- })
- setTimeout(function(){
- that.setData({
- loading:false,
- })
- },1400)
- }
- };
- 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) {
- wx.navigateTo({
- url: `/pages/coupon/detail/index?couponChannelId=${
- e.currentTarget.dataset.couponchannelid
- }&couponId=${e.currentTarget.dataset.couponid}`
- });
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- 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() {}
- });
|