netsale.js 4.81 KB
'use strict';
var $ = require('jquery'),
	common = require('../common/common');

var ENUM = {
	gender: {
		1: '男',
		2: '女',
		3: '通用'
	},
	ageLevel: {
		1: '成人',
		2: '大童',
		3: '小童'
	},
	status: {
		'-1': '待上架',
		'2': '待审核',
		'3': '驳回',
		'4': '通过',
		'1': '已上架',
		'0': '已下架',
		'5': '再上架待审核',
		'6': '再上架驳回',
		'7': '再上架通过'
	},
	attribute: {
		1: '普通',
		2: '赠品'
	}
};

var g = new common.grid({
	el: "#basicTable",
	parms: function() {
		return {
			productSkn: common.util.__input("productSkn"),
			productSkc: common.util.__input("productSkc"),
			productSku: common.util.__input("productSku"),
			productName: common.util.__input("productName"),
			shopId: common.util.__input("shopId"),
			brandId: common.util.__input("brandId"),
			isJit: common.util.__input("isJit"),
			stock: common.util.__input("stock"),
			isScreen: common.util.__input("isScreen"),
			isMeasure: common.util.__input("isMeasure"),
			gender: common.util.__input("gender"),
			maxSortId: common.util.__input("maxSortId"),
			middleSortId: common.util.__input("middleSortId"),
			smallSortId: common.util.__input("smallSortId"),
			isOutLets: common.util.__input("isOutLets"),
			productStatus: common.util.__input("productStatus"),
			size: common.util.__input("size")
		};
	},
	columns: [{
		display: '',
		type: 'checkbox'
	}, {
		display: 'skn',
		name: 'productSkn'
	}, {
		display: '图片',
		name: 'picImgUrl',
		render: function(item) {
			return '<img src="' + item.picImgUrl + '">';
		}
	}, {
		display: '商品信息',
		render: function(item) {
			return '<p><strong>名称:</strong>' + item.productName + '</p>' +
				'<p><strong>品牌:</strong>' + item.brandName + '</p>' +
				'<p><strong>类目:</strong>' + item.maxSortName + '/' + item.middleSortName + '</p>';
		}
	}, {
		display: '售价',
		render: function(item) {
			return '<p><strong>吊牌价:</strong>' + item.retailPrice + '</p>' +
				'<p><strong>销售价:</strong>' + item.salesPrice + '</p>' +
				'<p><strong>是否VIP:</strong></p>' +
				'<p style="color: #ccc;"><strong>yoho币:</strong>' + item.returnCoin + '</p>';
		}
	}, {
		display: '库存',
		name: 'stock'
	}, {
		display: '年龄层/性别',
		name: 'vip_discount_type',
		render: function(item) {
			return ENUM.ageLevel[item.ageLevel] + '/' + ENUM.gender[item.gender];
		}
	}, {
		display: '商品类别',
		name: 'attribute', //商品属性(1普通、2赠品等)   商品类别
		render: function(item) {
			return ENUM.attribute[item.attribute];
		}
	}, {
		display: '操作信息',
		render: function(item) {
			var html = '';
			if (item.founderName) {
				html += '<p>' + item.founderName + '</p>';
			}

			if (item.editTime) {
				html += '<p>' + item.editTime + '</p>';
			}
			return html;
		}
	}, {
		display: '上架状态',
		name: 'status', // -1待上架,2待审核,3驳回,4通过,1已上架,0已下架,5再上架待审核,6再上架驳回,7再上架通过。
		render: function(item) {
			return ENUM.status[item.status];
		}
	}, {
		display: '操作',
		render: function(item) {
			return '<a href="/goods/netsale/edit/' + item.productSkn + '" class="btn btn-info btn-xs edit-btn">编辑</a>' +
				'<a href="javascript:;" class="btn btn-info btn-xs edit-btn">上架</a>' +
				'<a href="javascript:;" class="btn btn-info btn-xs info-btn">查看</a>';
		}
	}]
});
g.init($("#gridurl").val());

//筛选
$("#filter-btn").click(function() {
	g.reload(1);
});

/*
 * 上架下架弹框
 * params: title(弹框标题), html(弹框内容html)
 */
function shelveModal(title, html) {
	var selectedArr = g.selected,
		len = selectedArr.length,
		productSknList = [],
		shelveModal = null;

	if (len <= 0) {
		common.util.__tip('请选择要' + title + '的商品', 'warning');
		return;
	}

	$.each(selectedArr, function(i, value) {
		productSknList.push(value['productSkn']);
	});

	shelveModal = common.dialog.open({
		title: '上架',
		content: html
	});

	var e = new common.edit('.shelve-form');
	e.init();

	$('.shelve-form').on('click', '.btn', function() {
		var type = $(this).data('type');
		$(this).closest('.form-group').find('input').attr('required', true)
			.end().siblings('.form-group').find('input').attr('required', false);

		e.submit('/goods/product/updateProductSknTimingInfo', function(option) {
			option.data.productSknList = JSON.stringify(productSknList);
			option.data.type = type;
			option.success = function(res) {
				if (res.data.code == 200) {
					e.$tip(res.data.message, function() {
						shelveModal.close();
					}, 'growl-success');
				} else {
					e.$tip(res.data.message);
				}
			}
		});
	});
}
//上架
$('#onshelve').on('click', function() {
	shelveModal('上架', $('#onshelve-template').html());
});
//下架
$('#offshelve').on('click', function() {
	shelveModal('下架', $('#offshelve-template').html());
});