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

var basicInfohtml = '',
	ENUM = {
		isSuppled: {
			'Y': '是',
			'N': '否'
		}
	},
	convertObj = {
		ageLevel: {
			'1': '成人',
			'2': '大童',
			'3': '小童'
		},
		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 || '';

/*
 * 基本信息value值转换
 * @param: basicInfo(请求的要渲染的数据), obj(转换的对象)
 */
function convert(basicInfo, obj) {
	$.each(basicInfo, function(key, value) {
		if (convertObj[key]) {
			basicInfo[key] = convertObj[key][value];
		}
	});
	return basicInfo;
}


var basicInfoData = convert(basicInfo, convertObj);
basicInfoData.expectArrivalTime = common.util.__dateFormat(new Date(basicInfoData.expectArrivalTime * 1000), "yyyy-MM-dd hh:mm:ss");
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);

//能否补货
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 ENUM.isSuppled[item.isSuppled];
		}
	}]
});
suppledTable.init(NETSALEDATA.goodsList, 'goodsSizeList')

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

//productExtBo.shopList =  
common.util.__ajax({
	url: '/goods/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 + '|';
		});
	}
	//
	$('#product-ext').html(common.util.__template2($('#productExtBoTemp').html(), productExtBo));
	e.init();
}, true);
$('#product-ext').html(common.util.__template2($('#productExtBoTemp').html(), productExtBo));

//如果是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('/goods/product/saveNetSaleBaseInfo', function(option) {
		option.data = GOLABDATA.fire("LYbasicInfo");;
		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("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;
	}
});