<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"  %>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <!-- 引入外部CSS文件 -->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/xadmin.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.css">

    <!--[if lt IE 9]>
    <![endif]-->
</head>
<body>
<%-- 注释掉的导航栏代码 --%>
<%--<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">演示</a>
            <a>
              <cite>导航元素</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" "location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>--%>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <!-- 注释掉的搜索表单代码 -->
                    <%--<form id="myform" class="layui-form layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" type="text" autocomplete="off" placeholder="请输入关键字" name="keyword" id="keyword" value="${param.keyword}">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn"  id="search_btn" ><i class="layui-icon">&#xe615;</i></button>
                        </div>
                        <div class="layui-inline layui-show-xs-block x-right">
                            <a class="layui-btn layui-btn-normal" href="${pageContext.request.contextPath}/dorm/findStudent?name=${sessionScope.adminInfo.name}&page=1&size=5"><i class="layui-icon">&#xe669;</i></a>
                        </div>
                    </form>--%>
                </div>
                <xblock>
                    <!-- 添加学生按钮 -->
                    <a href="${pageContext.request.contextPath}/student/addStudent" class="layui-btn layui-btn-normal"><i class="layui-icon">&#xe654;</i>添加</a>
                    <!-- 显示总数据条数 -->
                    <span class="x-right" style="line-height:40px">共有数据：${pageInfo.total} 条</span>
                </xblock>
                <div class="layui-card-body">
                    <!-- 表格展示学生信息 -->
                    <table class="layui-table layui-form">
                        <thead>
                        <tr style="text-align: center">
                            <th style="text-align: center">ID</th>
                            <th style="text-align: center">姓名</th>
                            <th style="text-align: center">性别</th>
                            <th style="text-align: center">学号</th>
                            <th style="text-align: center">班级</th>
                            <th style="text-align: center">联系方式</th>
                            <th style="text-align: center">宿舍号</th>
                            <th style="text-align: center">育人导师</th>
                            <th style="text-align: center">状态</th>
                            <th style="text-align: center">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <%
                            int j = 1; // 初始化行号计数器
                        %>
                        <!-- 遍历学生列表并生成表格行 -->
                        <c:forEach items="${pageInfo.list}" var="student">
                            <tr id="light" style="text-align: center">
                                <td><%=j++%></td> <!-- 显示行号 -->
                                <td>${student.name}</td> <!-- 显示学生姓名 -->
                                <td>${student.sex}</td> <!-- 显示学生性别 -->
                                <td>${student.sno}</td> <!-- 显示学生学号 -->
                                <td>${student.stu_class}</td> <!-- 显示学生班级 -->
                                <td>${student.phone}</td> <!-- 显示学生联系方式 -->
                                <td>${student.dorm_id}</td> <!-- 显示学生宿舍号 -->
                                <td>${student.teacher}</td> <!-- 显示学生育人导师 -->
                                <!-- 根据学生状态显示不同按钮 -->
                                <c:if test="${student.status == 1}">
                                    <td><button class="layui-btn layui-btn-normal layui-btn-sm">已激活</button></td>
                                </c:if>
                                <c:if test="${student.status == 0}">
                                    <td><button class="layui-btn layui-btn-danger layui-btn-sm">禁用</button></td>
                                </c:if>
                                <!-- 编辑按钮 -->
                                <td class="td-manage">
                                    <a title="编辑" href="${pageContext.request.contextPath}/student/editStudent?sno=${student.sno}">
                                        <i class="layui-icon">&#xe642;</i>
                                    </a>
                                </td>
                            </tr>
                        </c:forEach>
                        </tr>
                        </tbody>
                    </table>
                </div>
                <div class="pull-left">
                    <!-- 左侧浮动的分页信息 -->
                    <div class="form-group form-inline">
                        共&nbsp;${pageInfo.pages}&nbsp;页&emsp;当前页：${pageInfo.pageNum}&nbsp;/&nbsp;${pageInfo.pages}&emsp; 每页
                        <!-- 下拉框用于选择每页显示的条数 -->
                        <select class="form-control" id="changePageSize" onchange="changePageSize()">
                            <option value="1">${pageInfo.size}</option>
                            <option value="5">5</option>
                            <option value="10">10</option>
                            <option value="15">15</option>
                            <option value="20">20</option>
                        </select> 条
                    </div>
                </div>

                <c:choose>
                    <!-- 根据总页数和当前页码设置分页按钮的范围 -->
                    <c:when test="${pageInfo.pages < 5}">
                        <!-- 如果总页数小于5，则显示所有页码 -->
                        <c:set var="begin" value="1"></c:set>
                        <c:set var="end" value="${pageInfo.pages}"></c:set>
                    </c:when>
                    <c:when test="${pageInfo.pageNum <= 3}">
                        <!-- 如果当前页码小于等于3，则显示前5页 -->
                        <c:set var="begin" value="1"></c:set>
                        <c:set var="end" value="5"></c:set>
                    </c:when>
                    <c:when test="${pageInfo.pageNum > 3 and pageInfo.pageNum <= pageInfo.pages-2}">
                        <!-- 如果当前页码大于3且小于总页数减2，则显示当前页码前后各两页 -->
                        <c:set var="begin" value="${pageInfo.pageNum - 2}"></c:set>
                        <c:set var="end" value="${pageInfo.pageNum + 2}"></c:set>
                    </c:when>
                    <c:otherwise>
                        <!-- 其他情况，显示最后4页 -->
                        <c:set var="begin" value="${pageInfo.pages - 4}"></c:set>
                        <c:set var="end" value="${pageInfo.pages}"></c:set>
                    </c:otherwise>
                </c:choose>

                <div class="layui-card-body x-right" style="height: min-content">
                    <!-- 右侧浮动的分页导航 -->
                    <div class="page">
                        <div>
                            <!-- 首页链接 -->
                            <a class="next" href="${pageContext.request.contextPath}/dorm/findStudent?name=${sessionScope.adminInfo.name}&page=1&size=${pageInfo.pageSize}&keyword=${param.keyword}">首页</a>
                            <!-- 上一页链接，如果当前页码大于1 -->
                            <c:if test="${pageInfo.pageNum > 1}">
                                <a class="prev" href="${pageContext.request.contextPath}/dorm/findStudent?name=${sessionScope.adminInfo.name}&page=${pageInfo.pageNum-1}&size=${pageInfo.pageSize}&keyword=${param.keyword}">上一页</a>
                            </c:if>
                            <!-- 循环生成页码链接 -->
                            <c:forEach var="i" begin="${begin}" end="${end}" step="1">
                                <!-- 当前页码高亮显示 -->
                                <c:if test="${pageInfo.pageNum == i}">
                                    <span class="current">${i}</span>
                                </c:if>
                                <!-- 非当前页码的普通链接 -->
                                <c:if test="${pageInfo.pageNum != i}">
                                    <a class="num" href="${pageContext.request.contextPath}/dorm/findStudent?name=${sessionScope.adminInfo.name}&page=${i}&size=${pageInfo.pageSize}&keyword=${param.keyword}">${i}</a>
                                </c:if>
                            </c:forEach>
                            <!-- 下一页链接，如果当前页码小于总页数 -->
                            <c:if test="${pageInfo.pageNum < pageInfo.pages}">
                                <a class="next" href="${pageContext.request.contextPath}/dorm/findStudent?name=${sessionScope.adminInfo.name}&page=${pageInfo.pageNum+1}&size=${pageInfo.pageSize}&keyword=${param.keyword}">下一页</a>
                            </c:if>
                            <!-- 尾页链接 -->
                            <a class="next" href="${pageContext.request.contextPath}/dorm/findStudent?name=${sessionScope.adminInfo.name}&page=${pageInfo.pages}&size=${pageInfo.pageSize}&keyword=${param.keyword}">尾页</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


        <script>
            function changePageSize() {
                // 获取下拉框的值
                var pageSize = $("#changePageSize").val();
                // 向服务器发送请求，改变每页显示条数
                location.href = "${pageContext.request.contextPath}/dorm/findStudent?name=${sessionScope.adminInfo.name}&page=1&size=" + pageSize;
            }

            $("#search_btn").click(function () {
                // 获取搜索关键字
                var keyword = $("#keyword").val();
                // 向服务器发送请求，进行搜索
                location.href = "${pageContext.request.contextPath}/dorm/findStudent?name=${sessionScope.adminInfo.name}&page=1&size=5&keyword=" + keyword;
            });

            $("#refresh").click(function () {
                // 重置表单并刷新页面
                $("#myform").reset();
                location.href = "${pageContext.request.contextPath}/dorm/findStudent?name=${sessionScope.adminInfo.name}&page=1&size=5";
            });
        </script>
</body>
</html>
