var pageii = null;
var grid = null;
$(function() {
	grid = lyGrid({
		id : 'paging',
		l_column : [ {
			colkey : "advId",
			width : "50px",
			hide : true
		}, {
			colkey : "name",
			name : "广告名称",
			align: "left"
		}, {
			colkey : "type",
			name : "广告类型",
			renderData : function( rowindex ,data, rowdata, colkeyn) {
				if(rowdata.type=='1'){
					return "图片";
				}else{
					return "视频";
				}
			}
		}, {
			colkey : "payAmt",
			name : "计费（元）"
		}, {
			colkey : "status",
			name : "是否可用",
			renderData : function( rowindex ,data, rowdata, colkeyn) {
				if(rowdata.status=='1'){
					return "投放";
				}else{
					return "停止";
				}
			}
		}, {
			colkey : "beginTime",
			name : "开始时间",
		}, {
			colkey : "endTime",
			name : "结束时间"
		}],
		jsonUrl : rootPath + '/advertment/find.shtml',
		checkbox : true,
		serNumber : false,
		checkValue:'advId'
	});

	$("#search").click("click", function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();// 初始化传参数
		grid.setOptions({
			data : searchParams
		});
	});
	$("#addBtn").click("click", function() {
		addBoard();
	});
	$("#editBtn").click("click", function() {
		editBoard();
	});
	$("#delBtn").click("click", function() {
		delBoard();
	});
});
function editBoard() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1 || cbox == "") {
		layer.msg("只能选中一个");
		return;
	}
	pageii = layer.open({
		title : "广告编辑",
		type : 2,
		area : [ "650px", "60%" ],
		content : rootPath + '/advertment/editUI.shtml?id=' + cbox
	});
}
function addBoard() {
	pageii = layer.open({
		title : "新增广告",
		type : 2,
		area : [ "650px", "60%" ],
		content : rootPath + '/advertment/addUI.shtml'
	});
}
