var pageii = null;
var grid = null;
$(function() {
	grid = lyGrid({
		id : 'paging',
		l_column : [ {
			colkey : "id",
			name : "id",
			hide : true
		}, {
			colkey : "name",
			name : "菜单名称",
			align : 'left'
		}, {
			colkey : "rtype",
			name : "资源类型",
			width : "70px",
			renderData : function(rowindex, data, rowdata, column) {
				if(rowdata.rtype=="0"){
					return "目录";
				}else if(rowdata.rtype=="1"){
					return "菜单";
				}else if(rowdata.rtype=="2"){
					return "按钮";
				}else{
					return "其它";
				}
			}
		}, {
			colkey : "resSign",
			name : "唯一KEY"
		}, {
			colkey : "url",
			name : "URL地址",
			align : 'left'
		},{
			colkey : "open",
			name : "是否隐藏",
			renderData : function(rowindex, data, rowdata, column) {
				if(rowdata.open=="0"){
					return "否";
				}else if(rowdata.open=="1"){
					return "是";
				}
			}
		} ],
		jsonUrl : rootPath + '/system/resource/treelists.shtml',
		checkbox : true,
		usePage : false,
		records : "treelists",
		treeGrid : {
			type:1,
			tree : true,
			hide:false,
			name : 'name',
			id: "id",
			pid: "pId"
		}
	});
	
	$("#seach").click("click", function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();
		grid.setOptions({
			data : searchParams
		});
	});
	$("#addFun").click("click", function() {
		addFun();
	});
	$("#editFun").click("click", function() {
		editFun();
	});
	$("#delFun").click("click", function() {
		delFun();
	});
	
});
function editFun() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1 || cbox == "") {
		layer.alert("只能选中一个");
		return;
	}
	pageii = layer.open({
		title : "编辑",
		type : 2,
		area : [ "600px", "70%" ],
		content : rootPath + '/system/resource/editUI.shtml?resId=' + cbox
	});
}
function addFun() {
	pageii = layer.open({
		title : "新增",
		type : 2,
		area : [ "600px", "70%" ],
		content : rootPath + '/system/resource/addUI.shtml'
	});
}
function delFun() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.alert("请选择删除项！！");
		return;
	}
	layer.confirm('是否删除？', function(index) {
		var url = rootPath + '/system/resource/delete.shtml';
		var s = CommnUtil.ajax(url, {
			ids : cbox.join(",")
		}, "json");
		if (s == "success") {
			layer.msg('删除成功');
			grid.loadData();
		} else {
			layer.msg('删除失败');
		}
	});
}
