下面的是针对 多个 未付款订单倒计划:
在传入orderList的地方调用countdown
方法
countdown: function(){
var step = 1000;
var that = this;
var timer = setInterval(function(){
for (let i = 0; i < that.data.orderList.length; i++) {
if (that.data.orderList[i].orderStatus != 'UNPAID') {
continue;
}
var restTime = that.data.orderList[i].leftTime;
if (restTime >= 0) {
var timeSeconds = that.formatTime(restTime);
that.data.orderList[i].showTime = timeSeconds;
that.data.orderList[i].leftTime = restTime - step;
} else {
that.data.orderList[i].orderStatus = 'CANCELLED';//前台修改订单状态
that.data.orderList[i].leftTime = 0;
clearInterval(timer);//清空计时
}
that.setData({
orderList: that.data.orderList
});
}
}, step);
},
formatTime: function (s) {
var min = Math.floor(s / 60/1000) % 60;
var sec = parseInt((s /1000 % 60).toFixed(2));
min = min < 10 ? '0'+min : min;
sec = sec < 10 ? '0' + sec: sec;
return min + ':' + sec
},