createActivity.html
42 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
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<meta name=viewport content="width=device-width,initial-scale=1,user-scalable=0">
<link th:href="@{/static/css/mobiscroll.custom-3.0.0-beta6.min.css}" rel="stylesheet" type="text/css" />
<title>拼团购</title>
<style>
* {
margin: 0;
padding: 0;
font-size: 14px;
}
body,
html {
background: #f2f2f2;
color: #333;
}
input {
background: none;
outline: none;
border: none;
}
.fix_head {
background: #fff;
position: fixed;
top: 0px;
left: 0px;
right: 0px;
height: 40px;
line-height: 40px;
border-bottom: 1px solid #f2f2f2;
color: #fff;
padding: 0 10px;
text-align: center;
z-index: 999;
}
.mbsc-fr-btn-cont,
.mbsc-fr-popup {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
width: 100%;
}
.mbsc-fr-popup {
max-width: 100%;
position: absolute;
z-index: 2;
top: 0;
left: 0;
font-size: 12px;
text-shadow: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-ms-touch-action: pan-y;
touch-action: pan-y;
background: #fff;
}
.fix_head p {
text-decoration: none;
color: #333;
position: absolute;
height: 100%;
width: 116px;
font-size: 18px;
left: 0px;
}
.page_wrapper {
padding-top: 40px;
}
.activeBox {
background: #fff;
height: 100%;
width: auto;
border-top: 1px solid #fff;
margin: 10px 0;
}
.add {
margin: 0 20px;
height: 50px;
border-bottom: 1px solid #f2f2f2;
}
.add p {
margin-top: 15px;
}
.left {
float: left;
}
.right {
float: right;
}
.addBtn {
padding: 0 16px;
border: 1px solid #00A479;
border-radius: 20px 20px 20px 20px;
}
.product {
margin: 13px 20px;
height: 100%;
overflow: hidden;
}
.combinationList {
height: 50px;
}
.producttInp {
width: 30px;
height: 19px;
border: 1px solid #f2f2f2;
}
.mainProductt {
width: 80px;
height: 23px;
}
.product span {
padding: 0 10px;
border: 1px solid #f2f2f2;
background: #f2f2f2;
}
.display {
display: none;
}
.productMessage {
color: #FF9A33;
margin-left: 20px;
padding-bottom: 10px;
}
.delet {
border: 1px solid #333;
margin-left: 5px;
}
.QRcode {
padding: 9px 40px;
color: #fff;
background: #00A479;
border: 1px solid #00A479;
border-radius: 20px 20px;
text-align: center;
margin: 50px auto;
width: 112px;
}
.chrild {
background: #fff;
padding-top: 25px;
}
.chrildTitle {
margin-left: 20px;
}
.addchrildProduct {
margin: 10px 20px;
height: 200px;
}
.addchrildProductBox {
height: 14%;
position: relative;
}
.price {
height: 57px;
margin: 5px 17px;
padding: 7px 0;
}
.priceBox {
background: #f2f2f2;
margin: 10px 0;
}
.assemble {
height: 50%;
}
.priceBox input {
width: 125px;
}
.color {
color: #FF8202;
}
.chrildAdd {
height: 50px;
margin-left: 24%;
}
.radioBox{
-webkit-appearance: none;
position: relative;
width: 20px;
height: 20px;
}
.radioBox:before{
content: '';
width: 20px;
height: 20px;
border: 1px solid #7d7d7d;
display: inline-block;
border-radius: 50%;
vertical-align: middle;
}
.radioBox:checked:before{
content: '';
width: 20px;
height: 20px;
border: 1px solid #FF8A31;
background:#FF8A31;
display: inline-block;
border-radius: 50%;
vertical-align: middle;
}
.radioBox:checked:after{
content: '';
width: 10px;
height:5px;
border: 2px solid white;
border-top: transparent;
border-right: transparent;
text-align: center;
display: block;
position: absolute;
top: 6px;
left:5px;
vertical-align:middle;
transform: rotate(-45deg);
}
.radioBox:checked+label{
color: #c59c5a;
}
.relpceBtn{
line-height: 20px;
display: inline-block;
margin-left: 5px;
margin-right:15px;
color: #777;
}
.label{
margin-left: 10px;
}
.isImport{
padding: 0 6px;
border: 1px solid #FF8A31;
background:#FF8A31;
color: #fff;
display: none;
border-radius: 20px 20px 20px 20px;
}
.chrildAdd span {
padding: 9px 40px;
color: #fff;
background: #00A479;
border: 1px solid #00A479;
border-radius: 20px 20px;
text-align: center;
margin: 50px auto;
width: 112px;
}
.startproduct{
width: 60px;
}
.endproduct{
width: 60px;
}
.show{
display: block;
}
.green{
background: #00A479;
color:#fff;
}
.settlement p{
padding:5px 0 ;
}
</style>
</head>
<body>
<div class="page_wrapper">
<!-- 顶部菜单 开始 -->
<div class="fix_head">
<p>添加产品</p>
</div>
<!-- 顶部菜单 end -->
<div class='parent'>
<div class='activeBox'>
<div class="add">
<p class="left">添加产品组合</p>
<p class="right addBtn addSubsidy">添加</p>
</div>
<div class="product combination">
</div>
</div>
<div class='allActive'>
<div class='activeBox frist priceLevel'>
<div class="add">
<p class="left">设置梯度价格</p>
<p class="right addBtn addLadder">添加</p>
</div>
<div class="product">
<div class="left">订购量</div>
<div class="right">
<input class="producttInp startproduct" value="1" type="number" placeholder="请输入" maxlength="10" min="1"/>
<span >-</span>
<input class="producttInp endproduct" readonly="readonly" placeholder="不限" type="number" maxlength="10" />
</div>
</div>
<div class="product">
<div class="left">主拼产品单价</div>
<div class="right">
<input class="mainProductt majorIpt" type="number" placeholder="请输入价格" />
</div>
</div>
<P class="productMessage"></P>
</div>
</div>
<div class="activeBox">
<div class="product">
<div class="left">成团量(套)</div>
<div class="right">
<input class="mainProductt assembleNum" type="number" placeholder="请输入" />
</div>
</div>
<div class="product">
<div class="left">活动日期</div>
<div class="right">
<input class="mainProductt start" type="text" placeholder="开始时间" />
<input class="mainProductt end" type="text" placeholder="结束时间" />
</div>
</div>
</div>
<div class="activeBox">
<div class="product">
<p class="left">活动测算</p>
<p class="right addBtn calculation">测算</p>
</div>
<div class="product settlement">
</div>
</div>
<div class="QRcode">
生成二维码
</div>
</div>
<!-- 添加页面 -->
<div class="chrild display">
<p class="chrildTitle">请选择要添加的产品</p>
<div class="allProduct">
</div>
<div class="chrildAdd">
<span class="sure">添加</span>
<span class="return">返回</span>
</div>
</div>
</div>
</body>
<script type="text/javascript" th:src="@{/static/js/common/jquery.min.js}"></script>
<script type="text/javascript" th:src="@{/static/layer_mobile/layer.js}"></script>
<script type="text/javascript" th:src="@{/static/js/leftTime.min.js}"></script>
<script type="text/javascript" th:src="@{/static/js/mobiscroll.custom-3.0.0-beta6.min.js}"></script>
<script type="text/javascript" th:src="@{/static/js/qrcode.js}"></script>
<script type="text/javascript" th:src="@{/static/js/jquery.qrcode.js}"></script>
<script type="text/javascript">
$(function () {
var inquiryDetail = {};
/**
* 绑定event事件
*/
var productName=''
var productList=[]
var subsidy = ''
var flag= false
var data = []
var isCostPrice = 0//主拼产品成本价
var isAssemble = 0//主拼产品的拼团价
var isSubsidy = 0//主拼补贴
var assembleInp = 0 //加拼产品拼团价
var costPrice = 0//加拼产品成本价
var subsidy = 0//加拼补贴
var isProductNum = 0 //主拼产品件数
var productNum = 0 //加拼产品件数
var assembleNum = 0 //成团量
var packages = []; // 已选产品列表
var mLoading = layer.open({
type: 2,
content: '加载中'
});
$.ajax({
type: 'GET',
url: '/web-dj-mobile/groupbuy/merchant/product/list',
dataType: 'json',
success: function (res) {
layer.close(mLoading)
if (res.returnCode == 0) {
var productName = []
var newProductName = []
data = res.data
for (var i = 0; i <= data.length; i++) {
var priceBox = ''
priceBox += ' <div class="addchrildProduct" id="product_'+ data[i].id +'">'
priceBox += '<div class="addchrildProductBox">'
priceBox += '<div class="left">'
priceBox += '<input type="checkbox" class="radioBox" id="radioBox_' + data[i].id + '" value="' + data[i].productName + '" name="radioBox" productId="' + data[i].id + '" /><label class="relpceBtn" for="radioBox"></label >'
priceBox += '<span class="label productName" productId="' + data[i].id + '">'+data[i].productName+'</span>'
priceBox += '</div>'
priceBox += '<div class="right addBtn imporent" id="imporent_'+ data[i].id +'" productId="' + data[i].id + '">设为主拼 </div>'
priceBox += '<div class="right" style="opacity:0">'+data[i].productName+'</div>'
priceBox += '<div class="right cost" style="opacity:0">'+data[i].costPrice+'</div>'
priceBox += '</div>'
priceBox += '<div class="priceBox">'
priceBox += '<div class="price">'
priceBox += '<div class="assemble">'
priceBox += '<p class="left"> 拼团价(元/件)</p>'
priceBox += '<p class="right"> <input type="number" class="assembleInp" placeholder="请输入大于0的数字" maxlength="10" costPrice="' + data[i].costPrice + '"/> </p>'
priceBox += '</div>'
priceBox += ' <p class="color">成本价:' + data[i].costPrice + '元</p>'
priceBox += '</div> '
priceBox += '<div class="price">'
priceBox += '<div class="assemble">'
priceBox += '<p class="left"> 补贴比例(%)</p>'
priceBox += '<p class="right"> <input type="number" class="subsidy" placeholder="请输入0-100的数字" maxlength="10"/> </p>'
priceBox += '</div>'
priceBox += ' <p class="color">补贴 = (产品单价 - 成本价) x 补贴比例</p>'
priceBox += '</div> '
priceBox += '</div> '
priceBox += '</div>'
$('.allProduct').append(priceBox)
}
} else {
layer.open({
content: res.message || '出错了,请联系管理员',
btn: '关闭'
});
}
}
})
$(".addSubsidy").bind("click", function () {
$(".parent").addClass('display')
$(".chrild").removeClass('display')
$('.combinationList').remove()
});
$(".return").bind("click", function () {
$(".parent").removeClass('display')
$(".chrild").addClass('display')
});
$('.allProduct').on('blur', '.subsidy', function (event) {
subsidy = event.target.value
console.log(event.target.value)
});
$('.allProduct').on('blur', '.assembleInp', function (event) {
for(var i=0; i<$('.assembleInp').length;i++){
if($('.assembleInp').eq(i).val()!=''){
if(parseInt($('.assembleInp').eq(i).val())<parseInt($('.cost').eq(i).html())){
layer.open({
content: '拼团价不得小于成本价',
skin: 'msg',
time: 2
});
return false;
}else{
assembleInp =event.target.value
}
}
}
console.log(event.target.value)
});
// 添加阶梯价格
$('.allActive').on('click', '.addLadder', function (event) {
// 最多可以设置3个价格梯度
if ($(".allActive>.activeBox").size() < 3) {
var active = ''
active += '<div class="activeBox priceLevel">'
active += '<div class="add">'
active += '<p class="left">设置梯度价格</p>'
active += '<p class="right addBtn delet">删除</p>'
active += '<p class="right addBtn addLadder">添加</p>'
active += ' </div>'
active += '<div class="product">'
active += '<div class="left">订购量</div>'
active += ' <div class="right">'
active += '<input class="producttInp startproduct" placeholder="请输入" type="number" maxlength="10" readonly="readonly" />'
active += ' <span >-</span>'
active += ' <input class="producttInp endproduct" placeholder="请输入" type="number" maxlength="10" />'
active += ' </div>'
active += ' </div>'
active += '<div class="product">'
active += '<div class="left">主拼产品单价</div>'
active += '<div class="right">'
active += '<input class="mainProductt majorIpt" type="number" placeholder="请输入价格" maxlength="10" />'
active += ' </div>'
active += ' </div>'
active += ' <P class="productMessage"></P>'
active += ' </div>'
$('.allActive').append(active);
if($('.delet').length > 1){
// 移除上一个删除按钮,只保留最后一个
$('.delet').eq(0).remove();
}
// 隐藏当前添加按钮,只保留最后一个
$(this).hide();
for(var i = 0;i < $('.startproduct').length;i++){
if(isNaN($('.endproduct').eq(i).val()) || $('.endproduct').eq(i).val() == ''){
$('.endproduct').eq(i).val('')
$('.endproduct').eq(i).attr('placeholder', '请输入');
$('.endproduct').eq(i).removeAttr('readonly');
//$('.startproduct').eq(i+1).attr('readonly', 'readonly');
}else{
if($('.endproduct').eq(i).val() !=''){
$('.startproduct').eq(i+1).val( parseFloat($('.endproduct').eq(i).val())+1 )
}
}
if(i == $('.startproduct').length-1){
// 最后一个区间数值不能输入,默认数量不限
$('.endproduct').eq(i).attr({'placeholder':'不限', 'readonly':'readonly'});
}
}
}
if ($(".allActive>.activeBox").size() >= 3){
// 超过三个价格梯度,隐藏所有添加按钮
$('.addLadder').hide();
}
})
// 删除梯度价格
$('.allActive').on('click', '.delet', function (event) {
var self = $(this);
layer.open({
content:'确定删除梯度价格?',
btn: ['确定', '取消'],
yes: function(_index){
var index = self.index() + 1
$(".activeBox").eq(index).remove();
for(var i = 0;i < $('.startproduct').length;i++){
if(isNaN($('.endproduct').eq(i).val())){
$('.endproduct').eq(i).val('')
}else{
if($('.endproduct').eq(i).val() !=''){
$('.startproduct').eq(i+1).val( parseFloat($('.endproduct').eq(i).val())+1 )
}
}
if(i == $('.startproduct').length - 1){
$('.endproduct').eq(i).val('');
$('.endproduct').eq(i).attr({'placeholder':'不限', 'readonly':'readonly'});
}
}
// 删除当前价格梯度后,恢复上一个价格梯度的添加按钮
var i = $(".priceLevel").length;
$('.addLadder').hide();
$('.addLadder').eq(i-1).show();
layer.close(_index);
}
});
})
// 输入梯度价格
$('.allActive').on('blur', '.producttInp', function (event) {
for(var i = 0; i < $('.startproduct').length; i ++){
if($('.startproduct').eq(0).val() == '' || $('.endproduct').eq(0).val() == '' || event.target.value == ''){
return
}
if(i > 0){
if($('.startproduct').eq(i).val() && $('.endproduct').eq(i-1).val() && parseFloat($('.endproduct').eq(i-1).val()) >parseFloat($('.startproduct').eq(i).val())) {
layer.open({
content: '订单量区间设置有误',
skin: 'msg',
time: 3
});
return
}else if($('.startproduct').eq(i).val() && $('.endproduct').eq(i).val() && parseFloat($('.startproduct').eq(i).val()) >= parseFloat($('.endproduct').eq(i).val())){
layer.open({
content: '订单量区间设置有误',
skin: 'msg',
time: 3
});
return
}else{
$('.startproduct').eq(i+1).val(parseFloat($('.endproduct').eq(i).val()) + 1)
}
}else{
if(parseFloat($('.startproduct').eq(i).val()) >= parseFloat($('.endproduct').eq(i).val())){
layer.open({
content: '订单量区间设置有误',
skin: 'msg',
time: 3
});
}else{
$('.startproduct').eq(i+1).val(parseFloat($('.endproduct').eq(i).val()) + 1)
}
}
}
});
// 选择产品
$('.chrild').on('click', '.radioBox', function (event) {
index= $(this).nextAll()
var val =event.target.value
if(event.target.checked==true){
productList.push(val)
}else{
for(var i=0; i<productList.length;i++){
if(productList[i] == val){
productList.splice(i, 1);
}
}
var productId = $(this).attr('productId');
if($('#imporent_' + productId).hasClass('green')){
// 取消选中产品后,同时取消主拼
$('#imporent_' + productId).removeClass("green");
flag = false;
}
}
console.log(productList)
})
// 设置主拼产品
$('.allProduct').on('click', '.imporent', function (event) {
for(var i = 0;i < $('.imporent').length;i++){
if($('.imporent').is('.green')){
$('.imporent').removeClass("green")
}
}
var index = $(this).nextAll()
$(this).addClass("green")
productName = index[0].innerHTML
flag = true
// 选择为主拼,则默认选中此产品
var productId = $(this).attr('productId');
if(!$('#radioBox_' + productId).is(':checked')){
$('#radioBox_' + productId).trigger('click');
}
})
//添加产品
$(".sure").bind("click", function () {
var val = $('input:radio[name="radioBox"]:checked').val();
for(var i=0; i<$('.radioBox').length;i++){
if($('.radioBox').eq(i).is(":checked")){
if($('.assembleInp').eq(i).val()==''){
layer.open({
content: '请填写拼团价',
skin: 'msg',
time: 3
});
return false;
}else if(parseInt($('.assembleInp').eq(i).val()) < parseInt($('.assembleInp').eq(i).attr('costPrice'))){
layer.open({
content: '拼团价不得小于成本价',
skin: 'msg',
time: 3
});
return false;
}else if($('.subsidy').eq(i).val()==''){
layer.open({
content: '请填写补贴比例',
skin: 'msg',
time: 3
});
return false;
}
}
}
if(productList.length==0){
layer.open({
content: '请选择产品并填写正确价格',
skin: 'msg',
time: 3
});
return false;
}else{
if (flag) {
$(".parent").removeClass('display')
$(".chrild").addClass('display')
assembleInp = [];
packages = [];
var _plist = [];
for(var i=0; i<$('.assembleInp').length; i++){
if(!$('.radioBox').eq(i).is(":checked")){
continue;
}
var pkg = {
costPrice : parseInt($('.cost').eq(i).html()),
groupbuyPrice : parseInt($('.assembleInp').eq(i).val()),
isMain : 'N',
productId : $('.productName').eq(i).attr('productId'),
rebateRatio : parseInt($('.subsidy').eq(i).val())
};
if($('.imporent').eq(i).is('.green')){
isCostPrice = parseInt($('.cost').eq(i).html())
isAssemble = parseInt($('.assembleInp').eq(i).val())
isSubsidy = parseInt($('.subsidy').eq(i).val())
pkg['isMain'] = 'Y';
}
packages.push(pkg);
_plist.push('<div class="combinationList" id="combination_' + $('.productName').eq(i).attr('productId') + '">');
_plist.push('<div class="left productName">');
_plist.push($('.productName').eq(i).html());
_plist.push('</div>');
if(pkg['isMain'] == 'Y'){
_plist.push('<div class="left isImport show" productId="'+ $('.productName').eq(i).attr('productId') +'">主拼</div>');
}else{
_plist.push('<div class="left isImport" productId="'+ $('.productName').eq(i).attr('productId') +'">主拼</div>');
}
_plist.push('<div class="right isProductBtn">');
_plist.push('<span class="jian" productId="'+ $('.productName').eq(i).attr('productId') +'" productName="'+ $('.productName').eq(i).html() +'">-</span>');
_plist.push('<input class="producttInp productVal" value="1" type="number" maxlength="10" />');
_plist.push('<span class="addProduct">+</span>');
_plist.push('</div>');
_plist.push('</div>');
_plist.push('');
_plist.push('');
}
$('.combination').append(_plist.join(''))
console.log(packages);
} else if(flag==false) {
layer.open({
content: '请选择主拼产品',
skin: 'msg',
time: 3
});
return false;
}
}
});
//增加产品
$('.combination').on('click', '.addProduct', function (event) {
var num = parseInt( $(this).prev().val())
num++
$(this).prev().val(num)
});
$('.combination').on('click', '.jian', function (event) {
var num
var productId = $(this).attr('productId');
var productName = $(this).attr('productName');
console.log(productId);
num = parseInt( $(this).next().val())
num--
if(num == 0){
layer.open({
content:'是否删除此产品?',
btn: ['确定', '取消'],
yes: function(_index){
var isMain = false;
if($('#combination_' + productId).find('.show')){
isMain = true;
}
$('#combination_' + productId).remove();
$('#radioBox_' + productId).removeAttr('checked');
if(isMain){
// 如果删除的是主产品,则选择第一个为主产品
var _mp = $('.combinationList .isImport').eq(0);
_mp.addClass('show');
var mpid = _mp.attr('productId');
for(i in packages){
if(packages[i].productId == mpid){
packages[i]['isMain'] = 'Y';
}
}
$('.imporent').removeClass("green")
$('#imporent_' + mpid).addClass('green');
}
var removeIndex = 0;
for(i in packages){
if(packages[i].productId == productId){
removeIndex = i;
}
}
// 数量清零后,删除此产品
packages.splice(removeIndex, 1);
removeIndex = 0;
for(i in productList){
if(productList[i] == productName){
removeIndex = i;
}
}
productList.splice(removeIndex, 1);
if(packages.length == 0){
flag = false;
}
console.log(packages);
console.log(productList);
layer.close(_index);
}
});
}else{
$(this).next().val(num)
}
});
//主拼产品单价
$('.allActive').on('blur', '.majorIpt', function (event) {
for(var i=0; i<$('.majorIpt').length; i++){
if($('.majorIpt').eq(i).val()!==''){
if(isCostPrice==''){
layer.open({
content: '请选择主拼产品',
skin: 'msg',
time: 2
});
}else{
if(parseInt($('.majorIpt').eq(i).val())<parseInt(isCostPrice)){
layer.open({
content: '产品单价不得小于成本价',
skin: 'msg',
time: 2
});
}else{
var val = parseInt($('.majorIpt').eq(i).val())-parseInt(isCostPrice)
$('.productMessage').eq(i).html('主拼产品毛利'+val+'元一件')
}
}
}
}
})
//测算
$(".calculation").bind("click",function(){
var htmladd = ''
$('.settlementList').remove()
if($('.productVal').length ==0){
layer.open({
content: '请选择产品',
skin: 'msg',
time: 2
});
}else if($('.assembleNum').val()==''){
layer.open({
content: '请填写成团量',
skin: 'msg',
time: 2
});
}else{
for(var i=0; i<$('.productVal').length; i++){
packages[i]['productCount'] = parseInt($('.productVal').eq(i).val());
}
assembleNum = $('.assembleNum').val();
// 预计总收入
var income = 0;
// 预计总毛利
var profit = 0;
// 预计总补贴
var allSubsidy = 0;
for(i in packages){
var pkg = packages[i];
// ( X*主拼产品拼团价+Y*加拼产品拼团价)* 成团量
income += pkg.groupbuyPrice * pkg.productCount * assembleNum;
// (主拼产品拼团价-成本价)*(1-补贴比例)*成团量*X+(加拼产品拼团价-成本价)*(1-补贴比例)*成团量*Y
profit += ((pkg.groupbuyPrice - pkg.costPrice) * (100 - pkg.rebateRatio)/100) * pkg.productCount * assembleNum;
// (主拼产品拼团价-成本价)*补贴比例*成团量*X+(加拼产品拼团价-成本价)*补贴比例*成团量*Y
allSubsidy += ((pkg.groupbuyPrice - pkg.costPrice) * pkg.rebateRatio/100) * pkg.productCount * assembleNum;
}
income = parseInt(income);
profit = parseInt(profit);
allSubsidy = parseInt(allSubsidy);
htmladd +='<div class="settlementList"><p>预计总收入:'+income+'元</p><p>预计总毛利:'+profit+'元</p><p>预计总补贴:'+allSubsidy+'元</p></div>'
$('.settlement').append(htmladd)
}
})
//生成二维码
//判断阶梯价格是否填写
$('.QRcode').bind("click",function(){
if($('.productVal').length ==0){
layer.open({
content: '请选择产品',
skin: 'msg',
time: 2
});
return;
}
if($('.startproduct').val()==''){
layer.open({
content: '请填写订购量',
skin: 'msg',
time: 2
});
return;
}
if(parseInt($('.startproduct').eq(0).val()) < 1){
layer.open({
content: '起始订购量不能小于1',
skin: 'msg',
time: 2
});
return;
}
if($('.endproduct').length > 1){
for(i=0; i < $('.endproduct').length - 1; i++){
if($('.endproduct').eq(i).val()==''){
layer.open({
content: '请填写截止订购量',
skin: 'msg',
time: 2
});
return;
}
if(parseInt($('.endproduct').eq(i).val()) <= parseInt($('.startproduct').eq(i).val())){
layer.open({
content: '截止订购量不能小于起始订购量',
skin: 'msg',
time: 2
});
return;
}
}
}
for(var i=0; i<$('.majorIpt').length; i++){
if($('.majorIpt').eq(i).val() == '' ){
layer.open({
content: '请填写主产品单价',
skin: 'msg',
time: 2
});
return;
}
if(parseInt($('.majorIpt').eq(i).val()) < parseInt(isCostPrice)){
layer.open({
content: '产品单价不得小于成本价',
skin: 'msg',
time: 2
});
return;
}
}
if($('.start ').val()==''){
layer.open({
content: '请选择开始日期',
skin: 'msg',
time: 2
});
return;
}
if($('.end ').val()==''){
layer.open({
content: '请选择结束日期',
skin: 'msg',
time: 2
});
return;
}
if($('.start ').val() > $('.end ').val()){
layer.open({
content: '开始日期不能晚于结束日期',
skin: 'msg',
time: 2
});
return;
}
var curDate = new Date().format('yyyy-MM-dd');
if($('.end ').val() < curDate){
layer.open({
content: '结束日期不能早于当前日期',
skin: 'msg',
time: 2
});
return;
}
if($('.assembleNum').val()==''){
layer.open({
content: '请填写成团量',
skin: 'msg',
time: 2
});
return;
}
{
var data={}
var prices = []
data.beginTime = $('.start').val() + ' 00:00:00';
data.endTime = $('.end').val() + ' 23:59:59';
data.packageCount = parseInt($('.assembleNum').val())
for(var i=0; i<$('.productVal').length; i++){
packages[i]['productCount'] = parseInt($('.productVal').eq(i).val());
}
for(var n=0; n<$('.endproduct').length; n++){
if($('.endproduct').eq(n).val()=='不限'){
prices.push({
groupbuyPrice : parseInt($('.majorIpt').eq(n).val()),
maxPackages : '',
minPackages : parseInt($('.startproduct').eq(n).val())
})
} else{
prices.push({
groupbuyPrice : parseInt($('.majorIpt').eq(n).val()),
maxPackages : parseInt($('.endproduct').eq(n).val()),
minPackages : parseInt($('.startproduct').eq(n).val())
})
}
}
data.packages = packages
data.prices = prices
$.ajax({
type: 'POST',
url: '/web-dj-mobile/groupbuy/activity/create',
dataType: 'json',
data:JSON.stringify(data),
contentType:'application/json;charset=utf-8',
success: function(res) {
layer.close(mLoading)
if (res.returnCode == 0) {
layer.open({
content: '活动创建成功'
,btn: '确定'
,yes: function(){
var activityId = res.data.id
location.href='/web-dj-mobile/groupbuy/to/qrcode/'+activityId
}
});
} else {
layer.open({
content: res.message || '出错了,请联系管理员',
btn: '关闭'
});
}
}
})
}
})
Date.prototype.Format = function(formatStr)
{
var str = formatStr;
var Week = ['日','一','二','三','四','五','六'];
str=str.replace(/yyyy|YYYY/,this.getFullYear());
str=str.replace(/yy|YY/,(this.getYear() % 100)>9?(this.getYear() % 100).toString():'0' + (this.getYear() % 100));
str=str.replace(/MM/,this.getMonth()>9?this.getMonth().toString():'0' + this.getMonth());
str=str.replace(/M/g,this.getMonth());
str=str.replace(/w|W/g,Week[this.getDay()]);
str=str.replace(/dd|DD/,this.getDate()>9?this.getDate().toString():'0' + this.getDate());
str=str.replace(/d|D/g,this.getDate());
str=str.replace(/hh|HH/,this.getHours()>9?this.getHours().toString():'0' + this.getHours());
str=str.replace(/h|H/g,this.getHours());
str=str.replace(/mm/,this.getMinutes()>9?this.getMinutes().toString():'0' + this.getMinutes());
str=str.replace(/m/g,this.getMinutes());
str=str.replace(/ss|SS/,this.getSeconds()>9?this.getSeconds().toString():'0' + this.getSeconds());
str=str.replace(/s|S/g,this.getSeconds());
return str;
}
//日期
var opt = {
preset: 'date', //日期
theme: 'sense-ui', //皮肤样式
lang: 'zh',
display: 'modal', //显示方式
mode: 'scroller', //日期选择模式
dateFormat: 'yy-mm-dd', // 日期格式
setText: '确定', //确认按钮名称
cancelText: '取消',//取消按钮名籍我
dateOrder: 'yymmdd', //面板中日期排列格式
dayText: '日', monthText: '月', yearText: '年', //面板中年月日文字
endYear: 20202 //结束年份
};
$(".start").mobiscroll(opt).date(opt);
$(".end").mobiscroll(opt).date(opt);
})
</script>
</html>