<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>后台管理</title>

	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/admin/index/h-ui/css/H-ui.min.css" />
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/admin/index/h-ui.admin/css/H-ui.admin.css" />
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/admin/index/Hui-iconfont/1.0.8/iconfont.css" />
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/admin/index/h-ui.admin/skin/default/skin.css" id="skin" />
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/admin/index/h-ui.admin/css/style.css" />
	<link href="${pageContext.request.contextPath}/static/admin/css/page.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="${pageContext.request.contextPath}/static/admin/index/jquery/1.9.1/jquery.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/static/admin/index/layer/layer.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/static/admin/index/h-ui/js/H-ui.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/static/admin/index/h-ui.admin/js/H-ui.admin.js"></script>
</head>
<body>
	<nav class="breadcrumb">
		<i class="Hui-iconfont">&#xe67f;</i>新闻管理
		<i class="Hui-iconfont">&gt;</i> 新闻信息
		<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
	</nav>
	<div class="page-container">

		<form action="/admin/newsManage.html" method="post" id="search"  enctype="multipart/form-data">
			<div class="text-c">
				资讯分类：<select name="id" class="input-text" style="width: 150px;">
				<option value=" " selected>---请选择---</option>
				<c:forEach items="${listAllType}" var="item">
					<option  value="${item.id}" <c:if test="${item.id==id}">selected</c:if>>${item.typename}</option>
				</c:forEach>
			     </select>

				<input type="text" name="title" value="${title}" placeholder="标题" style="width:250px" class="input-text" id="title">

				<button  onclick="search()" class="btn btn-success" type="submit"><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
			</div>
		</form>

		<div class="cl pd-5 bg-1 bk-gray mt-20">
			<span class="l">
				<a class="btn btn-primary radius" href="/admin/addNews.html"><i class="Hui-iconfont">&#xe600;</i>添加</a>
				<input onclick="deleteNewsChecked()" class="btn btn-success radius" type="button" value="批量删除" id="deleteNewsChecked"/>
			</span>

			<span class="r">共有数据：<strong>${pageinfo.total }</strong> 条</span>
		</div>
		<div class="mt-20">
			<table class="table table-border table-bordered table-bg table-hover table-sort">
				<thead>
					<tr class="text-c">
						<%--<th><input type="checkbox" id="sltall"/> </th>--%>
						<th style="width: 1px"><input onclick="selectedAll('child-checkbox')" type="checkbox" id="parent-checkbox"></th>
							<td>新闻编号</td>
							<td>新闻图片</td>
							<td>新闻名称</td>
							<td>新闻类型</td>
							<td>内容主题</td>
							<td>发布时间</td>
						<th width="200">操作</th>
					</tr>
				</thead>
				<tbody>
					<c:forEach items="${pageinfo.list}" var="item">
						<tr class="text-c">
							<%--<td> <input type="checkbox" name="id" value="${item.id }"/></td>--%>
							<td style="width: 1px"><input class="child-checkbox" name="child-checkbox" type="checkbox"></td>
							<td>${item.id }</td>
							<td><img src="${item.newsimage}" width="50" height="50" ></td>
							<td>${item.newsname}</td>

					<c:forEach items="${listAllType}" var="type">
						   <c:if test="${item.typeid == type.id}"><td>${type.typename}</td></c:if>
					</c:forEach>

							<td width="200">${item.newsinfo}</td>
							<td><fmt:formatDate value="${item.newstime}" pattern="yyyy-MM-dd" /></td>
							<td class="f-14 td-manage">
								<a style="text-decoration:none" class="ml-5" href="/admin/updateNews.html?id=${item.id }" title="查看"><i class="Hui-iconfont">&#xe6df;</i></a>
								<a href="javascript:del(${item.id})"><i class="Hui-iconfont">&#xe6e2;</i></a>
							</td>
						</tr>
					</c:forEach>
				</tbody>
			</table>
		</div>

		<div id="PageNum">
			<section>
				<div class="bd points-goods-list">
					<ul class="pages">
						<c:if test="${pageinfo.pageNum == 1}">
							<li><a class="active" href="${pageContext.request.contextPath}/admin/newsManage.html?id=${id}&title=${title}&pageNum=1">首页</a></li>
						</c:if>
						<c:if test="${pageinfo.pageNum != 1}">
							<li><a href="${pageContext.request.contextPath}/admin/newsManage.html?id=${id}&title=${title}&pageNum=1">首页</a></li>
						</c:if>
						<li class="prev">
							<a href="${pageContext.request.contextPath}/admin/newsManage.html?id=${id}&title=${title}&pageNum=${pageinfo.pageNum-1}">上一页</a>
						</li>

						<c:forEach items="${pageinfo.navigatepageNums}" var="num">

							<%--<c:if test="${nav == pageinfo.pageNum}">--%>
								<%--<li><a href="${pageContext.request.contextPath}/newsManage.html?pageNum=${nav}" class="active">${nav}</a></li>--%>
							<%--</c:if>--%>
							<%--<c:if test="${nav != pageinfo.pageNum}">--%>
								<%--<li><a href="${pageContext.request.contextPath}/newsManage.html?pageNum=${nav}">${nav}</a></li>--%>
							<%--</c:if>--%>

							<c:if test="${num == pageinfo.pageNum}">
								<li><a class="active"
									   href="${pageContext.request.contextPath}/admin/newsManage.html?id=${id}&title=${title}&pageNum=${num}">${num}</a>
								</li>
							</c:if>
							<c:if test="${num != pageinfo.pageNum}">
								<li>
									<a href="${pageContext.request.contextPath}/admin/newsManage.html?id=${id}&title=${title}&pageNum=${num}">${num}</a>
								</li>
							</c:if>
						</c:forEach>
						<li class="next">
							<a href="${pageContext.request.contextPath}/admin/newsManage.html?id=${id}&title=${title}&pageNum=${pageinfo.pageNum+1}">下一页</a>
						</li>
						<c:if test="${pageinfo.pageNum == pageinfo.pages}">
							<li><a class="active"
								   href="${pageContext.request.contextPath}/admin/newsManage.html?id=${id}&title=${title}&pageNum=${pageinfo.lastPage}">末页</a>
							</li>
						</c:if>
						<c:if test="${pageinfo.pageNum != pageinfo.pages}">
							<li>
								<a href="${pageContext.request.contextPath}/admin/newsManage.html?id=${id}&title=${title}&pageNum=${pageinfo.lastPage}">末页</a>
							</li>
						</c:if>

					</ul>
				</div>
			</section>
		</div>
		</div>
	</div>
	<script type="text/javascript">
		// function search(){
		//     alert(12);
        //
         //    alert($("#title").val());
         //    alert($("#id").val());
        //
         //    $.ajax({
         //        type:"post",
         //        url:"newsManage.html",
         //        data:{"id":$("#id").val(),"title":$("#title").val()},
         //        dataType:"json",
         //        success:function () {
        //
         //        }
        //
         //    })
        //
		// }

        //全选与反选
        $("#sltall").click(function(){
            if($(this).prop("checked")){
                $("[name='id']").prop("checked",true);//全选
            }else{
                $("[name='id']").prop("checked",false);//取消全选
            }
        });


        function downs(){
            var chkvalue ="";//定义一个数组
            $("input[name='id']:checked").each(function(){
                chkvalue += $(this).val() + ",";
            });
            window.location.href="signexcels.html?chkvalue="+chkvalue;
        };

        function del(id){
            layer.confirm('确认要删除吗？',function(index){
                $.post("/admin/deleteNews.html",{id:id},function(data){
                    if(data.is){
                        // layer.alert(data.msg, {skin: 'layui-layer-molv',closeBtn: 0,anim: 4 },function(){
						alert(data.msg);
                            window.location.href = "/admin/newsManage.html?pageNum=${pageinfo.pageNum}";

                    }else{
                        alert(data.msg);
                    }
                },"json");
            });
        }

        function deleteNewsChecked() {
            var msg = "确认删除选中新闻";
            if(confirm(msg)==true){
                var news = [];//定义一个数组
                //利用将name等于ids的多选按钮得到
                $(".child-checkbox").parent().find(":input[class='child-checkbox']:checked").each(function(){
                    //获取id值，因为id单元格在复选框单元格的下一个元素
                    var val = $(this).parent().next().text();
                    //将id值添加到数组
                    news.push(val);
                });
                if (news.length == 0) {
                    alert("你还没有选择任何内容！");
                }
                if (news.length > 0) {
                    // window.location.href="deleteNewsArray.html?newsArray="+news;
                    <%--$.post("/deleteNewsArray.html",{newsArray:news},function (data) {--%>
						<%--if (data > 1){--%>
						    <%--window.location.href="newsManage.html?pageNum=${pageinfo.pageNum}";--%>
						<%--}--%>
                    <%--},"json");--%>
					$.ajax({
						type:"post",
						url:"/admin/deleteNewsArray.html?newsArray="+news,
						dataType:"json",
						success:function (data) {
							alert(data.msg);
							window.location.href="/admin/newsManage.html?pageNum=${pageinfo.pageNum}";
                        }
					})
                }

            }

        }
        // var searchValue = $("#search");
        // var  textvalue =searchValue.val();
        // if (textvalue != ''){
        //     alert(textvalue)
        // }
        //
        // function search(textvalue) {
			// $.post("newsManage.html",{textvalue:textvalue},function () {
        //         alert(textvalue);
        //     },"json")
        // }


	</script>
</body>
</html>