var pageii = null;
var grid = null;
$(function() {
	grid = lyGrid({
		id : 'paging',
		l_column : [ {
			colkey : "prodId",
			hide : true
		}, {
			colkey : "name",
			name : "标题",
			align: "left",
		}, {
			colkey : "merch",
			name : "所属商户",
			align: "left",
		}, {
			colkey : "auth",
			name : "是否认证",
			renderData : function( rowindex ,data, rowdata, colkeyn) {
				if(rowdata.auth=='1'){
					return "已认证";
				}else{
					return "未认证";
				}
			}
		}, {
			colkey : "province",
			name : "省份/州",
			align: "left",
		}, {
			colkey : "city",
			name : "城市",
			width:"120px",
			align: "left",
		}, {
			colkey : "linkman",
			name : "联系人",
			align: "left",
		}, {
			colkey : "phone",
			name : "电话",
			align: "left",
		}],
		jsonUrl : rootPath + '/rent/prod/search.shtml',
		checkbox : true,
		serNumber : false,
		checkValue:'prodId'
	});

	$("#search").click("click", function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();// 初始化传参数
		grid.setOptions({
			data : searchParams
		});
	});
	
	$("#addBtn").click("click", function() {
		add();
	});
	
	$("#detailBtn").click("click", function() {
		showDetail();
	});
	
	$("#editBtn").click("click", function() {
		edit();
	});
	
	$("#delBtn").click("click", function() {
		del();
	});
	
	$("#storeBtn").click(function(){
		showStore();
	});
	
   
});

function add(){
	pageii = layer.open({
		title : "新增出租产品",
		type : 2,
		area : [ "960px", "80%" ],
		content : rootPath + '/rent/prod/addUI.shtml'
	});
};

function edit() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1 || cbox == "") {
		layer.msg("只能选中一个");
		return;
	}
	pageii = layer.open({
		title : "产品编辑",
		type : 2,
		area : [ "960px", "80%" ],
		content : rootPath + '/rent/prod/editUI.shtml?id=' + cbox
	});
}
function del() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择下架商品吗！！");
		return;
	}
	layer.confirm('请选择下架当前商品吗？', function(index) {
		var _URL = rootPath + '/prod/down.shtml';
		var resp = CommnUtil.ajax(_URL, {
			ids : cbox.join(",")
		}, "json");
		layer.msg(resp.code,{icon: 5});
		if (resp.code == "01") {
			layer.msg(resp.msg,{icon: 1});
			grid.loadData();
		} else {
			layer.msg('删除失败',{icon: 5});
		}
	});
}

showPicture = function(){
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1 || cbox == "") {
		layer.msg("选中且只能选中一个商品");
		return;
	}
	pageii = layer.open({
		title : "产品图片",
		type : 2,
		area : [ "960px", "80%" ],
		content : rootPath + '/rent/prod/editUI.shtml?id=' + cbox
	});
};

