Authored by 李奇

倒计时问题修正

@@ -9,8 +9,6 @@ const SHOW_DETAIL = 'show_detail'; @@ -9,8 +9,6 @@ const SHOW_DETAIL = 'show_detail';
9 const SHOW_EXPRESS = 'show_express'; 9 const SHOW_EXPRESS = 'show_express';
10 import event from '../../utils/event'; 10 import event from '../../utils/event';
11 11
12 -let interval;  
13 -  
14 Component({ 12 Component({
15 /** 13 /**
16 * 组件的属性列表 14 * 组件的属性列表
@@ -47,7 +45,6 @@ attached: function () { @@ -47,7 +45,6 @@ attached: function () {
47 let that = this; 45 let that = this;
48 if (that.data.buttons){ 46 if (that.data.buttons){
49 let lastIndex = that.data.buttons.length - 1; 47 let lastIndex = that.data.buttons.length - 1;
50 - console.log("lastIndex===" + lastIndex);  
51 that.setData({ lastIndex: lastIndex }); 48 that.setData({ lastIndex: lastIndex });
52 } 49 }
53 50
@@ -56,7 +53,8 @@ attached: function () { @@ -56,7 +53,8 @@ attached: function () {
56 let timer = that.data.timer; 53 let timer = that.data.timer;
57 54
58 if (timer > 0){ 55 if (timer > 0){
59 - interval = setInterval(() => { 56 + this.data.interval && clearInterval(this.data.interval);
  57 + this.data.interval = setInterval(() => {
60 timer = timer - 1; 58 timer = timer - 1;
61 leftTime = formatTimeByMin(timer, 'm:s'); 59 leftTime = formatTimeByMin(timer, 'm:s');
62 if (timer <= 0) { 60 if (timer <= 0) {
@@ -64,7 +62,7 @@ attached: function () { @@ -64,7 +62,7 @@ attached: function () {
64 setTimeout(() => { 62 setTimeout(() => {
65 event.emit('refresh-order'); 63 event.emit('refresh-order');
66 }, 2000); 64 }, 2000);
67 - clearInterval(interval); 65 + clearInterval(this.data.interval);
68 } 66 }
69 that.setData({ 67 that.setData({
70 lefttime: leftTime, 68 lefttime: leftTime,
@@ -77,8 +75,8 @@ attached: function () { @@ -77,8 +75,8 @@ attached: function () {
77 }, 75 },
78 76
79 detached: function () { 77 detached: function () {
80 - if (interval){  
81 - clearInterval(interval); 78 + if (this.data.interval){
  79 + clearInterval(this.data.interval);
82 } 80 }
83 }, 81 },
84 82
@@ -10,7 +10,6 @@ import Yas from '../../utils/yas'; @@ -10,7 +10,6 @@ import Yas from '../../utils/yas';
10 const BUY_AGAIN = 'buy_again'; 10 const BUY_AGAIN = 'buy_again';
11 const NOW_BUY = 'now_buy'; 11 const NOW_BUY = 'now_buy';
12 const SHOW_EXPRESS = 'show_express'; 12 const SHOW_EXPRESS = 'show_express';
13 -let interval;  
14 13
15 let yas; 14 let yas;
16 15
@@ -28,7 +27,8 @@ Page({ @@ -28,7 +27,8 @@ Page({
28 orderCode: '', 27 orderCode: '',
29 cancelConfirm: false, 28 cancelConfirm: false,
30 cancelOrderCode: '', 29 cancelOrderCode: '',
31 - navBack: 1 30 + navBack: 1,
  31 + interval: ''
32 }, 32 },
33 33
34 /** 34 /**
@@ -64,8 +64,8 @@ Page({ @@ -64,8 +64,8 @@ Page({
64 * 生命周期函数--监听页面隐藏 64 * 生命周期函数--监听页面隐藏
65 */ 65 */
66 onHide: function () { 66 onHide: function () {
67 - if (interval) {  
68 - clearInterval(interval); 67 + if (this.data.interval) {
  68 + clearInterval(this.data.interval);
69 } 69 }
70 }, 70 },
71 71
@@ -73,8 +73,8 @@ Page({ @@ -73,8 +73,8 @@ Page({
73 * 生命周期函数--监听页面卸载 73 * 生命周期函数--监听页面卸载
74 */ 74 */
75 onUnload: function () { 75 onUnload: function () {
76 - if (interval) {  
77 - clearInterval(interval); 76 + if (this.data.interval) {
  77 + clearInterval(this.data.interval);
78 } 78 }
79 }, 79 },
80 80
@@ -135,7 +135,9 @@ Page({ @@ -135,7 +135,9 @@ Page({
135 that.setData({ 135 that.setData({
136 timer: formatTimeByMin(leftTime, 'm:s') 136 timer: formatTimeByMin(leftTime, 'm:s')
137 }); 137 });
138 - interval = setInterval(() => { 138 +
  139 + this.data.interval && clearInterval(this.data.interval);
  140 + this.data.interval = setInterval(() => {
139 leftTime = leftTime - 1; 141 leftTime = leftTime - 1;
140 timer = formatTimeByMin(leftTime, 'm:s'); 142 timer = formatTimeByMin(leftTime, 'm:s');
141 if (leftTime <= 0) { 143 if (leftTime <= 0) {
@@ -143,7 +145,7 @@ Page({ @@ -143,7 +145,7 @@ Page({
143 setTimeout(() => { 145 setTimeout(() => {
144 that.fetchOrderDetail(code); 146 that.fetchOrderDetail(code);
145 }, 2000); 147 }, 2000);
146 - clearInterval(interval); 148 + clearInterval(this.data.interval);
147 } 149 }
148 that.setData({ 150 that.setData({
149 timer: timer, 151 timer: timer,