productEdit.html
31.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>Yoho!Buy运营平台</title>
<script src="/ufoPlatform/js/include.js"></script>
<script src="/ufoPlatform/js/ajaxfileupload.js"></script>
<style>
.product-detail-page ul, .product-detail-page li {
list-style: none;
padding: 0;
margin: 0;
}
.product-detail-page .container > li {
border-bottom: 1px solid #eee;
padding-bottom: 20px;
}
.product-detail-page .container {
padding: 0 30px;
}
.product-detail-page .base-info li,
.product-detail-page .keyword {
display: flex;
align-items: center;
margin-bottom: 10px;
}
.product-detail-page .label {
width: 120px;
font-size: 14px;
text-align: right;
}
.product-detail-page .red {
color: red;
}
.product-detail-page .group-color, .product-detail-page .group-size {
display: flex;
align-items: center;
margin-bottom: 20px;
}
.product-detail-page .group-color li {
margin-right: 5px;
float: left;
line-height: 30px;
margin-left: 5px;
padding: 0 5px;
position: relative;
}
.product-detail-page .group-color .actived:before {
content: '';
width: 100%;
height: 100%;
display: block;
position: absolute;
top: 0;
background: #000;
opacity: 0.5;
border-radius: 5px;
}
.product-detail-page .group-size .size {
float:left;
margin-left: 10px;
}
.product-detail-page .goods-image {
display: flex;
}
.product-detail-page .goods-image .img {
width: 104px;
height: 104px;
margin-right: 10px;
background-size: cover;
background-repeat: no-repeat;
background-position: center;
position: relative;
}
.product-detail-page .goods-image .img:hover:before {
content: "删除";
width: 100%;
display: block;
position: absolute;
top: 0;
background: #000;
opacity: 0.5;
color: #fff;
text-align: center;
line-height: 104px;
}
</style>
</head>
<body class="easyui-layout product-detail-page" fit="true">
<div region="north">
<script>
document.write(addHead('商品管理 /基础商品 /商品创建', ''));
</script>
</div>
<div region="center" style="overflow-y: scroll; top: 65px; padding-top: 10px;">
<form id="productDetail">
<ul class="container">
<li>
<h2>基本信息</h2>
<ul class="base-info">
<li>
<div class="label">品牌 <span class="red">*</span>:</div>
<div class="base-info-item">
<input id="editBrandId" type="text" name="brandId"> 系列:<input id="editSeriesId" name="seriesId" type="text">
</div>
</li>
<li>
<div class="label">商品名称 <span class="red">*</span>:</div>
<div class="base-info-item">
<input id="editProductName" type="text" name="productName"/>
</div>
</li>
<li>
<div class="label">发售日期 <span class="red">*</span>:</div>
<div class="base-info-item">
<input id="editSaleTime" type="text" name="saleTime"/>
</div>
</li>
<li>
<div class="label">性别 <span class="red">*</span>:</div>
<div class="base-info-item">
<label for="boy"><input id="boy" type="radio" value="1" name="gender" checked>男</label>
<label for="girl"><input id="girl" type="radio" value="2" name="gender">女</label>
<label for="all"><input id="all" type="radio" value="3" name="gender">通用</label>
</div>
</li>
<li>
<div class="label">分类 <span class="red">*</span>:</div>
<div class="base-info-item">
<input id="editMaxSortId" type="text" name="maxSortId"/>
<input id="editMidSortId" type="text" name="midSortId"/>
货号 <span class="red">*</span>:<input id="editProductCode" type="text" name="productCode"/>
</div>
</li>
<li>
<div class="label">商品价格限制 <span class="red">*</span>:</div>
<div class="base-info-item">
<input id="editMinPrice" type="text" name="minPrice"/>
<span style="margin-right: 20px;c">~</span>
<input id="editMaxPrice" type="text" name="maxPrice"/>
</div>
</li>
<li>
<div class="label" style="align-self: flex-start;">出售类型<span class="red">*</span>:</div>
<div class="base-info-item">
<label><input type="radio" name="limitSale" value="0" />全部卖家可售</label>
<label><input type="radio" name="limitSale" value="1" />指定卖家可售 </label>
<a id="addLimitSaleBtn" class="easyui-linkbutton btn-success" style="float: right; height: 20px">添加行</a>
<table id="uidListTable" style="float: right;" border="1" cellspacing="0">
<tr>
<td>用户UID</td>
<td>结算比例(%)</td>
<td>操作</td>
</tr>
<!-- <tr>
<td>
<input class="easyui-textbox" style="width: 90px;height: 20px">
</td>
<td>
<input class="easyui-textbox" style="width: 70px;height: 20px">
</td>
<td>
<a class="easyui-linkbutton btn-delete" style="float: right;color: red;height: 20px" onclick='{if(confirm("确定要删除吗?")) {deleteCurrentRow(this); }else {}}'>删除行</a>
</td>
</tr> -->
</table>
</div>
</li>
<li>
<div class="label" style="align-self: flex-start;">同步至发售日历:</div>
<div class="base-info-item">
<label><input type="checkbox" name="isSynCalender" value="1" /></label>
</div>
</li>
<li>
<div class="label">发售价格:</div>
<div class="base-info-item">
<input id="editOfferPrice" type="text" name="offerPrice"/>
</div>
</li>
</ul>
</li>
<li>
<h2>颜色尺码</h2>
<div class="group-color">
<div class="label">*颜色</div>
<ul style="float: left; margin-left: 10px;">
</ul>
</div>
<div class="group-size">
<div class="label">*尺寸</div>
<div class="size"></div>
</div>
<table id="colorSizeTable" style="width:100%;height:auto"></table>
</li>
<li>
<h2>商品图片</h2>
<div class="goods-image">
<div id="imageUpload"></div>
</div>
</li>
<li>
<h2>商品关键词</h2>
<div class="keyword">
<div class="label" style="width: 120px;">商品关键词:</div>
<div class="keyword-right">
<input type="text" id="keyword" name="keyWords">
</div>
</div>
<div class="red" style="margin-left:120px;">*每个关键词用英文逗号隔开</div>
</li>
<li style="text-align: center; margin-top: 20px;">
<a id="submitBtn" class="easyui-linkbutton btn-success">提交</a>
<a id="cancelBtn" class="easyui-linkbutton btn-default">取消</a>
</li>
</ul>
</form>
</div>
<script>
/* 新增,修改公用页面
editImage代表图片是否修改过,新增固定传1。修改的时候根据是否修改,修改传1,无修改传0
1.新增,所有参数之前为空值,
提交地址:product/addOrUpdate
提交参数:{"brandId":78,"colorId":1,"colorName":"红色","editImage":1,"gender":3,"goodsName":"自定义红色","imageUrlList":["https://img10.static.yhbimg.com/goodsimg/2018/08/25/16/01e99496407347514356e5fe327d1f661d.jpg","https://img12.static.yhbimg.com/goodsimg/2018/08/25/16/0292fcebd071444401e6de340bcf2d8c19.jpg"],"keyWords":"球鞋,adidas","maxPrice":"899","maxSortId":10,"midSortId":18,"minPrice":"599","productCode":"009-009-009","productName":"测试商品009","saleTime":"2018-11-11","seriesId":8,"sizeIdList":[28,29]}
2.修改:首先根据传进来的id,获取商品信息把页面控件填写好。hidden记录id、goodsId、等参数
提交参数:{"brandId":78,"colorId":2,"colorName":"蓝色","editImage":1,"gender":3,"goodsId":6,"goodsName":"自定义蓝色","id":10000004,"imageUrlList":["https://img10.static.yhbimg.com/goodsimg/2018/08/25/16/01e99496407347514356e5fe327d1f661d.jpg","https://img12.static.yhbimg.com/goodsimg/2018/08/25/16/0292fcebd071444401e6de340bcf2d8c19.jpg"],"keyWords":"球鞋,adidas2","maxPrice":"898","maxSortId":10,"midSortId":18,"minPrice":"598","productCode":"009-009-009-e","productName":"测试商品009-e","saleTime":"2018-11-12","seriesId":8}
不可修改:品牌、分类、颜色、尺码、SKU(颜色展示名称除外:goodsName)
*/
var tempIndex = 0;
function deleteCurrentRow(obj){
var tr = obj.parentNode.parentNode;
var tbody = tr.parentNode;
tbody.removeChild(tr);
//只剩行首时删除表格
/* if(tbody.rows.length==1) {
tbody.parentNode.removeChild(tbody);
} */
//limitSaleInfoMap.delete($(obj).attr("rowid"));
}
var productDetail = {
initDom: function() {
this.dom = {
editBrandId: $('#editBrandId'),
editProductName: $('#editProductName'),
editSaleTime: $('#editSaleTime'),
editMinPrice: $('#editMinPrice'),
editMaxPrice: $('#editMaxPrice'),
editProductCode: $('#editProductCode'),
editMaxSortId: $('#editMaxSortId'),
editMidSortId: $('#editMidSortId'),
editSeriesId: $('#editSeriesId'),
imageUpload: $('#imageUpload'),
keyword: $('#keyword'),
colorSizeTable: $('#colorSizeTable'),
editOfferPrice: $('#editOfferPrice')
};
},
initFormData: function(detail) {
var that = this;
this.dom.editBrandId.combobox('select', detail.brandId)
this.dom.editProductName.textbox('setValue', detail.productName);
this.dom.editSaleTime.myDatebox('setValue', detail.saleTime);
this.dom.editMinPrice.textbox('setValue', detail.minPrice);
this.dom.editMaxPrice.textbox('setValue', detail.maxPrice);
this.dom.editProductCode.textbox('setValue', detail.productCode);
this.dom.editMaxSortId.combobox('select', detail.maxSortId);
this.dom.editMidSortId.combobox('select', detail.midSortId);
if (detail.seriesId && detail.seriesId != 0) {
this.dom.editSeriesId.combobox('select', detail.seriesId);
}
if(detail.limitSaleInfo.length>0) {
$("#addLimitSaleBtn").css('display','block');//隐藏
$("#uidListTable").css('display','block');//隐藏
for (var i = 0; i <detail.limitSaleInfo.length; i++){
var uid=detail.limitSaleInfo[i].split(" ")[0];
var percent=detail.limitSaleInfo[i].split(" ")[1];
addRowSetValue(uid,percent);
}
$("input[name=limitSale]:eq(1)").attr("checked",'checked');
}
if(detail.isSynCalender == 1){
$('input[name=isSynCalender]').attr('checked','checked');
}
this.dom.editOfferPrice.textbox('setValue', detail.offerPrice);
this.dom.keyword.textbox('setValue', detail.keyWords);
$('input[name=gender]').eq(detail.gender - 1).attr('checked','true');
$('.group-color li[data-id=' + detail.colorId + ']').addClass('actived');
if (detail.imageUrlList && detail.imageUrlList.length > 0) {
detail.imageUrlList.map(function(item) {
that.dom.imageUpload.before('<div class="img" data-url="' + item + '" style="background-image:url(' + item + ');">');
});
}
},
initForm: function() {
var that = this;
this.dom.editProductName.textbox({
required: true,
missingMessage: "商品名称不能为空",
prompt: "商品名称",
width: 460
});
this.dom.keyword.textbox({
width: 700
});
this.dom.editBrandId.combobox({
editable: false,
prompt: "选择品牌",
width: 200,
valueField: "id",
textField: "text",
onSelect: function(data) {
that.dom.editSeriesId.combobox('enable');
that.dom.editSeriesId.myCombobox('reload', contextPath + '/brandSeries/querySeriesByBrandId?brandId=' + data.id);
that.dom.editSeriesId.combobox('select')
}
});
this.dom.editSeriesId.myCombobox({
method: "get",
editable: false,
prompt: "请选择",
width: 200,
valueField: "id",
textField: "text",
loadFilter: function (data) {
if (data && data.code == 200 && data.data.length > 0) {
//that.dom.editSeriesId.combobox('select', data.data[0].id);
}
return defaultLoadFilter(data);
}
});
this.dom.editMaxSortId.myCombobox({
editable: false,
valueField: 'id',
textField: 'text',
prompt:"一级分类",
onSelect: function (rec) {
that.dom.editMidSortId.combobox('clear');
that.dom.editMidSortId.combobox('reload', contextPath + "/productSort/getLevel2SortBySortId?sortId=" + rec.id);
if (!that.productId) {
that.dom.editMidSortId.combobox('enable');
}
}
});
this.dom.editSaleTime.myDatebox({
prompt : "发售时间"
});
this.dom.editMidSortId.myCombobox({
method: 'get',
editable: false,
valueField: 'id',
textField: 'text',
prompt:"二级分类",
loadFilter: function(data) {
if (data && data.code == 200 && data.data.length > 0) {
//that.dom.editMidSortId.combobox('select', data.data[0].id);
}
return defaultLoadFilter(data);
},
onSelect: function(opt) {
that.getSizeInfo(opt.id);
}
});
this.dom.editProductCode.textbox({
prompt : "请输入",
required: true,
missingMessage: "货号不能为空"
});
this.dom.editMinPrice.textbox({
prompt : "最低价",
required: true,
missingMessage: "最低价不能为空"
});
this.dom.editMaxPrice.textbox({
prompt : "最高价",
required: true,
missingMessage: "最高价不能为空"
});
this.dom.editOfferPrice.textbox({
prompt : "发售价"
});
this.dom.colorSizeTable.myDatagrid({
fit: false,
fitColumns: true,
autoRowHeight: true,
nowrap: false,
columns: [[{
title: "色系名称",
field: "colorName",
width: 40,
align: "center"
}, {
title: "颜色展示名称",
field: "goodsName",
width: 80,
height: 50,
align: "center",
formatter: function(value) {
return '<input type="text" class="goods-name" value="' + value + '">';
}
}, {
title: "尺码",
field: "size",
width: 100,
align: "center"
}, {
title: "SKU",
field: "sku",
width: 80,
align: "center"
},{
title: "平台建议售价",
field: "suggestPrice",
width: 80,
align: "center"
}]],
cache: false,
pagination: false,
idField: "id",
singleSelect: false,
checkOnSelect: false,
onLoadSuccess: function() {
$('.goods-name').textbox({
width: 100
});
}
});
if (!this.productId) {
this.dom.editSeriesId.combobox('disable');
} else {
this.dom.editBrandId.combobox('disable');
this.dom.editMaxSortId.combobox('disable');
}
this.dom.editMidSortId.combobox('disable');
},
init: function() {
var that = this;
this.productId = this.getUrlParam('id');
this.detailData = {};
this.submitFlag = false;
this.colorSizeTableData = {
total: 0,
rows: []
};
this.initDom();
this.initForm();
this.dom.imageUpload.imageUpload({
width: 104,
height: 104,
realInputName: "goodsImage",
url: contextPath + '/fileupload/upload',
queryParams: {
bucket: "goodsimg"
},
onBeforeSubmit: function () {
$.messager.progress({
title: "正在执行",
msg: "正在执行,请稍后...",
interval: 500,
text: ""
});
},
filterFileName: function (data) {
if (!data || data.code != 200) {
$.messager.progress("close");
$.messager.alert("错误", data.message);
return "";
}
return data.data.url;
},
onLoadSuccess: function (data) {
$.messager.progress("close");
$(document).find('.file-close').click();
that.dom.imageUpload.before('<div class="img" data-url="' + data.data + '" style="background-image:url(' + data.data + ');">');
return false;
}
});
$.when(this.getBrandList(), this.getMaxSortList(), this.getColorInfo()).then(function(brand, maxSort, colors) {
var brandId = '';
brand = brand[0];
maxSort = maxSort[0];
colors = colors[0] || [];
if (brand && brand.code == 200) {
that.dom.editBrandId.combobox({
data: brand.data || []
});
}
if (maxSort && maxSort.code == 200) {
that.dom.editMaxSortId.combobox({
data: maxSort.data || []
});
}
if (colors && colors.code == 200) {
colors.data.map(function(item) {
var color = item.colorValue ? 'background: url('+item.colorValue+')' : 'background:#' + item.colorCode;
$('.group-color ul').append('<li data-id="' + item.id + '"><i style="float: left;width: 30px; height: 30px;border-radius: 50%; margin-right: 3px;' + color + ';background-size: contain;"></i>' + item.colorName + '</li>');
});
}
if (that.productId) {
that.getDetailInfo();
} else {
that.getSizeInfo();
}
});
$(document).on('click', '.group-color li', function() {
if (that.productId) {
$.messager.alert('操作提示', "颜色不可修改!");
return;
}
if (!$(this).hasClass('actived')) {
var colorName = $(this).text();
if (that.colorSizeTableData.rows.length > 0) {
that.colorSizeTableData.rows.map(function(item) {
item.colorName = colorName;
item.goodsName = colorName;
});
} else {
that.colorSizeTableData.rows.push({
colorName: colorName,
goodsName: colorName,
size: '',
sku: '-',
suggestPrice: '-'
});
}
that.mergeCells();
$(this).siblings().removeClass('actived');
$(this).addClass('actived');
}
});
$(document).on('click', '.group-size input', function() {
var colorName = goodsName = '';
if (that.productId && $(this).attr('exist') == 'true') {
$.messager.alert('操作提示', '尺码不可删除!');
return false;
}
if ($('.group-color .actived').length == 0) {
$.messager.alert('操作提示', '请先选择颜色!');
return false;
}
if (that.colorSizeTableData.rows.length > 0) {
colorName = that.colorSizeTableData.rows[0].colorName;
goodsName = that.colorSizeTableData.rows[0].goodsName;
} else {
colorName = goodsName = $('.group-color .actived').text();
}
var oldColorSizeTableData = {};
for (var rowItem in that.colorSizeTableData.rows) {
oldColorSizeTableData[that.colorSizeTableData.rows[rowItem].size] = that.colorSizeTableData.rows[rowItem];
}
that.colorSizeTableData.rows = [];
$('.size-item:checked').each(function(index, item) {
that.colorSizeTableData.rows.push({
colorName: colorName,
goodsName: goodsName,
size: $(item).parent().text(),
sku: ($(item).parent().text() in oldColorSizeTableData) ? oldColorSizeTableData[$(item).parent().text()].sku : '-',
suggestPrice: ($(item).parent().text() in oldColorSizeTableData) ? oldColorSizeTableData[$(item).parent().text()].suggestPrice : '-'
});
});
if ($('.size-item:checked').length == 0 && colorName) {
that.colorSizeTableData.rows.push({
colorName: colorName,
goodsName: goodsName,
size: '',
sku: '-',
suggestPrice:'-'
});
}
that.mergeCells();
});
$(document).on('click', '.goods-image .img', function() {
$(this).remove();
});
$('#cancelBtn').linkbutton({
onClick: function() {
window.location.href = contextPath + "/html/product/productList.html";
}
});
$('#submitBtn').linkbutton({
onClick: function () {
var limitSaleInfoMap = new Map();
for(var i=0;i<=tempIndex;i++) {
if($("#uid"+i).length > 0) {
var limi = {};
limi.uid = $("#uid"+i).val();
limi.per = $("#per"+i).val();
limitSaleInfoMap.set(i+'', limi);
}
}
var limitInfo = new Array();
for (var x of limitSaleInfoMap) { // 遍历Map
if(myTrim(x[1].uid)==""){
$.messager.alert('操作提示', '请填写有效的可售卖家信息!');
return false;
}
limitInfo.push(myTrim(x[1].uid) + " " + myTrim(x[1].per));
}
var limitSelect = $("input[name='limitSale']:checked").val();
if(limitSelect=="0") {
limitInfo = new Array();
} else{
if(limitInfo.length==0) {
$.messager.alert('操作提示', '请填写可售卖家信息!');
return false;
}
}
var imageUrlList = [];
var sizeIdList = [];
var editImage = 0;
if (that.submitFlag) {
return;
}
that.submitFlag = true;
$('.goods-image .img').each(function(index, item) {
imageUrlList.push($(item).data('url'));
});
if (that.productId) {
if (that.detailData.imageUrlList && imageUrlList.length == that.detailData.imageUrlList.length) {
$.each(imageUrlList, function(index, item) {
if (item != that.detailData.imageUrlList[index]) {
editImage = 1;
}
});
} else {
editImage = 1;
}
$('.group-size input:checked').each(function(index, item) {
if ($(item).attr('exist') != 'true') {
sizeIdList.push(+$(item).val());
}
});
} else {
editImage = 1;
$('.group-size input:checked').each(function(index, item) {
sizeIdList.push(+$(item).val());
});
}
var ajaxData = {
brandId: +that.dom.editBrandId.textbox('getValue'),
colorId: +$('.group-color .actived').data('id'),
colorName: $('.group-color .actived').text(),
editImage: editImage,
gender: +$('input[name="gender"]:checked').val(),
goodsName: $('.goods-name').length>0 && $('.goods-name').textbox('getValue') || '',
imageUrlList: imageUrlList,
keyWords: that.dom.keyword.textbox('getValue'),
maxPrice: that.dom.editMaxPrice.textbox('getValue'),
maxSortId: +that.dom.editMaxSortId.combobox('getValue'),
midSortId: +that.dom.editMidSortId.combobox('getValue'),
minPrice: that.dom.editMinPrice.textbox('getValue'),
productCode: that.dom.editProductCode.textbox('getValue'),
productName: that.dom.editProductName.textbox('getValue'),
saleTime: that.dom.editSaleTime.myDatebox('getValue'),
seriesId: +that.dom.editSeriesId.combobox('getValue'),
limitSaleInfo : limitInfo,
isSynCalender: $('input[name="isSynCalender"]:checked').val(),
offerPrice: that.dom.editOfferPrice.textbox('getValue'),
};
if (!ajaxData.brandId) {
$.messager.alert('操作提示', '请选择品牌!');
that.submitFlag = false;
return false;
}
if (!ajaxData.saleTime) {
$.messager.alert('操作提示', '请选择发售时间!');
that.submitFlag = false;
return false;
}
if (!ajaxData.maxSortId) {
$.messager.alert('操作提示', '请选择一级分类!');
that.submitFlag = false;
return false;
}
if (!ajaxData.midSortId) {
$.messager.alert('错误提示', '请选择二级分类!');
that.submitFlag = false;
return false;
}
if (imageUrlList.length == 0) {
$.messager.alert('操作提示', '至少添加一张图片!');
that.submitFlag = false;
return false;
}
if (!$('#productDetail').form("validate")) {
that.submitFlag = false;
return false;
}
if (!that.productId) {
ajaxData.sizeIdList = sizeIdList;
if (!ajaxData.colorName) {
$.messager.alert('错误提示', '请选择颜色!');
that.submitFlag = false;
return false;
}
if (sizeIdList.length ==0) {
$.messager.alert('错误提示', '请选择尺码!');
that.submitFlag = false;
return false;
}
} else {
ajaxData.sizeIdList = sizeIdList;
ajaxData.id = that.detailData.id;
ajaxData.goodsId = that.detailData.goodsId;
}
$.messager.progress({
title: "正在执行",
msg: "正在执行,请稍后...",
interval: 500,
text: ""
});
$.ajax({
url: contextPath + '/product/addOrUpdate',
contentType: "application/json",
dataType: "json",
type: "POST",
data: JSON.stringify(ajaxData),
success: function(ret) {
$.messager.progress("close");
that.submitFlag = false;
if (ret && ret.code == 200) {
$.messager.alert('操作提示', '提交成功!');
window.location.href = contextPath + "/html/product/productList.html";
} else {
$.messager.alert('操作提示', ret.message || '提交失败');
}
},
error: function(err) {
that.submitFlag = false;
$.messager.progress("close");
$.messager.alert('操作提示', err.message || '提交失败');
}
});
}
});
},
mergeCells: function() {
this.colorSizeTableData.total = this.colorSizeTableData.rows.length;
this.dom.colorSizeTable.datagrid('loadData', this.colorSizeTableData);
this.dom.colorSizeTable.datagrid('mergeCells', {index: 0, field: 'colorName', rowspan: this.colorSizeTableData.total});
this.dom.colorSizeTable.datagrid('mergeCells', {index: 0, field: 'goodsName', rowspan: this.colorSizeTableData.total});
this.dom.colorSizeTable.datagrid('resize');
},
getUrlParam: function(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) {
return unescape(r[2]);
}
return null;
},
getDetailInfo: function() {
var that = this;
// 编辑的情况需要根据id查询商品信息
$.get(contextPath + '/product/find?id=' + this.productId).then(function(ret) {
if (ret && ret.code == 200) {
ret = ret.data || {};
that.initFormData(ret);
that.detailData = ret;
}
});
},
getBrandList: function() {
// 获取所有品牌
return $.get(contextPath + '/brand/getBrandName');
},
getMaxSortList: function() {
// 获取一级分类
return $.get(contextPath + "/productSort/getLevel1SortIdAndName");
},
getSizeInfo: function(sortId) {
var that = this;
sortId = sortId || 0;
// 获取所有尺寸
$.get(contextPath + '/size/queryAllSecondSize4Goods?sortId=' + sortId, function(ret) {
if (ret && ret.code == 200) {
$('.group-size .size').html('');
$.each(ret.data || [], function(index, item) {
if (item.id) {
$('.group-size .size').append('<label for="size" style="margin-right: 5px;" data-id="' + item.id + '"><input type="checkbox" value="' + item.id + '" class="size-item">'+item.text+'</label>');
}
});
if (that.detailData.sizeIdList) {
/* that.detailData.sizeIdList.map(function(item) {
$('.group-size label[data-id=' + item + '] input').attr('checked','true');
that.colorSizeTableData.rows.push({
colorName: $('.group-color li[data-id='+that.detailData.colorId+']').text(),
goodsName: that.detailData.goodsName,
size: $('.group-size label[data-id=' + item + ']').text(),
sku: '-'
});
}); */
for ( var i = 0; i <that.detailData.sizeIdList.length; i++){
item = that.detailData.sizeIdList[i];
$('.group-size label[data-id=' + item + '] input').attr('checked','true').attr('exist','true');
that.colorSizeTableData.rows.push({
colorName: $('.group-color li[data-id='+that.detailData.colorId+']').text(),
goodsName: that.detailData.goodsName,
size: $('.group-size label[data-id=' + item + ']').text(),
sku: that.detailData.storageIdList[i],
suggestPrice: that.detailData.suggestPriceList[i]
});
}
}
that.mergeCells();
}
});
},
getColorInfo: function() {
// 获取所有颜色
return $.get(contextPath + '/productColor/getAllColor');
}
};
$(function () {
productDetail.init();
$("#addLimitSaleBtn").linkbutton({
onClick: function () {
addRow(tempIndex,0);
}
});
$("#addLimitSaleBtn").linkbutton({
onClick: function () {
addRow(1,1);
//$.parser.parse($("#addLimitSaleBtn").parent());
}
});
$('input[name="limitSale"]').click(function(){
if($(this).val() == "0") {
$("#addLimitSaleBtn").css('display','none');//隐藏
$("#uidListTable").css('display','none');//隐藏
} else {
$("#addLimitSaleBtn").css('display','block');//隐藏
$("#uidListTable").css('display','block');//隐藏
if($("#uidListTable").find("tr").length==1) {
$("#uidListTable tr:not(:first)").empty("");
addRow(tempIndex,0);
}
}
});
$("#addLimitSaleBtn").css('display','none');//隐藏
$("#uidListTable").css('display','none');//隐藏
$("input[name=limitSale]:eq(0)").attr("checked",'checked');
});
function addRowSetValue(uid,percent) {
tempIndex++;
if(percent==null || percent=="null") percent = "";
var rowStr ="<tr>";
rowStr += "<td><input id=\"uid" +tempIndex+ "\" style=\"width: 90px;height: 15px\"></td>";
rowStr += "<td><input id=\"per" +tempIndex+ "\" style=\"width: 70px;height: 15px\"></td>";
rowStr += "<td><a rowid=\"" +tempIndex+ "\" class=\"easyui-linkbutton btn-delete\" style=\"float: right;color: red;height: 20px\" onclick='{ var that = this;$.messager.confirm(\"操作提示\", \"确定要删除吗?\", function (data) { if(data) deleteCurrentRow(that);})}'>删除行</a></td>";
rowStr += "</tr>";
$("#uidListTable").append(rowStr);
$.parser.parse($("#addLimitSaleBtn").parent());
$("#uid"+tempIndex).val(uid);
$("#per"+tempIndex).val(percent);
}
function addRow(percent) {
tempIndex++;
var rowStr ="<tr>";
rowStr += "<td><input id=\"uid" +tempIndex+ "\" style=\"width: 90px;height: 15px\"></td>";
rowStr += "<td><input id=\"per" +tempIndex+ "\" style=\"width: 70px;height: 15px\"></td>";
rowStr += "<td><a rowid=\"" +tempIndex+ "\" class=\"easyui-linkbutton btn-delete\" style=\"float: right;color: red;height: 20px\" onclick='{ var that = this;$.messager.confirm(\"操作提示\", \"确定要删除吗?\", function (data) { if(data) deleteCurrentRow(that);})}'>删除行</a></td>";
rowStr += "</tr>";
$("#uidListTable").append(rowStr);
$.parser.parse($("#addLimitSaleBtn").parent());
}
function myTrim(x) {
return x.replace(/^\s+|\s+$/gm,'');
}
</script>
</body>
</html>