orderDetail.js
39.8 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
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
import {API_HOST, SERVICE_HOST} from '../../../libs/config';
import {GET, POST} from '../../../libs/request';
import {wexinPay} from '../../../utils/wxpay';
import { getYHStorageSync, getImageUrlWithWH} from '../../../utils/util';
import { getChannelCode, getGenderCode, getRecPosCode, getRecommandContentCode } from '../../../utils/home';
import { parseBrandListData } from '../../../utils/productList';
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_DEPOSITTAIL_ASSETS_PAYMENT = "app.Shopping.depositTail.assets.payment";
const APP_SPACEORDERS_DEPOSITTAIL_ASSETS_COUNTUSABLECOUPON = "app.Shopping.depositTail.assets.countUsableCoupon";
const APP_SPACEORDERS_DEPOSITTAIL_ASSETS_COMPUTE = "app.Shopping.depositTail.assets.compute"
const APP_SPACEORDERS_DEPOSITTAIL_ASSETS_SUBMIT =
"app.Shopping.depositTail.assets.submit"
const APP_SPACEORDERS_DEPOSITTAIL_ASSETS_ROLLBACK =
"app.Shopping.depositTail.assets.rollback"
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: '00:00:00',
token: '',
activityBanner: '',
depositTailAssetsPaymentData: {},
countUsableCoupon: 0,
redPac: "红包",
isShowRedPac: false,//红包条目是否显示
isRedPacEnable: false,
isSwitchRedPac: false,//开关是否可用 false:可用 true:不可用
enableRedPacNum: 0,//可用红包数量
redPacDesc: '',//点击问号图标弹窗提示内容
redReduction: '',//
redStrUsedNum: '',//带有羊角符的可用余额
redTotalNum: 0,//红包总数
open_red_package: true,
promotion_formula_list: [],
promotion: '',
promotion_amount: '¥00.00',
yohoCoupon: "优惠券",
yohoCouponMomey: '0.00',
usable_couponsCount: 0,
hasSelectYohoCouponCode: false,
coupon_pay_rule: '',
coupon_code: '',
coupon_count: 0,
select_yoho_coupon_code_count: 0,
addressIcon: "../../statements/images/dizhi_icon@2x.png",
invoiceIcon: "../../statements/images/payment_yoho_coin@2x.png",
arrowIcon_m: "../../statements/images/disclosure-arrow_m@2x.png",
yohoCode: "有货币",
needYohoCode: false,
isSwitchYohoCoin: true,
updateYohoCoin: false,
use_yoho_coin: 0,
yoho_coin: 0,
yoho_coin_pay_rule: {},
total_yoho_coin_num: 0,
textArray: ['红包', '优惠券', '有货币', '发票'],
order_tail_pay_amount: 0,
closeOrder_tips: '订单取消后不能恢复,确认取消此订单么?',
invoice: "发票",
invoiceDetailTitle: "发票信息",
invoiceDetail: "电子发票-个人",
invoiceData: null,
needInvoice: false,
},
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)
GET(API_HOST, formIdParams)
},
getRefundSeason: function () {
let param = {
method: 'app.SpaceOrders.refundApplyReasons',
fromPage: 'aFP_MineOrderContent'
}
GET(API_HOST, 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;
wx.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"
}
GET(API_HOST, param)
.then(json => {
if (json && json.code && json.code == 200) {
wx.showToast({
title: '加入购物车成功',
complete: function () {
wx.switchTab({
url: '../../shopCart/shopCart',
})
}
})
}
})
}
}
})
},
//申请退款
onRefundApplyTapped: function (e) {
let that = this;
var code = e.currentTarget.dataset.order_code;
that.setData({
order_code:code,
});
let content = '申请退款后,本单享有的优惠可能会一并取消,确定申请吗?';
if (this.data.data && this.data.data.order_extInfo && this.data.data.order_extInfo.refund_apply_tips) {
content = this.data.data.order_extInfo.refund_apply_tips;
}
wx.showModal({
title: '提示',
content: content,
cancelText: '确定',
cancelColor: '#e0e0e0',
confirmText: '算了',
confirmColor: "#d0021b",
success: function (res) {
if (res.cancel) {
// 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,
}
GET(API_HOST, param)
.then(json => {
this.hidderPicker();
if (json && json.code == 200) {
wx.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"
}
GET(API_HOST, param)
.then(json => {
this.hidderPicker();
if (json && json.code == 200) {
wx.navigateBack({
delta: 1
})
}
})
.catch(error => {
this.hidderPicker();
})
}
},
yohoCodeCellArrowIconAction: function (e) {
let yoho_coin_pay_rule = this.data.depositTailAssetsPaymentData.yoho_coin_pay_rule;
let message = `1.订单金额大于${yoho_coin_pay_rule.amount_limit}元(含)\r\n2.有货币数量大于${yoho_coin_pay_rule.num_limit}个(含)\r\n3.有货币支付上限为每笔订单应付金额的${yoho_coin_pay_rule.max_pay_rate_desc}\r\n备注:使用有货币数量为100的整数倍,100有货币抵1元。`;
wx.showModal({
title: '有货币使用说明',
content: message,
showCancel: false,
confirmText: "知道了",
success: function (res) {
}
})
},
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);
},
switch2Change: function (e) {
let needInvoice = e.detail.value;
this.setData({
needInvoice,
});
},
switchChangeForYohoCode: function (e) {
let isRedPacEnable = this.data.isRedPacEnable;
let use_red_pacakge = isRedPacEnable ? 1 : 0
let needYohoCode = e.detail.value;
let updateYohoCoin = false;
let yoho_coin;
if (needYohoCode) {
yoho_coin = this.data.yoho_coin;
}
this.setData({
needYohoCode,
updateYohoCoin,
});
setTimeout(() => {
this.computeGetPaymentInfo(this.data.order_code, use_red_pacakge, this.data.coupon_code, yoho_coin, true);
}, 100);
},
yohoCouponAction: function (e) {
let delivery_wayAry = this.data.depositTailAssetsPaymentData.delivery_way ? this.data.depositTailAssetsPaymentData.delivery_way : [];
let currentDelivery_way = null;
let use_red_pacakge = this.data.enableRedPacNum;
let open_red_package = this.data.isRedPacEnable;
if (!this.data.isRedPacEnable) {
use_red_pacakge = 0;
}
let is_buyNow = 0;
if (this.data.from_page_name == 'shopCart') {
is_buyNow = 0;
} else if (this.data.from_page_name == 'groupPurchaseDetail') {
return;
} else {
is_buyNow = 1;
}
let goods_list = [];
if (this.data.depositTailAssetsPaymentData && this.data.depositTailAssetsPaymentData.order_goods) {
goods_list = this.data.depositTailAssetsPaymentData.order_goods;
}
let goods = goods_list[0];
let selectedSKU = goods && goods.product_sku ? goods.product_sku : 0;
let buy_number = goods && goods.buy_number ? goods.buy_number : 0;
var timestamp = Date.parse(new Date());
try {
wx.setStorageSync(timestamp + '', this.data.coupon_code);
} catch (e) {
}
let delivery_way_id = 1;
if (currentDelivery_way && currentDelivery_way.delivery_way_id) {
delivery_way_id = currentDelivery_way.delivery_way_id
}
console.log(delivery_way_id)
let open_yoho_code = this.data.needYohoCode ? 1 : 0;
wx.navigateTo({
url: '../../../page/subPackage/pages/useCoupons/useCoupons' + '?timestamp=' + timestamp + '' + '&delivery_way=' + delivery_way_id + '&product_sku=' + selectedSKU + '&is_buyNow=' + is_buyNow + '&buy_number=' + buy_number + "&use_red_pacakge=" + use_red_pacakge + "&open_red_package=" + open_red_package + "&isDepositTail=true" + "&order_code=" + this.data.order_code + "&open_yoho_code=" + open_yoho_code
})
},
yohoCouponTipAction: function (e) {
let message = this.data.depositTailAssetsPaymentData.coupon_pay_rule.desc;
wx.showModal({
title: '优惠券使用规则',
content: message,
showCancel: false,
confirmText: "知道了",
success: function (res) {
}
})
},
yohoRedCellArrowIconAction: function (e) {
let that = this;
wx.showModal({
title: '红包使用说明',
content: that.data.redPacDesc,
showCancel: false,
confirmText: "知道了",
success: function (res) {
}
})
},
getDetail:function (order_code) {
let param = {
method: APP_SPACEORDERS_DETAIL,
order_code: order_code,
uid: app.getUid(),
api_version: 1
}
wx.showLoading();
GET(API_HOST, param)
.then(json => {
wx.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;
}
}
}
if (json.data && json.data.order_extInfo && json.data.order_extInfo.closeOrder_tips) {
this.setData({
closeOrder_tips: json.data.order_extInfo.closeOrder_tips,
});
}
this.setData({
data: json.data,
requestOK: true,
pay_lefttime,
isShowExpress,
promotion_formula_list: json.data.order_amount_info.promotion_formulas,
promotion: json.data.order_amount_info.real_amount.promotion,
promotion_amount: json.data.order_amount_info.real_amount.promotion_amount,
order_tail_pay_amount: json.data.order_extInfo.order_tail_pay_amount,
order_deposit_amount: json.data.order_extInfo.order_deposit_amount
});
// 203 是尾款支付
if (json.data.order_detail_info.key === '203') {
this.regainGetPaymentInfo(order_code);
}
if (needTimer) {
this.stopTimer();
this.startTimer();
} else {
this.stopTimer();
}
}
})
.catch(error => {
wx.hideLoading();
this.setData({
isLoading: false,
});
});
},
invoiceIconAction: function (e) {
var timestamp = Date.parse(new Date());
try {
wx.setStorageSync(timestamp + '', this.data.invoiceData);
} catch (e) {
}
wx.navigateTo({
url: '../../invoice/invoice' + '?timestamp=' + timestamp + '' + '&userTel=' + this.data.data.delivery_info.mobile,
})
},
//发票选择回调
invoiceCallBack: function (data) {
let invoiceData = data;
// console.log(invoiceData);
this.setData({
invoiceData,
});
},
switch2ChangeForRedPac: function (e) {
let isRedPacEnable = !this.data.isRedPacEnable;
let use_red_pacakge = isRedPacEnable ? 1 : 0;
let needYohoCode = this.data.needYohoCode;
this.setData({
isRedPacEnable,
use_red_pacakge
});
let yoho_coin;
if (needYohoCode) {
yoho_coin = this.data.yoho_coin;
}
console.log('-------------------: ',needYohoCode);
setTimeout(() => {
this.computeGetPaymentInfo(this.data.order_code, use_red_pacakge, this.data.coupon_code, yoho_coin);
}, 100);
},
computeGetPaymentInfo(order_code, open_red_package, coupon_code, yoho_coin, isChangeYohoCode) {
let param_payment = {
method: APP_SPACEORDERS_DEPOSITTAIL_ASSETS_COMPUTE,
order_code: order_code,
open_red_package: open_red_package,
coupon_code: coupon_code,
use_yoho_coin: yoho_coin
}
wx.showLoading();
console.log('执行了');
GET(API_HOST, param_payment)
.then(json => {
wx.hideLoading();
this.setData({
isLoading: false,
});
if (!isChangeYohoCode) {
if (!this.data.needYohoCode) {
let total_yoho_coin_num = json.data.total_yoho_coin_num;
let amount_limit = json.data.yoho_coin_pay_rule.amount_limit;
let max_pay_rate_desc = json.data.yoho_coin_pay_rule.max_pay_rate_desc;
let num_limit = json.data.yoho_coin_pay_rule.num_limit;
let actualAmount = json.data.order_tail_pay_amount;
let use_yoho_coin = json.data.use_yoho_coin.toFixed(2);
let isSwitchYohoCoin = false;
let needYohoCode = this.data.needYohoCode;
console.log(actualAmount);
if (parseInt(total_yoho_coin_num) < parseInt(num_limit) || parseInt(actualAmount) < 20 || parseInt(use_yoho_coin) < 0) {
isSwitchYohoCoin = false;
needYohoCode = false;
} else {
isSwitchYohoCoin = true;
}
this.setData({
needYohoCode,
isSwitchYohoCoin,
});
}
}
if (json && json.code && json.code == 200) {
this.setData({
promotion_formula_list: json.data.promotion_formula_list,
use_yoho_coin: json.data.use_yoho_coin.toFixed(2),
yoho_coin: json.data.yoho_coin.toFixed(2),
yoho_coin_pay_rule: json.data.yoho_coin_pay_rule,
total_yoho_coin_num: json.data.total_yoho_coin_num,
order_tail_pay_amount: json.data.order_tail_pay_amount
});
if (this.data.data.order_detail_info.key === '203') {
this.setData({
promotion: json.data.real_amount.promotion,
promotion_amount: json.data.real_amount.promotion_amount,
});
}
if (json.data && json.data.coupon_pay) {
this.setData({
hasSelectYohoCouponCode: true,
yohoCouponMomey: json.data.coupon_pay.coupon_amount_str,
coupon_count: json.data.coupon_pay.coupon_count,
coupon_code: json.data.coupon_pay.coupon_code
})
}
}
this.getRedPackageResult(json);
}).catch(error => {
wx.hideLoading();
this.setData({
isLoading: false,
});
console.log(error);
});
this.getCountUsableCoupon(order_code, open_red_package);
},
getRedPackageResult(json) {
if (json.data && json.data.red_package_result) {
let redPacResult = json.data.red_package_result;
let redPacDesc = redPacResult.red_package_desc ? redPacResult.red_package_desc : '';
let redReduction = redPacResult.reduction_line ? redPacResult.reduction_line : '';
let isShowRedPac = true;
let enableRedPacNum = redPacResult.used_red_package ? redPacResult.used_red_package : 0;
let redTotalNum = redPacResult.total_red_package ? redPacResult.total_red_package : 0;
let redStrUsedNum = redPacResult.str_used_red_package ? redPacResult.str_used_red_package : '';
let isRedPacEnable = redPacResult.enabled_red_package == 1;
let isSwitchRedPac = !redPacResult.usable_red_package || redPacResult.usable_red_package <= 0;
let use_red_pacakge = enableRedPacNum;
this.setData({
isShowRedPac,
redPacDesc,
redReduction,
isRedPacEnable,
enableRedPacNum,
isSwitchRedPac,
redStrUsedNum,
redTotalNum,
use_red_pacakge
})
}
},
regainGetPaymentInfo(order_code) {
// 请求资产
// APP_SPACEORDERS_DEPOSITTAIL_ASSETS_PAYMENT
let param_payment = {
method: APP_SPACEORDERS_DEPOSITTAIL_ASSETS_PAYMENT,
order_code: order_code,
open_red_package: this.data.open_red_package, // 第一次请求,直接打开开关
}
wx.showLoading();
GET(API_HOST, param_payment)
.then(json => {
wx.hideLoading();
this.setData({
isLoading: false,
});
if (json && json.code && json.code == 200) {
this.setData({
depositTailAssetsPaymentData: json.data,
promotion_formula_list: json.data.shopping_cart_data.promotion_formula_list,
use_yoho_coin: json.data.use_yoho_coin.toFixed(2),
yoho_coin: json.data.yoho_coin.toFixed(2),
yoho_coin_pay_rule: json.data.yoho_coin_pay_rule,
total_yoho_coin_num: json.data.total_yoho_coin_num
});
if (this.data.data.order_detail_info.key === '203') {
let total_yoho_coin_num = json.data.total_yoho_coin_num;
let amount_limit = json.data.yoho_coin_pay_rule.amount_limit;
let max_pay_rate_desc = json.data.yoho_coin_pay_rule.max_pay_rate_desc;
let num_limit = json.data.yoho_coin_pay_rule.num_limit;
let actualAmount = json.data.shopping_cart_data.order_tail_pay_amount;
let use_yoho_coin = json.data.use_yoho_coin.toFixed(2);
this.setData({
promotion: json.data.shopping_cart_data.real_amount.promotion,
promotion_amount: json.data.shopping_cart_data.real_amount.promotion_amount,
});
let isSwitchYohoCoin = false;
let needYohoCode = this.data.needYohoCode;
if (parseInt(total_yoho_coin_num) < parseInt(num_limit) || parseInt(actualAmount) < 20 || parseInt(use_yoho_coin) < 0) {
isSwitchYohoCoin = false;
needYohoCode = false;
} else {
isSwitchYohoCoin = true;
}
this.setData({
needYohoCode,
isSwitchYohoCoin,
})
}
if (this.data.needYohoCode) {
this.computeGetPaymentInfo(order_code, this.data.open_red_package, json.data.coupon_pay.coupon_code, json.data.yoho_coin);
}
if (json.data && json.data.coupon_pay) {
this.setData({
hasSelectYohoCouponCode: true,
yohoCouponMomey: json.data.coupon_pay.coupon_amount_str,
coupon_code: json.data.coupon_pay.coupon_code,
coupon_count: json.data.coupon_pay.coupon_count
})
}
}
// 获取红包相关
this.getRedPackageResult(json);
}).catch(error => {
wx.hideLoading();
this.setData({
isLoading: false,
});
});
this.getCountUsableCoupon(order_code, true);
},
getCountUsableCoupon(order_code, open_red_package) {
// 请求
// APP_SPACEORDERS_DEPOSITTAIL_ASSETS_COUNTUSABLECOUPON
let param_count_usable_coupon = {
method: APP_SPACEORDERS_DEPOSITTAIL_ASSETS_COUNTUSABLECOUPON,
order_code: order_code,
open_red_package: open_red_package,
}
wx.showLoading();
GET(API_HOST, param_count_usable_coupon)
.then(json => {
wx.hideLoading();
this.setData({
isLoading: false,
});
if (json && json.code && json.code == 200) {
this.setData({
countUsableCoupon: json.data.count
});
}
}).catch(error => {
wx.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) {
wx.switchTab({
url: '../../userCenter/userCenter',
})
}
}
}.bind(this))
wx.showLoading({
title: '加载中...',
})
this.setData({
isLoading: true,
});
this.getDetail(this.data.order_code);
this.getRecommed();
this.getRefundSeason();
this.getResources();
},
onReady:function(){
// 生命周期函数--监听页面初次渲染完成
},
onShow:function(){
// 生命周期函数--监听页面显示
let yoho_code;
if (this.data.needYohoCode) {
yoho_code = this.data.yoho_coin;
}
if (this.data.data && this.data.data.order_detail_info && this.data.data.order_detail_info.key === '203') {
this.computeGetPaymentInfo(this.data.order_code, this.data.open_red_package, this.data.coupon_code, yoho_code);
}
},
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("查看物流");
wx.navigateTo({
url: '../../logisticsDetails/logisticsDetails?order_code=' + code,
})
},
/**
* 取消尾款支付
*/
onCloseTailOrderTapped(e) {
var code = e.currentTarget.dataset.order_code;
var app = getApp();
var _self = this;
_self.setData({
order_code: code,
});
wx.showModal({
title: '提示',
content: _self.data.closeOrder_tips,
cancelText: '确定',
cancelColor: '#e0e0e0',
confirmText: '算了',
confirmColor: "#d0021b",
success: function (res) {
if (res.cancel) {
let param = {
method: APP_SPACEORDERS_DEPOSITTAIL_ASSETS_ROLLBACK,
order_code: code,
uid: app.getUid(),
miniapp_type: app.globalData.miniapp_type,
}
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 => {
})
}
}
});
},
/**
* 取消订单
*/
onCloseOrderTapped: function(e) {
var code = e.currentTarget.dataset.order_code;
var app = getApp();
var _self = this;
_self.setData({
order_code:code,
})
wx.showModal({
title: '提示',
content: _self.data.closeOrder_tips,
cancelText: '确定',
cancelColor: '#e0e0e0',
confirmText: '算了',
confirmColor: "#d0021b",
success: function(res) {
if (res.cancel) {
let param = {
method: APP_SPACEORDERS_CLOSE,
order_code: code,
uid: app.getUid(),
miniapp_type: app.globalData.miniapp_type,
}
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 => {
})
}
}
})
},
/**
* 确认收货
*/
onConfirmTapped: function(e) {
var code = e.currentTarget.dataset.order_code;
var _self = this;
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,
uid: app.getUid(),
miniapp_type: app.globalData.miniapp_type,
}
GET(API_HOST, param)
.then((json) => {
if (json && json.code && json.code == 200) {
wx.navigateBack({
delta: 1
})
}
else {
}
})
.catch(error => {
})
}
}
})
},
//拼团购商品 点击立即购买
onBuyFromApp: function (e) {
wx.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 : '';
if (this.data.data.order_detail_info.key === '201') {
// let that = this;
// wx.showModal({
// title: "提示",
// content: '预售商品定金不支持退款,如需取消订单,只退等同于定金30%的有货币,同意后方可下单。',
// showCancel: true,
// cancelText: "我再想想",
// confirmText: "同意下单",
// success: function (res) {
// if (res.cancel) {
// } else {
let payment_amount = this.data.order_deposit_amount;
let mOrder = { payment_amount};
let payParam = {};
mOrder.order_code = mCode;
wexinPay(mOrder, payParam);
// }
// }
// });
return;
}
// 如果是尾款支付状态
if (this.data.data.order_detail_info.key === '203') {
let needInvoice = this.data.needInvoice;
let invoiceData = this.data.invoiceData;
let invoices_title = invoiceData ? (invoiceData.personal ? invoiceData.personName : invoiceData.companyName) : '个人';
let invoices_type = 2;//int 是 2 null 发票类型 1 纸质 2 电子
let invoice_content = 12//int 是 12 12 发票内容id 12:明细
let buyerTaxNumber = invoiceData ? (invoiceData.personal ? '' : invoiceData.taxNum) : '';//String 是 440300568519737 null 购买方纳税人识别号, 需要开具电子发票且发票抬头为单位信息时为必填项
let param = {
method: APP_SPACEORDERS_DEPOSITTAIL_ASSETS_SUBMIT,
order_code: mCode,
use_red_package: this.data.enableRedPacNum,
use_yoho_coin: this.data.use_yoho_coin,
coupon_code: this.data.coupon_code
}
if (needInvoice) {
param.invoices_title = invoices_title;
param.invoices_type = invoices_type;
param.invoice_content = 12;
param.buyerTaxNumber = buyerTaxNumber;
}
GET(API_HOST, param)
.then((json) => {
if (json && json.code && json.code == 200) {
let mOrder = json.data;
let payParam = {};
mOrder.order_code = mCode;
wexinPay(mOrder, payParam)
}
})
.catch(error => {
})
} else {
let payment_amount = this.data.order_tail_pay_amount;
let mOrder = {
payment_amount
};
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;
wx.showModal({
content: '确认删除订单?',
cancelText: '取消',
confirmText: '确定',
confirmColor: '#FF0000',
success: function(res) {
if (res.confirm) {
let param = {
method: APP_SPACEORDERS_DELORDERBYCODE,
order_code: code,
uid: app.getUid()
}
GET(API_HOST, param)
.then((json) => {
if (json && json.code && json.code == 200) {
wx.navigateBack({
delta: 1
})
}
})
.catch(error => {
})
}
}
})
},
/**
* 申请售后
*/
onAfterServiceTapped: function(e) {
// 跳转售后按钮
wx.navigateTo({
url: `/page/subPackage/pages/afterSale/afterSale?order_code=${this.data.order_code}`,
})
// wx.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) {
//可以点击进入换地址
wx.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) {
},
goTODefraudPage: function () {
wx.navigateTo({
url: '/pagesSecond/pages/antifraud/antifraud',
})
},
//获取红包信息
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) {
});
},
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 : '';
wx.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",
}
GET(API_HOST, 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;
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,
})
},
getResources: function () {
var app = getApp();
let that = this;
let content_code = "384329629395526cdb4c8bbb7be4d619";
let param = {
content_code,
};
GET(API_HOST + '/operations/api/v5/resource/get', param).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 => {});
},
})