var pageii = null;
var grid = null;
$(function() {
	grid = lyGrid({
		id : 'paging',
		l_column : [ {
			colkey : "lwId",
			width : "100px",
			hide : true
		}, {
			colkey : "uname",
			name : "留言人"
		}
		, {
			colkey : "tel",
			name : "电话",
		}, {
			colkey : "status", 
			name : "状态",
			renderData : function( rowindex ,data, rowdata, colkeyn) {
				if(rowdata.status=='1'){
					return "已处理";
				}else{
					return "<span style='color:red;'>未处理</span>";
				}
			}
		},{
			colkey : "lvword",
			name : "留言内容",
		},{
			colkey : "createTime",
			name : "留言时间",
		},
		{
			colkey : "replay",
			name : "回复内容",
			renderData : function( rowindex ,data, rowdata, colkeyn) {
				if(rowdata.replay==''||rowdata.replay==null){
					return "无回复";
				}else{
					return rowdata.replay;
				}
			}
		}],
		jsonUrl : rootPath + '/leaveword/find.shtml',
		checkbox : true,
		serNumber : false,
		checkValue:'lwId'
	});

	$("#search").click("click", function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();// 初始化传参数
		grid.setOptions({
			data : searchParams
		});
	});
	$("#editBtn").click("click", function() {
		editWord();
	});
	$("#delBtn").click("click", function() {
		deleteWord();
	});
});
function editWord() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1 || cbox == "") {
		layer.msg("只能选中一个");
		return;
	}
	pageii = layer.open({
		title : "留言回复",
		type : 2,
		area : [ "600px", "40%" ],
		content : rootPath + '/leaveword/edit.shtml?id=' + cbox
	});
}

function deleteWord() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择删除项！！");
		return;
	}
	layer.confirm('确认删除吗？', function(index) {
		var _URL = rootPath + '/leaveword/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});
		}
	});
}

