productEdit.html
14.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
<!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;
}
.product-detail-page .container {
padding: 0 30px;
}
.product-detail-page .base-info {
border-bottom: 1px solid #eee;
}
.product-detail-page .base-info li {
display: flex;
align-items: center;
margin-bottom: 10px;
}
.product-detail-page .base-info .label {
width: 120px;
font-size: 14px;
text-align: right;
}
.product-detail-page .base-info .red {
color: red;
}
.product-detail-page .group-color, .product-detail-page .group-size {
display: flex;
align-items: center;
margin-bottom: 10px;
}
.product-detail-page .group-color li {
margin-right: 5px;
float: left;
line-height: 30px;
margin-left: 5px;
padding: 0 5px;
}
.product-detail-page .group-color .actived {
background: #8fa9bb;
color: #fff;
border-radius: 5px;
}
.product-detail-page .group-size .size {
float:left;
margin-left: 10px;
}
</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;">
<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"> 系列:<input id="editSeriesId" type="text"></div>
</li>
<li>
<div class="label">商品名称 <span class="red">*</span>:</div>
<div class="base-info-item"><input id="editProductName" type="text"/></div>
</li>
<li>
<div class="label">发售日期 <span class="red">*</span>:</div>
<div class="base-info-item"><input id="editSaleTime" type="text"/></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="sex" checked>男</label>
<label for="girl"><input id="girl" type="radio" value="2" name="sex">女</label>
<label for="all"><input id="all" type="radio" value="3" name="sex">通用</label>
</div>
</li>
<li>
<div class="label">分类 <span class="red">*</span>:</div>
<div class="base-info-item"><input id="editMaxSortId" type="text"/><input id="editMidSortId" type="text"/> 货号 <span class="red">*</span>:<input id="editProductCode" type="text"/></div>
</li>
<li>
<div class="label">商品价格限制 <span class="red">*</span>:</div>
<div class="base-info-item"><input id="editMinPrice" type="text"/><span style="margin-right: 20px;c">~</span><input id="editMaxPrice" type="text"/></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"></table>
</li>
</ul>
<!-- <input id="editGender" type="text"/>
<input id="editColorId" type="text"/>
<input id="editColorName" type="text"/>
<input id="editGoodsName" type="text"/>
<input id="editSizeIdList" type="text"/>
<input id="editImageUrlList" type="text"/>
<input id="editKeyWords" type="text"/>
<input id="editGoodsId" type="hidden"/>
<input id="editId" type="hidden"/> -->
</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 productDetail = {
initData: function(detail) {
$("#editSeriesId").myCombobox({
url: contextPath + '/brandSeries/querySeriesByBrandId?brandId=' + detail.brandId,
method: "get",
editable: false,
prompt: "请选择",
width: 200,
valueField: "id",
textField: "text",
loadFilter: function (data) {
return defaultLoadFilter(data);
}
});
$("#editBrandId").combobox('select', detail.brandId)
$("#editProductName").textbox('setValue', detail.productName);
$("#editSaleTime").myDatebox('setValue', detail.saleTime);
$('input[name=sex]').eq(detail.gender - 1).attr('checked','true');
$('#editMinPrice').textbox('setValue', detail.minPrice);
$('#editMaxPrice').textbox('setValue', detail.maxPrice);
$('#editProductCode').textbox('setValue', detail.productCode);
$("#editMaxSortId").combobox('select', detail.maxSortId);
$("#editMidSortId").combobox('select', detail.midSortId);
$("#editSeriesId").combobox('select', detail.seriesId)
this.getSizeInfo(detail.midSortId);
},
initForm: function() {
$("#editProductName").textbox({
required: true,
missingMessage: "商品名称不能为空",
prompt: "商品名称",
width: 460
});
$("#editBrandId").combobox({
editable: false,
prompt: "选择品牌",
width: 200,
valueField: "id",
textField: "text"
});
$('#editMaxSortId').myCombobox({
editable: false,
valueField: 'id',
textField: 'text',
prompt:"一级分类",
onSelect: function (rec) {
if (0 === rec.id) {
try {
$('#midSortId').combobox('disable');
} catch (e) { }
return;
}
try {
$('#editMidSortId').combobox('clear');
$('#editMidSortId').combobox('reload', contextPath + "/productSort/getLevel2SortBySortId?sortId=" + rec.id);
$('#editMidSortId').combobox('enable');
} catch (e) { }
}
});
$("#editSaleTime").myDatebox({
prompt : "发售时间"
});
$('#editMidSortId').myCombobox({
method: 'get',
editable: false,
valueField: 'id',
textField: 'text',
multiple: true,
prompt:"二级分类",
loadFilter: function(data) {
console.log(data)
return defaultLoadFilter(data);
}
});
$("#editProductCode").textbox({
prompt : "请输入"
});
$("#editMinPrice").textbox({
prompt : "最低价"
});
$("#editMaxPrice").textbox({
prompt : "最高价"
});
$("#editKeyWords").textbox({
prompt : "请输入"
});
},
init: function() {
var that = this;
var productId = this.getUrlParam('id');
var ajaxList = [];
var colorSizeSelected = {}
this.initForm();
this.getColorInfo();
$.when(this.getBrandList(), this.getMaxSortList()).then(function(brand, maxSort) {
var brandId = '';
brand = brand[0];
maxSort = maxSort[0];
if (brand && brand.code == 200) {
$("#editBrandId").combobox({
data: brand.data || []
});
}
if (maxSort && maxSort.code == 200) {
$("#editMaxSortId").combobox({
data: maxSort.data || []
});
}
if (productId) {
that.getDetailInfo(productId);
} else {
this.getSizeInfo();
}
});
this.changeColorOrSize();
$(document).on('click', '.group-color li', function() {
$(this).siblings().removeClass('actived');
$(this).addClass('actived');
});
},
changeColorOrSize: function() {
$("#colorSizeTable").myDatagrid({
fit: true,
fitColumns: true,
nowrap: false,
columns: [[{
title: "色系名称",
field: "id",
width: 40,
align: "center"
}, {
title: "颜色展示名称",
field: "colorImage",
width: 80,
align: "center",
formatter: function(value) {
return '<img src="' + value + '" style="width: 48px; height: 48px;vertical-align: middle;">'
}
}, {
title: "尺码",
field: "productName",
width: 100,
align: "center"
}, {
title: "SKU",
field: "sortName",
width: 80,
align: "center"
}]],
cache: false,
pagination: false,
idField: "id",
singleSelect: false,
checkOnSelect: false,
onLoadSuccess: function () {
// 编辑
$(this).myDatagrid("getPanel").find("a[role='edit']").linkbutton({
iconCls: "icon-edit",
onClick: function () {
var id = $(this).attr("dataId");
editRow(id);
}
});
// 关闭品牌
$(this).myDatagrid("getPanel").find("a[role='closeBrandSeries']").linkbutton({
iconCls: "icon-more",
onClick: function () {
updateBrandSeriesStatus($(this).attr("dataId"), 2);
}
});
// 开启品牌
$(this).myDatagrid("getPanel").find("a[role='openBrandSeries']").linkbutton({
iconCls: "icon-more",
onClick: function () {
updateBrandSeriesStatus($(this).attr("dataId"), 1);
}
});
}
});
},
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(productId) {
var that = this;
// 编辑的情况需要根据id查询商品信息
$.get(contextPath + '/product/find?id=' + productId).then(function(ret) {
if (ret && ret.code == 200) {
that.initData(ret.data);
}
});
},
getBrandList: function() {
// 获取所有品牌
return $.get(contextPath + '/brand/getBrandName');
},
getMaxSortList: function() {
// 获取一级分类
return $.get(contextPath + "/productSort/getLevel1SortIdAndName");
},
getMinSortList: function() {
// 获取二级分类
return $.get(contextPath + "/productSort/getLevel1SortIdAndName");
},
getSizeInfo: function(sortId) {
// 获取所有尺寸
$.ajax({
contentType: 'application/json',
dataType: 'json',
type : 'GET',
url: contextPath + '/size/queryAllSize4Goods?sortId=' + sortId,
success: function (ret) {
if (ret && ret.code == 200) {
$.each(ret.data || [], function(index, item) {
$('.group-size .size').append('<label for="size" style="margin-right: 5px;"><input type="checkbox" name="size">'+item.text+'</label>');
});
}
}
});
},
getColorInfo: function() {
// 获取所有颜色
$.ajax({
contentType: 'application/json',
dataType: 'json',
type : 'GET',
url: contextPath + '/productColor/getAllColor',
success: function (ret) {
if (ret && ret.code == 200) {
$.each(ret.data || [], function(index, item) {
var color = item.colorValue ? 'background: url('+item.colorValue+')' : 'background:#' + item.colorCode;
$('.group-color ul').append('<li data-color="' + color + '"><i style="float: left;width: 30px; height: 30px;border-radius: 50%; margin-right: 3px;' + color + ';background-size: contain;"></i>' + item.colorName + '</li>')
});
}
}
})
}
};
$(function () {
productDetail.init();
});
</script>
</body>
</html>