|
- // pages/index/sw/index.js
- 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: ""
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- 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(that.data.day);
- 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
- });
-
- /**
- * 页面上显示的时间
- */
- console.log(that.data.list);
- for (let i = 0; i < that.data.list.length; i++) {
- console.log(that.data.list[i].endTime);
- var startTime = util.fmtDate(that.data.list[i].endTime);
- console.log(startTime);
- var s1 = new Date(startTime.replace(/-/g, "/"));
- var s2 = new Date();
- var runTime = parseInt((s1.getTime() - s2.getTime()) / 1000);
- var year = Math.floor(runTime / 86400 / 365);
- var runTime = runTime % (86400 * 365);
- var month = Math.floor(runTime / 86400 / 30);
- var runTime = runTime % (86400 * 30);
- var day = Math.floor(runTime / 86400);
- var runTime = runTime % 86400;
- var hour = Math.floor(runTime / 3600);
- var runTime = runTime % 3600;
- var minute = Math.floor(runTime / 60);
- var runTime = runTime % 60;
- var second = runTime;
- console.log(month, day, hour, minute, second);
- that.setData({
- month: month,
- day: day,
- hour: hour,
- minute: minute
- });
- }
- });
- } 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.couponchannelid);
- console.log("couponChannelId");
- wx.navigateTo({
- url: `/pages/coupon/detail/index?couponChannelId=${
- e.currentTarget.dataset.couponchannelid
- }&couponId=${e.currentTarget.dataset.couponId}`,
- 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() {}
- });
|