var pageii = null;
var grid = null;
$(function() {

	grid = lyGrid({
		pagId : 'paging',
		l_column : [{
			colkey : "adminId",
			name : "adminId",
			hide : true
		}, {
			colkey : "uname",
			name : "用户名",
			isSort:true,
		}, {
			colkey : "email",
			name : "邮箱",
		}, {
			colkey : "name",
			name : "姓名",
		}, {
			colkey : "phone",
			name : "联系电话",
		}, {
			colkey : "supman",
			name : "是否超管",
			renderData : function( rowindex ,data, rowdata, colkeyn) {
				if(rowdata.supman=='1'){
					return "是";
				}else{
					return "否";
				}
			}
		}, {
			colkey : "type",
			name : "账户归属",
			renderData : function( rowindex ,data, rowdata, colkeyn) {
				if(rowdata.type=='1'){
					return "总部直属";
				}else{
					return "区域管理";
				}
			}
		},{
			name : "账号状态",
			width : '90px',
			renderData : function( rowindex ,data, rowdata, colkeyn) {
				if(rowdata.status=='1'){
					return "正常";
				}else{
					return "锁定";
				}
			}
		}],
		jsonUrl : rootPath + '/user/find.shtml',
		checkbox : true,
		serNumber : false,
		checkValue:'adminId'
	});

	$("#search").click("click", function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();// 初始化传参数
		grid.setOptions({
			data : searchParams
		});
	});

	$("#addAccount").click("click", function() {
		addAccount();
	});

	$("#editAccount").click("click", function() {
		editAccount();
	});

	$("#delAccount").click("click", function() {
		delAccount();
	});
	/*	$("#permissions").click("click", function() {
		permissions();
	});*/
});

function editAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1 || cbox == "") {
		layer.msg("只能选中一个");
		return;
	}
	pageii = layer.open({
		title : "编辑",
		type : 2,
		area : [ "600px", "80%" ],
		content : rootPath + '/user/editUI.shtml?hostId=' + cbox
	});
}
function addAccount() {
	pageii = layer.open({
		title : "新增",
		type : 2,
		area : [ "600px", "80%" ],
		content : rootPath + '/user/addUI.shtml'
	});
}
function delAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择删除项！！");
		return;
	}
	layer.confirm('是否删除？', function(index) {
		/*var url = rootPath + '/user/deleteEntity.shtml';
		var s = CommnUtil.ajax(url, {
			ids : cbox.join(",")
		}, "json");
		if (s == "success") {
			layer.msg('删除成功');
			grid.loadData();
		} else {
			layer.msg('删除失败');
		}*/
		layer.msg("管理账户不允许删除",{icon: 5});
	});
}
/*function permissions() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1 || cbox == "") {
		layer.msg("请选择一个对象！");
		return;
	}
	var url = rootPath + '/resources/permissions.shtml?userId='+cbox;
	pageii = layer.open({
		title : "分配权限",
		type : 2,
		area : [ "700px", "80%" ],
		content : url
	});
}*/