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


var e = new common.edit('#addinfo-wrap'),
	basicInfo = NETSALEDATA.baseProductInfo.baseProduct;

common.util.__ajax({
	url: '/goods/product/queryMakingProcess',
	data: {
		displayPosition: 2,
		categoryId: basicInfo.maxSortId
	}
}, function(res) {
	var obj = res.data;
	obj.makeCrafts = NETSALEDATA.productExtBo.makeCrafts.replace(/,/g, "|");
	var html = common.util.__template2($('#makingProcessTemp').html(), obj);
	$('.making-process-wrap .col-sm-11').html(html);
	e.init();
}, true);

var addInfoHtml = common.util.__template2($('#addInfoTemp').html(), NETSALEDATA.productExtBo);
$('.addinfo-wrap').append($(addInfoHtml));

basicInfo.style = basicInfo.style.replace(/,/g, "|");
basicInfo.pattern = basicInfo.pattern.replace(/,/g, "|");
$('#productStyleWrap').html(common.util.__template2($('#productStyleWrap').html(), basicInfo));
$('#productElementsWrap').html(common.util.__template2($('#productElementsWrap').html(), basicInfo));
$('#brandModelWrap').html(common.util.__template2($('#brandModelWrap').html(), NETSALEDATA.productExtBo));
$('#brandSeriesWrap').html(common.util.__template2($('#brandSeriesWrap').html(), NETSALEDATA.productExtBo));
//console.log(NETSALEDATA.wearSenses);
/*$('#wearSenseWrap').html(common.util.__template2($('#wearSenseWrap').html(), {
	wearSenses: NETSALEDATA.wearSenses
}));
*/
new common.dropDown({
	el: '#brandModelSelect',
	ajax: 'queryAll4Select',
	params: {
		type: 1,
		status: 1,
		shopsId: basicInfo.shopId,
		brandId: basicInfo.brandId
	}
});

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

/*e.on("render", function() {
	if ($('#brandModel').val()) {
		$('#brandModelSelect').val($('#brandModel').val());
	}

	if ($('#brandSeries').val()) {
		$('#brandSeriesSelect').val($('#brandSeries').val());
	}
})*/

e.on("bind", function() {

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


$('#saveAddInfo').on('click', function() {
	e.submit('/goods/product/saveAfterSaleInfo', function(option) {
		option.data.productSkn = $('#productSkn').val();
		option.data.style = option.data.style.split('|').join(',');
		option.data.pattern = option.data.pattern.split('|').join(',');
		option.data.makeCrafts = option.data.makeCrafts.split('|').join(',');
		option.data.wearSense = function() {
			var arr = [];
			$('#wearSenseWrap').find('select').each(function() {
				if ($(this).val()) {
					arr.push({
						wearSenseId: $(this).attr('name'),
						value: $(this).val()
					});
				}

			});

			return JSON.stringify(arr);
		}
		option.success = function(res) {
			res = res.data;
			if (res.code == '200') {
				NETSALEEDIT.$tip(res.message, function() {}, 'growl-success');
			} else {
				NETSALEEDIT.$tip(res.message);
			}
			return false;
		}
	});
});