Authored by 王水玲

商品创建

... ... @@ -105,7 +105,7 @@
</script>
</div>
<div region="center" style="overflow-y: scroll; top: 65px; padding-top: 10px;">
<from id="productDetail">
<form id="productDetail">
<ul class="container">
<li>
<h2>基本信息</h2>
... ... @@ -159,7 +159,7 @@
<h2>颜色尺码</h2>
<div class="group-color">
<div class="label">*颜色</div>
<ul style="float:left; margin-left: 10px;">
<ul style="float: left; margin-left: 10px;">
</ul>
</div>
<div class="group-size">
... ... @@ -192,7 +192,7 @@
<a id="cancelBtn" class="easyui-linkbutton btn-default">取消</a>
</li>
</ul>
</from>
</form>
</div>
<script>
/* 新增,修改公用页面
... ... @@ -205,30 +205,45 @@
不可修改:品牌、分类、颜色、尺码、SKU(颜色展示名称除外:goodsName)
*/
var productDetail = {
initData: function(detail) {
$("#editBrandId").combobox('select', detail.brandId)
$("#editProductName").textbox('setValue', detail.productName);
$("#editSaleTime").myDatebox('setValue', detail.saleTime);
$('input[name=gender]').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);
initDom: function() {
this.dom = {
editBrandId: $('#editBrandId'),
editProductName: $('#editProductName'),
editSaleTime: $('#editSaleTime'),
editMinPrice: $('#editMinPrice'),
editMaxPrice: $('#editMaxPrice'),
editProductCode: $('#editProductCode'),
editMaxSortId: $('#editMaxSortId'),
editMidSortId: $('#editMidSortId'),
editSeriesId: $('#editSeriesId'),
imageUpload: $('#imageUpload')
};
},
initFormData: function(detail) {
var that = this;
$('.group-color li[data-id='+detail.colorId+']').addClass('actived');
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);
this.dom.editSeriesId.combobox('select', detail.seriesId);
$('input[name=gender]').eq(detail.gender - 1).attr('checked','true');
$('.group-color li[data-id=' + detail.colorId + ']').addClass('actived');
if (detail.imageUrlList.length > 0) {
detail.imageUrlList.map(function(item) {
$('#imageUpload').before('<div class="img" data-url="' + item + '" style="background-image:url(' + item + ');">');
that.dom.imageUpload.before('<div class="img" data-url="' + item + '" style="background-image:url(' + item + ');">');
});
}
},
initForm: function() {
var that = this;
$("#editProductName").textbox({
this.dom.editProductName.textbox({
required: true,
missingMessage: "商品名称不能为空",
prompt: "商品名称",
... ... @@ -239,20 +254,20 @@
width: 700
});
$("#editBrandId").combobox({
this.dom.editBrandId.combobox({
editable: false,
prompt: "选择品牌",
width: 200,
valueField: "id",
textField: "text",
onSelect: function(data) {
$('#editSeriesId').combobox('enable');
$("#editSeriesId").myCombobox('reload', contextPath + '/brandSeries/querySeriesByBrandId?brandId=' + data.id);
$("#editSeriesId").combobox('select')
that.dom.editSeriesId.combobox('enable');
that.dom.editSeriesId.myCombobox('reload', contextPath + '/brandSeries/querySeriesByBrandId?brandId=' + data.id);
that.dom.editSeriesId.combobox('select')
}
});
$("#editSeriesId").myCombobox({
this.dom.editSeriesId.myCombobox({
method: "get",
editable: false,
prompt: "请选择",
... ... @@ -261,32 +276,32 @@
textField: "text",
loadFilter: function (data) {
if (data && data.code == 200 && data.data.length > 0) {
$("#editSeriesId").combobox('select', data.data[0].id);
that.dom.editSeriesId.combobox('select', data.data[0].id);
}
return defaultLoadFilter(data);
}
});
$('#editMaxSortId').myCombobox({
this.dom.editMaxSortId.myCombobox({
editable: false,
valueField: 'id',
textField: 'text',
prompt:"一级分类",
onSelect: function (rec) {
$('#editMidSortId').combobox('clear');
$('#editMidSortId').combobox('reload', contextPath + "/productSort/getLevel2SortBySortId?sortId=" + rec.id);
that.dom.editMidSortId.combobox('clear');
that.dom.editMidSortId.combobox('reload', contextPath + "/productSort/getLevel2SortBySortId?sortId=" + rec.id);
if (!that.productId) {
$('#editMidSortId').combobox('enable');
that.dom.editMidSortId.combobox('enable');
}
}
});
$("#editSaleTime").myDatebox({
this.dom.editSaleTime.myDatebox({
prompt : "发售时间"
});
$('#editMidSortId').myCombobox({
this.dom.editMidSortId.myCombobox({
method: 'get',
editable: false,
valueField: 'id',
... ... @@ -294,7 +309,7 @@
prompt:"二级分类",
loadFilter: function(data) {
if (data && data.code == 200 && data.data.length > 0) {
$("#editMidSortId").combobox('select', data.data[0].id);
that.dom.editMidSortId.combobox('select', data.data[0].id);
}
return defaultLoadFilter(data);
... ... @@ -304,22 +319,21 @@
}
});
$("#editProductCode").textbox({
this.dom.editProductCode.textbox({
prompt : "请输入",
required: true,
missingMessage: "货号不能为空"
});
$("#editMinPrice").textbox({
this.dom.editMinPrice.textbox({
prompt : "最低价",
required: true,
missingMessage: "最低价不能为空"
});
$("#editMaxPrice").textbox({
this.dom.editMaxPrice.textbox({
prompt : "最高价",
required: true,
missingMessage: "最高价不能为空"
});
$('#colorSizeTable').myDatagrid({
fit: false,
fitColumns: true,
... ... @@ -363,27 +377,28 @@
});
if (!this.productId) {
$('#editSeriesId').combobox('disable');
$('#editMidSortId').combobox('disable');
this.dom.editSeriesId.combobox('disable');
} else {
$("#editBrandId").combobox('disable');
$("#editMaxSortId").combobox('disable');
$("#editMidSortId").combobox('disable');
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.productId = this.getUrlParam('id');
this.detailData = {};
this.submitFlag = false;
this.colorSizeTableData = {
total: 0,
rows: []
};
this.initDom();
this.initForm();
$("#imageUpload").imageUpload({
this.dom.imageUpload.imageUpload({
width: 104,
height: 104,
realInputName: "goodsImage",
... ... @@ -410,7 +425,7 @@
onLoadSuccess: function (data) {
$.messager.progress("close");
$(document).find('.file-close').click();
$('#imageUpload').before('<div class="img" data-url="' + data.data.url + '" style="background-image:url(' + data.data.url + ');">');
that.dom.imageUpload.before('<div class="img" data-url="' + data.data.url + '" style="background-image:url(' + data.data.url + ');">');
return false;
}
});
... ... @@ -423,13 +438,13 @@
colors = colors[0] || [];
if (brand && brand.code == 200) {
$("#editBrandId").combobox({
that.dom.editBrandId.combobox({
data: brand.data || []
});
}
if (maxSort && maxSort.code == 200) {
$("#editMaxSortId").combobox({
that.dom.editMaxSortId.combobox({
data: maxSort.data || []
});
}
... ... @@ -536,11 +551,11 @@
var sizeIdList = [];
var editImage = 0;
if (this.submitFlag) {
if (that.submitFlag) {
return;
}
this.submitFlag = true;
that.submitFlag = true;
$('.goods-image .img').each(function(index, item) {
imageUrlList.push($(item).data('url'));
... ... @@ -564,7 +579,7 @@
}
var ajaxData = {
brandId: +$('#editBrandId').textbox('getValue'),
brandId: +that.dom.editBrandId.textbox('getValue'),
colorId: +$('.group-color .actived').data('id'),
colorName: $('.group-color .actived').text(),
editImage: editImage,
... ... @@ -572,14 +587,14 @@
goodsName: $('.goods-name').length>0 && $('.goods-name').textbox('getValue') || '',
imageUrlList: imageUrlList,
keyWords: $('#keyword').textbox('getValue'),
maxPrice: $('#editMaxPrice').textbox('getValue'),
maxSortId: +$('#editMaxSortId').combobox('getValue'),
midSortId: +$('#editMidSortId').combobox('getValue'),
minPrice: $('#editMinPrice').textbox('getValue'),
productCode: $('#editProductCode').textbox('getValue'),
productName: $('#editProductName').textbox('getValue'),
saleTime: $("#editSaleTime").myDatebox('getValue'),
seriesId: +$('#editSeriesId').combobox('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')
};
if (!ajaxData.brandId) {
... ... @@ -645,10 +660,11 @@
that.submitFlag = false;
$.messager.progress("close");
$.messager.alert('操作提示', '提交成功!');
window.location.href = contextPath + "/html/product/productList.html";
},
error: function(err) {
that.submitFlag = false;
$.messager.alert('操作提示', err.message);
$.messager.alert('操作提示', err.message || '提交失败');
}
});
}
... ... @@ -680,7 +696,7 @@
if (ret && ret.code == 200) {
ret = ret.data || {};
that.initData(ret);
that.initFormData(ret);
that.detailData = ret;
}
});
... ...