statements.js
31.2 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
import { API_HOST, SERVICE_HOST } from '../../common/config';
import { GET, POST } from '../../common/request';
import { wexinPay } from '../../utils/wxpay';
import {
logEvent,
YB_SC_ORD,
YB_PAGE_OPEN_L,
} from '../../common/analytics.js'
let PV_ID = new Date().getTime() + '';
import md5 from '../../vendors/md5';
//获取应用实例
let app = getApp();
Page({
data: {
//固定不变数据
arrowIcon_h: "./images/disclosure-arrow_h@2x.png",
arrowIcon_i: "./images/disclosure-arrow_i@2x.png",
arrowIcon_m: "./images/disclosure-arrow_m@2x.png",
address_UnCheckIcon: "./images/address_Check@2x.png",
address_CheckedIcon: "./images/address_Checked@2x.png",
productImageBottomImage_price_gift: "./images/jjg-lab@2x.png",
productImageBottomImage_gift: "./images/zp-lab@2x.png",
addressIcon: "./images/dizhi_icon@2x.png",
invoiceIcon: "./images/payment_yoho_coin@2x.png",
addressPlaceholder: "请填入收货地址",
deliveryTitle: "配送方式",
deliveryExpand: false,//是否张开配送方式
delivery_way: null,
deliveryTimeExpand: false,//是否张开送货时间
deliveryTime: "送货时间",
delivery_time: null,
yohoCoupon: "优惠劵/优惠劵码",
yohoCouponMomey: '0.00',
usable_couponsCount: 0,
hasSelectYohoCouponCode: null,
hasSelectyohoCouponList: [],
invoice: "发票",
productAmountTitle: "商品金额",
freight: "运费",
activity: "活动金额",
payAmount: "实付金额",
payMentButtonTitle: "微信安全支付",
invoiceDetailTitle: "发票信息",
invoiceDetail: "个人-明细",
invoiceData: null,
needInvoice: false,
lineIcon: "./images/boy_xie@2x.png",
//可变变数据
productData: {},
addressId: "",
hasAddress: false,
listTop : 100,
addressName: "",
userTel: "",
currentAddress: "",
goods_list: null,//商品列表
isJit: false,
jitProductSku: '',
use_yoho_coin: 0,
yoho_coin: 0,
total_yoho_coin_num: 0,
amount_limit: 0,
max_pay_rate_desc: 0,
num_limit: 0,
yohoCode: "有货币",
needYohoCode: false,
isSwitchYohoCoin: false,
updateYohoCoin: false,
productAmount: "00.00",
freightAmount: "00.00",
activityAmount: "00:00",
hasActivity: false,
actualAmount: "00.00",
from_page_name: '',
from_page_param: '',
current_page_name: 'statements',
current_page_param: '',
promotion_formula_list: [],
package_title_detail: '',
formId:'',
},
formSubmit: function (e) {
// console.log('####e:', e.detail.formId)
let formId = e.detail.formId;
this.setData({
formId,
});
if (this.data.from_page_name == 'shopCart') {
this.paymentFromShopCar();
} else {
this.paymentNow();
}
},
switch2Change: function (e) {
let needInvoice = e.detail.value;
this.setData({
needInvoice,
});
},
//发票
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.userTel,
})
},
//发票选择回调
invoiceCallBack: function (data) {
let invoiceData = data;
// console.log(invoiceData);
this.setData({
invoiceData,
});
},
//选择送货时间
selectDeliveryTimeAction: function (e) {
let deliveryTimeSelectIndex = e.target.dataset.name;
let delivery_time = this.data.delivery_time;
for (var i = 0; i < delivery_time.length; i++) {
let item = delivery_time[i];
if (deliveryTimeSelectIndex == i) {
item.default = "Y";
} else {
item.default = "N";
}
}
let deliveryTimeExpand = false;
this.setData({
delivery_time,
deliveryTimeExpand
});
},
//展开选择送货时间
expandSelectDeliveryTimeAction: function (e) {
let deliveryTimeExpand = !this.data.deliveryTimeExpand;
this.setData({
deliveryTimeExpand,
});
},
//选择快递方式
selectDeliveryAction: function (e) {
let deliverySelectIndex = e.target.dataset.name;
let delivery_way = this.data.delivery_way;
for (var i = 0; i < delivery_way.length; i++) {
let item = delivery_way[i];
if (deliverySelectIndex == i) {
if (item.is_support == "N") {
wx.showModal({
content: '暂不支持',
showCancel: false,
confirmText: "OK",
success: function (res) {
}
})
return;
}
item.default = "Y";
} else {
item.default = "N";
}
}
let deliveryExpand = false;
this.setData({
delivery_way,
deliveryExpand,
});
if (this.data.from_page_name == 'shopCart') {
this.shoppingCompute();
} else {
this.shoppingComputeForBuyNow();
}
},
//展开选择快递方式
deliveryExpandSelectDeliveryAction: function (e) {
let deliveryExpand = !this.data.deliveryExpand;
this.setData({
deliveryExpand,
});
},
//优惠劵点击
yohoCouponAction: function (e) {
let delivery_wayAry = this.data.delivery_way ? this.data.delivery_way : [];
let currentDelivery_way = null;
for (var i = 0; i < delivery_wayAry.length; i++) {
let item = delivery_wayAry[i];
if (item.default == "Y") {
currentDelivery_way = item;
}
}
let is_buyNow = 0;
if (this.data.from_page_name == 'shopCart') {
is_buyNow = 0;
} else {
is_buyNow = 1;
}
let goods_list = [];
if (this.data.productData && this.data.productData.data && this.data.productData.data.goods_list) {
goods_list = this.data.productData.data.goods_list;
}
let goods = goods_list[0];
let selectedSKU = goods && goods.product_sku ? goods.product_sku : 0;
var timestamp = Date.parse(new Date());
try {
wx.setStorageSync(timestamp + '', this.data.hasSelectyohoCouponList);
} catch (e) {
}
let delivery_way_id = ''
if (currentDelivery_way && currentDelivery_way.delivery_way_id) {
delivery_way_id = currentDelivery_way.delivery_way_id
}
wx.navigateTo({
url: '../useCoupon/useCoupon' + '?timestamp=' + timestamp + '' + '&delivery_way=' + delivery_way_id + '&product_sku=' + selectedSKU + '&is_buyNow=' + is_buyNow + '&buy_number=' + goods.buy_number,
})
},
//优惠劵选择页回调
couponTapped: function (data) {
let hasSelectYohoCouponCode = null;
if (data && data.length > 0) {
for (var i = 0; i < data.length; i++) {
let item = data[i];
if (item.hasSelect) {
if (hasSelectYohoCouponCode) {
hasSelectYohoCouponCode = hasSelectYohoCouponCode + ',' + item.coupon_code;
} else {
hasSelectYohoCouponCode = item.coupon_code;
}
}
}
}
this.setData({
hasSelectYohoCouponCode,
hasSelectyohoCouponList: data,
})
if (this.data.from_page_name == 'shopCart') {
// console.log('shoppingCompute shopcar');
this.shoppingCompute();
} else {
// console.log('shoppingComputeForBuyNow');
this.shoppingComputeForBuyNow();
}
},
//yoho币点击
switch2ChangeForYohoCode: function (e) {
let needYohoCode = !this.data.needYohoCode;
let updateYohoCoin = false;
this.setData({
needYohoCode,
updateYohoCoin
});
if (this.data.from_page_name == 'shopCart') {
this.shoppingCompute();
} else {
this.shoppingComputeForBuyNow();
}
},
//有货币可点击问号按钮点击
yohoCodeCellArrowIconAction: function (e) {
let message = "1.订单金额大于20元(含)" + "\r" + "2.有货币数量大于100个(含)" + "\r" + "3.有货币支付上限为每笔订单应付金额的50%" + "\r" + "备注:使用有货币数量为100的整数倍,100有货币抵1元。";
wx.showModal({
title: '有货币使用说明',
content: message,
showCancel: false,
confirmText: "知道了",
success: function (res) {
}
})
},
//跳转地址选择页
otherAddressTapped: function (e) {
let delivery_address = this.data.hasAddress ? this.data.productData.data.delivery_address : "";
let addre_ID = this.data.addressId ? this.data.addressId : (delivery_address ? delivery_address.address_id : "");
wx.navigateTo({
url: '../addressManager/addressManager?fromPage=statement¤tMode=modeSelect&address_id=' + addre_ID
})
},
//地址选择页回调
selectComplete: function (data) {
if (data) {
let listTop = 190;
this.setData({
hasAddress: true,
listTop,
addressName: data.consignee,
userTel: data.mobile,
addressId: data.address_id,
currentAddress: data.area + data.address,
})
}
},
loadData: function (value) {
let delivery_time = value.data.delivery_time;
let delivery_way = value.data.delivery_way;
let shopping_cart_data = value.data.shopping_cart_data;
let promotion_formula_list = shopping_cart_data.promotion_formula_list;
let use_yoho_coin = value.data.use_yoho_coin.toFixed(2);
let yoho_coin = value.data.yoho_coin.toFixed(2);
let total_yoho_coin_num = value.data.total_yoho_coin_num;
let amount_limit = value.data.yoho_coin_pay_rule.amount_limit;
let max_pay_rate_desc = value.data.yoho_coin_pay_rule.max_pay_rate_desc;
let num_limit = value.data.yoho_coin_pay_rule.num_limit;
let isSwitchYohoCoin = false;
let needYohoCode = this.data.needYohoCode;
let actualAmount = value.data.shopping_cart_data.last_order_amount.toFixed(2);
let package_list = shopping_cart_data.package_list;
let package_title = shopping_cart_data.package_title;
let package_title_detail = '';
let jitProductSku = this.data.jitProductSku;
// console.log(package_list);
// console.log(jitProductSku);
// console.log(promotion_formula_list);
if (this.data.isJit) {
package_list && package_list.length > 0 && package_list.map((item, index) => {
if (package_title_detail.length == 0) {
let goods_list = item.goods_list;
goods_list && goods_list.length > 0 && goods_list.map((goodsItem, index) => {
if (package_title_detail.length == 0 && goodsItem.product_sku == jitProductSku) {
package_title_detail = item.title;
}
});
}
});
}
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.isloading = false;
this.setData({
delivery_time,
delivery_way,
isSwitchYohoCoin,
needYohoCode,
use_yoho_coin,
yoho_coin,
total_yoho_coin_num,
amount_limit,
max_pay_rate_desc,
num_limit,
productAmountTitle: promotion_formula_list[0].promotion,
productAmount: promotion_formula_list[0].promotion_amount,
freight: promotion_formula_list.length > 1 ? promotion_formula_list[1].promotion : '',
freightAmount: promotion_formula_list.length > 1 ? promotion_formula_list[1].promotion_amount : '',
hasActivity: promotion_formula_list.length > 2 ? true : false,
activity: promotion_formula_list.length > 2 ? promotion_formula_list[2].promotion : '',
activityAmount: promotion_formula_list.length > 2 ? promotion_formula_list[2].promotion_amount : '',
actualAmount,
promotion_formula_list,
package_title_detail,
})
if (this.data.from_page_name == 'shopCart') {
this.loadCouponList();
} else {
this.loadCouponListForBuyNow();
}
},
loadCouponList: function () {
// console.log('from shopCar loadCouponList');
let app = getApp();
let that = this;
let delivery_wayAry = this.data.delivery_way ? this.data.delivery_way : [];
let currentDelivery_way = null;
for (var i = 0; i < delivery_wayAry.length; i++) {
let item = delivery_wayAry[i];
if (item.default == "Y") {
currentDelivery_way = item;
}
}
let param = {
method: 'app.Shopping.countUsableCoupon',
uid: app.getUid(),
fromPage: 'iFP_Coupon',
delivery_way: currentDelivery_way ? currentDelivery_way.delivery_way_id : 1,
};
// console.log(param);
let usable_couponsCount = 0;
GET(API_HOST, param)
.then(function (data) {
if (data && data.code == 200) {
let {
count,
} = data.data;
// console.log(data);
that.setData({
usable_couponsCount: count,
});
} else {
}
})
.catch(function (error) {
});
},
loadCouponListForBuyNow: function () {
// console.log('for buyNow loadCouponListForBuyNow');
let app = getApp();
let that = this;
let goods_list = [];
if (this.data.productData && this.data.productData.data && this.data.productData.data.goods_list) {
goods_list = this.data.productData.data.goods_list;
}
let goods = goods_list[0];
let param = {
method: 'app.Buynow.countUsableCoupon',
uid: app.getUid(),
fromPage: 'iFP_Coupon',
product_sku: goods && goods.product_sku > 0 ? goods.product_sku : 0,
sku_type: 'I',
buy_number: goods && goods.buy_number ? goods.buy_number: '',
};
// console.log(param);
let usable_couponsCount = 0;
GET(API_HOST, param)
.then(function (data) {
if (data && data.code == 200) {
let {
count,
} = data.data;
// console.log(data);
that.setData({
usable_couponsCount: count,
});
} else {
// console.log(data);
}
})
.catch(function (error) {
// console.log(error);
});
},
shoppingCompute: function () {
// console.log('shoppingCompute');
let app = getApp();
let that = this;
let delivery_wayAry = this.data.delivery_way;
let delivery_way = null;
for (var i = 0; i < delivery_wayAry.length; i++) {
let item = delivery_wayAry[i];
if (item.default == "Y") {
delivery_way = item;
}
}
let param = {
method: 'app.Shopping.compute',
payment_type: 1,//支付方式,1 在线支付 2 货到付款
delivery_way: delivery_way.delivery_way_id,
use_yoho_coin: this.data.needYohoCode ? this.data.yoho_coin : 0,//使用的yoho币金额,单位元1:00
use_red_envelopes: 0,//使用的红包,单位元
coupon_code: this.data.hasSelectYohoCouponCode ? this.data.hasSelectYohoCouponCode : "",//优惠券code,多个用","分割
promotion_code: "",//优惠码code
fromPage: "iFP_Payment",
cart_type: "ordinary",
uid: app.getUid(),
};
// console.log(param);
GET(API_HOST, param)
.then(function (data) {
if (data && data.code == 200) {
// console.log(data);
// console.log('data');
that.shoppingComputeData(data);
} else {
}
})
.catch(function (error) {
});
},
shoppingComputeForBuyNow: function () {
// console.log('shoppingComputeForBuyNow');
let app = getApp();
let that = this;
let goods_list = [];
if (this.data.productData && this.data.productData.data && this.data.productData.data.goods_list) {
goods_list = this.data.productData.data.goods_list;
}
let goods = goods_list[0];
let delivery_wayAry = this.data.delivery_way;
let delivery_way = null;
for (var i = 0; i < delivery_wayAry.length; i++) {
let item = delivery_wayAry[i];
if (item.default == "Y") {
delivery_way = item;
}
}
// console.log(this.data);
let param = {
method: 'app.Buynow.compute',
fromPage: "iFP_Payment",
cart_type: "ordinary",
uid: app.getUid(),
product_sku: goods && goods.product_sku > 0 ? goods.product_sku : 0,
sku_type: 'I',
buy_number: goods.buy_number,
payment_type: 1,//支付方式,1 在线支付 2 货到付款
delivery_way: delivery_way.delivery_way_id,
use_yoho_coin: this.data.needYohoCode ? this.data.yoho_coin : 0,//使用的yoho币金额,单位元1:00
use_red_envelopes: 0,//使用的红包,单位元
coupon_code: this.data.hasSelectYohoCouponCode ? this.data.hasSelectYohoCouponCode : "",//优惠券code,多个用","分割
promotion_code: "",//优惠码code
};
// console.log(param);
GET(API_HOST, param)
.then(function (data) {
if (data && data.code == 200) {
// console.log(data);
// console.log('data');
that.shoppingComputeData(data);
} else {
}
})
.catch(function (error) {
});
},
shoppingComputeData: function (value) {
let promotion_formula_list = value.data.promotion_formula_list;
let use_yoho_coin = value.data.use_yoho_coin.toFixed(2);
let yoho_coin = value.data.yoho_coin.toFixed(2);
let total_yoho_coin_num = value.data.total_yoho_coin_num;
let amount_limit = value.data.yoho_coin_pay_rule.amount_limit;
let max_pay_rate_desc = value.data.yoho_coin_pay_rule.max_pay_rate_desc;
let num_limit = value.data.yoho_coin_pay_rule.num_limit;
let yohoCouponMomey = value.data.coupon_amount.toFixed(2);
let actualAmount = value.data.last_order_amount.toFixed(2);
let updateYohoCoin = true;
this.isloading = false;
// console.log(use_yoho_coin);
let isSwitchYohoCoin = false;
if (parseInt(total_yoho_coin_num) < parseInt(num_limit) || parseInt(actualAmount) < 20 || parseInt(use_yoho_coin) < 0) {
isSwitchYohoCoin = false;
} else {
isSwitchYohoCoin = true;
}
this.setData({
isSwitchYohoCoin,
updateYohoCoin,
use_yoho_coin,
yoho_coin,
total_yoho_coin_num,
amount_limit,
max_pay_rate_desc,
num_limit,
productAmountTitle: promotion_formula_list[0].promotion,
productAmount: promotion_formula_list[0].promotion_amount,
freight: promotion_formula_list.length > 1 ? promotion_formula_list[1].promotion : '',
freightAmount: promotion_formula_list.length > 1 ? promotion_formula_list[1].promotion_amount : '',
hasActivity: promotion_formula_list.length > 2 ? true : false,
activity: promotion_formula_list.length > 2 ? promotion_formula_list[2].promotion : '',
activityAmount: promotion_formula_list.length > 2 ? promotion_formula_list[2].promotion_amount : '',
actualAmount,
yohoCouponMomey,
promotion_formula_list,
});
},
paymentBtnAction: function (event) {
// console.log('paymentBtnAction');
if (!this.data.hasAddress) {
wx.showModal({
content: '请先添加收货地址!',
showCancel: false,
confirmText: "OK",
success: function (res) {
}
})
return;
}
if (this.isloading) {
// console.log('aaaaa');
return
}
this.isloading = true;
},
//微信支付action
paymentFromShopCar: function () {
let that = this;
let app = getApp();
// console.log('paymentFromShopCar');
let delivery_address = this.data.productData.data.delivery_address;
let addre_ID = this.data.addressId ? this.data.addressId : delivery_address ? delivery_address.address_id : "";
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 delivery_timeAry = this.data.delivery_time;
let delivery_time = null;
for (var i = 0; i < delivery_timeAry.length; i++) {
let item = delivery_timeAry[i];
if (item.default == "Y") {
delivery_time = item;
}
}
let delivery_wayAry = this.data.delivery_way;
let delivery_way = null;
for (var i = 0; i < delivery_wayAry.length; i++) {
let item = delivery_wayAry[i];
if (item.default == "Y") {
delivery_way = item;
}
}
let goods_list = [];
if (this.data.productData && this.data.productData.data && this.data.productData.data.goods_list) {
goods_list = this.data.productData.data.goods_list;
}
let skn = '';
let sku = '';
let pID = '';
for (var i = 0; i < goods_list.length; i++) {
let goods = goods_list[i];
let skn_i = goods && goods.product_skn ? goods.product_skn : 0;
let sku_i = goods && goods.product_sku ? goods.product_sku : 0;
let pID_i = goods && goods.product_id ? goods.product_id : 0;
if (i == 0) {
// console.log('0');
skn = skn_i;
sku = sku_i;
pID = pID_i;
} else {
// console.log('1');
skn = skn + ',' + skn_i;
sku = sku + ',' + sku_i;
pID = pID + ',' + pID_i;
}
}
let param = {
method: 'app.Shopping.submit',
uid: this.data.productData.data.uid,// int 否 3236556 0 用户id
cart_type: 'ordinary',//string 否 ordinary ordinary 购物车类型
address_id: addre_ID,//int 否 5816006 送货地址id
delivery_way: delivery_way ? delivery_way.delivery_way_id : 1,//int 否 1 发货方式(1:普通, 2顺丰)
delivery_time: delivery_time ? delivery_time.delivery_time_id : 0,//int 否 2 寄送时间类型
receiverMobile: delivery_address ? delivery_address.mobile : "",
use_yoho_coin: this.data.needYohoCode ? this.data.use_yoho_coin : 0,//double 否 1.00 使用的yoho币金额,单位元
use_red_envelopes: 0,//使用的红包,单位元
payment_id: 15,//int 否 15 支付id
payment_type: 1,//支付方式,1 在线支付 2 货到付款
coupon_code: this.data.hasSelectYohoCouponCode ? this.data.hasSelectYohoCouponCode : "",//优惠券code,多个用","分割
client_type: 'miniapp',//string 否 web iphone 终端
is_print_price: "N",//string 否 "Y" "N" 是否打印
is_continue_buy: "N",//string 否 "N" "Y" 是否继续结算
sale_channel: '1',
miniapp_type: app.globalData.miniapp_type,
}
if (needInvoice) {
param.invoices_title = invoices_title;
param.invoices_type = invoices_type;
param.invoice_content = 12;
param.buyerTaxNumber = buyerTaxNumber;
}
// console.log(param);
GET(API_HOST, param)
.then(function (data) {
if (data && data.code == 200) {
// console.log(data);
that.isloading = false;
let params = {
PRD_SKN: skn,
RPD_SKU: sku,
ORD_NUM: data.data.order_code,
PRD_ID: pID,
ORDER_TYPE: 101,
};
logEvent(YB_SC_ORD, params);
wx.reportAnalytics('order_created', {
order: '',
order_code: md5(data.data.order_code),
order_type: 101,
});
//上报formId
let formIdParams = {
uid: app.getUid(),
order_code: data.data.order_code,
openId: app.globalData.openID ? app.globalData.openID : wx.getStorageSync('openID'),
miniapp_type: app.globalData.miniapp_type,
formId: that.data.formId,
method: 'wechat.formId.add',
}
GET(API_HOST, formIdParams)
// console.log(params);
if (parseInt(that.data.actualAmount) > 0) {
wexinPay(data.data)
} else {
wx.navigateTo({
url: "../paymentSuccessed/paymentSuccessed?orderCode=" + data.data.order_code + '&hasSuc=true' + '&price=' + parseInt(that.data.actualAmount).toFixed(2)
});
}
} else {
wx.showModal({
content: data.message,
showCancel: false,
confirmText: "确定",
});
that.isloading = false;
}
})
.catch(function (error) {
});
},
//微信支付action
paymentNow: function () {
let app= getApp();
// console.log('paymentNow');
let that = this;
let goods_list = [];
if (this.data.productData && this.data.productData.data && this.data.productData.data.goods_list) {
goods_list = this.data.productData.data.goods_list;
}
let goods = goods_list[0];
let delivery_address = this.data.productData.data.delivery_address;
let addre_ID = this.data.addressId ? this.data.addressId : delivery_address ? delivery_address.address_id : "";
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 delivery_timeAry = this.data.delivery_time;
let delivery_time = null;
for (var i = 0; i < delivery_timeAry.length; i++) {
let item = delivery_timeAry[i];
if (item.default == "Y") {
delivery_time = item;
}
}
let delivery_wayAry = this.data.delivery_way;
let delivery_way = null;
for (var i = 0; i < delivery_wayAry.length; i++) {
let item = delivery_wayAry[i];
if (item.default == "Y") {
delivery_way = item;
}
}
let param = {
method: 'app.Buynow.submit',
uid: this.data.productData.data.uid,
product_sku: goods && goods.product_sku ? goods.product_sku : 0,
sku_type: 'I',
buy_number: goods.buy_number,
address_id: addre_ID,//int 否 5816006 送货地址id
delivery_way: delivery_way ? delivery_way.delivery_way_id : 1,//int 否 1 发货方式(1:普通, 2顺丰)
delivery_time: delivery_time ? delivery_time.delivery_time_id : 0,//int 否 2 寄送时间类型
use_yoho_coin: this.data.needYohoCode ? this.data.use_yoho_coin : 0,//double 否 1.00 使用的yoho币金额,单位元
use_red_envelopes: 0,//使用的红包,单位元
payment_id: 15,//int 否 15 支付id
payment_type: 1,//支付方式,1 在线支付 2 货到付款
coupon_code: this.data.hasSelectYohoCouponCode ? this.data.hasSelectYohoCouponCode : "",//优惠券code,多个用","分割
client_type: 'miniapp',//string 否 web iphone 终端
receiverMobile: delivery_address ? delivery_address.mobile : "",
sale_channel:'1',
miniapp_type: app.getMiniappType(),
}
// console.log('#####param',param)
// if (needInvoice) {
// param.invoices_title = invoices_title;
// param.invoices_type = invoices_type;
// }
if (needInvoice) {
param.invoices_title = invoices_title;
param.invoices_type = invoices_type;
param.invoice_content = 12;
param.buyerTaxNumber = buyerTaxNumber;
}
// console.log(param);
// console.log(goods);
GET(API_HOST, param)
.then(function (data) {
if (data && data.code == 200) {
// console.log(data);
that.isloading = false;
let params = {
PRD_SKN: goods && goods.product_skn ? goods.product_skn: 0,
RPD_SKU: goods && goods.product_sku ? goods.product_sku: 0,
ORD_NUM: data.data.order_code,
PRD_ID: goods.product_id > 0 ? goods.product_id : 0,
ORDER_TYPE: 102,
};
logEvent(YB_SC_ORD, params);
wx.reportAnalytics('order_created', {
order: '',
order_code: md5(data.data.order_code),
order_type: 102,
});
//上报formId
let formIdParams = {
uid: app.getUid(),
order_code: data.data.order_code,
openId: app.globalData.openID ? app.globalData.openID : wx.getStorageSync('openID'),
miniapp_type: app.getMiniappType(),
formId: that.data.formId ,
method: 'wechat.formId.add',
}
GET(API_HOST, formIdParams)
.then(function (data) {
})
.catch(function (error) {
});
if (parseInt(that.data.actualAmount) > 0) {
wexinPay(data.data)
} else {
wx.navigateTo({
url: "../paymentSuccessed/paymentSuccessed?orderCode=" + data.data.order_code + '&hasSuc=true' + '&price=' + parseInt(that.data.actualAmount).toFixed(2)
});
}
} else {
wx.showModal({
content: data.message,
showCancel: false,
confirmText: "确定",
});
that.isloading = false;
}
})
.catch(function (error) {
});
},
onLoad: function (options) {
let timestamp = options.timestamp;
let value = wx.getStorageSync(timestamp);
try {
wx.setStorageSync(timestamp, null);//清除内存
} catch (e) {
}
let delivery_address = value.data.delivery_address;
let goods_list = value.data.goods_list;
let isJit = false;
let jitProductSku = '';
for (var i = 0; i < goods_list.length; i++) {
let item = goods_list[i];
item.goods_images = item.goods_images.replace(/{width}/, 100).replace(/{height}/, 100);
item.sales_price = parseInt(item.sales_price).toFixed(2);
item.last_price = parseInt(item.last_price).toFixed(2);
if (!isJit && item.is_jit == 'Y') {
isJit = true;
jitProductSku = item.product_sku;
}
let tags = item.tags;
item.LRE = false;
item.L15DE = false;
for (var j = 0; j < tags.length; j++) {
if (tags[j] == 'LRE') {
item.LRE = true;
}else if (tags[j] == 'L15DE') {
item.L15DE = true;
}
}
}
// console.log(goods_list);
let listTop = 100;
if (delivery_address){
listTop = 190;
}
this.setData({
productData: value,
hasAddress: delivery_address ? true : false,
addressName: delivery_address ? delivery_address.consignee : "",
userTel: delivery_address ? delivery_address.mobile : "",
addressId: delivery_address ? delivery_address.address_id : "",
currentAddress: delivery_address ? delivery_address.area + delivery_address.address : "",
goods_list,
isJit,
jitProductSku,
listTop,
})
let from_page_name = options.page_name ? options.page_name : '';
let from_page_param = options.page_param ? options.page_param : '';
this.setData({
from_page_name,
from_page_param,
});
this.loadData(value);
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,
PV_ID: PV_ID,
PAGE_PATH: url
};
logEvent(YB_PAGE_OPEN_L, params);
// console.log(this.data);
},
})