add-info.js 5.74 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 : "";



/*上架补全信息*/
$('#saveAddInfo').on('click', function() {
	e.submit('/goods/product/saveAfterSaleInfo', function(option) {
		option.data = GOLABDATA.fire('LYaddInfo');
		option.success = function(res) {
			res = res.data;
			if (res.code == '200') {
				e.$tip(res.message, function() {}, 'growl-success');
			} else {
				e.$tip(res.message);
			}
			return false;
		}
	});
});

GOLABDATA.on("LYaddInfo", function() {
	return e.submit('', function(option) {
		$.each(option.data, function(key, value) {
			if (value) {
				option.data[key] = value.split('|').join(',');
			}
		});
		option.data.productSkn = $('#productSkn').val();
		//option.data.wearSense = sense();
		option.data.attributeProValuesTwo = JSON.stringify(attributeObj());


		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() {
				attributeArr.push({
					productSkn: option.data.productSkn,
					attributeId: $(this).find('[id]').attr('id'),
					attributeValueId: $(this).find('[id]').val().split('|').join(',')
				})
			});

			return attributeArr;
		}
		option.debug = true;
	});
});

$.ajax({
	type: 'POST',
	url: '/goods/product/queryAttributesByConf',
	data: {
		saleType: 2,
		displayPosition: 2,
		categoryId: basicInfo.smallSortId
	},
	dataType: 'json',
	success: function(res) {
		var data = res.data;
		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));

		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();

		if ($('.contentpanel').data('type') == 'info') {
			$('.contentpanel').find('input').prop('disabled', true);
			$('.contentpanel').find('select').prop('disabled', true);
			$('.contentpanel').find('.btn').addClass('disabled');
			$('#addinfo-wrap').find('input').not(":checked").parents('label').hide();
		}

	}
});


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


/*商品参数*/
var goodsParamArr = [];
var goodsParamEdit = new common.edit('#goodsParamWrap');
common.util.__ajax({
	url: '/goods/product/queryAttributesByConfEx',
	data: {
		saleType: 2,
		displayPosition: 3,
		categoryId: basicInfo.smallSortId
	}
}, function(res) {
	var data = res.data;
	if (NETSALEDATA.attributeProValuesBosOne) {
		$.each(NETSALEDATA.attributeProValuesBosOne, function(i, value) {
			$.each(data, function(i2, value2) {
				if (value.attributeId == value2.attributeId) {
					value2.selectedValues = value.attributeValueId.replace(/,/g, "|");
				}
			});
		});
	}

	if (res.data.length == 0) {
		$("#goodsParams-footer").hide();
	}

	$('#goodsParamWrap').html(common.util.__template2($('#goodsParamTemp').html(), {
		data: data
	}));
	goodsParamEdit.init();

	if ($('.contentpanel').data('type') == 'info') {
		$('.contentpanel').find('input').prop('disabled', true);
		$('.contentpanel').find('select').prop('disabled', true);
		$('.contentpanel').find('.btn').addClass('disabled');
		$('#goodsParamWrap').find('input').not(":checked").parents('label').hide();
	}


}, true);


GOLABDATA.on("TYcaizhi", function() {
	var a = goodsParamEdit.submit(false, function(option) {
		$('.goods-param-group').each(function() {
			goodsParamArr.push({
				productSkn: $('#productSkn').val(),
				attributeId: $(this).find(':hidden').attr('id'),
				attributeValueId: $(this).find(':hidden').val().split('|').join(',')
			});
		});
		option.data.attributeProValuesOne = JSON.stringify(goodsParamArr);
		option.data.productSkn = $('#productSkn').val();
		option.debug = true;
	});
	return a ? a : goodsParamEdit.errMessage;
});

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