orderDetail.js
21.6 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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
import api from '../../../common/api.js';
// import {wexinPay} from '../../../utils/wxpay';
import { getYHStorageSync, getImageUrlWithWH} from '../../../utils/util';
import { getChannelCode, getGenderCode, getRecPosCode, getRecommandContentCode } from '../../../utils/home';
import { parseBrandListData } from '../../../utils/productListUtil';
// import {
// logEvent,
// YB_PAGE_OPEN_L,
// YB_SHARE_RESULT_L,
// } from '../../../libs/analytics.js'
// import {listen } from '../../../utils/login';
const APP_SPACEORDERS_DETAIL = "app.SpaceOrders.detail";
const APP_SPACEORDERS_CLOSE = "app.SpaceOrders.close";
const APP_SPACEORDERS_DELORDERBYCODE = "app.SpaceOrders.delOrderByCode";
const APP_SPACEORDERS_CONFIRM = "app.SpaceOrders.confirm";
let app = getApp();
const pixelRatio = app.globalData.systemInfo.pixelRatio;
const windowWidth = app.globalData.systemInfo.windowWidth;
const windowHeight = app.globalData.systemInfo.windowHeight;
const BANNER_RATIO = 324 / 750;
let bannerWidth = windowWidth;
let bannerHeight = bannerWidth * BANNER_RATIO;
let timer;
Page({
data: {
isShowExpress: false,
isLoading: true,
isShowHomeNav: false,
resources:[],
recommdData:[],
data:{},
bannerWidth,
bannerHeight,
requestOK: false,
order_code: "",
create_time: "",
from_page_name: '',
from_page_param: '',
current_page_name: 'orderDetail',
current_page_param: '',
tipimgsrc: '../images/tan-ic@2x.png',
arrowImg: '../images/arrow_right@2x.png',
refundReason: [],//退款理由
showReason:false,
reFaudCode:"",
reasonIndex:0,
pay_lefttime: 0,
time_left: '',
token: '',
activityBanner: '',
},
formSubmit: function (e) {
let formId = e.detail.formId;
let _self = this;
if (!app.getUid() || !formId || formId.length === 0) return;
//上报formId
let formIdParams = {
uid: app.getUid(),
order_code: _self.data.order_code,
openId: app.globalData.openID ? app.globalData.openID : getYHStorageSync('openID','orderDetail'),
miniapp_type: app.globalData.miniapp_type,
formId: formId,
method: 'wechat.formId.add',
}
// console.log('params', formIdParams)
api.get({data: formIdParams})
},
getRefundSeason: function () {
let param = {
method: 'app.SpaceOrders.refundApplyReasons',
fromPage: 'aFP_MineOrderContent'
}
api.get({data: param})
.then(json => {
if (json && json.code == 200) {
// console.log('退货理由获取成功')
this.setData({
refundReason: json.data
})
}
})
},
/**
* 再次购买
*/
onReaddTapped: function (e) {
// console.log("再次购买tab");
var code = e.currentTarget.dataset.order_code;
var that = this;
tt.showModal({
title: '确认将商品再次加入购物车?',
cancelText: '取消',
confirmText: '确定',
confirmColor: '#FF0000',
success: function (res) {
if (res.confirm) {
// console.log("Click confirm button");
let param = {
method: "app.Shopping.readd",
order_code: code,
fromPage: "aFP_MineOrderContent"
}
api.get({data: param})
.then(json => {
if (json && json.code && json.code == 200) {
tt.showToast({
title: '加入购物车成功',
complete: function () {
tt.switchTab({
url: '../../shopCart/shopCart',
})
}
})
}
})
}
}
})
},
//申请退款
onRefundApplyTapped: function (e) {
let that = this;
var code = e.currentTarget.dataset.order_code;
that.setData({
order_code:code,
})
tt.showModal({
content: '申请退款后,本单享有的优惠可能会一并取消,确定申请吗?',
cancelText: '取消',
confirmText: '确定',
confirmColor: '#FF0000',
success: function (res) {
if (res.confirm) {
// console.log('用户点击确定')
that.setData({
showReason: true,
reFaudCode: code,
})
}
}
})
},
chooseReason: function (e) {
let app = getApp();
let _self = this;
let reason_id = e.currentTarget.dataset.id;
let reason = e.currentTarget.dataset.reason;
let order_code = this.data.reFaudCode;
if (order_code) {
_self.setData({
order_code,
})
let param = {
method: 'app.SpaceOrders.refundApply',
reason_id,
reason,
order_code,
fromPage: "aFP_MineOrderContent",
miniapp_type: app.globalData.miniapp_type,
}
api.get({data: param})
.then(json => {
this.hidderPicker();
if (json && json.code == 200) {
tt.navigateBack({
delta:1
})
}
})
.catch(error => {
this.hidderPicker();
})
}
},
//picker-view的监听
bindChange:function(e){
// console.log(e);
let value = e.detail.value;
this.setData({
reasonIndex:value[0]
})
},
//选定退货理由
reasonSure:function(e){
// console.log('选定退货理由');
if (!this.data.refundReason || this.data.refundReason.length<0){
return;
}
let reasonIndex = this.data.reasonIndex;
// console.log("下标" + reasonIndex)
let reason_id = this.data.refundReason[reasonIndex].id;
let reason = this.data.refundReason[reasonIndex].reason;
let order_code = this.data.reFaudCode;
this.setData({
reasonIndex:0,
order_code: order_code,
})
if (order_code) {
let param = {
method: 'app.SpaceOrders.refundApply',
reason_id,
reason,
order_code,
fromPage: "aFP_MineOrderContent"
}
api.get({data: param})
.then(json => {
this.hidderPicker();
if (json && json.code == 200) {
tt.navigateBack({
delta: 1
})
}
})
.catch(error => {
this.hidderPicker();
})
}
},
hidderPicker: function () {
this.setData({
showReason: false,
reFaudCode: ''
})
},
add0: function(m) {
return m<10?'0'+m:m
},
formatDate: function(shijianchuo) {
var time = new Date(shijianchuo * 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();
return y + '-' + this.add0(m) + '-' + this.add0(d) + ' ' + this.add0(h) + ':' + this.add0(mm) + ':' + this.add0(s);
},
formatImgUrl: function(json) {
json.data.order_goods && json.data.order_goods.map((item, index) => {
let replaceStr = "{width}";
let url = item.goods_image;
let real_pay_price = item.real_pay_price;
let goods_price = item.goods_price;
let goods_sale_price = item.sales_price;
if (new Number(real_pay_price).toFixed(2) == new Number(goods_sale_price) || !real_pay_price){
item.real_pay_price = item.goods_price ? item.goods_price : item.sales_price;
item.sales_price = '';
}
if (item.sales_price){
item.sales_price = new Number(item.sales_price).toFixed(2);
}
url = url.replace(new RegExp('{width}', 'gm'), '65').replace(new RegExp('{height}', 'gm'), '100');
item.goods_image = url;
});
// console.log(json);
},
getDetail:function (order_code) {
let param = {
method: APP_SPACEORDERS_DETAIL,
order_code: order_code,
uid: app.getUid()
}
api.get({data: param})
.then(json => {
tt.hideLoading();
this.setData({
isLoading: false,
});
if (json && json.code && json.code == 200) {
this.formatImgUrl(json);
let requestOK = true;
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);
}
let isShowExpress = false;
if (json.data.links && json.data.links.length > 0){
for (var i = 0;i < json.data.links.length;i++){
if (json.data.links[i] === "getExpress"){
isShowExpress = true;
break;
}
}
}
this.setData({
data: json.data,
requestOK: true,
pay_lefttime,
isShowExpress,
});
if (needTimer) {
this.stopTimer();
this.startTimer();
} else {
this.stopTimer();
}
}
})
.catch(error => {
tt.hideLoading();
this.setData({
isLoading: false,
});
});
},
onLoad:function(options){
// 生命周期函数--监听页面加载
let from_page_name = options.page_name ? options.page_name : '';
let from_page_param = options.page_param ? options.page_param : '';
let current_page_param = options.order_code;
this.setData({
order_code: options.order_code,
from_page_name, from_page_param, current_page_param,
isShowHomeNav: app.globalData.currentScene === 1014 || app.globalData.currentScene === "1014",
});
this.loadEnvelopesData();
var pages = getCurrentPages()
var currentPage = pages[pages.length - 1]
var url = currentPage.route
// let params = {
// PAGE_NAME: this.data.current_page_name,
// PAGE_PARAM: this.data.current_page_param,
// FROM_PAGE_NAME: this.data.from_page_name,
// FROM_PAGE_PARAM: this.data.from_page_param,
// PAGE_PATH: url
// };
// logEvent(YB_PAGE_OPEN_L, params);
// //订阅登录完成通知
// listen(function (succeed) {
// if (succeed) {
// this.getDetail(this.data.order_code);
// } else {
// let app = getApp()
// if (!app.getUid() || app.getUid() === 0) {
// tt.switchTab({
// url: '../../userCenter/userCenter',
// })
// }
// }
// }.bind(this))
},
onReady:function(){
// 生命周期函数--监听页面初次渲染完成
},
onShow:function(){
// 生命周期函数--监听页面显示
tt.showLoading({
title: '加载中...',
})
this.setData({
isLoading: true,
});
this.getDetail(this.data.order_code);
this.getRecommed();
this.getRefundSeason();
this.getResources();
},
onHide:function(){
// 生命周期函数--监听页面隐藏
this.stopTimer();
},
onUnload:function(){
// 生命周期函数--监听页面卸载
this.stopTimer();
},
onPullDownRefresh: function() {
// // 页面相关事件处理函数--监听用户下拉动作
// let params = {
// PAGE_NAME: this.data.current_page_name,
// PAGE_PARAM: this.data.current_page_param,
// FROM_PAGE_NAME: this.data.from_page_name,
// FROM_PAGE_PARAM: this.data.from_page_param,
// };
// logEvent(YB_PAGE_OPEN_L, params);
},
onReachBottom: function() {
// 页面上拉触底事件的处理函数
},
onExpressTapped: function (e) {
var code = e.currentTarget.dataset.order_code;
// console.log("查看物流");
tt.navigateTo({
url: '../../logisticsDetails/logisticsDetails?order_code=' + code,
})
},
/**
* 取消订单
*/
onCloseOrderTapped: function(e) {
var code = e.currentTarget.dataset.order_code;
var app = getApp();
var _self = this;
_self.setData({
order_code:code,
})
tt.showModal({
title: '取消订单',
content: '订单取消后不能恢复,确认取消此订单么?',
cancelText: '返回',
confirmText: '取消订单',
confirmColor: "#000000",
success: function(res) {
if (res.confirm) {
let param = {
method: APP_SPACEORDERS_CLOSE,
order_code: code,
uid: app.getUid(),
miniapp_type: app.globalData.miniapp_type,
}
api.get({data: param})
.then((json) => {
if (json && json.code && json.code == 200) {
tt.navigateBack({
delta: 1
})
}
else if (json && json.code && json.code != 200){
tt.showModal({title: json.message, showCancel:false})
}
})
.catch(error => {
})
}
}
})
},
/**
* 确认收货
*/
onConfirmTapped: function(e) {
var code = e.currentTarget.dataset.order_code;
var _self = this;
var app = getApp()
tt.showModal({
title: '确认收货',
content: '请确认是否已经收到商品?',
cancelText: '取消',
confirmText: '确定',
confirmColor: '#FF0000',
success: function(res) {
if (res.confirm) {
let param = {
method: APP_SPACEORDERS_CONFIRM,
order_code: code,
uid: app.getUid(),
miniapp_type: app.globalData.miniapp_type,
}
api.get({data: param})
.then((json) => {
if (json && json.code && json.code == 200) {
tt.navigateBack({
delta: 1
})
}
else {
}
})
.catch(error => {
})
}
}
})
},
//拼团购商品 点击立即购买
onBuyFromApp: function (e) {
tt.showModal({
title: '提示',
content: "拼团订单只能在APP支付,请在应用市场搜索下载“Yoho!buy有货”,使用微信登录完成支付",
confirmText: '确定',
showCancel: false,
success: function (res) {
if (res.confirm) {
}
}
})
},
/**
* 立即付款
*/
onBuyNowTapped: function(e) {
// let mCode = e.target.dataset.order_code;
// let group_no = e.target.dataset.group_no ? e.target.dataset.group_no : '';
// let activity_id = e.target.dataset.activity_id ? e.target.dataset.activity_id : '';
// let mOrder = {};
// let payParam = {};
// if (group_no && group_no != ''){
// payParam = {
// group_no,
// activity_id,
// fromPage:"groupPurchaseDetail"
// }
// }
// mOrder.order_code = mCode;
// wexinPay(mOrder,payParam)
},
/**
* 删除订单
*/
onDelOrderTapped: function(e) {
var code = e.currentTarget.dataset.order_code;
var _self = this;
tt.showModal({
content: '确认删除订单?',
cancelText: '取消',
confirmText: '确定',
confirmColor: '#FF0000',
success: function(res) {
if (res.confirm) {
let param = {
method: APP_SPACEORDERS_DELORDERBYCODE,
order_code: code,
uid: app.getUid()
}
api.get({data: param})
.then((json) => {
if (json && json.code && json.code == 200) {
tt.navigateBack({
delta: 1
})
}
})
.catch(error => {
})
}
}
})
},
/**
* 申请售后
*/
onAfterServiceTapped: function(e) {
tt.showModal({
title: '提示',
content: '小程序暂不支持退换货,请使用有货APP或官网退换货!',
showCancel: false,
confirmText: '确定',
})
},
changeAddress: function() {
// console.log(this.data.data.can_update_delivery_address)
// this.data.data.can_update_delivery_address == "Y" 不让在订单详情页 修改地址
if (false) {
//可以点击进入换地址
tt.navigateTo({
url: '../../addressManager/addressManager?currentMode=modeChange&order_code=' + this.data.data.order_code + '&page_name=' + this.data.current_page_name + '&page_param=' + this.data.current_page_param
})
}
else {
}
},
selectComplete: function(json) {
// console.log(json);
},
goTODefraudPage: function () {
// console.log("订单详情页跳转到防诈骗页面");
tt.navigateTo({
url: '../../antifraud/antifraud',
})
},
//获取红包信息
loadEnvelopesData: function () {
let app = getApp();
let that = this;
let param = {
// method: 'app.activity.payActivityProfile',
// uid: '500029682',//app.getUid(),
// orderCode: '1701060848',//this.data.orderCode,
// debug: 'XYZ',
method: 'app.activity.payActivityProfile',
uid: app.getUid(),
orderCode: this.data.order_code,
};
api.get({data: 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) {
});
},
onShareAppMessage: function (res) {
let param = {
FROM: res.from,
SHARE_RESUIL: 0,
TITLE: '我在有货给你发红包啦,专属好礼送不停!',
PATH: '/pages/envelopesActivity/envelopesActivity?token=' + this.data.token,
}
return {
title: param.TITLE,
path: param.PATH,
imageUrl: 'https://cdn.yoho.cn/20171218/fenxianghongbao.png',
success: function (res) {
// param.SHARE_RESUIL = 1
// logEvent(YB_SHARE_RESULT_L, param);
},
fail: function (res) {
// param.SHARE_RESUIL = 2
// logEvent(YB_SHARE_RESULT_L, param);
}
}
},
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);
},
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;
},
gotoGroupBuyDetail: function (res) {
let target = res.target;
let group_no = res.target.dataset.group_no ? res.target.dataset.group_no : '';
let activity_id = res.target.dataset.activity_id ? res.target.dataset.activity_id : '';
tt.navigateTo({
url: "../../groupPurchase/groupPurchaseResult?activity_id=" + activity_id + '&group_no=' + group_no + '&page_name=' + 'orderDetail' + '&page_param=' + this.data.current_page_param
});
},
/**
* 为你优选
*/
getRecommed: function () {
let gender = getGenderCode(getApp().globalData.selectedChannel);
let yh_channel = getChannelCode(getApp().globalData.selectedChannel);
let param = {
method: "app.home.newPreference",
gender,
yh_channel,
rec_pos: 100004,
limit: 30,
fromPage: "aFP_My",
}
api.get({data: param})
.then(json => {
if (json && json.code && json.code == 200) {
let data = json.data.product_list;
data = parseBrandListData(data);
this.setData({
recommdData: data,
})
}
});
},
copy: function (e) {
var that = this;
var content = e.currentTarget.dataset.copy_content;
var type = e.currentTarget.dataset.copy_type;
tt.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;
tt.setClipboardData({
data: '' + copy_url,
success: function (res) {
tt.hideToast();
},
})
tt.showModal({
title: '',
content: copy_content,
showCancel: false,
})
},
getResources: function () {
let that = this;
api.get({
url: '/operations/api/v5/resource/get',
data: {
content_code: "384329629395526cdb4c8bbb7be4d619"
},})
.then(json => {
if (json && json.code && json.code == 200 && json.data) {
for(var i = 0;i < json.data.length;i++){
//图片url转换
if(json.data[i] && json.data[i].data && json.data[i].data.list){
for (var j = 0;j < json.data[i].data.list.length; j++){
json.data[i].data.list[j].src = json.data[i].data.list[j].src.replace('{width}', json.data[i].data.imageWidth).replace('{height}', json.data[i].data.imageHeight).replace('{mode}',2);
// json.data[i].data.list[j].src = getImageUrlWithWH(json.data[i].data.list[j].src, windowWidth, windowWidth * json.data[i].data.imageHeight /json.data[i].data.imageWidth);
}
}
//图片宽高转换(为什么这个写法可行还需要再研究)
if (json.data[i] && json.data[i].data && json.data[i].data.imageHeight && json.data[i].data.imageWidth){
json.data[i].data.imageHeight = parseInt(json.data[i].data.imageHeight) / parseInt(json.data[i].data.imageWidth) * 750;//rpx
json.data[i].data.imageWidth = 750;//750rpx是固定的设计标准
}
}
that.setData({
resources: json.data,
});
}
}).catch(error => {});
},
})