var pageii = null;
var grid = null;
$(function() {
	grid = lyGrid({
		id : 'paging',
		l_column : [ {
			colkey : "foldId",
			width : "100px",
			hide : true
		}, {
			colkey : "name",
			name : "名称"
		}
		, {
			colkey : "sys",
			name : "系统内置",
			renderData : function( rowindex ,data, rowdata, colkeyn) {
				if(rowdata.sys=='1'){
					return "是";
				}else{
					return "否";
				}
			}
		}, {
			colkey : "open",
			name : "开放",
			renderData : function( rowindex ,data, rowdata, colkeyn) {
				if(rowdata.open=='1'){
					return "是";
				}else{
					return "否";
				}
			}
		}],
		jsonUrl : rootPath + '/folder/find.shtml',
		checkbox : true,
		serNumber : false,
		checkValue:'foldId'
	});

	$("#search").click("click", function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();// 初始化传参数
		grid.setOptions({
			data : searchParams
		});
	});
	$("#addBtn").click("click", function() {
		createFolder();
	});
	$("#editBtn").click("click", function() {
		editFolder();
	});
	$("#delBtn").click("click", function() {
		delFolder();
	});
	$("#uploadBtn").click("click",function(){
		uploadFile();
	});
	$("#filesBtn").click("click",function(){
		showFile();
	});
});
function editFolder() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1 || cbox == "") {
		layer.msg("只能选中一个");
		return;
	}
	pageii = layer.open({
		title : "编辑",
		type : 2,
		area : [ "600px", "40%" ],
		content : rootPath + '/folder/editUI.shtml?id=' + cbox
	});
}
function createFolder() {
	pageii = layer.open({
		title : "创建文件夹",
		type : 2,
		area : [ "600px", "40%" ],
		content : rootPath + '/folder/addUI.shtml'
	});
}
function delFolder() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择删除项！！");
		return;
	}
	layer.confirm('确认删除吗？', function(index) {
		var _URL = rootPath + '/folder/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});
		}
	});
}

function uploadFile(){
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1 || cbox == "") {
		layer.msg("选择一个上传文件夹");
		return;
	}
	pageii = layer.open({
		title : "上传文件",
		type : 2,
		area : [ "1024px", "80%" ],
		content : rootPath + '/folder/upload.shtml?id=' + cbox
	});
}

function showFile(){
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1 || cbox == "") {
		layer.msg("选择一个上传文件夹");
		return;
	}
	pageii = layer.open({
		title : "文件",
		type : 2,
		area : [ "1024px", "80%" ],
		content : rootPath + '/folder/files.shtml?id=' + cbox
	});
}
