Commit d1e20fee by 高淑倩

订单倒计时

parent 365303fa
...@@ -11,7 +11,12 @@ wxService.page({ ...@@ -11,7 +11,12 @@ wxService.page({
*/ */
data: { data: {
detail: null, detail: null,
id: '' id: '',
localNowTime: 0,
hour: '00',
min: '00',
sec: '00',
ms: '0',
}, },
/** /**
...@@ -50,13 +55,71 @@ wxService.page({ ...@@ -50,13 +55,71 @@ wxService.page({
const { result, data } = res.data const { result, data } = res.data
if (result == 0) { if (result == 0) {
wx.hideLoading() wx.hideLoading()
const { localNowTime} = this.data
data.localNowTime = localNowTime ? localNowTime : new Date().getTime();
data.createOrderTime = new Date(data.createTime.replace(/-/g,'/')).getTime() || [];
data.countDownOrderTime = 7200000; // 2时(h)=7200000毫秒(ms)
// 订单倒计时 超多两小时 刷新当前页
// 本地时间 - 创建时间 > 2小时 刷新当前页
this.setData({ this.setData({
detail: data detail: data
}, ()=>{
this.initCountDown(data.countDownOrderTime, data.createOrderTime, data.localNowTime)
}) })
} }
} }
}) })
}, },
initCountDown(countDownOrderTime,startTime,localTime) {
// 毫秒差 本地时间 - 创建时间
let countTimeSpan = localTime - startTime
let countDownTimer = setInterval(() => {
countDownOrderTime -= 1000
let result = this.getCountDown(countTimeSpan, countDownOrderTime);
if (result.isOver) {
clearInterval(countDownTimer);
} else {
this.setData({
hour: result.hour,
min: result.min,
sec: result.sec,
ms: result.ms,
})
}
}, 1000);
},
getCountDown(time, countDownOrderTime) {
// 判断是否为时间戳
let distancetime = time < countDownOrderTime ? countDownOrderTime - time : 0;
// 毫秒差 本地时间 - 创建时间 7200000毫秒(ms)
let result = {
hour: '00',
min: '00',
sec: '00',
ms: '00',
isOver: true,
};
if (distancetime) {
// 如果大于7200000.说明尚未到达截止时间
result.ms = Math.floor((distancetime % 1000) / 100);
result.sec = Math.floor((distancetime / 1000) % 60);
result.min = Math.floor((distancetime / 1000 / 60) % 60);
result.hour = Math.floor((distancetime / 1000 / 60 / 60) % 24);
result.isOver = false;
if (result.ms < 10) result.ms = result.ms;
if (result.sec < 10) result.sec = '0' + result.sec;
if (result.min < 10) result.min = '0' + result.min;
if (result.hour < 10) result.hour = '0' + result.hour;
} else {
const {id} = this.data
this.getOrderDetail(id)
}
return result;
},
// 删除订单 // 删除订单
handelDelOrder(e) { handelDelOrder(e) {
const { id } = e.currentTarget.dataset const { id } = e.currentTarget.dataset
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
</view> </view>
<view class="order-status" wx-if="{{detail.status == 'N'}}"> <view class="order-status" wx-if="{{detail.status == 'N'}}">
<view class="status">待付款</view> <view class="status">待付款</view>
<view class="desc">支付时间仅剩:2小时34分钟,超时将自动关闭</view> <view class="desc">支付时间仅剩:{{hour}}小时{{min}}分钟{{sec}}秒,超时将自动关闭</view>
</view> </view>
<view class="order-status" wx-if="{{detail.status == 'P'}}"> <view class="order-status" wx-if="{{detail.status == 'P'}}">
<view class="status">待发货</view> <view class="status">待发货</view>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment