sellingPoint.js 1.94 KB
var $ = require('jquery'),
	common = require('../../../../common/common'),
	util = require('../../../../common/util');

$('#btn-salePonit').on('click', function() {
	var sellingPointMap = [];
	$('#salePoint').find('input').each(function (){
		if ($(this).val() && '' != $(this).val()) {
			sellingPointMap.push({"productSkn" : NETSALEDATA.baseProductInfo.baseProduct.productSkn, "sellingPoint" : $(this).val()});
		}
	})

	if (sellingPointMap.length == 0) {   // 如果都没有值,代表需要清理该商品的主要卖点
		sellingPointMap.push({"productSkn" : NETSALEDATA.baseProductInfo.baseProduct.productSkn, "sellingPoint" : ""});
	}

	var sellingPointStr =  JSON.stringify(sellingPointMap);

	var params = {
		sellingPoint:sellingPointStr
	};
	common.util.__ajax(
		{
			url:'/sensitiveWord/validate',
			data: {
				"validateContent": JSON.stringify(params)
			}
		},
		function(rs) {
			if (rs.data) {
				var jsonMain = rs.data;
				if(!$.isEmptyObject(jsonMain.sellingPoint)){
					var tipText = "商品主要卖点包含违禁词:" + jsonMain.sellingPoint+"!";
					
                    /*common.dialog.confirm("温馨提示", tipText + "确定提交吗?", function(){
                        submitPointForm(sellingPointStr);
                    });*/
                    util.__tip(tipText, 'warning');
                } else {
                    submitPointForm(sellingPointStr);
                }
            }
		},true);

})


function submitPointForm(sellingPointStr) {
    common.util.__ajax({
        url:'/product/saveSellingPoint',
        data:{
            sellingPointStr:sellingPointStr
        }
    })
}

$(document).ready(function(){
	initSellingPointInfo(NETSALEDATA.sellingPointList);
});

function initSellingPointInfo(sellingPointList) {
	if (sellingPointList && sellingPointList.length > 0) {
		for (var index = 0; index < sellingPointList.length; index++) {
			$('#salePoint').find('input').eq(index).val(sellingPointList[index]);
		}
	}
}