basic-info.js 9.14 KB
var $ = require('jquery'),
	common = require('../../../../common/common');
	util = require('../../../../common/util');
var basicInfohtml = '',
	ENUM = {
		isSuppled: {
			'Y': '是',
			'N': '否'
		}
	},
	convertObj = {
		ageLevel: {
			'1': '成人',
			'2': '大童',
			'3': '小童',
			'2|3': "大小童",
        	'3|2': "大小童"
		},
		gender: {
			1: '男',
			2: '女',
			3: '通用'
		},
		grade: {
			'1': '是',
			'0': '否'
		},
		isOutLets: {
			'Y': '是',
			'N': '否',
			'B': '品牌设置'
		},
		isLimited: {
			'Y': '是',
			'N': '否'
		},
		isPromotionalGifts: {
			'Y': '是',
			'N': '否'
		},
		isAdvance: {
			'Y': '是',
			'N': '否'
		},
		isLimitbuy: {
			'Y': '是',
			'N': '否'
		},
		attribute: {
			1: '普通',
			2: '赠品'
		},
		goodsSeason: {
			0: '四季',
			1: '春',
			2: '夏',
			3: '秋',
			4: '冬',
			5: '春夏',
			6: '秋冬'
		},
		seasons: {
			'seasons': '四季',
			'spring': '春',
			'summer': '夏',
			'autumn': '秋',
			'winter': '冬'
		},
		isVip: {
			'Y': '是',
			'N': '否',
			'B': '品牌设置'
		},
		classic: {
			'1': '是',
			'0': '否'
		},
		sellType: {
			'1': '经销',
			'2': '代销',
			'3': 'JIT',
			'4': '专营店代销入库',
			'5': '专营店代销不入库',
		}
	},
	basicInfo = NETSALEDATA.baseProductInfo.baseProduct || '',
	productExtBo = NETSALEDATA.productExtBo || '';
   //alert('basic:' + JSON.stringify(basicInfo));
var basicInfoTmp = JSON.stringify(basicInfo);
basicInfoTmp = JSON.parse(basicInfoTmp);
var oldphrase = productExtBo.phrase ?  productExtBo.phrase + '' :'';
/*
 * 基本信息value值转换
 * @param: basicInfo(请求的要渲染的数据), obj(转换的对象)
 */
function convert(basicInfo, obj) {
	$.each(basicInfo, function(key, value) {
		if (convertObj[key]) {
			if(key==="ageLevel"){
				basicInfo[key] = common.config.__ageLevel(value);
			}else if(key == "seasons") {
				basicInfo[key] = basicInfo[key].replace(/seasons/g, "四季")
					.replace(/spring/g, "春")
					.replace(/summer/g, "夏")
					.replace(/autumn/g, "秋")
					.replace(/winter/g, "冬");
			}else{
				basicInfo[key] = convertObj[key][value];
			}
		}
	});
	return basicInfo;
}


var basicInfoData = convert(basicInfo, convertObj);
basicInfoData.expectArrivalTime =basicInfoData.expectArrivalTime? common.util.__dateFormat(new Date(basicInfoData.expectArrivalTime * 1000), "yyyy-MM-dd hh:mm:ss"):"";
basicInfoData.expectShelfTime =basicInfoData.expectShelfTime? common.util.__dateFormat(new Date(basicInfoData.expectShelfTime * 1000), "yyyy-MM-dd hh:mm:ss"):"";
basicInfoData.renderType = $('.contentpanel').data('type');

console.log('basic:' + JSON.stringify(basicInfoData));

//基本信息
basicInfohtml = common.util.__template2($('#basicInfo').html(), basicInfoData);
$('#basic-info').html(basicInfohtml);

//加载动态数据
$(document).ready(function(){
	initInfo(basicInfoTmp);
});

function initInfo(basicInfo) {
	$("#seasons").val(basicInfo.seasons);
	$("#grade").val(basicInfo.grade);
	$("#isLimited").val(basicInfo.isLimited);
	$("#isOutLets2").val(basicInfo.isOutLets);
	$("#productName").val(basicInfo.productName);

	$(":radio[name=seasons]").each(function(){
		if(basicInfo.seasons!=null&&basicInfo.seasons!=undefined&&basicInfo.seasons!=''&&
			basicInfo.seasons.indexOf($(this).val())>-1){
			$(this).prop("checked",true)
		}
	});
	$(":radio[name=grade]").each(function(){
		if(basicInfo.grade!=null&&basicInfo.grade!=undefined&&basicInfo.grade!=''&&
			basicInfo.grade.indexOf($(this).val())>-1){
			$(this).prop("checked",true)
		}
	});
	$(":radio[name=isLimited]").each(function(){
		if(basicInfo.isLimited!=null&&basicInfo.isLimited!=undefined&&basicInfo.isLimited!=''&&
			basicInfo.isLimited.indexOf($(this).val())>-1){
			$(this).prop("checked",true)
		}
	});
	$(":radio[name=isOutLets]").each(function(){
		if(basicInfo.isOutLets!=null&&basicInfo.isOutLets!=undefined&&basicInfo.isOutLets!=''&&
			basicInfo.isOutLets.indexOf($(this).val())>-1){
			$(this).prop("checked",true)
		}
	});
}

