/**
|
* 初始化商品信息详情对话框
|
*/
|
var MallGoodsInfoDlg = {
|
mallGoodsInfoData : {},
|
validFields: {
|
goodsName: Feng.def_valid_info( true, null, null, null, {
|
stringLength: {
|
max: 50,
|
message: "最多支持50个字符"
|
}
|
}), // 不能为空
|
// classifyIdOne: Feng.def_valid_info( true), // 不能为空
|
// goodsImage: Feng.def_valid_info( true), // 不能为空
|
// introImage: Feng.def_valid_info( true), // 不能为空
|
// introH5: Feng.def_valid_info( true) // 不能为空
|
}
|
};
|
|
/**
|
* 清除数据
|
*/
|
MallGoodsInfoDlg.clearData = function() {
|
this.mallGoodsInfoData = {};
|
};
|
|
/**
|
* 设置对话框中的数据
|
* @param key 数据的名称
|
* @param val 数据的具体值
|
*/
|
MallGoodsInfoDlg.set = function(key, val) {
|
this.mallGoodsInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
|
return this;
|
};
|
|
/**
|
* 设置对话框中的数据
|
* @param key 数据的名称
|
* @param val 数据的具体值
|
*/
|
MallGoodsInfoDlg.get = function(key) {
|
return $("#" + key).val();
|
};
|
|
/**
|
* 关闭此对话框
|
*/
|
MallGoodsInfoDlg.close = function() {
|
parent.layer.close(window.parent.MallGoods.layerIndex);
|
};
|
|
/**
|
* 收集数据
|
*/
|
MallGoodsInfoDlg.collectData = function() {
|
this
|
.set('id')
|
.set('goodsName')
|
.set('goodsTitle')
|
.set('goodsNo')
|
.set('price')
|
.set('priceSale')
|
.set('priceMember')
|
.set('stock')
|
.set('state')
|
.set('tagIds', Feng.get_chosen_selected( "#tagIds"))
|
.set('classifyIdOne')
|
.set('classifyIdTwo')
|
.set('goodsImage')
|
.set('introImage')
|
.set('purchaseH5', Feng.getEditorContent(MallGoodsInfoDlg.purchaseH5))
|
.set('introH5', Feng.getEditorContent(MallGoodsInfoDlg.introH5))
|
;
|
};
|
function isNull ( val) { return val == undefined || val == null || val == ""; }
|
|
/**
|
* 遍历循环规格表格的所有列input元素值,拼接字符串
|
*/
|
MallGoodsInfoDlg.getSpecGroup = function() {
|
// 定义规格组合值
|
let specGroup = [];
|
// 遍历循环规格表格的所有列
|
$(".specGroup").each(function (i, item) {
|
// 遍历循环拿到列中所有input元素值
|
let inputSpec = $(item).find(".inputSpec");
|
specGroup[i] = {"spec_ids": inputSpec[0].value, "grep_name": inputSpec[1].value, "stock": inputSpec[2].value,"price_sale": inputSpec[3].value,"price_member": inputSpec[4].value}
|
});
|
return specGroup;
|
}
|
|
MallGoodsInfoDlg.getGoodsSet = function() {
|
// 定义规格组合值
|
let set = {
|
"buyCoef": $("#buyCoef").val(),
|
"v3BuyCoef": $("#v3BuyCoef").val(),
|
"v3BrokerageCoef": $("#v3BrokerageCoef").val(),
|
"v4BuyCoef": $("#v4BuyCoef").val(),
|
"v4BrokerageCoef": $("#v4BrokerageCoef").val(),
|
"v5BuyCoef": $("#v5BuyCoef").val(),
|
"v5BrokerageCoef": $("#v5BrokerageCoef").val(),
|
}
|
return set;
|
}
|
|
MallGoodsInfoDlg.clear_move_table = function() {
|
this.moveTable && this.moveTable.clear();
|
this.specs_item = {};
|
}
|
|
MallGoodsInfoDlg.add_specs = function () {
|
let specsItems = [];
|
var query_item = {
|
oneClassifyId: this.get( "classifyIdOne"),
|
selectedItems: specsItems,
|
};
|
$(".specGroup").each(function (i, item) {
|
// 遍历循环拿到列中所有input元素值
|
let inputSpec = $(item).find(".inputSpec");
|
specsItems[i] = inputSpec[1].value
|
});
|
console.log(specsItems)
|
if ( !query_item.oneClassifyId) {
|
return Feng.error( "请先选择分类!")
|
}
|
this.layerIndex = layer.open({
|
type: 2,
|
title: '添加规格',
|
area: ['45%', '45%'], //宽高
|
fix: false, //不固定
|
maxmin: true,
|
content: Feng.url_params( Feng.ctxPath + '/mallGoods/getGoodsSpecs', query_item)
|
});
|
}
|
|
MallGoodsInfoDlg.close_specs = function(specGroup) {
|
// 生成规格表格
|
MallGoodsInfoDlg.setSpecTable(specGroup);
|
this.layerIndex && layer.close( this.layerIndex);
|
}
|
|
MallGoodsInfoDlg.initSpecData = function() {
|
$.ajax({
|
url : Feng.ctxPath + "/mallGoods/getGoodsSpecData",
|
type : "get",
|
data : {"goodsId": $("#id").val()},
|
dataType : "json",
|
success : function (list) {
|
// 生成规格表格
|
MallGoodsInfoDlg.setSpecTable(list);
|
}
|
});
|
}
|
function delTr(buttonElement) {
|
// 获取按钮所在的<tr>元素
|
var row = buttonElement.closest('tr');
|
|
// 从DOM中移除该<tr>元素
|
row.parentNode.removeChild(row);
|
}
|
/**
|
* 生成规格表格
|
* @param specGroup
|
*/
|
MallGoodsInfoDlg.setSpecTable = function(specGroup) {
|
// specGroup = [{"id":1,"grepName":"规格1","stock":1, priceMember: 20, priceSale: 10},{"id":2,"grepName":"规格2","stock":2, priceMember: 20, priceSale: 10}]
|
// 商品分类
|
let className = $('#classifyIdOne option:selected').text();
|
let thStr = "<thead><tr><th>规格名称</th><th>商品分类</th><th>商品库存</th><th>美天销售价</th><th>会员价</th><th>操作</th></tr></thead><tbody></tbody>";
|
if (!$("#specsTable").html()){
|
$("#specsTable").html(thStr);
|
}
|
let tdStr = '';
|
for (let i = 0; i < specGroup.length; i++) {
|
let item = specGroup[i];
|
$(item).find(".inputSpec").each(function (ii, iitem) {
|
specGroup += (iitem.value == "" ? "0" : iitem.value) + "__";
|
});
|
|
tdStr = "<tr class='specGroup'>" +
|
"<td>" +
|
"<input type='hidden' class='inputSpec' value='" + item.id + "'>" +
|
"<input type='hidden' class='inputSpec' value='" + item.grepName + "'>" +
|
item.grepName +
|
"</td>" +
|
"<td>" + (item.classifyName != "" ? item.classifyName : className) + "</td>" +
|
"<td><input type='text' class='inputSpec' value='" + item.stock + "' style='width: 92px'></td>" +
|
"<td><input type='text' class='inputSpec' value='" + item.priceSale + "' style='width: 92px'></td>" +
|
"<td><input type='text' class='inputSpec' value='" + item.priceMember + "' style='width: 92px'></td>" +
|
'<td><button type="button" class="btn btn-outline btn-danger btn-xs" onclick="delTr(this)" value="1">删除</button></td>' +
|
"</tr>";
|
// 生成规格表格
|
$("#specsTable tbody").append(tdStr)
|
}
|
}
|
/**
|
* 提交添加
|
*/
|
MallGoodsInfoDlg.addSubmit = function() {
|
this.clearData();
|
this.collectData();
|
|
if ( !Feng.check_form( "formId")) { return; }
|
|
this.mallGoodsInfoData.goodsSkusJson = JSON.stringify(MallGoodsInfoDlg.getSpecGroup());
|
this.mallGoodsInfoData.goodsSetJson = JSON.stringify(MallGoodsInfoDlg.getGoodsSet());
|
|
//提交信息
|
var ajax = new $ax(Feng.ctxPath + "/mallGoods/add", function(data){
|
if(data.code == 200){
|
Feng.success("添加成功!");
|
window.parent.MallGoods.table.refresh();
|
MallGoodsInfoDlg.close();
|
} else {
|
Feng.error("添加失败!" + data.message);
|
}
|
},function(){
|
Feng.error("添加失败!");
|
});
|
ajax.set(this.mallGoodsInfoData);
|
ajax.start();
|
};
|
|
/**
|
* 提交修改
|
*/
|
MallGoodsInfoDlg.editSubmit = function() {
|
this.clearData();
|
this.collectData();
|
|
if ( !Feng.check_form( "formId")) { return; }
|
|
this.mallGoodsInfoData.goodsSkusJson = JSON.stringify(MallGoodsInfoDlg.getSpecGroup());
|
this.mallGoodsInfoData.goodsSetJson = JSON.stringify(MallGoodsInfoDlg.getGoodsSet());
|
|
//提交信息
|
var ajax = new $ax(Feng.ctxPath + "/mallGoods/update", function(data){
|
if(data.code == 200){
|
Feng.success("修改成功!");
|
window.parent.MallGoods.table.refresh();
|
MallGoodsInfoDlg.close();
|
} else {
|
Feng.error("修改失败!" + data.message);
|
}
|
},function(){
|
Feng.error("修改失败!");
|
});
|
ajax.set(this.mallGoodsInfoData);
|
ajax.start();
|
};
|
|
MallGoodsInfoDlg.editBuyCountSubmit = function() {
|
// 提交信息
|
var ajax = new $ax(Feng.ctxPath + "/mallGoods/updateBuyCount", function(data){
|
if(data.code == 200){
|
Feng.success("修改成功!");
|
window.parent.MallGoods.table.refresh();
|
MallGoodsInfoDlg.close();
|
} else {
|
Feng.error("修改失败!" + data.message);
|
}
|
},function(){
|
Feng.error("修改失败!");
|
});
|
ajax.set("mallGoodsId", $("#id").val());
|
ajax.set("buyCount", $("#buyCount").val());
|
ajax.start();
|
};
|
|
$(function() {
|
$("#tagIds").val((($("#tagIds").data("value")||"")+"").split(","));
|
|
Feng.initValidator( "formId", MallGoodsInfoDlg.validFields);
|
});
|