<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<!-- bootstrap 3.0.2 -->
<link href="<c:url value='/styles/lib/bootstrap.min.css'/>" rel="stylesheet" type="text/css" />
<!-- font Awesome -->
<link href="<c:url value='/styles/lib/font-awesome.min.css'/>" rel="stylesheet" type="text/css" />
<!-- Ionicons -->
<link href='<c:url value='/styles/lib/ionicons.min.css' />' rel="stylesheet" type="text/css" />
<!-- DATA TABLES -->
<link href="<c:url value='/styles/lib/datatables/dataTables.bootstrap.css' />" rel="stylesheet" type="text/css" />
<!-- Theme style -->
<link href="<c:url value='/styles/AdminLTE.css'/>" rel="stylesheet" type="text/css" />
<!-- date -->
<script src="${ctx }/scripts/lib/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="<c:url value='/scripts/loading/jquery.blockUI.js'/>"></script>
<script type="text/javascript" src="<c:url value='/scripts/loading/loading.js'/>"></script>
<script type="text/javascript" src="<c:url value='/scripts/My97DatePicker/WdatePicker.js'/>" ></script>
<script type="text/javascript">

$(document).ready(function(){
	function fn(selector,container){
	    $(selector).click(function(){
	        var stats = $(this).prop('checked') || false;
	        $(container).each(function(idx,item){
	            $(item).prop('checked',stats);
	        });
	    });
	    
	    $(container).click(function(){
	     var chklen = $(container).filter(function(idx,el){
		     if($(el).prop('checked')){
		    	 return el;
		     }
	     }).length;
		var chkStats = $(container).length === chklen;
	 		$(selector).prop('checked',chkStats);
	    });
	};
	fn("#checkAll","input[name='chkBtn']");
	
	//添加
	$("#addBtn").click(function(){
		showBlock();
		location.href='<c:url value='/estate/msgTemplate/preAdd'/>';
	});
	
	$("#delBtn").click(function(){
		var contextPath =$("#contextPath").val();
		if($("#dataareaid input:checked[name='chkBtn']").length < 1){
			alert('请选要删除的数据！');
			return;
		}
		if(confirm('<fmt:message key='button.delete'/>?')){
			var dataAreaIds="";
			for(var i=0;i<$("#dataareaid input:checked[name='chkBtn']").length;i++){
				dataAreaIds+=$("#dataareaid input:checked[name='chkBtn']")[i].value+";";
			}
			showBlock();
			$.ajax({
				url: contextPath+"/estate/msgTemplate/detele",
				type:"post",
				data: {dataAreaIds:dataAreaIds},
				dataType:"json",
				success:function(data){
					if(data.errcode==200){
						$("#conditionform").submit();
					}else{
						alert('删除失败');
					}
					hideBlock();
				},
				error:function(data){
					alert('服务器异常，删除失败');
					hideBlock();
				}
			});
		}
	});
});

function update(id){
	var contextPath =$("#contextPath").val();
	showBlock();
	location.href=contextPath+"/estate/msgTemplate/preModify?id="+id;
}

function goPage(pageNo){
	if(pageNo=="gopage"){
		$("#pageNo").val($("#gopage").val());
	}else{
		$("#pageNo").val(pageNo);
	}
	$("#conditionform").submit();
}
</script>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
	th{ text-align:center;}
	td{ text-align:center;vertical-align:middle;}
</style>
</head>
<body>
<input type="hidden" value="${ctx}" id="contextPath"> 
	<section class="content">
		<div class="row">
			<div class="col-xs-12">
				<div class="boxlist" >
					<!-- /.box-header -->
					<div class="box-body table-responsive">
						<form action="${ctx}/estate/msgTemplate/query" method="POST" id="conditionform">
							<input type="hidden" id="pageNo" name="pageNo" />
							<div class="form-group">
								<label>公众号</label>
								<select id="developId" name="developId" style="width: 200px;">
									<c:forEach items="${publicnos}" var="no">
										<c:if test="${developId==no.developId }">
											<option value="${no.developId}" selected="selected">${no.name}</option>	
										</c:if>
										<c:if test="${developId!=no.developId }">
											<option value="${no.developId}" >${no.name}</option>	
										</c:if>
									</c:forEach>
								</select> 
								<label>关键字</label>
								<input id="name" name="name" value="${name }" style="width: 200px;" placeholder="请输入关键字" /> 
								<!-- <label>状态</label>
								<select id="state" name="state" > 
									<option value="">请选择</option>
									<option value="0">无效</option>
									<option value="1">有效</option>
								</select> -->
							</div>
						</form>
						<div  class="form-search-wp">
							<button class="btn btn-red" type="button" onclick="goPage(1);">查询</button>
							<c:if test="${addAct =='1' }">
							<button id="addBtn" type="button" class="btn btn-white">新增</button>
							</c:if>
							<c:if test="${deleteAct =='1' }">
							<button class="btn btn-white" type="button" id="delBtn">删除</button>
							</c:if>
						</div>
						<table class="table table-bordered table-hover" id="dataareaid">
							<thead>
								<tr>
									<th><input type="checkbox" id="checkAll"></th>
									<th>公众号名称</th>
									<th>关键字</th>
									<th>描述</th>
									<th>消息类型</th>
									<th>创建人</th>
									<th>创建时间</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody>
								<c:forEach items="${page.items }" var="obj">
									<tr>
										<td><input type="checkbox" name="chkBtn"
											value="${obj.replyKeywordsId }" /></td>
										<td>${obj.publicname }</td>
										<td>${obj.name }</td>
										<td>${obj.remark }</td>
										<td><c:if test="${obj.replyContentType eq '1'}">文字</c:if><c:if test="${obj.replyContentType eq '2'}">图文</c:if></td>
										<td>${obj.createPerson }</td>
										<td><fmt:formatDate value="${obj.createTime }"
												pattern="yyyy-MM-dd HH:mm:ss" /></td>
										<td>
										<c:if test="${updateAct =='1' }">
										<a href="javascript:update(${obj.replyKeywordsId });">修改</a>
										</c:if>
										</td>
									</tr>
								</c:forEach>
							</tbody>
						</table>
						<div class="btn-page">
		                    <!-- 页码 -->
		                    <div align="center" class="pages clearfix">
		                           <c:forEach items="${page.iterPages }" var="pageNo">
									<c:choose>
										<c:when test="${pageNo == page.currentPage }">
											<span class='current'>${pageNo }</span>
										</c:when>
										<c:when test="${pageNo != null}">
											<a href="javascript:void(0);" onclick='goPage(${pageNo});'>${pageNo}</a>
										</c:when>
										<c:otherwise>
											<em>...</em>
										</c:otherwise>
									</c:choose>
								</c:forEach>
								<strong>共<span style="color:black;font-weight:bold;font-size:16px;">${page.totalCount}</span>条</strong>
								<strong>跳转到第</strong><input type="text" id="gopage" style="width: 40px;" onkeyup="this.value=this.value.replace(/\D/g,'')" onkeypress="this.value=this.value.replace(/\D/g,'')"/><strong>页</strong>
								<a class="btn-sm btn-red" href="javascript:goPage('gopage');" id='bindBtn'>确定</a>
		                	</div>
			            </div>
					</div>
				</div>
			</div>
		</div>
	</section>
</body>
</html>