//能否补货
var suppledTable = new common.grid({
	el: '#suppled-table',
	hash: false,
	secondIndex: 1,
	columns: [{
		display: 'SKC(色系颜色)',
		render: function(item) {
			return item.productSkc + '(' + item.goodsName + ')';
		}
	}, {
		display: 'SKU(尺码)',
		render: function(item) {
			return item.productSku + '(' + item.sizeName + ')';
		}
	}, {
		display: '条码',
		render: function(item) {
			return item.factoryCode;
		}
	},{
		display: '能否补货',
		render: function(item) {
			return ENUM.isSuppled[item.isSuppled];
		}
	}, {
		display: '尾款支付时间',
		render: function(item) {
			var balanceTimeStr = '';
			if(item.balanceTime && item.balanceTime != 0) {
				balanceTimeStr = new Date(item.balanceTime * 1000).toLocaleString();
			}

			return balanceTimeStr;
		}
	}]
});
suppledTable.init(NETSALEDATA.goodsList, 'goodsSizeList')

//上架必填
productExtBo.renderType = $('.contentpanel').data('type');
productExtBo.sellChannels = productExtBo.sellChannels ? productExtBo.sellChannels.replace(/,/g, "|") : '';

common.util.__ajax({
	url: '/goods/ShopsRest/queryShopsByBrandId',
	data: {
		brandId: basicInfo.brandId
	}
}, function(res) {
	productExtBo.shopList = res.data;
	productExtBo.shopIds = productExtBo.shopIdList&&productExtBo.shopIdList.length?productExtBo.shopIdList.join('|'):NETSALEDATA.baseProductInfo.baseProduct.shopId;
	$('#product-ext').html(common.util.__template2($('#productExtBoTemp').html(), productExtBo));
}, true);

$(document).on("change",":radio[name=seasons]",function(){
	var value=$(this).val();
	/*var c=$(":radio[name=seasons]");
	if($(this).is(":checked")){
		if(value=="seasons"){
			c.slice(0,3).prop("checked",false);
		}else{
			c.eq(3).prop("checked",false);
		}
	}
	var arr=[];
	$(":radio[name=seasons]").each(function(){
		arr.push($(this).val())
	});*/
	$("#seasons").val($(this).val());
});

$(document).on("change",":radio[name=isOutLets]",function(){
	$("#isOutLets2").val($(this).val());
});
$(document).on("change",":radio[name=grade]",function(){
	$("#grade").val($(this).val());
});
$(document).on("change",":radio[name=isLimited]",function(){
	$("#isLimited").val($(this).val());
});


$('#saveBasicInfo').on('click', function() {
    var phraseValue = common.util.__input('phrase');

    if (phraseValue && phraseValue != '' && phraseValue.trim().length < 60) {
    	util.__tip("推荐短语不能少于60个字符", 'warning');
    	return;
    }

	var params = {
		productName:common.util.__input('productName'),
		phrase: phraseValue
	}
	common.util.__ajax(
		{
			url:'/sensitiveWord/validate',
			data: {
				"validateContent": JSON.stringify(params)
			}
		},
		function(rs) {
			if (rs.data) {
				var jsonMain = rs.data;
				if(!$.isEmptyObject(jsonMain.productName) || !$.isEmptyObject(jsonMain.phrase)){
					var tipText = "";
					if (!$.isEmptyObject(jsonMain.productName)) {
						tipText += "商品名称包含违禁词:"+jsonMain.productName+"!";
					}
					if (!$.isEmptyObject(jsonMain.phrase)) {
						tipText += "推荐短语包含违禁词:"+jsonMain.phrase+"!";
					}
                    //common.dialog.confirm("温馨提示",tipText + "确定提交吗?",function(){
                    //    submitForm();
                    //});
                    util.__tip(tipText, 'warning');
                } else {
                    submitForm();
                }
            }
		},true);

})

function submitForm() {
    common.util.__ajax({
        url:'/goods/product/saveNetSaleBaseInfo',
        data:{
            productSkn:basicInfo.productSkn,
            productName:common.util.__input('productName'),
            isNew:common.util.__input('[name=isNew]:checked'),
            sellChannels:common.util.__input('[name=sellChannels]:checked'),
            phrase:common.util.__input('phrase'),
            outSaleTime:common.util.__input('outSaleTime'),
            shopIds:common.util.__input('[name=shopIds]:checked'),
            delayArrivalNotice:common.util.__input('delayArrivalNotice'),
            grade:common.util.__input('grade')||0,
            isLimited:common.util.__input('isLimited')||'N',
            isOutlets:common.util.__input('isOutLets2')||'N',
            seasons:common.util.__input('seasons')
        }
    })

    if (common.util.__sknOperateLog(basicInfo.productSkn, common.util.__input('phrase'), oldphrase, 6)) {
        oldphrase = common.util.__input('phrase');
    }
}
// var e = new common.edit('#basicInfoWrap');
// e.init();

// //保存基本信息
// $('#saveBasicInfo').on('click', function() {
// 	e.submit('/goods/product/saveNetSaleBaseInfo', function(option) {
// 		option.data = GOLABDATA.fire("LYbasicInfo");;
// 		option.success = function(res) {
// 			res = res;
// 			if (res.code == '200') {
// 				e.$tip(res.message, function() {}, 'growl-success');
// 			} else {
// 				e.$tip(res.message);
// 			}
// 			return false;
// 		}
// 	});
// });

// GOLABDATA.on("LYbasicInfo", function() {
// 	var data = null;
// 	if (!e.validate(true)) {
// 		return e.errMessage;
// 	} else {
// 		data = e.getSubmitData();
// 		data.productSkn = $('#productSkn').val();
// 		data.sellChannels = data.sellChannels.split('|').join(',');
// 		data.shopIds = data.shopIds ? data.shopIds.split('|').join(',') : '';
// 		return data;
// 	}
// });