/**
|
* 初始化规格属性详情对话框
|
*/
|
var MallGoodsSpecInfoDlg = {
|
mallGoodsSpecInfoData : {},
|
deleteSpecValueIds: '',
|
validFields: {
|
specName: Feng.def_valid_info( true, null, null, null, {
|
stringLength: {
|
max: 20,
|
message: "最多支持10个字"
|
}
|
}), // 不能为空
|
classifyIdOne: Feng.def_valid_info( true), // 不能为空
|
// classifyIdTwo: Feng.def_valid_info( true), // 不能为空
|
}
|
};
|
|
/**
|
* 清除数据
|
*/
|
MallGoodsSpecInfoDlg.clearData = function() {
|
this.mallGoodsSpecInfoData = {};
|
};
|
|
/**
|
* 设置对话框中的数据
|
* @param key 数据的名称
|
* @param val 数据的具体值
|
*/
|
MallGoodsSpecInfoDlg.set = function(key, val) {
|
this.mallGoodsSpecInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
|
return this;
|
};
|
|
/**
|
* 设置对话框中的数据
|
* @param key 数据的名称
|
* @param val 数据的具体值
|
*/
|
MallGoodsSpecInfoDlg.get = function(key) {
|
return $("#" + key).val();
|
};
|
|
/**
|
* 关闭此对话框
|
*/
|
MallGoodsSpecInfoDlg.close = function() {
|
parent.layer.close(window.parent.MallGoodsSpec.layerIndex);
|
};
|
|
/**
|
* 收集数据
|
*/
|
MallGoodsSpecInfoDlg.collectData = function() {
|
this
|
.set('id')
|
.set('classifyIdOne', Feng.get_chosen_selected( "#classifyIdOne"))
|
// .set('classifyIdTwo', Feng.get_chosen_selected( "#classifyIdTwo"))
|
.set('specName')
|
.set('specValuesJson', JSON.stringify( this.get_spec_values()))
|
.set('remark');
|
};
|
|
MallGoodsSpecInfoDlg.check_value = function () {
|
if ( !Feng.check_form( "formId")) { return false; }
|
if ( Feng.get_chosen_selected( "#classifyIdOne").length <= 0) {
|
Feng.error( "请选择商品分类")
|
return false;
|
}
|
// if (this.get_spec_values().length <= 0) {
|
// Feng.error( "请设置规格值");
|
// return false;
|
// }
|
return true;
|
}
|
|
/**
|
* 提交添加
|
*/
|
MallGoodsSpecInfoDlg.addSubmit = function() {
|
this.clearData();
|
this.collectData();
|
|
if ( !this.check_value()) { return; }
|
|
//提交信息
|
var ajax = new $ax(Feng.ctxPath + "/mallGoodsSpec/add", function(data){
|
if(data.code == 200){
|
Feng.success("添加成功!");
|
window.parent.MallGoodsSpec.search();
|
MallGoodsSpecInfoDlg.close();
|
} else {
|
Feng.error("添加失败!" + data.message);
|
}
|
},function(){
|
Feng.error("添加失败!");
|
});
|
ajax.set(this.mallGoodsSpecInfoData);
|
ajax.start();
|
};
|
|
|
MallGoodsSpecInfoDlg.change_classify_two = function() {
|
return;
|
// var twoIds = Feng.get_chosen_selected( "#classifyIdTwo");
|
// twoIds = twoIds || $( "#classifyIdTwo").data( "value");
|
// $("#classifyIdTwo").data( "value", "").val("").empty().trigger("chosen:updated");
|
// var oneIds = Feng.get_chosen_selected( "#classifyIdOne");
|
// if ( oneIds.length <= 0) { return; }
|
// Feng.base_ajax_data( "/mallClassifyTwo/getMallClassTwoAll", { classOneIds: oneIds}, function (array) {
|
// $("#classifyIdTwo").empty()
|
// .append('<option value="0">全部</option>')
|
// .append( (array||[]).map(function (val) {
|
// var $op = $( "<option value='"+val.id+"'>"+ val.classifyName +"</option>");
|
// $op.data( val);
|
// return $op;
|
// })).val( ((twoIds||"")+"").split( ",")).trigger("chosen:updated");
|
// })
|
}
|
|
MallGoodsSpecInfoDlg.add_spec = function() {
|
var $content = $( "#spec_content"), $tr = $( "<tr>");
|
|
$tr.append( $( "<td>").css({"padding-left": "10px"}).append( "<input maxlength='30' placeholder='请输入规格名称' class='form-control'>"))
|
$tr.append( $( "<td>").append( "<a style='color: blue' href='javascript:void(0);'>删除</a>"));
|
|
$tr.find( "a").on( "click", function () {
|
Feng.confirm( "是否确定删除所选中的规格?", function () { $tr.remove(); });
|
});
|
$content.append( $tr);
|
}
|
|
MallGoodsSpecInfoDlg.del_spec_ = function( $id) {
|
if (this.get("id")) {
|
Feng.confirm( "已使用的商品规格值会发生变化,是否确定删除", function () {
|
MallGoodsSpecInfoDlg.deleteSpecValueIds += $id + ",";
|
$( "#" + $id).remove();
|
});
|
} else {
|
Feng.confirm( "是否确定删除所选中的规格?", function () { $( "#" + $id).remove() });
|
}
|
}
|
|
MallGoodsSpecInfoDlg.get_spec_values = function() {
|
var result = [];
|
$( "#spec_content").find( "tr").each(function () {
|
result.push( { specValue: $(this).find( "input").val() , id: $( this).attr("id")})
|
});
|
return result;
|
}
|
|
/**
|
* 提交修改
|
*/
|
MallGoodsSpecInfoDlg.editSubmit = function() {
|
this.clearData();
|
this.collectData();
|
|
if ( !this.check_value()) { return; }
|
|
//提交信息
|
var ajax = new $ax(Feng.ctxPath + "/mallGoodsSpec/update", function(data){
|
if(data.code == 200){
|
Feng.success("修改成功!");
|
window.parent.MallGoodsSpec.table.refresh();
|
MallGoodsSpecInfoDlg.close();
|
} else {
|
Feng.error("修改失败!" + data.message);
|
}
|
},function(data){
|
Feng.error("修改失败!");
|
});
|
ajax.set(this.mallGoodsSpecInfoData);
|
ajax.set("deleteSpecValueIds", MallGoodsSpecInfoDlg.deleteSpecValueIds);
|
ajax.start();
|
};
|
|
$(function() {
|
Feng.initValidator( "formId", MallGoodsSpecInfoDlg.validFields);
|
$("#classifyIdOne").val((($("#classifyIdOne").data("value")||"")+"").split(","));
|
|
$( "#classifyIdOne, #classifyIdTwo").on( "change", function () {
|
if (0 != $(this).val()) { return; }
|
Feng.chose_change( this, Feng.get_select_option_values( this)
|
.filter(function(val) { return val != 0 && val})).trigger( "change");
|
});
|
});
|