add-info.js 9.21 KB
var $ = require('jquery'),
	common = require('../../../../common/common');


var e = new common.edit('#addinfo-wrap'),
	basicInfo = NETSALEDATA.baseProductInfo.baseProduct || '',
	productExtBo = NETSALEDATA.productExtBo || '',
	comfort = NETSALEDATA.specialAttrBo ? NETSALEDATA.specialAttrBo.wearSenses : "";




/*上架补全信息*/
function sense() {
	var arr = [];
	$('#wearSenseWrap').find('select').each(function() {
		if ($(this).val()) {
			arr.push({
				id: $(this).attr('name'),
				value: $(this).val()
			});
		}

	});
	if (arr.length > 0) {
		return JSON.stringify(arr);
	} else {
		return '';
	}
}
function attributeObj() {
	var attributeArr = [];
	$('.attribute-group').each(function() {
		var id=$(this).find('[id]').attr('id');
		attributeArr.push({
			productSkn: basicInfo.productSkn,
			attributeId: id,
			attributeValueId: common.util.__input(id).split('|').join(',')
		})
	});

	return attributeArr;
}
$('#saveAddInfo').on('click', function() {
	common.util.__ajax({
		url:'/goods/product/saveAfterSaleInfo',
		data:{
			productSkn:basicInfo.productSkn,
			makeCrafts:common.util.__input('makeCrafts'),
			salesPhrase:common.util.__input('salesPhrase'),
			isHostsell:common.util.__input('[name=isHostsell]:checked'),
			wearSense:sense(),
			attributeProValuesTwo:JSON.stringify(attributeObj())
		}
	});
});
function inputDisabled(callback) {
	if ($('.contentpanel').data('type') == 'info') {
		$('.contentpanel').find('input').prop('disabled', true);
		$('.contentpanel').find('select').prop('disabled', true);
		$('.contentpanel').find('.btn').addClass('disabled');
		$(".attr_checkobx_class").hide();
		callback && callback();
	}
}

common.util.__ajax({
	url: '/goods/product/queryAttributesByConf',
	data: {
		saleType: 2,
		displayPosition: 2,
		categoryId: basicInfo.smallSortId
	}
},function(res){
		var data = res;
		data.style = basicInfo.style;
		data.pattern = basicInfo.pattern;
		data.brandModel = productExtBo.brandModel;
		data.brandModelText = productExtBo.brandModelText;
		data.brandSeriesText = productExtBo.brandSeriesText;
		data.brandSeries = productExtBo.brandSeries;
		data.makeCrafts = productExtBo.makeCrafts;
		data.salesPhrase = productExtBo.salesPhrase;
		data.isHostsell = productExtBo.isHostsell;

		$.each(data, function(key, value) {
			if (value) {
				data[key] = value;
			} else {
				data[key] = '';
			}
			if (typeof value == 'string') {
				data[key] = value.replace(/,/g, "|");
			}
		});

		if (NETSALEDATA.attributeProValuesBosTwo) {
			$.each(NETSALEDATA.attributeProValuesBosTwo, function(i, value) {
				$.each(data.data, function(i2, value2) {
					if (value.attributeId == value2.attributeId) {
						value2.selectedValues = value.attributeValueId.replace(/,/g, "|");
					}
				});
			});
		}

		$('#addinfo-wrap').html(common.util.__template2($('#addInfoTemp').html(), data));
		$('#goodsParamWrap3').html(common.util.__template2($('#brandModelSeries').html(), data));

		e.on("bind", function() {
			$('#brandModelSelect').on('change', function() {
				$('#brandModel').val($(this).val());
			});
			$('#brandSeriesSelect').on('change', function() {
				$('#brandSeries').val($(this).val());
			});
		});


		$('#wearSenseWrap').find('select').each(function() {
			$(this).val($(this).siblings('input:hidden').val());
		});

		new common.dropDown({
			el: '#brandModelSelect',
			ajax: 'queryAll4Select',
			params: {
				type: 1,
				status: 1,
				brandId: basicInfo.brandId
			}
		});

		new common.dropDown({
			el: '#brandSeriesSelect',
			ajax: 'queryAll4Select',
			params: {
				type: 2,
				status: 1,
				brandId: basicInfo.brandId
			}
		});

		e.init();

		inputDisabled(function() {
			$('#addinfo-wrap').find('input').not(":checked").parents('label').hide();
		});
},true);

//去编辑商品名称
$('#editProductName').on('click', function() {
	$('#productName').focus();
});


var common_columns = [{
	display: "名称",
	width: '10%',
	name: "attributeName",
	render: function(item) {
		item.required = item.isMust == "Y" ? "required" : "";
		var arr = [];
		arr.push(item.attributeName);
		if (item.required) {
			arr.push("<span class='red'>*</span>");
		}
		return arr.join('');
	}
}]

/*陈超*/

var ag = new common.grid({
	el: "#attributeTable",
	hash: false,
	columns: common_columns.concat([{
		display: "属性",
		render: function(item) {
			item.required = item.isMust == "Y" ? "required" : "";

			var attrs = NETSALEDATA.productStandardRelationBoList;
			if (attrs) {
				for (var i in attrs) {
					if (attrs[i].standardId == item.attributeId) {
						item.val = attrs[i].parameterMakeId;
						item.__val = attrs[i].parameterMakeId;
					}
				}
			}

			item.__name = "attributeTable";
			return common.util.__template2($("#template33").html(), item);
		}
	}]),
	complete: function() {
		ag.__edit.init();
	}
});
ag.__edit = new common.edit("#attributeTable");

