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

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': '品牌设置'
		}
	},
	basicInfo = NETSALEDATA.baseProductInfo.baseProduct || '',
	productExtBo = NETSALEDATA.productExtBo || '';
var basicInfoTmp = JSON.stringify(basicInfo);
basicInfoTmp = JSON.parse(basicInfoTmp);
//alert( JSON.stringify(basicInfo));
/*
 * 基本信息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');
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||'0');
	$("#isLimited").val(basicInfo.isLimited);
	$("#isOutlets").val(basicInfo.isOutLets);

	$(":checkbox[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;
		}
	}]
});
suppledTable.init(NETSALEDATA.goodsList, 'goodsSizeList')

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

//productExtBo.shopList =  
common.util.__ajax({
	url: '/ShopsRest/queryShopsByBrandId',
	data: {
		brandId: basicInfo.brandId
	}
}, function(res) {
	productExtBo.shopList = res.data;
	productExtBo.shopIds = '';
	if (productExtBo.shopIdList && productExtBo.shopIdList.length > 0) {
		//如有选择店铺
		productExtBo.shopIds = productExtBo.shopIdList ? productExtBo.shopIdList.join('|') : '';
	}
	//  else if (res.data.length > 0) {
	// 	//如没有已选择店铺,默认选择全部
	// 	$.each(res.data, function(i, value) {
	// 		productExtBo.shopIds += value.shopsId + '|';
	// 	});
	// }
	else{
		productExtBo.shopIds=$("#myshopsId").val();
	}
	//
	$('#product-ext').html(common.util.__template2($('#productExtBoTemp').html(), productExtBo));
	e.init();
}, true);
$('#product-ext').html(common.util.__template2($('#productExtBoTemp').html(), productExtBo));


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

$(document).on("change",":radio[name=isOutLets]",function(){
	$("#isOutlets").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());
});


//如果是info页,所有input btn置灰
if ($('.contentpanel').data('type') == 'info') {
	$('.contentpanel').find('input').prop('disabled', true);
	$('.contentpanel').find('.btn').addClass('disabled');
}

var e = new common.edit('#basicInfoWrap');
e.init();

//保存基本信息
$('#saveBasicInfo').on('click', function() {
	e.submit('/product/saveNetSaleBaseInfo', function(option) {
		option.data = GOLABDATA.fire("LYbasicInfo");;
		option.success = function(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(',') : '';
		data.grade = common.util.__input('grade')||'0';
		data.isLimited = common.util.__input('isLimited')||'N';
		data.isOutlets =$('#isOutlets').val()||'N';
		data.seasons = common.util.__input('seasons');

		return data;
	}
});