var pageii = null;
var grid = null;
$(function() {
	grid = lyGrid({
		id : 'paging',
		l_column : [ {
			colkey : "typeId",
			name : "typeId",
			hide : true
		}, {
			colkey : "name",
			name : "名称",
			align : 'left'
		}, {
			colkey : "sortv",
			name : "排序值",
			width : "70px",
		}, {
			colkey : "icon",
			name : "图标"
		}],
		jsonUrl : rootPath + '/prod/type/treelists.shtml',
		checkbox : true,
		checkValue:'typeId',
		usePage : false,
		records : "treelists",
		treeGrid : {
			type:1,
			tree : true,
			hide:false,
			name : 'name',
			id: "typeId",
			pid: "supId"
		}
	});
	
	$("#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", "40%" ],
		content : rootPath + '/prod/type/editUI.shtml?id=' + cbox
	});
}
function addFun() {
	var supId = 0;
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1) {
		layer.alert("只能选中一个");
		return;
	}
	if(cbox !=''){
		supId = cbox;
	}
	pageii = layer.open({
		title : "新增",
		type : 2,
		area : [ "600px", "40%" ],
		content : rootPath + '/prod/type/addUI.shtml?supId=' + supId
	});
}
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('删除失败');
		}
	});
}