common.util.__ajax({
	url: '/base/goods/queryAllProductAttr',
	data: {
		param: basicInfo.smallSortId,
		displayPosition: 1
	}
}, function(res) {
	ag.init(res.data);
	inputDisabled(function() {
		$('#attributeTable').find('input').not(":checked").parents('label').hide();
	});
}, true);



/*马力*/
var ag2 = new common.grid({
	el: "#goodsParamWrap",
	hash: false,
	columns: common_columns.concat([{
		display: "属性",
		render: function(item) {
			item.required = item.isMust == "Y" ? "required" : "";
			item.id = item.parameterMakeId;
			var attrs = NETSALEDATA.attributeProValuesBosOne;
			if (attrs) {
				for (var i in attrs) {
					if (attrs[i].attributeId == item.attributeId) {
						item.val = attrs[i].attributeValueId;
						item.__val = attrs[i].attributeValueId.replace(/,/g, '|');
					}
				}
			}
			item.__name = "goodsParamWrap";
			return common.util.__template2($("#template33").html(), item);
		}
	}]),
	complete: function() {
		ag2.__edit.init();
	}
});
ag2.__edit = new common.edit("#goodsParamWrap");

common.util.__ajax({
	url: '/goods/product/queryAttributesByConfEx',
	data: {
		saleType: 2,
		displayPosition: 3,
		categoryId: basicInfo.smallSortId
	}
}, function(res) {
	ag2.init(res.data);
	inputDisabled(function() {
		$('#goodsParamWrap').find('input').not(":checked").parents('label').hide();
	});
}, true);


var ag3 = new common.grid({
	el: "#goodsParamWrap2",
	hash: false,
	columns: common_columns.concat([{
		display: "属性",
		render: function(item) {
			item.required = item.isMust == "Y" ? "required" : "";
			item.id = item.parameterMakeId;
			var attrs = NETSALEDATA.specialAttrBo;
			if (attrs && attrs.materialList) {
				var _arr = [];
				for (var i in attrs.materialList) {
					_arr.push(attrs.materialList[i].id);
				}
				item.__val = _arr.join('|');
			}

			item.__name = "goodsParamWrap2";
			return common.util.__template2($("#template33").html(), item);
		}
	}]),
	complete: function() {
		ag3.__edit.init();
	}
});
ag3.__edit = new common.edit("#goodsParamWrap2");
common.util.__ajax({
	url: '/base/goods/queryMaterialList',
	data: {
		categoryId: basicInfo.maxSortId
	}
}, function(res) {
	ag3.init([res.data]);
	inputDisabled(function() {
		$('#goodsParamWrap2').find('input').not(":checked").parents('label').hide();
	});
}, true);


$(document).on("change", "#goodsParamWrap .attr_input", function() {
	var item = ag2.rows[$(this).data("index")];
	item.val = $(this).val();
});

$(document).on("change", "#attributeTable .attr_input", function() {
	var item = ag.rows[$(this).data("index")];
	item.val = $(this).val();
});

$(document).on("change", "#goodsParamWrap .attr_checkobx_class", function() {
	var item = ag2.rows[$(this).data("index")];
	item.val = $("#goodsParamWrap_attr_" + $(this).data("index")).val().replace(/\|/g, ',');
})

$(document).on("change", "#goodsParamWrap2 .attr_checkobx_class", function() {
	var item = ag3.rows[$(this).data("index")];
	item.val = $("#goodsParamWrap2_attr_" + $(this).data("index")).val().replace(/\|/g, ',');
})


/*保存*/
function TYgoodsParams(){
	var data = {};
	if (!ag.__edit.validate(true)) {
		return ag.__edit.errMessage;
	}
	if (!ag2.__edit.validate(true)) {
		return ag2.__edit.errMessage;
	}
	if (!ag3.__edit.validate(true)) {
		return ag3.__edit.errMessage;
	}

	var productStandardRelationStr = [];
	if (ag.rows.length > 0) {
		for (var i in ag.rows) {
			if (ag.rows[i].val) {
				var idNameList = ag.rows[i].idNameList;
				for (var x in idNameList) {
					if (ag.rows[i].val == idNameList[x].id) {
						productStandardRelationStr.push({
							standardId: ag.rows[i].attributeId,
							standardVal: idNameList[x].text,
							parameterMakeId: idNameList[x].id
						});
					}
				}
			}
		}
	}
	data.productStandardRelationStr = JSON.stringify(productStandardRelationStr);

	var goodsParamArr = [];
	if (ag2.rows.length > 0) {
		for (var i in ag2.rows) {
			if (ag2.rows[i].val) {

				goodsParamArr.push({
					attributeId: ag2.rows[i].attributeId,
					productSkn: $('#productSkn').val(),
					attributeValueId: ag2.rows[i].val
				});

			}
		}
	}
	data.attributeProValuesOne = JSON.stringify(goodsParamArr);

	data.productMaterial = "";
	if (ag3.rows.length > 0) {
		data.productMaterial = ag3.rows[0].val;
	}

	data.productSkn = $('#productSkn').val();

	data.brandModel = common.util.__input('brandModel');
	data.brandSeries = common.util.__input('brandSeries');
	return data;
};

$("#propertySave").on('click', function() {
	common.util.__ajax({
		url: '/netSale/saveProductParam',
		data: TYgoodsParams()
	});
});