basegoods.Edit.js
15.1 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
'use strict';
var $ = require('jquery'),
common=require('../../common/common');
/*基础商品模型(Model)*/
var ViewModel=window.ViewModel;
var RESPONSEDATA=ViewModel.data||{};
var PageENUM={
"ADD":{
url:"/base/goods/add"
},
"UPDATE":{
url:"/product/updateBaseProduct"
}
}
var ACTION=$("#basicForm").attr("action");
var param=ACTION==="UPDATE"?true:false;
/*货品年,规则从2015年开始,到今年之后的10年*/
RESPONSEDATA.ENUMYEAR=(function(){
var _y=[];
for(var i=2005;i<(new Date).getFullYear()+10;i++){
_y.push({YEAR:i});
}
return _y;
})()
console.log(RESPONSEDATA);
/*根据Model渲染View 基础商品基本信息*/
$("#basicInfo").html(common.util.__template2($("#template2").html(),RESPONSEDATA));
/*类目配置*/
var ENUM={
goodsSizeList:{"sizeId":"","salePrice":$("#salesPriceStr").val(),"factoryCode":"","isSuppled":"Y"}
}
/*公共模块*/
var Bll={
/*判断类目级别,如果符合三级四级,返回对应id*/
validateSort:function(){
var id=false;
var select=tabTree.getAddress();
if(select.length>2){
if(select[2]&&select[2].id){
id=select[2].id;
}
if(select[3]&&select[3].id){
id=select[3].id;
}
}
return id;
},
/*商品名称*/
IsEnter:false,
productNameArr:['','男',''],
setProductName:function(){
if(!Bll.IsEnter&&!param){
$("#productName").val(Bll.productNameArr.join(""));
}
}
}
/*品类初始化*/
var SORTDATA={
url:"/product/querySortBySmallSort",
datas:[
{id:RESPONSEDATA.maxSortId,sortName:RESPONSEDATA.maxSortName},
{id:RESPONSEDATA.middleSortId,sortName:RESPONSEDATA.middleSortName},
{id:RESPONSEDATA.smallSortId,sortName:RESPONSEDATA.smallSortName},
{id:RESPONSEDATA.sortId,sortName:RESPONSEDATA.sortName}
],
otherParam:function(){
return {brandId:$("#brandId").val(),supplierId:common.util.__input("supplierId")}
},
complete:function(data,bool){
if(!bool){
if(data.length>2){
Bll.productNameArr[2]=data[data.length-1].sortName;
Bll.setProductName();
}
if(data[0]&&data[0].text&&data[0].text.indexOf("潮童")>-1){
$("#ageLevel").val("2|3");
}else{
$("#ageLevel").val("1");
}
$(":checkbox[name=ageLevel]").prop("checked",false);
$(":checkbox[name=ageLevel]").each(function(){
var name=$("#ageLevel").val();
if(name.indexOf($(this).val())>-1){
$(this).prop("checked",true)
}
});
}
}
};
var tabTree=new common.tabTree("#tree",SORTDATA);
tabTree.init(SORTDATA.datas);
if(param&&(RESPONSEDATA.isAuditing==100)){
//上架之前可以修改,编辑状态
//||(RESPONSEDATA.isAuditing==200&&RESPONSEDATA.status==8)
tabTree.isfeeze=false;
}else{
tabTree.isfeeze=true;
}
if(RESPONSEDATA.isAuditing==200){
$("#goodsYears").add("#goodsSeason").add("#attribute")
.add("#retailPriceStr").add("#salesPriceStr").add("#stock").prop("disabled",true);
}
/*下拉选择*/
var e=new common.edit("#basicInfo");
e.init();
if(!param){
new common.dropDown({el:"#brandId",ajax:"queryBrandByShopId",params:function(){
return {status:1}
},midData:function(data){
data=data.map(function(item){
if(item.brandNameEn){
item.text+="("+item.brandNameEn+")";
}
// item.text=item.brandNameEn||item.text;
return item;
});
}});
new common.dropDown({el:"#supplierId",ajax:"getjitSup",params:function(){
return {brandId:$("#brandId").val()}
}});
}
var g=new common.grid({
el:"#basicTable",
columns:[
{display:"颜色",render:function(item){
var html=[];
var txt=item.factoryGoodsName?item.factoryGoodsName:item.goodsName;
html.push("<p>厂家颜色:<input type='text' class='w-goods-text' data-index="+item.__index+" value='"+txt+"' placeholder='厂家颜色' required/><p>");
html.push("<p>色系:"+item.goodsName+"<p>");
html.push('<button type="button" data-index='+item.__index+' class="sortdelete btn btn-danger btn-xs">删除</button>');
return html.join("");
}},
{
display:"图片",render:function(item){
//goodsColorImage
return "<input type=file name='goodsColorImage' id='file__"+item.__index+"' value='"+item.goodsColorImage+"' />";
}
},
{
display:"<label class='red'>厂家颜色、尺码、销售价、条码必填</label>",render:function(item){
if(!item.isAdd&&!g.__gsm.hasOwnProperty(item.__index)){
g.__gsm[item.__index]=item.goodsSizeList.length;
}
var html=[];
html.push("<div class='form-group'><div class='col-sm-11 red'><input type=text value='"+item.factoryCode+"' data-index="+item.__index+" class='modelCode form-control' placeholder='款型编码' /></div></div>");
html.push("<dov class='rows'><div class='form-group'><div class='col-sm-2'>尺码</div><div class='col-sm-2'>销售价</div><div class='col-sm-2'>条码</div><div class='col-sm-2'>是否补货</div><div class='col-sm-2'>UPM条码</div></div></div>");
html.push('<div class="rows" id="rows__'+item.__index+'">');
item.goodsSizeList=item.goodsSizeList||[$.extend({},ENUM.goodsSizeList)];
html.push(common.util.__template2($("#template").html(),{index:item.__index,goodsSizeList:item.goodsSizeList}));
html.push('</div>');
return html.join('');
}
}
],
complete:function(){
var sort=Bll.validateSort();
if(sort){
new common.dropDown({
el: ".btn-sort-chima",
ajax: "sortsize2",
params: function(){
return {
"sortId" : Bll.validateSort()
};
}
});
}
g.__e.init();
for(var i in g.__gsm){
var warp=$("#rows__"+i).children(".form-group").slice(0, g.__gsm[i]);
warp.find("input").prop("readonly",true);
warp.find(".btn-sort-chima").prop("disabled",true);
warp.find(".btn-sort-tiaoma").prop("readonly",false);
warp.find(".btn-sort-upmCode").prop("readonly",false);
warp.find(".btn-sort-remove").remove();
// warp.find(".btn-sort-kucun").prop("readonly",false);
}
for(var i=0;i<g.__length;i++){
var warp=$("#basicTable").find("tbody").children("tr").eq(i);
// warp.find(".w-goods-text").prop("readonly",true).prop("disabled",true);
warp.find("input[name=file]").prop("readonly",true).prop("disabled",true);
// warp.find(".modelCode").prop("readonly",true).prop("disabled",true);
// 如果为undefind,则清除require,并且设置为空
if(warp.find(".modelCode").val()=="undefined"){
warp.find(".modelCode").removeAttr("required").val('');
}
//
warp.find(".sortdelete").remove();
}
}
});
g.__rows=RESPONSEDATA.baseGoodList||[];
g.__gsm={};
g.__length=g.__rows.length;
g.__e=new common.edit("#basicTable",{bucket:"goodsimg"});
g.init(g.__rows);
g.__e.on("callback", function(obj) {
if(/^file_onComplete/.test(obj.key)){
var _index=obj.key.replace(/^file_onComplete_file__/,'');
g.__rows[_index].goodsColorImage=obj.data;
}
});
$(document).on("click",".sortadd",function(){
var text=$(this).text();
if(!Bll.validateSort()){
common.util.__tip("请选择完整的分类目录","warning");
return;
}
if ($.trim($("#salesPriceStr").val())=="") {
common.util.__tip("请填写销售价","warning");
return;
}
if(g.__e.validate()){
var goodsSizeList=$.extend({},ENUM.goodsSizeList);
goodsSizeList.salePrice=$("#salesPriceStr").val();
g.__rows.push({
"factoryCode": "",
"goodsColorImage": "",
goodsName: $(this).text(),
colorId: (+$(this).data("id")),
goodsSizeList: [goodsSizeList],
isAdd:true
});
g.reload();
// g.__e.init();
}
});
$(document).on("keydown","#productName",function(){
Bll.IsEnter=true;
});
$(document).on("change","#brandId",function(){
var id=$(this).val();
Bll.productNameArr[0]=$(this).find("option[value='"+id+"']").text();
if(/\((.*)\)/g.test(Bll.productNameArr[0])){
Bll.productNameArr[0]=Bll.productNameArr[0].match(/\((.*)\)/)[1];
}
Bll.setProductName();
$("#supplierId").val(-1).trigger("change");
// $("#shopId").val(-1).trigger("change");
tabTree.isfeeze=false;
tabTree.init([{id:"",sortName:""},{id:"",sortName:""},{id:"",sortName:""},{id:"",sortName:""}]);
});
$(document).on("change","#supplierId",function(){
tabTree.isfeeze=false;
tabTree.init([{id:"",sortName:""},{id:"",sortName:""},{id:"",sortName:""},{id:"",sortName:""}]);
});
$(document).on("change",":radio[name=gender]",function(){
Bll.productNameArr[1]=["男","女","通用"][+$(this).val()-1];
Bll.setProductName();
});
$(document).on("change",":radio[name=isAdvance]",function(){
g.reload();
// $("#stock").val("");
// $.each(g.__rows,function(inex,item){
// $.each(item.goodsSizeList,function(inex1,item1){
// item1.presaleStorageNum="";
// });
// });
if($(this).val()=="Y"){
$("#expectArrivalTimeStr").attr("required","required");
$("#expectArrivalTimeStrTxt").html("预计到货时间<span class='red'>*</span>");
}else{
$("#expectArrivalTimeStr").removeAttr("required");
$("#expectArrivalTimeStrTxt").html("预计到货时间");
}
});
$(document).on("change",".salesPriceStr",function(){
ENUM.goodsSizeList.salePrice=$.trim($(this).val());
});
$(document).on("click",".sortdelete",function(){
var that=this;
common.dialog.confirm("温馨提示","你确定删除吗?",function(){
var index=$(that).data("index");
[].splice.call(g.__rows,index,1);
g.reload();
});
// g.__e.init();
});
$(document).on("change",".modelCode",function(){
var item=g.__rows[$(this).data("index")];
item.factoryCode=$(this).val();
});
$(document).on("click",".btn-sort-add",function(){
var item=g.__rows[$(this).data("index")];
var goodsSizeList=$.extend({},ENUM.goodsSizeList);
goodsSizeList.salePrice=$("#salesPriceStr").val();
item.goodsSizeList.push(goodsSizeList);
g.reload();
// g.__e.init();
});
$(document).on("click",".btn-sort-remove",function(){
var item=g.__rows[$(this).data("index")];
var __index=$(this).data("eq");
[].splice.call(item.goodsSizeList,__index,1);
g.reload();
// g.__e.init();
});
$(document).on("change",".btn-sort-upmCode",function(){
var _index=$(this).data("index");
var _eq=$(this).data("eq");
var item=g.__rows[_index].goodsSizeList[_eq];
item.upmCode=$(this).val();
});
$(document).on("change",".btn-sort-chima",function(){
var _index=$(this).data("index");
var _eq=$(this).data("eq");
var item=g.__rows[_index].goodsSizeList[_eq];
item.sizeId=$(this).val();
item.sizeName=$(this).find("option[value='"+item.sizeId+"']").text();
});
$(document).on("change",".btn-sort-xiaoshou",function(){
var _index=$(this).data("index");
var _eq=$(this).data("eq");
var item=g.__rows[_index].goodsSizeList[_eq];
item.salePrice=$(this).val();
});
$(document).on("change",".btn-sort-tiaoma",function(){
var _index=$(this).data("index");
var _eq=$(this).data("eq");
var item=g.__rows[_index].goodsSizeList[_eq];
item.factoryCode=$(this).val();
});
$(document).on("change",".btn-sort-kebu",function(){
var _index=$(this).data("index");
var _eq=$(this).data("eq");
var item=g.__rows[_index].goodsSizeList[_eq];
item.isSuppled=$(this).val();
});
$(document).on("change",".w-goods-text",function(){
var item=g.__rows[$(this).data("index")];
item.factoryGoodsName=$(this).val();
console.log("item.factoryGoodsName",item.factoryGoodsName);
});
$(document).on("change",":checkbox[name=seasons]",function(){
var value=$(this).val();
var c=$(":checkbox[name=seasons]");
if($(this).is(":checked")){
if(value=="seasons"){
c.slice(0,4).prop("checked",false);
}else{
c.eq(4).prop("checked",false);
}
}
var arr=[];
$(":checked[name=seasons]").each(function(){
arr.push($(this).val())
});
$("#seasons").val(arr.join('|'));
});
$(document).on("change",".attr_input",function(){
var item=ag.rows[$(this).data("index")];
item.val=$(this).val();
});
$(document).on("change",".attr_checkobx_class",function(){
var item=ag.rows[$(this).data("index")];
item.val=$("#attr_"+$(this).data("index")).val();
})
var e=new common.edit("#basicInfo");
e.on("validate",function(){
return g.__e.validate();
});
e.init();
e.on("validate",function(){
if(Bll.validateSort()){
return true;
}
return "请选择完整的分类目录";
});
e.on("validate",function(){
console.log(g.__gsm);
if(g.__rows.length==0){
return "请添加销售属性";
}
var map={},map2={},map3=[],_count=0,_count1=0;
if(g.__rows.length>0){
$.each(g.__rows,function(index,item){
var gname= item.factoryGoodsName?item.factoryGoodsName:item.goodsName;
$.each(item.goodsSizeList,function(index1,item1){
var key=gname+"_"+item1.sizeId;
if(map.hasOwnProperty(key)){
_count++;
return;
}
//RESPONSEDATA.productSkn
console.log("item1.factoryCode",item1.factoryCode)
map[gname+"_"+item1.sizeId]="";
map3.push({'productSku': item1.productSku, 'factoryCode':item1.factoryCode});
});
});
}
if(_count>0){
return "同一颜色包含两组相同尺码";
}
if(map3.length>0&&common.util.__input("supplierId")){
var len=map3.length;
map3=map3.filter(function(item){
return $.trim(item.factoryCode)?true:false;
});
var __m={};
map3.forEach(function(item){
if(!__m.hasOwnProperty(item.factoryCode)){
__m[item.factoryCode]=true;
}
});
var ispass=true;
if(len==map3.length&&len==Object.keys(__m).length){
common.util.__ajax2({
url:'/product/checkSkuBarCodeExist',
async:false,
data:{barCode: JSON.stringify(map3)}
},function(res){
if(res.data.length){
ispass="商品条码"+res.data.join(',')+"已经存在";
}
},true);
}else{
ispass="商品条码不可为空或者条码重复";
}
return ispass;
}
});
e.on("validate",function(){
if((+$("#salesPriceStr").val())>(+$("#retailPriceStr").val())){
return "销售价应该限定小于等于吊牌价";
}
});
$(document).on("click","#btnReview",function(){
var $this=$(this);
if(e.validate()){
common.dialog.confirm("温馨提示","<p>你确定提交吗?</p>",function(){
common.util.__disButton.call($this);
e.submit(PageENUM[ACTION].url,function(option){
var select=tabTree.getAddress();
option.data.supplierId=common.util.__input("supplierId")?$("#supplierId").val():"0";
// option.data.shopId=common.util.__input("shopId")?$("#shopId").val():"0";
option.data.productSkn=RESPONSEDATA.productSkn||"";
option.data.maxSortId=select[0]?select[0].id:"";
option.data.middleSortId=select[1]?select[1].id:"";
option.data.smallSortId=select[2]?select[2].id:"";
option.data.sortId=select[3]?select[3].id:"";
option.data.isVip=option.data.isVip||'B';
option.data.isOutLets=option.data.isOutLets||'N';
// option.data.shopId=$("#shopId").val();
option.data.brandId=$("#brandId").val();
option.data.isAuditing=RESPONSEDATA.isAuditing?RESPONSEDATA.isAuditing:"";
option.data.seasons=option.data.seasons?option.data.seasons.replace(/\|/g,','):"";
//expectShelfTime
// option.data=new Date(expectShelfTime).getTime();
option.data.baseGoodInfoStr=JSON.stringify(g.__rows);
option.success=function(res){
if(res.code == "200") {
e.$tip("提交成功", function() {
location.href="/product/base/index"
}, 'growl-success');
}else{
e.$tip(res.message);
}
},
option.error=function(res){
e.$tip(res.message);
}
});
})
}
return false;
});