netsale.js 9.17 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: '赠品'
	},
	tab: {
		'0': 0,
		'1': 0,
		'2': 0,
		'3': 0,
		'all': 0
	}
};

var t = new common.tab({
	el: "#basicTab",
	click: function() {
		g.options.columns[11].hidden = true;
		g.options.columns[8].hidden = true;
		if ($(this).find('a').attr('columnname') == 3) {
			g.options.columns[11].hidden = false;
		} else if ($(this).find('a').attr('columnname') == 2) {
			g.options.columns[8].hidden = false;
		};
		g.init($("#gridurl").val());
	},
	columns: [{
		name: "0",
		value: '-1,3',
		display: "上架前"
	}, {
		name: "1",
		value: '4,1,0,5,6',
		display: "上架后"
	}, {
		name: "2",
		value: '1',
		display: "搜索/标签"
	}, {
		name: "3",
		value: '1',
		display: "上架后信息缺失"
	}, {
		name: "all",
		value: '',
		display: "全部商品"
	}]
}).init();

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"),
			productStatusStr: t.value
		};
	},
	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: '搜索/标签',
		hidden: true,
		render: function(item) {
			return '关键词:' + '<br>' +
				'风格:' + item.style + '<br>' +
				'纹理:' + item.style + '<br>' +
				'工艺:' + item.style + '<br>';
		}
	}, {
		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) {
			var html = '';
			html += ENUM.status[item.status];
			if (item.shelveTime) {
				html += '<br>上架时间:' + item.shelveTime;
			}
			return html;
		}
	}, {
		display: '缺失信息',
		hidden: true,
		render: function(item) {
			return '缺失信息';
		}
	}, {
		display: '操作',
		render: function(item) {
			var HtmArr = [];

			if (item.status == 1) {
				HtmArr.push('<a href="/goods/netsale/edit/' + item.productSkn + '" class="btn btn-info btn-xs edit-btn">编辑</a>');
				HtmArr.push('<a href="javascript:;" class="btn btn-danger btn-xs shelve-btn" data-skn="' + item.productSkn + '">下架</a>');
			} else if (item.status != 2 && item.status != 5) {
				HtmArr.push('<a href="/goods/netsale/edit/' + item.productSkn + '" class="btn btn-info btn-xs edit-btn">编辑</a>');
				HtmArr.push('<a href="javascript:;" class="btn btn-success btn-xs shelve-btn" data-skn="' + item.productSkn + '">上架</a>');
			}
			HtmArr.push('<a href="javascript:;" class="btn btn-info btn-xs info-btn">查看</a>');
			return HtmArr.join('');
		}
	}]
});
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);
				}
			}
		});
	});
}
//批量skn上架
$('#onshelve').on('click', function() {
	shelveModal('上架', $('#onshelve-template').html());
});
//批量skn下架
$('#offshelve').on('click', function() {
	shelveModal('下架', $('#offshelve-template').html());
});

//导出
$('#export-btn').on('click', function() {

});

//单个sku,skc上下架
$('#basicTable').on('click', '.shelve-btn', function() {
	var that = this,
		skn = $(this).data('skn'),
		shelveModalHtml = '',
		shelveModal = null;

	var shelveModalHtml = common.util.__template($('#template').html());

	$(that).addClass('disabled');

	common.util.__ajax({
		url: '/goods/product/getNetSaleInfo',
		data: {
			param: skn
		}
	}, function(res) {
		shelveModalHtml = common.util.__template($('#template').html(), res.data.baseProductInfo.baseProduct);
		shelveModal = common.dialog.open({
			title: '上/下架',
			width: 900,
			content: shelveModalHtml
		});

		$(that).removeClass('disabled');

		var shelveTable = new common.grid({
			el: "#shelve-table",
			secondIndex: 2,
			columns: [{
				display: 'SKC(商品信息)',
				render: function(item) {

					return 'SKC:' + item.productSkc + '<br>' +
						'颜色:' + item.goodsName;
				}
			}, {
				display: 'SKC上架操作(状态)',
				render: function(item) {
					if (item.status == 0) {
						return '<a class="btn btn-success" data-type="1" data-skc="' + item.productSkc + '" href="javascript:;">点击上架</a>';
					} else {
						return '<a class="btn btn-danger" data-type="0" data-skc="' + item.productSkc + '" href="javascript:;">点击下架</a>';
					}
				}
			}, {
				display: 'SKU',
				name: 'productSku'
			}, {
				display: '尺码',
				name: 'sizeName'
			}, {
				display: '库存',
				name: 'stock'
			}, {
				display: 'SKU上架操作',
				render: function(item) {
					if (item.status == 0) {
						return '下架';
					} else {
						return '上架';
					}
				}
			}, {
				display: 'SKU上架操作',
				render: function(item) {
					if (item.status == 0) {
						return '<a class="btn btn-success" data-type="1" data-sku="' + item.productSku + '"  href="javascript:;">上架</a>';
					} else {
						return '<a class="btn btn-danger" data-type="0" data-sku="' + item.productSku + '" href="javascript:;">下架</a>';
					}
				}
			}]
		});
		shelveTable.init(res.data.goodsList, 'goodsSizeList');

		$('#shelve-table').on('click', '.btn', function() {
			var param = {},
				reqUrl = '';
			if ($(this).data('skc')) {
				param.productSkc = $(this).data('skc');
				reqUrl = '/goods/product/updateGoodsStatus';
			} else if ($(this).data('sku')) {
				param.productSku = $(this).data('sku');
				reqUrl = '/goods/product/updateProductSkuStatus';
			}

			param.targetStatus = $(this).data('type');
			console.log(param);
			common.util.__ajax({
				url: reqUrl,
				data: param
			}, function(res) {
				console.log(res);
				if (res.data.code == 200) {
					shelveModal.close();
				}
			})
		})
	}, true);

});