diff --git a/pages/bargain/bargainDatail/bargainDatail.js b/pages/bargain/bargainDatail/bargainDatail.js index 2993621..530e852 100644 --- a/pages/bargain/bargainDatail/bargainDatail.js +++ b/pages/bargain/bargainDatail/bargainDatail.js @@ -51,6 +51,9 @@ Page({ todayDate: todayDate, showButton:false }) + if(that.data.pressEndDate){ + that.countdown(that.data.pressEndDate) + } }, goback:function(){ wx.switchTab({ @@ -145,6 +148,9 @@ Page({ file.createDate = diffTime(file.createDate) }) that.countdown(res.data.pressEndDate); + that.setData({ + pressEndDate: res.data.pressEndDate + }) res.data.orderPressList.map(file=>{ compare(file.first); }) @@ -165,14 +171,15 @@ Page({ wx.stopPullDownRefresh(); }) }, - - countdown(end_time) { + + setIntervalTime(end_time) { let that = this; var EndTime = end_time; var NowTime = new Date().getTime(); var total_micro_second = EndTime - NowTime || []; // 渲染倒计时时钟 let obj = that.dateformat(total_micro_second); + console.log(obj); if (total_micro_second > 0) { that.setData({ clock: obj, @@ -189,13 +196,23 @@ Page({ min: "00", sec: "00", }) + //如果倒计时结束,需要重新查询一下券的状态 + // 给getDetail一个标识 } - setTimeout(function() { - total_micro_second -= 1000; - that.countdown(end_time); + total_micro_second -= 1000; + }, + countdown: function (end_time) { + let that = this; + that.setIntervalTime(end_time); + that.data.setInterval = setInterval(function () { + that.setIntervalTime(end_time); }, 1000) }, + + + + // 时间格式化输出,如11:03 25:19 每1s都会调用一次 dateformat(micro_second) { // 总秒数 @@ -457,6 +474,14 @@ Page({ } }) }, + onUnload: function () { + let that = this; + clearInterval(that.data.setInterval) + }, + onHide: function () { + let that = this; + clearInterval(that.data.setInterval) + }, /** * * @param {朋友邀请砍价} e