/**
|
* 初始化规格组详情对话框
|
*/
|
var MallGroupSpecInfoDlg = {
|
mallGroupSpecInfoData : {}
|
};
|
|
/**
|
* 清除数据
|
*/
|
MallGroupSpecInfoDlg.clearData = function() {
|
this.mallGroupSpecInfoData = {};
|
};
|
|
/**
|
* 设置对话框中的数据
|
* @param key 数据的名称
|
* @param val 数据的具体值
|
*/
|
MallGroupSpecInfoDlg.set = function(key, val) {
|
this.mallGroupSpecInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
|
return this;
|
};
|
|
/**
|
* 设置对话框中的数据
|
* @param key 数据的名称
|
* @param val 数据的具体值
|
*/
|
MallGroupSpecInfoDlg.get = function(key) {
|
return $("#" + key).val();
|
};
|
|
/**
|
* 关闭此对话框
|
*/
|
MallGroupSpecInfoDlg.close = function() {
|
parent.layer.close(window.parent.MallGroupSpec.layerIndex);
|
};
|
|
/**
|
* 收集数据
|
*/
|
MallGroupSpecInfoDlg.collectData = function() {
|
let goodsSkuJson = MallGroupSpecInfoDlg.getGoodsSkuJson(1);
|
if (goodsSkuJson == 'ERROR') {
|
return false;
|
}
|
|
this
|
.set('id')
|
.set('specName')
|
.set('goodsIds', Feng.getMultipleSelectVal("goodsIds"))
|
.set('goodsSkuJson', goodsSkuJson)
|
.set('goodsNames')
|
.set('classifyIdOne')
|
.set('classifyIdTwo')
|
.set('startTime')
|
.set('endTime')
|
.set('stock')
|
.set('areaCityId')
|
.set('remark')
|
.set('createTime')
|
.set('isLock')
|
.set('isDelete')
|
.set('provinceCode')
|
.set('provinceName', $('#provinceCode option:selected').text());
|
|
return true;
|
};
|
|
MallGroupSpecInfoDlg.getGoodsSkuJson = function(isCheck) {
|
let result = '';
|
let goodsSkuJson = [];
|
$(".goods_sku_json").each(function() {
|
let inputs = $(this).find("input"); // 找到当前<td>元素中的所有输入框
|
let input1Value = $(inputs[0]).val(); // 获取第一个输入框的内容-商品id
|
let input2Value = $(inputs[1]).val(); // 获取第二个输入框的内容-输入数量
|
let input3Value = $(inputs[2]).val(); // 获取第三个输入框的内容-库存
|
|
// 是否需要验证
|
if(isCheck == 1) {
|
if(input3Value - input2Value < 0) {
|
Feng.error("数量不能大于商品库存");
|
// 错误标记
|
result = "ERROR";
|
// 中断each()循环
|
return false;
|
}
|
if(input2Value == 0) {
|
Feng.error("数量不能小于1");
|
// 错误标记
|
result = "ERROR";
|
// 中断each()循环
|
return false;
|
}
|
}
|
|
let json = {
|
"goodsId": input1Value,
|
"goodsNum": input2Value
|
};
|
|
goodsSkuJson.push(json);
|
});
|
if (result == '') {
|
result = JSON.stringify(goodsSkuJson);
|
}
|
return result;
|
}
|
|
MallGroupSpecInfoDlg.chooseGoods = function() {
|
// $.ajax({
|
// url : Feng.ctxPath + "/mallGoods/goodsByIdsList",
|
// type : "get",
|
// data : {"ids": Feng.getMultipleSelectVal("goodsIds")},
|
// dataType : "json",
|
// success : function (list) {
|
// let goodsSelectTbodyStr = '';
|
// $.each(list, function(i, item) {
|
// goodsSelectTbodyStr += "<tr>"
|
// + "<td> " + item.goodsNo + " </td>"
|
// + "<td> " + item.goodsName + " </td>"
|
// + "<td> " + item.price + " </td>"
|
// + "<td> " + item.priceSale + " </td>"
|
// + "<td> " + item.stock + " </td>"
|
// + "<td style='text-align: center;' class='goods_sku_json'>" +
|
// "<input type='hidden' value='" + item.goodsNo + "'>" +
|
// "<input type='text' value='0'>" +
|
// "</td>"
|
// + "</tr>"
|
// });
|
//
|
// $("#goodsSelectTbody").html(goodsSelectTbodyStr);
|
// }
|
// });
|
$.ajax({
|
url : Feng.ctxPath + "/mallGoods/goodsByGoodsSpecId",
|
type : "get",
|
data : {
|
"goodsIds": Feng.getMultipleSelectVal("goodsIds"),
|
"groupSpecId": $("#id").val(),
|
"oldGoodsSkuJson": MallGroupSpecInfoDlg.getGoodsSkuJson(0)
|
},
|
dataType : "json",
|
success : function (list) {
|
let goodsSelectTbodyStr = '';
|
$.each(list, function(i, item) {
|
goodsSelectTbodyStr += "<tr>"
|
+ "<td> " + item.goodsNo + " </td>"
|
+ "<td> " + item.goodsName + " </td>"
|
+ "<td> " + item.price + " </td>"
|
+ "<td> " + item.priceSale + " </td>"
|
+ "<td> " + item.stock + " </td>"
|
+ "<td style='text-align: center;' class='goods_sku_json'>" +
|
"<input type='hidden' value='" + item.id + "'>" +
|
"<input type='text' value='" + item.goodsNum + "'>" +
|
"<input type='hidden' value='" + item.stock + "'>" +
|
"</td>"
|
+ "</tr>"
|
});
|
|
$("#goodsSelectTbody").html(goodsSelectTbodyStr);
|
}
|
});
|
}
|
|
|
/**
|
* 提交添加
|
*/
|
MallGroupSpecInfoDlg.addSubmit = function() {
|
this.clearData();
|
let checkForm = this.collectData();
|
if (!checkForm) {
|
return;
|
}
|
|
//提交信息
|
var ajax = new $ax(Feng.ctxPath + "/mallGroupSpec/add", function(data){
|
if(data.code == 200){
|
Feng.success("添加成功!");
|
window.parent.MallGroupSpec.table.refresh();
|
MallGroupSpecInfoDlg.close();
|
} else {
|
Feng.error("添加失败!" + data.message);
|
}
|
},function(){
|
Feng.error("添加失败!");
|
});
|
ajax.set(this.mallGroupSpecInfoData);
|
ajax.start();
|
};
|
|
/**
|
* 提交修改
|
*/
|
MallGroupSpecInfoDlg.editSubmit = function() {
|
this.clearData();
|
let checkForm = this.collectData();
|
if (!checkForm) {
|
return;
|
}
|
|
//提交信息
|
var ajax = new $ax(Feng.ctxPath + "/mallGroupSpec/update", function(data){
|
if(data.code == 200){
|
Feng.success("修改成功!");
|
window.parent.MallGroupSpec.table.refresh();
|
MallGroupSpecInfoDlg.close();
|
} else {
|
Feng.error("修改失败!" + data.message);
|
}
|
},function(data){
|
Feng.error("修改失败!");
|
});
|
ajax.set(this.mallGroupSpecInfoData);
|
ajax.start();
|
};
|
|
$(function() {
|
// 初始化开始时间、结束时间
|
laydate.render({
|
elem: '#startTime'
|
});
|
laydate.render({
|
elem: '#endTime'
|
});
|
|
MallGroupSpecInfoDlg.chooseGoods();
|
});
|