detail.js
3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import orderModel from '../../../models/home/order';
import orderHandle from './order-handle';
import Yas from '../../../common/yas';
const router = global.router;
let app = getApp();
const yas = new Yas(app);
Page({
data: {
receiveAddress: {}
},
onLoad(options) {
if (!options.orderCode || !app.getUid()) {
return router.go('home', {}, 'switchTab');
}
this.loadOrderDetail(options.orderCode);
yas.pageOpenReport();
},
loadOrderDetail(orderCode) {
this.orderCode = orderCode;
orderModel.getOrderDetail(orderCode).then(res => {
if (res.code === 200) {
let data = res.data;
if (data.counter_flag === 'Y' &&
data.is_cancel !== 'Y' && data.pay_lefttime > 0) {
this.timeCountDown(parseInt(data.pay_lefttime));
}
this.setData({
pageLoaded: true,
receiveAddress: {
consignee: data.user_name,
address: data.address,
area: data.area,
mobile: data.mobile,
hideRightIcon: true
},
orderCode: data.order_code,
orderStatus: data.status_str,
createTime: this.formatDate(data.create_time),
goodsList: data.order_goods || [],
promotionList: data.promotion_formulas || [],
paymentAmount: data.payment_amount,
attribute: data.attribute,
links: data.links
});
}
})
},
timeCountDown(second) {
const that = this;
this.setData({payLeftTime: this.formatSecond(second)});
this.timer = setInterval(function() {
let payLeftTime = '';
second--;
if (second > 0) {
payLeftTime = that.formatSecond(second);
} else {
clearInterval(that.timer);
that.loadOrderDetail(that.orderCode);
}
that.setData({payLeftTime});
}, 1000);
},
fill2(m) {
m = m || 0;
return m < 10 ? `0${m}` : m;
},
formatDate(time) {
time = new Date(time * 1000);
return `${time.getFullYear()}-${this.fill2(time.getMonth() + 1)}-${this.fill2(time.getDate())}` +
` ${this.fill2(time.getHours())}:${this.fill2(time.getMinutes())}:${this.fill2(time.getSeconds())}`;
},
formatSecond(second) {
let hr = Math.floor(second / 3600);
let min = Math.floor((second - hr * 3600) / 60);
let sec = second % 60;
return `${this.fill2(hr)}:${this.fill2(min)}:${this.fill2(sec)}`;
},
cancelOrder() {
orderHandle.cancelOrder(this.orderCode);
},
payNow() {
orderHandle.payNow({
order_code: this.orderCode,
order_amount: this.data.paymentAmount
});
},
deleteOrder() {
orderHandle.deleteOrder(this.orderCode);
},
viewExpress() {
orderHandle.expressDetail(this.orderCode);
},
confirmOrder() {
orderHandle.confirmReceive(this.orderCode);
},
refundNow() {
orderHandle.confirmReceive(this.orderCode);
}
});