var pageii = null;
var grid = null;
$(function() {
	grid = lyGrid({
		id : 'paging',
		l_column : [ {
			colkey : "boardId",
			width : "50px",
			hide : true
		}, {
			colkey : "name",
			name : "栏目名称"
		}, {
			colkey : "prop",
			name : "是否内置",
			renderData : function( rowindex ,data, rowdata, colkeyn) {
				if(rowdata.state=='1'){
					return "是";
				}else{
					return "否";
				}
			}
		}, {
			colkey : "status",
			name : "是否可用",
			renderData : function( rowindex ,data, rowdata, colkeyn) {
				if(rowdata.status=='1'){
					return "是";
				}else{
					return "<span color='red'>否</span>";
				}
			}
		}, {
			colkey : "nav",
			name : "导航显示",
			renderData : function( rowindex ,data, rowdata, colkeyn) {
				if(rowdata.nav=='1'){
					return "<span color='red'>是</span>";
				}else{
					return "否";
				}
			}
		}, {
			colkey : "spend",
			name : "允许发帖（文）",
			renderData : function( rowindex ,data, rowdata, colkeyn) {
				if(rowdata.spend=='1'){
					return "是";
				}else{
					return "<span color='red'>否</span>";
				}
			}
		}, {
			colkey : "path",
			name : "路径",
			align:"left",
		}],
		jsonUrl : rootPath + '/board/find.shtml',
		checkbox : true,
		serNumber : false,
		checkValue:'boardId'
	});

	$("#search").click("click", function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();// 初始化传参数
		grid.setOptions({
			data : searchParams
		});
	});
	$("#addBtn").click("click", function() {
		addBoard();
	});
	$("#editBtn").click("click", function() {
		editBoard();
	});
	$("#delBtn").click("click", function() {
		delBoard();
	});
});
function editBoard() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1 || cbox == "") {
		layer.msg("只能选中一个");
		return;
	}
	pageii = layer.open({
		title : "板块编辑",
		type : 2,
		area : [ "650px", "55%" ],
		content : rootPath + '/board/editUI.shtml?id=' + cbox
	});
}
function addBoard() {
	pageii = layer.open({
		title : "添加板块",
		type : 2,
		area : [ "650px", "55%" ],
		content : rootPath + '/board/addUI.shtml'
	});
}
function delBoard() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择删除项！！");
		return;
	}
	layer.confirm('确认删除吗？', function(index) {
		var _URL = rootPath + '/board/delete.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});
		}
	});
}
