Authored by 王水玲

商品创建

@@ -105,7 +105,7 @@ @@ -105,7 +105,7 @@
105 </script> 105 </script>
106 </div> 106 </div>
107 <div region="center" style="overflow-y: scroll; top: 65px; padding-top: 10px;"> 107 <div region="center" style="overflow-y: scroll; top: 65px; padding-top: 10px;">
108 -<from id="productDetail"> 108 +<form id="productDetail">
109 <ul class="container"> 109 <ul class="container">
110 <li> 110 <li>
111 <h2>基本信息</h2> 111 <h2>基本信息</h2>
@@ -159,7 +159,7 @@ @@ -159,7 +159,7 @@
159 <h2>颜色尺码</h2> 159 <h2>颜色尺码</h2>
160 <div class="group-color"> 160 <div class="group-color">
161 <div class="label">*颜色</div> 161 <div class="label">*颜色</div>
162 - <ul style="float:left; margin-left: 10px;"> 162 + <ul style="float: left; margin-left: 10px;">
163 </ul> 163 </ul>
164 </div> 164 </div>
165 <div class="group-size"> 165 <div class="group-size">
@@ -192,7 +192,7 @@ @@ -192,7 +192,7 @@
192 <a id="cancelBtn" class="easyui-linkbutton btn-default">取消</a> 192 <a id="cancelBtn" class="easyui-linkbutton btn-default">取消</a>
193 </li> 193 </li>
194 </ul> 194 </ul>
195 -</from> 195 +</form>
196 </div> 196 </div>
197 <script> 197 <script>
198 /* 新增,修改公用页面 198 /* 新增,修改公用页面
@@ -205,30 +205,45 @@ @@ -205,30 +205,45 @@
205 不可修改:品牌、分类、颜色、尺码、SKU(颜色展示名称除外:goodsName) 205 不可修改:品牌、分类、颜色、尺码、SKU(颜色展示名称除外:goodsName)
206 */ 206 */
207 var productDetail = { 207 var productDetail = {
208 - initData: function(detail) {  
209 - $("#editBrandId").combobox('select', detail.brandId)  
210 - $("#editProductName").textbox('setValue', detail.productName);  
211 - $("#editSaleTime").myDatebox('setValue', detail.saleTime);  
212 - $('input[name=gender]').eq(detail.gender - 1).attr('checked','true');  
213 - $('#editMinPrice').textbox('setValue', detail.minPrice);  
214 - $('#editMaxPrice').textbox('setValue', detail.maxPrice);  
215 - $('#editProductCode').textbox('setValue', detail.productCode);  
216 - $("#editMaxSortId").combobox('select', detail.maxSortId);  
217 - $("#editMidSortId").combobox('select', detail.midSortId);  
218 - $("#editSeriesId").combobox('select', detail.seriesId); 208 + initDom: function() {
  209 + this.dom = {
  210 + editBrandId: $('#editBrandId'),
  211 + editProductName: $('#editProductName'),
  212 + editSaleTime: $('#editSaleTime'),
  213 + editMinPrice: $('#editMinPrice'),
  214 + editMaxPrice: $('#editMaxPrice'),
  215 + editProductCode: $('#editProductCode'),
  216 + editMaxSortId: $('#editMaxSortId'),
  217 + editMidSortId: $('#editMidSortId'),
  218 + editSeriesId: $('#editSeriesId'),
  219 + imageUpload: $('#imageUpload')
  220 + };
  221 + },
  222 + initFormData: function(detail) {
  223 + var that = this;
219 224
220 - $('.group-color li[data-id='+detail.colorId+']').addClass('actived'); 225 + this.dom.editBrandId.combobox('select', detail.brandId)
  226 + this.dom.editProductName.textbox('setValue', detail.productName);
  227 + this.dom.editSaleTime.myDatebox('setValue', detail.saleTime);
  228 + this.dom.editMinPrice.textbox('setValue', detail.minPrice);
  229 + this.dom.editMaxPrice.textbox('setValue', detail.maxPrice);
  230 + this.dom.editProductCode.textbox('setValue', detail.productCode);
  231 + this.dom.editMaxSortId.combobox('select', detail.maxSortId);
  232 + this.dom.editMidSortId.combobox('select', detail.midSortId);
  233 + this.dom.editSeriesId.combobox('select', detail.seriesId);
  234 + $('input[name=gender]').eq(detail.gender - 1).attr('checked','true');
  235 + $('.group-color li[data-id=' + detail.colorId + ']').addClass('actived');
221 236
222 if (detail.imageUrlList.length > 0) { 237 if (detail.imageUrlList.length > 0) {
223 detail.imageUrlList.map(function(item) { 238 detail.imageUrlList.map(function(item) {
224 - $('#imageUpload').before('<div class="img" data-url="' + item + '" style="background-image:url(' + item + ');">'); 239 + that.dom.imageUpload.before('<div class="img" data-url="' + item + '" style="background-image:url(' + item + ');">');
225 }); 240 });
226 } 241 }
227 }, 242 },
228 initForm: function() { 243 initForm: function() {
229 var that = this; 244 var that = this;
230 245
231 - $("#editProductName").textbox({ 246 + this.dom.editProductName.textbox({
232 required: true, 247 required: true,
233 missingMessage: "商品名称不能为空", 248 missingMessage: "商品名称不能为空",
234 prompt: "商品名称", 249 prompt: "商品名称",
@@ -239,20 +254,20 @@ @@ -239,20 +254,20 @@
239 width: 700 254 width: 700
240 }); 255 });
241 256
242 - $("#editBrandId").combobox({ 257 + this.dom.editBrandId.combobox({
243 editable: false, 258 editable: false,
244 prompt: "选择品牌", 259 prompt: "选择品牌",
245 width: 200, 260 width: 200,
246 valueField: "id", 261 valueField: "id",
247 textField: "text", 262 textField: "text",
248 onSelect: function(data) { 263 onSelect: function(data) {
249 - $('#editSeriesId').combobox('enable');  
250 - $("#editSeriesId").myCombobox('reload', contextPath + '/brandSeries/querySeriesByBrandId?brandId=' + data.id);  
251 - $("#editSeriesId").combobox('select') 264 + that.dom.editSeriesId.combobox('enable');
  265 + that.dom.editSeriesId.myCombobox('reload', contextPath + '/brandSeries/querySeriesByBrandId?brandId=' + data.id);
  266 + that.dom.editSeriesId.combobox('select')
252 } 267 }
253 }); 268 });
254 269
255 - $("#editSeriesId").myCombobox({ 270 + this.dom.editSeriesId.myCombobox({
256 method: "get", 271 method: "get",
257 editable: false, 272 editable: false,
258 prompt: "请选择", 273 prompt: "请选择",
@@ -261,32 +276,32 @@ @@ -261,32 +276,32 @@
261 textField: "text", 276 textField: "text",
262 loadFilter: function (data) { 277 loadFilter: function (data) {
263 if (data && data.code == 200 && data.data.length > 0) { 278 if (data && data.code == 200 && data.data.length > 0) {
264 - $("#editSeriesId").combobox('select', data.data[0].id); 279 + that.dom.editSeriesId.combobox('select', data.data[0].id);
265 } 280 }
266 281
267 return defaultLoadFilter(data); 282 return defaultLoadFilter(data);
268 } 283 }
269 }); 284 });
270 285
271 - $('#editMaxSortId').myCombobox({ 286 + this.dom.editMaxSortId.myCombobox({
272 editable: false, 287 editable: false,
273 valueField: 'id', 288 valueField: 'id',
274 textField: 'text', 289 textField: 'text',
275 prompt:"一级分类", 290 prompt:"一级分类",
276 onSelect: function (rec) { 291 onSelect: function (rec) {
277 - $('#editMidSortId').combobox('clear');  
278 - $('#editMidSortId').combobox('reload', contextPath + "/productSort/getLevel2SortBySortId?sortId=" + rec.id); 292 + that.dom.editMidSortId.combobox('clear');
  293 + that.dom.editMidSortId.combobox('reload', contextPath + "/productSort/getLevel2SortBySortId?sortId=" + rec.id);
279 if (!that.productId) { 294 if (!that.productId) {
280 - $('#editMidSortId').combobox('enable'); 295 + that.dom.editMidSortId.combobox('enable');
281 } 296 }
282 } 297 }
283 }); 298 });
284 299
285 - $("#editSaleTime").myDatebox({ 300 + this.dom.editSaleTime.myDatebox({
286 prompt : "发售时间" 301 prompt : "发售时间"
287 }); 302 });
288 303
289 - $('#editMidSortId').myCombobox({ 304 + this.dom.editMidSortId.myCombobox({
290 method: 'get', 305 method: 'get',
291 editable: false, 306 editable: false,
292 valueField: 'id', 307 valueField: 'id',
@@ -294,7 +309,7 @@ @@ -294,7 +309,7 @@
294 prompt:"二级分类", 309 prompt:"二级分类",
295 loadFilter: function(data) { 310 loadFilter: function(data) {
296 if (data && data.code == 200 && data.data.length > 0) { 311 if (data && data.code == 200 && data.data.length > 0) {
297 - $("#editMidSortId").combobox('select', data.data[0].id); 312 + that.dom.editMidSortId.combobox('select', data.data[0].id);
298 } 313 }
299 314
300 return defaultLoadFilter(data); 315 return defaultLoadFilter(data);
@@ -304,22 +319,21 @@ @@ -304,22 +319,21 @@
304 } 319 }
305 }); 320 });
306 321
307 - $("#editProductCode").textbox({ 322 + this.dom.editProductCode.textbox({
308 prompt : "请输入", 323 prompt : "请输入",
309 required: true, 324 required: true,
310 missingMessage: "货号不能为空" 325 missingMessage: "货号不能为空"
311 }); 326 });
312 - $("#editMinPrice").textbox({ 327 + this.dom.editMinPrice.textbox({
313 prompt : "最低价", 328 prompt : "最低价",
314 required: true, 329 required: true,
315 missingMessage: "最低价不能为空" 330 missingMessage: "最低价不能为空"
316 }); 331 });
317 - $("#editMaxPrice").textbox({ 332 + this.dom.editMaxPrice.textbox({
318 prompt : "最高价", 333 prompt : "最高价",
319 required: true, 334 required: true,
320 missingMessage: "最高价不能为空" 335 missingMessage: "最高价不能为空"
321 }); 336 });
322 -  
323 $('#colorSizeTable').myDatagrid({ 337 $('#colorSizeTable').myDatagrid({
324 fit: false, 338 fit: false,
325 fitColumns: true, 339 fitColumns: true,
@@ -363,27 +377,28 @@ @@ -363,27 +377,28 @@
363 }); 377 });
364 378
365 if (!this.productId) { 379 if (!this.productId) {
366 - $('#editSeriesId').combobox('disable');  
367 - $('#editMidSortId').combobox('disable'); 380 + this.dom.editSeriesId.combobox('disable');
  381 +
368 } else { 382 } else {
369 - $("#editBrandId").combobox('disable');  
370 - $("#editMaxSortId").combobox('disable');  
371 - $("#editMidSortId").combobox('disable'); 383 + this.dom.editBrandId.combobox('disable');
  384 + this.dom.editMaxSortId.combobox('disable');
372 } 385 }
  386 + this.dom.editMidSortId.combobox('disable');
373 }, 387 },
374 init: function() { 388 init: function() {
375 var that = this; 389 var that = this;
376 - this.productId = this.getUrlParam('id');  
377 390
  391 + this.productId = this.getUrlParam('id');
378 this.detailData = {}; 392 this.detailData = {};
379 this.submitFlag = false; 393 this.submitFlag = false;
380 this.colorSizeTableData = { 394 this.colorSizeTableData = {
381 total: 0, 395 total: 0,
382 rows: [] 396 rows: []
383 }; 397 };
  398 + this.initDom();
384 this.initForm(); 399 this.initForm();
385 400
386 - $("#imageUpload").imageUpload({ 401 + this.dom.imageUpload.imageUpload({
387 width: 104, 402 width: 104,
388 height: 104, 403 height: 104,
389 realInputName: "goodsImage", 404 realInputName: "goodsImage",
@@ -410,7 +425,7 @@ @@ -410,7 +425,7 @@
410 onLoadSuccess: function (data) { 425 onLoadSuccess: function (data) {
411 $.messager.progress("close"); 426 $.messager.progress("close");
412 $(document).find('.file-close').click(); 427 $(document).find('.file-close').click();
413 - $('#imageUpload').before('<div class="img" data-url="' + data.data.url + '" style="background-image:url(' + data.data.url + ');">'); 428 + that.dom.imageUpload.before('<div class="img" data-url="' + data.data.url + '" style="background-image:url(' + data.data.url + ');">');
414 return false; 429 return false;
415 } 430 }
416 }); 431 });
@@ -423,13 +438,13 @@ @@ -423,13 +438,13 @@
423 colors = colors[0] || []; 438 colors = colors[0] || [];
424 439
425 if (brand && brand.code == 200) { 440 if (brand && brand.code == 200) {
426 - $("#editBrandId").combobox({ 441 + that.dom.editBrandId.combobox({
427 data: brand.data || [] 442 data: brand.data || []
428 }); 443 });
429 } 444 }
430 445
431 if (maxSort && maxSort.code == 200) { 446 if (maxSort && maxSort.code == 200) {
432 - $("#editMaxSortId").combobox({ 447 + that.dom.editMaxSortId.combobox({
433 data: maxSort.data || [] 448 data: maxSort.data || []
434 }); 449 });
435 } 450 }
@@ -536,11 +551,11 @@ @@ -536,11 +551,11 @@
536 var sizeIdList = []; 551 var sizeIdList = [];
537 var editImage = 0; 552 var editImage = 0;
538 553
539 - if (this.submitFlag) { 554 + if (that.submitFlag) {
540 return; 555 return;
541 } 556 }
542 557
543 - this.submitFlag = true; 558 + that.submitFlag = true;
544 559
545 $('.goods-image .img').each(function(index, item) { 560 $('.goods-image .img').each(function(index, item) {
546 imageUrlList.push($(item).data('url')); 561 imageUrlList.push($(item).data('url'));
@@ -564,7 +579,7 @@ @@ -564,7 +579,7 @@
564 } 579 }
565 580
566 var ajaxData = { 581 var ajaxData = {
567 - brandId: +$('#editBrandId').textbox('getValue'), 582 + brandId: +that.dom.editBrandId.textbox('getValue'),
568 colorId: +$('.group-color .actived').data('id'), 583 colorId: +$('.group-color .actived').data('id'),
569 colorName: $('.group-color .actived').text(), 584 colorName: $('.group-color .actived').text(),
570 editImage: editImage, 585 editImage: editImage,
@@ -572,14 +587,14 @@ @@ -572,14 +587,14 @@
572 goodsName: $('.goods-name').length>0 && $('.goods-name').textbox('getValue') || '', 587 goodsName: $('.goods-name').length>0 && $('.goods-name').textbox('getValue') || '',
573 imageUrlList: imageUrlList, 588 imageUrlList: imageUrlList,
574 keyWords: $('#keyword').textbox('getValue'), 589 keyWords: $('#keyword').textbox('getValue'),
575 - maxPrice: $('#editMaxPrice').textbox('getValue'),  
576 - maxSortId: +$('#editMaxSortId').combobox('getValue'),  
577 - midSortId: +$('#editMidSortId').combobox('getValue'),  
578 - minPrice: $('#editMinPrice').textbox('getValue'),  
579 - productCode: $('#editProductCode').textbox('getValue'),  
580 - productName: $('#editProductName').textbox('getValue'),  
581 - saleTime: $("#editSaleTime").myDatebox('getValue'),  
582 - seriesId: +$('#editSeriesId').combobox('getValue') 590 + maxPrice: that.dom.editMaxPrice.textbox('getValue'),
  591 + maxSortId: +that.dom.editMaxSortId.combobox('getValue'),
  592 + midSortId: +that.dom.editMidSortId.combobox('getValue'),
  593 + minPrice: that.dom.editMinPrice.textbox('getValue'),
  594 + productCode: that.dom.editProductCode.textbox('getValue'),
  595 + productName: that.dom.editProductName.textbox('getValue'),
  596 + saleTime: that.dom.editSaleTime.myDatebox('getValue'),
  597 + seriesId: +that.dom.editSeriesId.combobox('getValue')
583 }; 598 };
584 599
585 if (!ajaxData.brandId) { 600 if (!ajaxData.brandId) {
@@ -645,10 +660,11 @@ @@ -645,10 +660,11 @@
645 that.submitFlag = false; 660 that.submitFlag = false;
646 $.messager.progress("close"); 661 $.messager.progress("close");
647 $.messager.alert('操作提示', '提交成功!'); 662 $.messager.alert('操作提示', '提交成功!');
  663 + window.location.href = contextPath + "/html/product/productList.html";
648 }, 664 },
649 error: function(err) { 665 error: function(err) {
650 that.submitFlag = false; 666 that.submitFlag = false;
651 - $.messager.alert('操作提示', err.message); 667 + $.messager.alert('操作提示', err.message || '提交失败');
652 } 668 }
653 }); 669 });
654 } 670 }
@@ -680,7 +696,7 @@ @@ -680,7 +696,7 @@
680 if (ret && ret.code == 200) { 696 if (ret && ret.code == 200) {
681 ret = ret.data || {}; 697 ret = ret.data || {};
682 698
683 - that.initData(ret); 699 + that.initFormData(ret);
684 that.detailData = ret; 700 that.detailData = ret;
685 } 701 }
686 }); 702 });