let config = require("../../config/config.js"); let app = getApp(); const Http = require("../../utils/HttpBasics"); const util = require("../../utils/util"); Page({ data: { data: {}, couponId: null, orderId: "", day: "", hour: "", minute: "" }, onLoad(options) { let that = this; console.log(options.id); wx.showLoading({ title: "加载中..." }); if (options.flag) { this.orderFunc(); } else { Http.get({ url: config.api.couponDetail, data: { couponId: options.id, targetAd:options.targetAd } }).then(res => { console.log(res); //当前时间与优惠券下架时间做计算 var startTime = util.fmtDate(res.data.sendEndDate); 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(year, month, day, hour, minute, second); that.setData({ year: year, month: month, day: day, hour: hour, minute: minute }); console.log(that.data.day); wx.hideLoading(); that.setData({ data: res.data, couponId: options.id }); }); } } });