var pageii = null;
var grid = null;
$(function() {
	grid = lyGrid({
		id : 'paging',
		l_column : [ {
			colkey : "fileId",
			width : "100px",
			hide : true
		}, {
			name : "文件",
			renderData : function( rowindex ,data, rowdata, colkeyn) {
				// 图片
				if(rowdata.ext=='png'||rowdata.ext=='jpg'||rowdata.ext=='gif'){
					return "<img style='max-width:150px;height:80px;' src='"+rootPath+"/upload/"+rowdata.fpath+"'>";
				}else{
					return "<img src='"+rootPath+"/images/filedefault.jpg'>";
				}
			}
		}, {
			colkey : "name",
			name : "名称"
		}
		, {
			colkey : "ext",
			name : "文件类型",
		}, {
			colkey : "uploadTime",
			name : "上传时间",
			renderData : function( rowindex ,data, rowdata, colkeyn) {
				return new Date(rowdata.uploadTime).format("yyyy/MM/dd hh:mm:ss");
			}
		}],
		jsonUrl : rootPath + '/cmsfile/find.shtml',
		checkbox : true,
		serNumber : false,
		checkValue:'fileId'
	});

	$("#search").click("click", function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();// 初始化传参数
		grid.setOptions({
			data : searchParams
		});
	});
	$("#editBtn").click("click", function() {
		editFolder();
	});
	$("#delBtn").click("click", function() {
		delFolder();
	});
});
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 delFolder() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择删除项！！");
		return;
	}
	layer.confirm('确认删除吗？', function(index) {
		var _URL = rootPath + '/cmsfile/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});
		}
	});
}

