shopCart.js
35.5 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
// shopCart.js
import api from '../../common/api.js';
import { curShoppingCartDataAddExpandedFlag, editInfoDicFromGoodsList, hasLackStorageGoodsInList, curPageDataAllSelectWhenEditing,
curPageDataSingleSelectWhenEditing, curPageDataSingleSelectBundleProductWhenEditing, editInfoOfAllGoods, editInfoSelectedGoodsList, editInfoDicFromBundleItem} from '../../utils/shopCartContent';
import { getGoodInfo, getGoodSize, getGoodImages } from '../../utils/productDetail';
// import {
// logEvent,
// YB_MAIN_TAB_C,
// YB_PAGE_OPEN_L,
// } from '../../libs/analytics.js'
//获取应用实例
let app = getApp();
const screenHeight = app.globalData.systemInfo.screenHeight;
const screenWidth = app.globalData.systemInfo.screenWidth;
const pixelRatio = app.globalData.systemInfo.pixelRatio;
const DEVICE_WIDTH_RATIO = screenWidth / 375.0;
let imageWidth = Math.ceil(75 * DEVICE_WIDTH_RATIO * pixelRatio);
let imageHeight = Math.ceil(100 * DEVICE_WIDTH_RATIO * pixelRatio);
Page({
/**
* 页面的初始数据
*/
data: {
commonProductNaviTitle: '普通商品(0)',
commonShoppingCartData: {},
presellProductNavTitle: '预售商品(0)',
presellShoppingCartData: {},
isSelectCommonNavi: true,
curShoppingCartData: {},
scrollerViewTop: 0,
scrollerViewHeight: 0,
isEditing: false,
isReduceOrPlue: false,
current_page_name: 'shopcart',
has_close_price_down_tip: false, //是否已经关闭降价提示
touchX: 0,
touchY: 0,
tempSku: '',
AnimatingSku: '',
deleteAnimation: '', // 控制是否给相应的单元增加删除动画
enableScroll: true,
//picker 需要的数据
//选中的sku
selectedSKU: 0,
//选中sku的库存
storageNumber: 0,
//判断是否选择了颜色
colorSelected: false,
//当前操作的商品
curProcessGoodsItem: {},
pickerShow: false,
pickerData: {
view: {
isShow: false,
isSoldOutSoon: false, //是否显示即将售罄
goodsList: [],
sizeList: [],
image: '',
goodPrice: '',
price: '',
buyNumber: 1,
minusButtonEnable: false,
plusButtonEnable: true,
buyButtonEnable: true,
should_hidden_number_view: false, //由于套餐不支持 修改数量 故弹窗需要隐藏
min_buy_number: 1,
},
sourceType: 'shopCart',
},
from_page: 'shopCart',
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
new app.WeToast();
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
if (app.isLogin()) {
this.queryShoppingcartData();
}
this.animation = tt.createAnimation({
duration: 300,
timingFunction: 'ease',
})
//埋点上报 页面加载
var pages = getCurrentPages()
var currentPage = pages[pages.length - 1]
var url = currentPage.route
// logEvent(YB_MAIN_TAB_C, { TAB_ID: 2 });
// let params = {
// PAGE_NAME: this.data.from_page,
// PAGE_PARAM: '',
// FROM_PAGE_NAME: '',
// FROM_PAGE_PARAM: '',
// PAGE_PATH: url
// };
// logEvent(YB_PAGE_OPEN_L, params);
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
if (this.data.isEditing) {
this.setData({
isEditing: false,
});
}
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 查询购物车数据,包括普通购物车和预售购物车
*/
queryShoppingcartData: function () {
let param = {
method: 'app.Shopping.queryCart',
uid: app.getUid()
};
api.post({data:param})
.then(json => {
if (json && json.code && json.code == 200) {
let data = json.data
this.processShopCartData(data);
}
})
.catch(error => {
});
},
processShopCartData:function(data){
if (!data) {
return;
}
let commonShoppingCartData = data.ordinary_cart_data
let presellShoppingCartData = data.advance_cart_data
let commonProductNaviTitle = '普通商品(' + commonShoppingCartData.shopping_cart_data.goods_count + ')'
let presellProductNavTitle = '预售商品(' + presellShoppingCartData.shopping_cart_data.goods_count + ')'
commonShoppingCartData = curShoppingCartDataAddExpandedFlag(commonShoppingCartData);
// presellShoppingCartData = curShoppingCartDataAddExpandedFlag(presellShoppingCartData);
let curShoppingCartData = commonShoppingCartData;
// if (this.data.isSelectCommonNavi) {
// curShoppingCartData = commonShoppingCartData
// } else {
// curShoppingCartData = presellShoppingCartData
// }
const windowHeight = app.globalData.systemInfo.windowHeight;
let scrollerViewTop = 0;
if (curShoppingCartData.shipping_cost_prompt.shipping_cost_tips != '' || curShoppingCartData.shipping_cost_prompt.price_down_tips != '')
{
scrollerViewTop += 40;
}
let scrollerViewHeight = app.globalData.systemInfo.windowHeight - scrollerViewTop - 64;
this.setData({
commonShoppingCartData,
presellShoppingCartData,
commonProductNaviTitle,
presellProductNavTitle,
curShoppingCartData,
scrollerViewTop,
scrollerViewHeight,
});
},
onShoppingCartProductAction: function(event) {
console.log(event);
let dataset = event.detail.currentTarget.dataset;
console.log(dataset);
if (Object.keys(dataset).length === 0) {
dataset = event.detail.detail.currentTarget.dataset;
}
let identifier = dataset.identifier;
console.log('===onShoppingCartProductAction====');
console.log(dataset);
console.log('====================================');
switch (identifier) {
case "selectSingleGoodsAction":
this.selectSingleGoodsAction(dataset);
break;
case "deleteGoodsCell":
this.deleteGoodsCell(dataset);
break;
case "navtoProductDetailPage":
this.navtoProductDetailPage(dataset);
break;
case "chooseSizeColorAction":
this.chooseSizeColorAction(dataset);
break;
case "cutDownBuyCountAction":
this.cutDownBuyCountAction(dataset);
break;
case "plusBuyCountAction":
this.plusBuyCountAction(dataset);
break;
case "plusReachedMaxAction":
this.plusReachedMaxAction();
break;
case "navToPromotionPage":
this.navToPromotionPage(dataset);
break;
default:
break;
}
},
navToGiftPage: function (event) {
let data = event.detail.currentTarget.dataset;
let item = data.promotionItem;
console.log(item);
tt.navigateTo({
url: './giftPage?promotion_id=' + item.promotion_ids + '&is_gift=' + item.isGift + '&status=10',
});
},
naviTabSelected:function(event) {
let selectedNaviType = event.currentTarget.dataset.type;
let isSelectCommonNavi = true;
let curShoppingCartData = this.data.commonShoppingCartData;
if (selectedNaviType == 'presellProduct') {
isSelectCommonNavi = false;
curShoppingCartData = this.data.presellShoppingCartData;
}
this.setData({
curShoppingCartData,
isSelectCommonNavi,
})
},
editBtnSelected:function(event) {
let isEditing = this.data.isEditing;
isEditing = !isEditing;
if (isEditing && this.data.AnimatingSku){
var tempAniamtion = this.animation.left('0px').step();
this.data.AnimatingSku = '';
this.setData({
AnimatingSku: '',
deleteAnimation: tempAniamtion.export(),
isEditing,
})
} else {
this.setData({
isEditing,
})
}
},
flexOrUnflexPromotion:function(poolItem) {
let index = poolItem.currentTarget.dataset.type;
let curShoppingCartData = this.data.curShoppingCartData;
let goodsPoolList = curShoppingCartData.goods_pool_list;
goodsPoolList[index].isPromotionExpanded = !goodsPoolList[index].isPromotionExpanded;
curShoppingCartData.goods_pool_list = goodsPoolList;
this.setData({
curShoppingCartData,
})
},
selectSingleGoodsAction:function(dataset) {
let goodsItem = dataset.type;
let isEditing = this.data.isEditing;
if (isEditing) {
let curShoppingCartData = this.data.curShoppingCartData;
curShoppingCartData = curPageDataSingleSelectWhenEditing(curShoppingCartData, goodsItem);
this.setData({
curShoppingCartData,
})
} else {
if (goodsItem.bLackStorage) {
this.wetoast.toast({
title: '您勾选的商品库存不足',
titleClassName: 'wetoast-title',
duration: 1000
});
return;
}
let goodsEditInfoList = editInfoDicFromGoodsList([goodsItem], !goodsItem.bSelected);
this.queryShopCartGoodsWithSkuList(goodsEditInfoList);
}
},
selectAllGoodsAction:function(event){
let bSelectAll = event.detail.currentTarget.dataset.type;
let isEditing = this.data.isEditing;
if(isEditing) {
let curShoppingCartData = this.data.curShoppingCartData;
curShoppingCartData = curPageDataAllSelectWhenEditing(curShoppingCartData, !bSelectAll);
curShoppingCartData.isValidGoodsSelectAll = !bSelectAll,
this.setData({
curShoppingCartData,
})
}else {
let allGoodsEditInfoList = editInfoDicFromGoodsList(this.data.curShoppingCartData.validGoodsList, !bSelectAll);
let allGoodsEditInfoJson = JSON.stringify(allGoodsEditInfoList);
let param = {
product_sku_list: allGoodsEditInfoJson,
method: 'app.Shopping.selectedAndQryCart',
is_support_mlp: 'Y',
shopping_key: '',
uid: app && app.getUid(),
};
// console.log(param);
api.post({data:param})
.then(json => {
if (json && json.code && json.code == 200) {
let data = json.data;
this.processShopCartData(data);
if (hasLackStorageGoodsInList(this.data.curShoppingCartData.validGoodsList) && !bSelectAll) {
this.wetoast.toast({
title: '您全选的商品中存在库存不足商品,已帮您自动取消勾选成功',
titleClassName: 'wetoast-title',
duration: 1000
});
}
}
})
.catch(error => {
});
}
},
editCompletedAction:function(){
this.editBtnSelected(null);
let allGoodsEditInfoList = editInfoOfAllGoods(this.data.curShoppingCartData.validGoodsList);
this.queryShopCartGoodsWithSkuList(allGoodsEditInfoList);
},
moveStart: function (e) {
let enableScroll = true;
let isEditing = this.data.isEditing;
if(isEditing){
return;
}
let changedTouches = e.detail.detail.changedTouches;
if (!changedTouches) {
changedTouches = e.detail.changedTouches;
}
console.log(changedTouches);
this.data.touchX = changedTouches[0].clientX;
this.data.touchY = changedTouches[0].clientY;
var tempAniamtion = this.animation.left('0px').step();
this.setData({
deleteAnimation: tempAniamtion.export(),
AnimatingSku: '',
enableScroll,
});
},
moveEnd: function (e) {
// console.log('moveEnd');
let isEditing = this.data.isEditing;
if (isEditing) {
return;
}
let changedTouches = e.detail.detail.changedTouches;
if (!changedTouches) {
changedTouches = e.detail.changedTouches;
}
let dataset = e.detail.detail.currentTarget.dataset;
if (!dataset) {
dataset = e.detail.currentTarget.dataset;
}
var X = changedTouches[0].clientX;
var Y = changedTouches[0].clientY;
var curGoods = dataset.type;
var data = null, tempAniamtion = null;
var angle = this.angle({ X: X, Y: Y }, { X: this.data.touchX, Y: this.data.touchY});
if (Math.abs(angle) > 30) return;
if (this.data.touchX - X > 3) {
// console.log('左滑动');
if (this.data.AnimatingSku) {
let enableScroll = false;
tempAniamtion = this.animation.left('0px').step();
this.setData({
AnimatingSku: '',
deleteAnimation: tempAniamtion.export(),
enableScroll,
})
} else {
let enableScroll = false;
tempAniamtion = this.animation.left('-70px').step();
this.setData({
AnimatingSku: curGoods && curGoods.product_sku?curGoods.product_sku:'',
deleteAnimation: tempAniamtion.export(),
tempSku: curGoods && curGoods.unique_identifier?curGoods.unique_identifier:'',
enableScroll,
})
}
} else if (this.data.touchX - X < -3) {
// console.log('右滑动');
let enableScroll = true;
tempAniamtion = this.animation.left('0px').step();
this.setData({
deleteAnimation: tempAniamtion.export(),
AnimatingSku: '',
enableScroll,
});
}
},
queryShopCartGoodsWithSkuList: function(skuListInfo){
let goodsEditInfoJson = JSON.stringify(skuListInfo);
let param = {
product_sku_list: goodsEditInfoJson,
method: 'app.Shopping.selectedAndQryCart',
is_support_mlp: 'Y',
shopping_key: '',
uid: app && app.getUid(),
};
api.post({data:param})
.then(json => {
this.setData({
isReduceOrPlue: false,
});
if (json && json.code && json.code == 200) {
let data = json.data;
this.processShopCartData(data);
}
})
.catch(error => {
this.setData({
isReduceOrPlue: false,
});
});
},
deleteGoodsRequest:function(skuList){
let goodsInfoJson = JSON.stringify(skuList);
let param = {
product_sku_list: goodsInfoJson,
method: 'app.Shopping.removeAndQryCart',
is_support_mlp: 'Y',
uid: app.getUid(),
shopping_key: '',
};
api.post({data:param})
.then(json => {
if (json && json.code && json.code == 200) {
let data = json.data;
this.processShopCartData(data);
}
})
.catch(error => {
// console.log(error);
});
},
deleteGoodsCell:function(dataset){
let that = this;
tt.showModal({
title: '',
content: '是否确认删除此商品?',
cancelText: '取消',
confirmText: '确认',
confirmColor: "#d0021b",
success: function (res) {
if (res.confirm) {
let goodsItem = dataset.type;
if (that.data.AnimatingSku != '') {
var tempAniamtion = that.animation.left('0px').step();
that.setData({
AnimatingSku: '',
deleteAnimation: tempAniamtion.export(),
})
}
let goodsInfo = [{
buy_number: goodsItem.buy_number,
product_sku: goodsItem.product_sku,
promotion_id: goodsItem.promotion_id,
activity_id: goodsItem.bundle_activity_id ? goodsItem.bundle_activity_id : 0,
batch_no: goodsItem.batch_no ? goodsItem.batch_no : 0,
}];
that.deleteGoodsRequest(goodsInfo);
}
}
});
},
cutDownBuyCountAction:function(dataset){
let isReduceOrPlue = this.data.isReduceOrPlue;
if (isReduceOrPlue){
return;
}
let goodsItem = dataset.type;
let min_buy_number = goodsItem.min_buy_number > 0 ? goodsItem.min_buy_number : 1;
let current_buy_number = parseInt(goodsItem.buy_number);
if (current_buy_number > 0 && current_buy_number <= min_buy_number) {
this.wetoast.toast({
title: '最低' + min_buy_number + '件起',
titleClassName: 'wetoast-title',
duration: 1000
});
return;
}
this.setData({
isReduceOrPlue: true,
});
let reduceBuyCountParam = {
product_sku: goodsItem.product_sku,
decrease_number: 1,
method: 'app.Shopping.decrease',//app.Shopping.incrBundle
uid: app.getUid(),
shopping_key: '',
};
api.post({data:reduceBuyCountParam})
.then(json => {
if (json && json.code && json.code == 200) {
let reduceBuyGoodsInfo = [{
buy_number: goodsItem.buy_number - 1,
goods_type: goodsItem.goods_type,
product_sku: goodsItem.product_sku,
promotion_id: goodsItem.promotion_id,
selected: 'Y',
activity_id: goodsItem.bundle_activity_id ? goodsItem.bundle_activity_id : 0,
batch_no: goodsItem.batch_no ? goodsItem.batch_no : 0,
}];
this.queryShopCartGoodsWithSkuList(reduceBuyGoodsInfo);
} else {
this.setData({
isReduceOrPlue: false,
});
}
})
.catch(error => {
this.setData({
isReduceOrPlue: false,
});
this.wetoast.toast({
title: error.code + error.message + '',
titleClassName: 'wetoast-title',
duration: 1000
});
});
},
plusBuyCountAction:function(dataset){
let isReduceOrPlue = this.data.isReduceOrPlue;
if (isReduceOrPlue) {
return;
}
this.setData({
isReduceOrPlue: true,
});
let goodsItem = dataset.type;
let increaseBuyCountParam = {
product_sku: goodsItem.product_sku,
increase_number: 1,
method: 'app.Shopping.increase',
uid: app.getUid(),
shopping_key: '',
};
api.post({data:increaseBuyCountParam})
.then(json => {
if (json && json.code && json.code == 200) {
let increaseBuyGoodsInfo = [{
buy_number: goodsItem.buy_number + 1,
goods_type: goodsItem.goods_type,
product_sku: goodsItem.product_sku,
promotion_id: goodsItem.promotion_id,
selected: 'Y',
activity_id: goodsItem.bundle_activity_id ? goodsItem.bundle_activity_id : 0,
batch_no: goodsItem.batch_no ? goodsItem.batch_no : 0,
}];
this.queryShopCartGoodsWithSkuList(increaseBuyGoodsInfo);
} else {
this.setData({
isReduceOrPlue: false,
});
}
})
.catch(error => {
this.setData({
isReduceOrPlue: false,
});
this.wetoast.toast({
title: error.code + error.message + '',
titleClassName: 'wetoast-title',
duration: 1000
});
});
},
plusReachedMaxAction:function(){
this.wetoast.toast({
title: '对不起,没有更多库存了',
titleClassName: 'wetoast-title',
duration: 1000
});
},
chooseSizeColorAction:function(dataset){
var that = this
let goodsItem = dataset.type;
// console.log(goodsItem);
this.setData({
curProcessGoodsItem: goodsItem,
should_hidden_number_view: (goodsItem.bundle_activity_id && goodsItem.batch_no),
});
let min_buy_number = goodsItem.min_buy_number > 0 ? goodsItem.min_buy_number : 1;
this.data.pickerData.view.should_hidden_number_view = (goodsItem.bundle_activity_id && goodsItem.batch_no);
this.data.pickerData.view.min_buy_number = min_buy_number;
this.fetchGoodInfo(goodsItem.product_skn);
// Picker.pickerShow(event, that);
this.setData({pickerShow: true});
},
//获取商品基本信息(包括颜色、尺码)
fetchGoodInfo: function (productSKN) {
let param = {
method: 'app.product.data',
product_skn: productSKN
}
var that = this
api.get({data:param})
.then(function (data) {
if (!data || data.code != 200)
return
let color_length = 0;
if (data.data.goods_list) {
color_length = data.data.goods_list.length;
}
let ImgUrls = [];
data.data.goods_list && data.data.goods_list.map((item, index) => {
let images = getGoodImages(item.images_list, imageWidth, imageHeight)
ImgUrls = [...ImgUrls, ...images]
if (index == 0 && color_length == 1) {
item.selected = true;
that.data.colorSelected = true;
}
});
let isSoldOutSoon = false;
let tags = data.data.tags;
if (tags) {
tags.map((item) => {
if (item == "is_soon_sold_out") {
isSoldOutSoon = true;
}
});
}
//pickerData
var temData = that.data.pickerData;
temData.view.goodsList = data.data.goods_list;
temData.view.isSoldOutSoon = isSoldOutSoon;
//默认显示第一种颜色的尺码
temData.view.sizeList = data.data.goods_list.length > 0 ? data.data.goods_list[0].size_list : [];
let plusButtonEnable = false;
let minusButtonEnable = false;
//根据库存设置该尺码是否可以选择
let size_length = 0;
if (temData.view.sizeList) {
size_length = temData.view.sizeList.length;
}
temData.view.sizeList && temData.view.sizeList.map((item, index) => {
item.enable = item.storage_number > 0 ? true : false;
if (index == 0 && size_length == 1 && that.data.colorSelected) {
//当颜色被选中 并且只有一个size 时 才会自动 做选中尺码操作
temData.view.buyButtonEnable = item.enable;
if (item.enable) {
item.selected = true;
plusButtonEnable = item.storage_number > 1;
that.setData({
selectedSKU: item.product_sku,
storageNumber: item.storage_number,
});
}
}
});
temData.view.plusButtonEnable = plusButtonEnable;
temData.view.minusButtonEnable = minusButtonEnable;
temData.view.image = ImgUrls.length > 0 ? ImgUrls[0] : '';
temData.view.price = data.data.format_market_price;
temData.view.goodPrice = data.data.format_sales_price;
that.setData({
pickerData: temData,
});
})
.catch(function (error) {
this.wetoast.toast({
title: error.code + error.message + '',
titleClassName: 'wetoast-title',
duration: 1000
});
});
},
//点击背景,隐藏picker
showChange:function(){
let pickerShow = !this.data.pickerShow
this.setData({pickerShow});
},
errorToast: function(event) {
let detail = event.detail;
this.wetoast.toast({
title: detail.title,
titleClassName: detail.titleClassName,
duration: 1000
});
},
chooseSizeColorCompleted:function(event){
this.setData(event.detail);
if (!this.data.selectedSKU) {
this.wetoast.toast({
title: '请选择颜色或尺码',
titleClassName: 'wetoast-title',
duration: 1000
});
return;
}
let buyNumber = this.data.pickerData.view.buyNumber;
let min_buy_number = this.data.pickerData.view.min_buy_number > 0 ? this.data.pickerData.view.min_buy_number : 1;
if (buyNumber > 0 && buyNumber < min_buy_number && min_buy_number != 1) {
this.wetoast.toast({
title: '最低' + min_buy_number + '件起',
titleClassName: 'wetoast-title',
duration: 1000
});
return;
}
// Picker.pickerHide(event, this);
this.setData({pickerShow: false});
let processGoodsItem = this.data.curProcessGoodsItem;
let goodsInfo = [{
old_product_sku: processGoodsItem.product_sku,
new_product_sku: this.data.selectedSKU,
buy_number: this.data.pickerData.view.buyNumber,
activity_id: processGoodsItem.bundle_activity_id,
batch_no: processGoodsItem.batch_no,
selected: 'Y',
}];
let goodInfoJson = JSON.stringify(goodsInfo);
let swapParams ={
swap_data: goodInfoJson,
method: "app.Shopping.swap",
uid: app.getUid(),
};
api.post({data:swapParams})
.then(json => {
if (json && json.code && json.code == 200) {
let swapGoodsInfo = [{
buy_number: this.data.pickerData.view.buyNumber,
goods_type: processGoodsItem.goods_type,
product_sku: this.data.selectedSKU,
promotion_id: processGoodsItem.promotion_id,
selected: 'Y',
}];
this.queryShopCartGoodsWithSkuList(swapGoodsInfo);
this.resetPickerData();
}
})
.catch(error => {
this.resetPickerData();
});
},
resetPickerData:function(event){
let pickerData = this.data.pickerData;
pickerData.view.buyNumber = 1;
this.setData({
pickerData,
selectedSKU: 0,
storageNumber: 0,
colorSelected: false,
curProcessGoodsItem: {},
min_buy_number: 1,
})
},
mutilDeleteEditing:function(event){
let that = this;
tt.showModal({
title: '',
content: '是否删除选中的全部商品?',
cancelText: '取消',
confirmText: '确认',
confirmColor: "#d0021b",
success: function (res) {
if (res.confirm) {
let selectedGoodsInfo = editInfoSelectedGoodsList(that.data.curShoppingCartData.validGoodsList);
that.deleteGoodsRequest(selectedGoodsInfo);
}
}
});
},
mutilAddToFav:function(event){
let selectedGoodsInfo = editInfoSelectedGoodsList(this.data.curShoppingCartData.validGoodsList);
let selectedGoodsJson = JSON.stringify(selectedGoodsInfo);
let param = {
product_sku_list: selectedGoodsJson,
method: 'app.Shopping.addfavoriteAndQryCart',
is_support_mlp: 'Y',
uid: app.getUid(),
shopping_key: '',
};
api.post({data:param})
.then(json => {
if (json && json.code && json.code == 200) {
let data = json.data;
this.processShopCartData(data);
}
})
.catch(error => {
// console.log(error);
});
},
navtoProductDetailPage: function(dataset){
if (this.data.AnimatingSku) {
let tempAniamtion = this.animation.left('0px').step();
this.setData({
deleteAnimation: tempAniamtion.export(),
AnimatingSku: ''
});
return;
}
let data = dataset.item;
// console.log(data);
if (data.off_shelves) {
this.wetoast.toast({
title: '商品已下架',
titleClassName: 'wetoast-title',
duration: 1000,
});
return;
}
let productSkn = data.product_skn;
tt.navigateTo({
url: '../goodsDetail/goodsDetail?productSkn=' + productSkn + '&page_name=' + this.data.current_page_name,
});
},
navToPromotionPage: function(dataset) {
let promotionItem = dataset.promotionItem;
let promotion_type = promotionItem.promotion_type;
// console.log(promotionItem);
if (promotion_type == 'Gift' && (promotionItem.status == 10 || promotionItem.status == 30)) {
// console.log("跳转赠品页面");
tt.navigateTo({
url: './giftPage?promotion_id=' + promotionItem.promotion_id + '&is_gift=' + true + '&status=' + promotionItem.status,
});
} else if (promotion_type == 'Needpaygift' && (promotionItem.status == 10 || promotionItem.status == 30)) {
// console.log("跳转加价购页面");
tt.navigateTo({
url: './giftPage?promotion_id=' + promotionItem.promotion_id + '&is_gift=' + false + '&status=' + promotionItem.status,
});
} else {
// console.log("跳转促销商品列表页面");
let spliceUrl = "?title=优惠活动商品" + "&promotionTitle=以下商品参加【" + promotionItem.promotion_title + "】促销活动&promotion_id=" + promotionItem.promotion_id;
tt.navigateTo({
url: '../goodsList/PromotionList' + spliceUrl,
});
}
},
//清空所有失效商品
cleanInvalidAction: function(event){
let that = this;
tt.showModal({
title: '',
content: '是否确认清空所有失效商品?',
cancelText: '取消',
confirmText: '确认',
confirmColor: "#d0021b",
success: function (res) {
if (res.confirm) {
let currentShopCartInfo = that.data.curShoppingCartData;
var invalidList = [];
// console.log(currentShopCartInfo);
// 售罄商品列表
let sold_out_goods_sku_list = editInfoOfAllGoods(currentShopCartInfo.sold_out_goods_list);
invalidList.push.apply(invalidList, sold_out_goods_sku_list);
//下架商品列表
let off_shelves_goods_sku_list = editInfoOfAllGoods(currentShopCartInfo.off_shelves_goods_list);
invalidList.push.apply(invalidList, off_shelves_goods_sku_list);
// //失效商品池 (套餐)
// let sold_out_goods_pool = currentShopCartInfo.sold_out_goods_pool;
// for (var index in sold_out_goods_pool) {
// let pool = sold_out_goods_pool[index];
// if (pool.pool_type == 3) {
// let bundle_invalid_sku_list = editInfoOfAllGoods(pool.goods_list);
// invalidList.push.apply(invalidList, bundle_invalid_sku_list);
// }
// }
// console.log("失效商品sku列表:");
// console.log(invalidList);
let param = {
product_sku_list: JSON.stringify(invalidList),
method: "app.Shopping.removeAndQryCart",
is_support_mlp: "Y",
uid: app.getUid(),
};
// console.log(param);
api.post({data:param})
.then(json => {
// console.log(json);
if (json && json.code && json.code == 200) {
let data = json.data
that.processShopCartData(data);
}
})
.catch(error => {
});
}
}
});
},
//仅有点击结算时 如果没有选择赠品才会调用
navToChooseGiftPage: function() {
let promotionIds = '';
this.data.curShoppingCartData.match_gift_ids.map((item, index) => {
promotionIds = promotionIds + (index == 0 ? '' : ',') + item;
});
tt.navigateTo({
url: './giftPage?promotion_id=' + promotionIds + '&is_gift=' + true + '&status=10',
});
},
// 跳转结算页面
paymentAction: function() {
//如果没有选中商品则不能进入结算页
if (this.data.curShoppingCartData.shopping_cart_data.selected_goods_count <= 0) {
this.wetoast.toast({
title: '您还没有选择宝贝哦',
titleClassName: 'wetoast-title',
duration: 1000
});
return;
}
if (this.data.curShoppingCartData.match_gift_ids.length > 0) {
let that = this;
tt.showModal({
title: '',
content: '您还未选择赠品,是否去选择赠品?',
cancelText: '不要赠品',
confirmText: '去选择',
confirmColor: "#444444",
cancelColor: "#444444",
success: function (res) {
if (res.confirm) {
//去选择赠品
that.navToChooseGiftPage();
} else if (res.cancel) {
//直接跳转 结算页面
that.navToPaymentAction();
}
}
});
return;
}
this.navToPaymentAction();
},
navToPaymentAction: function() {
let paramters = {
method: 'app.Shopping.enhancedPayment',
cart_type: 'ordinary',
yoho_coin_mode: 0,
uid: app.getUid(),
};
let that = this;
api.post({data:paramters})
.then(json => {
if (json && json.code && json.code == 200) {
let keyValue = 'paymentdata';
tt.setStorage({
key: keyValue,
data: json,
success: function (res) {
tt.navigateTo({
url: '../statements/statements?timestamp=' + keyValue + '&page_name=' + that.data.from_page,
})
}
})
} else {
that.wetoast.toast({
title: json.message,
titleClassName: 'wetoast-title',
duration: 1000
});
}
})
.catch(error => {
that.wetoast.toast({
title: error.code + error.message + '',
titleClassName: 'wetoast-title',
duration: 1000
});
});
},
navToNewArriaval: function() {
tt.switchTab({
url: '../index/index' + '?page_name=' + this.data.current_page_name + '&page_param=' + '',
})
},
tapPriceDownTipsAction: function() {
this.setData({
has_close_price_down_tip: true,
});
},
tapBundleProductHeader: function(evevt) {
let bundleData = evevt.currentTarget.dataset.bundledata;
// console.log("点击套餐");
// console.log(bundleData);
let select = bundleData.selected;
if (select == 'N' && (bundleData.int_pool_buy_number > bundleData.int_pool_storage_number)) {
this.wetoast.toast({
title: '您勾选的商品库存不足',
titleClassName: 'wetoast-title',
duration: 1000
});
return;
}
bundleData.selected = (select == 'Y' ? 'N' : 'Y');
let that = this;
if (that.data.isEditing) {
let curShoppingCartData = curPageDataSingleSelectBundleProductWhenEditing(that.data.curShoppingCartData, bundleData);
that.setData({
curShoppingCartData,
})
} else {
let goodsEditInfoList = editInfoDicFromBundleItem(bundleData);
that.queryShopCartGoodsWithSkuList(goodsEditInfoList);
}
},
bundleReduceTap: function(event) {
let isReduceOrPlue = this.data.isReduceOrPlue;
if (isReduceOrPlue) {
return;
}
let bundleItem = event.currentTarget.dataset.item;
// console.log('套餐 -');
// console.log(bundleItem);
this.setData({
isReduceOrPlue: true,
});
let reduceBuyCountParam = {
activity_id: bundleItem.pool_id,
batch_no: bundleItem.pool_batch_no,
decrease_number: 1,
method: 'app.Shopping.decrBundle',
};
let that = this;
api.post({data:reduceBuyCountParam})
.then(json => {
if (json && json.code && json.code == 200) {
let reduceBuyGoodsInfo = editInfoDicFromGoodsList(bundleItem.goods_list, true);
that.queryShopCartGoodsWithSkuList(reduceBuyGoodsInfo);
} else {
that.setData({
isReduceOrPlue: false,
});
}
})
.catch(error => {
that.setData({
isReduceOrPlue: false,
});
that.wetoast.toast({
title: error.code + error.message + '',
titleClassName: 'wetoast-title',
duration: 1000
});
});
},
bundleAddTap: function(event) {
let isReduceOrPlue = this.data.isReduceOrPlue;
if (isReduceOrPlue) {
return;
}
let bundleItem = event.currentTarget.dataset.item;
// console.log('套餐 +');
// console.log(bundleItem);
this.setData({
isReduceOrPlue: true,
});
let reduceBuyCountParam = {
activity_id: bundleItem.pool_id,
batch_no: bundleItem.pool_batch_no,
increase_number: 1,
method: 'app.Shopping.incrBundle',
};
let that = this;
api.post({data:reduceBuyCountParam})
.then(json => {
if (json && json.code && json.code == 200) {
let reduceBuyGoodsInfo = editInfoDicFromGoodsList(bundleItem.goods_list, true);
that.queryShopCartGoodsWithSkuList(reduceBuyGoodsInfo);
} else {
that.setData({
isReduceOrPlue: false,
});
}
})
.catch(error => {
that.setData({
isReduceOrPlue: false,
});
that.wetoast.toast({
title: error.code + error.message + '',
titleClassName: 'wetoast-title',
duration: 1000
});
});
},
/**
* 计算滑动角度
* @param {Object} start 起点坐标
* @param {Object} end 终点坐标
*/
angle: function (start, end) {
var _X = end.X - start.X,
_Y = end.Y - start.Y
return 360 * Math.atan(_Y / _X) / (2 * Math.PI);
},
})