visualOrderDetail.js
11.4 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
import { API_HOST, SERVICE_HOST } from '../../../libs/config';
import { GET, POST } from '../../../libs/request';
import { wexinPay } from '../../../utils/wxpay';
import { getYHStorageSync } from '../../../utils/util';
import {
logEvent,
YB_PAGE_OPEN_L,
YB_SHARE_RESULT_L,
} from '../../../libs/analytics.js';
let app = getApp();
const windowWidth = app.globalData.systemInfo.windowWidth;
const windowHeight = app.globalData.systemInfo.windowHeight;
let timer;
const BANNER_RATIO = 324 / 750;
let bannerWidth = windowWidth;
let bannerHeight = bannerWidth * BANNER_RATIO;
Page({
data:{
data: {},
isShowPayment: false,
isHaveInvoice: false,
isShowInvoice: false,
isShowQrcode: false,
isShowTips: true,
pay_lefttime: 0,
time_left: '',
order_code:'',
status_str:'',
create_time:'',
status_str: '',
status: '',
payment_amount: '',
links:[],
invoice: {
buyerTaxNumber:'',
title:'',
orderCode:'',
type:"电子发票",
},
qrcodes:[],
current: 0,
currentCode:'',
activityBanner:'',
token:'',
},
onLoad: function (options) {
var app = getApp();
new app.WeToast();
this.setData({
order_code:options.order_code,
});
this.getDetail();
},
onShow: function () {
},
//获取红包信息
loadEnvelopesData: function () {
let app = getApp();
let that = this;
let param = {
method: 'app.activity.payActivityProfile',
uid: app.getUid(),
orderCode: this.data.order_code,
};
GET(API_HOST, param)
.then(function (data) {
if (data && data.code == 200) {
let activityBanner = data.data.activityBanner.replace(/{width}/, bannerWidth).replace(/{height}/, bannerHeight);
let token = data.data.token;
that.setData({
activityBanner,
token,
});
} else {
}
})
.catch(function (error) {
});
},
//获取订单详情
getDetail: function () {
let param = {
method:'app.SpaceOrders.detail',
order_code: this.data.order_code,
};
GET(API_HOST, param).then(json => {
if (json && json.code && json.code == 200) {
//设置图片参数
for (var i=0;i < json.data.order_goods.length;i++){
var item = json.data.order_goods[i];
item.goods_image = item.goods_image.replace(/{width}/, 100).replace(/{height}/, 100);
};
//是否显示二维码
var showQrcode = false;
if (json.data.links){
for (var i=0;i < json.data.links.length;i++){
var item = json.data.links[i];
if (item === "lookQrcode"){
showQrcode = true;
this.getQrcode();
}
}
}
// console.log(this.data.data.order_goods);
//倒计时
let needTimer = false;
let pay_lefttime = 0;
if (json.data.order_detail_info && json.data.order_detail_info.ext && json.data.order_detail_info.ext.need_create === 'Y'){
needTimer = true;
pay_lefttime = parseInt(json.data.order_detail_info.ext.pay_lefttime);
}
if (needTimer) {
this.stopTimer();
this.startTimer();
} else {
this.stopTimer();
}
//给该页面data赋值
this.setData({
data:json.data,
create_time: this.formatDateForDetail(json.data.create_time),
isShowPayment: json.data.payment_status === "Y",
isHaveInvoice: json.data.invoice?json.data.invoice:false,
isShowInvoice: json.data.invoice && json.data.invoice.showInvoice ? true:false,
isShowQrcode: showQrcode,
isShowTips: json.data.status !== "6",
pay_lefttime,
});
}
}).catch(error => {
// console.log(error);
});
},
/**
* 获取二维码
*/
getQrcode: function (res){
var that = this;
let params = {
method: "app.SpaceOrders.getQrByOrderCode",
order_code: this.data.order_code,
};
GET(API_HOST,params).then(json => {
if (json && json.data && json.data.ticks){
that.setData({
qrcodes:json.data.ticks,
current: 0,
currentCode: json.data.ticks.length > 0 ? json.data.ticks[0].ticket_code:'',
});
}
}).catch(error => {
});
},
/**
*手动滑动
*/
bindChange: function (e){
if (e.detail.source === "touch"){
this.setData({
current: e.detail.current,
currentCode: this.data.qrcodes[e.detail.current].ticket_code,
});
}
},
next: function (){
var index = this.data.current;
index = (index + 1) % this.data.qrcodes.length;
this.setData({
current: index,
currentCode: this.data.qrcodes[index].ticket_code,
});
},
pre: function (){
var index = this.data.current;
index = index - 1;
if (index < 0) {
index = 0;
}
if (index !== this.data.current) {
this.setData({
current: index,
currentCode: this.data.qrcodes[index].ticket_code,
});
}
},
formatDateForDetail: function (timestamp) {
var time = new Date(timestamp * 1000);
var y = time.getFullYear();
var m = time.getMonth() + 1;
var d = time.getDate();
var h = time.getHours();
var mm = time.getMinutes();
var s = time.getSeconds();
// console.log(y + '-' + m + '-' + d + ' ' + h + ':' + mm + ':' + s);
return y + '-' + this.add0(m) + '-' + this.add0(d) + ' ' + this.add0(h) + ':' + this.add0(mm) + ':' + this.add0(s);
},
formatDateForTimer: function (second) {
var dateStr = "";
var hr = Math.floor(second / 3600);
var min = Math.floor((second - hr * 3600) / 60);
var sec = (second - hr * 3600 - min * 60);// equal to => var sec = second % 60;
dateStr = this.add0(hr) + "时" + this.add0(min) + "分" + this.add0(sec) + "秒";
return dateStr;
},
add0: function (m) {
if (m < 10 && m > 0){
return '0' + m;
} else if (m === 0){
return '00';
} else {
return m;
}
},
startTimer: function (e) {
let that = this;
timer = setInterval(function () {
let pay_lefttime = that.data.pay_lefttime;
let time_left = '';
if (pay_lefttime > 0) {
pay_lefttime = pay_lefttime - 1;
time_left = that.formatDateForTimer(pay_lefttime);
if (pay_lefttime == 0) {
that.getDetail(that.data.order_code);
}
} else {
pay_lefttime = 0;
}
that.setData({
pay_lefttime,
time_left,
})
}, 1000);
},
stopTimer: function (e) {
// console.log('stopTimer');
clearInterval(timer);
},
copy: function (e) {
var that = this;
var content = e.currentTarget.dataset.copy_content;
var type = e.currentTarget.dataset.copy_type;
wx.setClipboardData({
data: '' + content,
})
},
lookup: function (e) {
var that = this;
var copy_url = e.currentTarget.dataset.copy_url;
var copy_content = e.currentTarget.dataset.copy_content;
var copy_type = e.currentTarget.dataset.copy_type;
wx.setClipboardData({
data: '' + copy_url,
success: function (res) {
wx.hideToast();
},
})
wx.showModal({
title: '',
content: copy_content,
showCancel: false,
})
},
//复制订单号
copyOrderNum: function (e) {
var that = this;
var code = e.currentTarget.dataset.order_code;
wx.setClipboardData({
data: ""+code,
success: function(res){
},
})
},
//复制税号
copyTaxNum: function (e) {
var that = this;
var code = e.currentTarget.dataset.buyer_tax_number;
wx.setClipboardData({
data: "" + code,
success: function (res) {
},
})
},
//查看发票
lookupInvoice: function (e) {
var pdf_url = e.currentTarget.dataset.pdf_url;
var order_code = e.currentTarget.dataset.order_code;
wx.setClipboardData({
data: pdf_url,
success: function (res) {
wx.hideToast();
},
})
wx.showModal({
title: '',
content: '发票链接地址已复制成功,请粘贴到浏览器中打开,您也可以通过下载有货APP查看',
showCancel: false,
})
},
previewImage: function (e){
var urls = new Array();
for (var i=0;i<this.data.qrcodes.length;i++){
urls[i] = this.data.qrcodes[i].qr_image;
}
wx.previewImage({
current: e.currentTarget.dataset.src,
urls: urls,
})
},
/**
* 取消订单
*/
onCloseOrderTapped: function (e) {
var code = e.currentTarget.dataset.order_code;
var app = getApp();
wx.showModal({
title: '取消订单',
content: '订单取消后不能恢复,确认取消此订单么?',
cancelText: '返回',
confirmText: '取消订单',
confirmColor: "#000000",
success: function (res) {
if (res.confirm) {
let param = {
method: "app.SpaceOrders.close",
order_code: code,
}
GET(API_HOST, param)
.then((json) => {
if (json && json.code && json.code == 200) {
wx.navigateBack({
delta: 1
})
}
else if (json && json.code && json.code != 200) {
wx.showModal({ title: json.message, showCancel: false })
}
})
.catch(error => {
})
}
}
})
},
/**
* 立即付款
*/
onBuyNowTapped: function (e) {
var amount = ""
if(e && e.currentTarget.dataset && e.currentTarget.dataset.order_amount){
var amount = e.currentTarget.dataset.order_amount
if (amount.startsWith("¥")){
amount = amount.replace("¥", "");
}
}
let mOrder = {
order_code: e.currentTarget.dataset.order_code,
order_amount: amount,
};
let payParam = {isVirtual:true,};
wexinPay(mOrder, payParam)
},
/**
* 删除订单
*/
onDelOrderTapped: function (e) {
var code = e.currentTarget.dataset.order_code;
wx.showModal({
content: '确认删除订单?',
cancelText: '取消',
confirmText: '确定',
confirmColor: '#FF0000',
success: function (res) {
if (res.confirm) {
let param = {
method: "app.SpaceOrders.delOrderByCode",
order_code: code,
}
GET(API_HOST, param)
.then((json) => {
if (json && json.code && json.code == 200) {
wx.navigateBack({
delta: 1
})
}
})
.catch(error => {
})
}
}
})
},
/**
* 确认收货
*/
onConfirmTapped: function (e) {
var code = e.currentTarget.dataset.order_code;
var app = getApp()
wx.showModal({
title: '确认收货',
content: '请确认是否已经收到商品?',
cancelText: '取消',
confirmText: '确定',
confirmColor: '#FF0000',
success: function (res) {
if (res.confirm) {
let param = {
method: "app.SpaceOrders.confirm",
order_code: code,
}
GET(API_HOST, param)
.then((json) => {
if (json && json.code && json.code == 200) {
wx.navigateBack({
delta: 1
})
}
else {
}
})
.catch(error => {
})
}
}
})
},
})