<%@ page language="java" contentType="text/html;charset=UTF-8" %> 
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> 
<%@ page isELIgnored="false" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title>推荐消息列表</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="stylesheet" href="<%=request.getContextPath() %>/js/bootstrap/css/bootstrap.min.css">
	<link rel="stylesheet" href="<%=request.getContextPath() %>/js/bootstrap/css/bootstrap-theme.min.css">
    <script type="text/javascript" charset="utf-8" src="<%=request.getContextPath() %>/js/jquery/jquery-1.11.2.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="<%=request.getContextPath() %>/js/bootstrap/js/bootstrap.min.js"></script>
	<script type="text/javascript" charset="utf-8" src="<%=request.getContextPath() %>/js/jquery.twbsPagination/jquery.twbsPagination.js"></script>
</head>
<body>
<div class="container-fluid">
			<form class="form-inline">
			<div class="row">
			  <div class="form-group col-md-6">
			    <label>标题:</label>
			    <input type="text" name="title" value="${param.title==null?'':param.title}" style="width: inherit;" class="form-control" placeholder="标题">
			  </div>
			  <div class="form-group col-md-6">
			    <label>类别:</label>
				  <select name="type" value=""class="form-control">
					  <option value="-1" ${param.type==null && param.type=='-1'?'selected':''}>全部</option>
					  <option value="0" ${param.type==0?'selected':''}>宠爱推送</option>
					  <option value="1" ${param.type==1?'selected':''}>业务办理</option>
					  <option value="2" ${param.type==2?'selected':''}>会员通知</option>
					  <option value="3" ${param.type==3?'selected':''}>邮寄信息</option>
					  <option value="4" ${param.type==4?'selected':''}>我的订阅</option>
				  </select>
			  </div>			
			</div>	
			<input type="hidden" id="pageval" name="page" class="form-control" value="${param.page==null?1:param.page}">
			<input type="hidden" name="limit" class="form-control" value="10">
			<div class="alert alert-default" role="alert" style="text-align: center;">
				<button type="button" id="subbtn" class="btn btn-default">提交</button>
		  		<button type="reset" class="btn btn-default">重置</button>
		  		<a href="<%=request.getContextPath() %>/message/toUpdate.do?type=add" type="button" class="btn btn-success">添加</a>
			</div>

			    <table class="table">
			      <thead>
			        <tr>
			          <th>ID</th>
			          <th>类别</th>
			          <th>标题</th>
			          <th>内容</th>
					  <th>创建人</th>
					  <th>创建时间</th>
					  <th>操作</th>
			        </tr>
			      </thead>
			      <tbody id="showcontent">
					<c:forEach var="item" items="${pageList.list}">
				        <tr>
				          <td>${item.id}</td>
							<c:if test="${item.type==0}">
								<td>宠爱推送</td>
							</c:if>
							<c:if test="${item.type==1}">
								<td>业务办理</td>
							</c:if>
							<c:if test="${item.type==2}">
								<td>会员通知</td>
							</c:if>
							<c:if test="${item.type==3}">
								<td>邮寄信息</td>
							</c:if>
							<c:if test="${item.type==4}">
								<td>我的订阅</td>
							</c:if>
				          <td>${item.title}</td>
							<td>${item.content}</td>
							<td>${item.sysUser.userName}</td>
							<td><fmt:formatDate value="${item.createTime}" pattern="yyyy-MM-dd HH:mm:ss"  /></td>
				          <td>
							  <c:if	test="${item.status==0}">
								  <a type="button" class="btn btn-info" href="<%=request.getContextPath() %>/message/toUpdate.do?type=edit&id=${item.id}">修改</a>
								  <button type="button" onclick="del(${item.id})" class="btn btn-danger">删除</button>
								  <c:if test="${user.role==1 }">
									  <a type="button" class="btn btn-info" onclick="changeStatus(${item.id})">审核</a>
								  </c:if>
								  <c:if test="${user.role==0 }">
									  <a type="button" class="btn btn-info">未审核</a>
								  </c:if>
							  </c:if>
							  <c:if	test="${item.status==1}">
								  <a type="button" class="btn btn-info">已审核</a>
							  </c:if>
				          </td>
				        </tr>
					</c:forEach>
			      </tbody>
			    </table>
			    <nav id="pagination_box"><ul class="pagination" id="pagercontent"></ul></nav>
			 </form>   
</div>
<script>
$("#subbtn").on("click",function(){
	$('#pageval').val(1);
    $("form").submit();
})
$('#pagercontent').twbsPagination({
	  startPage: ${param.page==null?1:param.page},
	  initiateStartPageClick: false,
	  totalPages: ${pageList.totalCount}==0?1:Math.ceil(${pageList.totalCount}/10),
	  onPageClick: function (event, page) {
	    $('#pageval').val(page);
	    $("form").submit();
	  }
	});
	function del(id){
		$.ajax({
			type:"get",
			url:"<%=request.getContextPath() %>/message/deleteMessage.do",
			data:{id:id},
 			dataType: 'json',
	        timeout: 30000,
	        success: function(json){
	        	console.log(json);
	        	alert(json.msg);
	        	if(json.rc==0){
	    			window.location.reload();
	    		}
	        },
	        error: function(xhr, type){
	            
	        }
		});
	}
function changeStatus(id){
	$.ajax({
		type:"get",
		url:"<%=request.getContextPath() %>/message/changeStatus.do",
		data:{id:id},
		dataType: 'json',
		timeout: 30000,
		success: function(json){
			console.log(json);
			alert(json.msg);
			if(json.rc==0){
				window.location.reload();
			}
		},
		error: function(xhr, type){

		}
	});
}
</script>	
</body>
</html>
