Authored by 李奇

倒计时问题修正

... ... @@ -9,8 +9,6 @@ const SHOW_DETAIL = 'show_detail';
const SHOW_EXPRESS = 'show_express';
import event from '../../utils/event';
let interval;
Component({
/**
* 组件的属性列表
... ... @@ -47,7 +45,6 @@ attached: function () {
let that = this;
if (that.data.buttons){
let lastIndex = that.data.buttons.length - 1;
console.log("lastIndex===" + lastIndex);
that.setData({ lastIndex: lastIndex });
}
... ... @@ -56,7 +53,8 @@ attached: function () {
let timer = that.data.timer;
if (timer > 0){
interval = setInterval(() => {
this.data.interval && clearInterval(this.data.interval);
this.data.interval = setInterval(() => {
timer = timer - 1;
leftTime = formatTimeByMin(timer, 'm:s');
if (timer <= 0) {
... ... @@ -64,7 +62,7 @@ attached: function () {
setTimeout(() => {
event.emit('refresh-order');
}, 2000);
clearInterval(interval);
clearInterval(this.data.interval);
}
that.setData({
lefttime: leftTime,
... ... @@ -77,8 +75,8 @@ attached: function () {
},
detached: function () {
if (interval){
clearInterval(interval);
if (this.data.interval){
clearInterval(this.data.interval);
}
},
... ...
... ... @@ -10,7 +10,6 @@ import Yas from '../../utils/yas';
const BUY_AGAIN = 'buy_again';
const NOW_BUY = 'now_buy';
const SHOW_EXPRESS = 'show_express';
let interval;
let yas;
... ... @@ -28,7 +27,8 @@ Page({
orderCode: '',
cancelConfirm: false,
cancelOrderCode: '',
navBack: 1
navBack: 1,
interval: ''
},
/**
... ... @@ -64,8 +64,8 @@ Page({
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
if (interval) {
clearInterval(interval);
if (this.data.interval) {
clearInterval(this.data.interval);
}
},
... ... @@ -73,8 +73,8 @@ Page({
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
if (interval) {
clearInterval(interval);
if (this.data.interval) {
clearInterval(this.data.interval);
}
},
... ... @@ -135,7 +135,9 @@ Page({
that.setData({
timer: formatTimeByMin(leftTime, 'm:s')
});
interval = setInterval(() => {
this.data.interval && clearInterval(this.data.interval);
this.data.interval = setInterval(() => {
leftTime = leftTime - 1;
timer = formatTimeByMin(leftTime, 'm:s');
if (leftTime <= 0) {
... ... @@ -143,7 +145,7 @@ Page({
setTimeout(() => {
that.fetchOrderDetail(code);
}, 2000);
clearInterval(interval);
clearInterval(this.data.interval);
}
that.setData({
timer: timer,
... ...