<%@ page import="java.util.List" %>
<%@ page import="pojo.User" %>
<%@ page import="pojo.ParkingSpot" %>
<%@ page import="pojo.ParkingRecord" %>
<%@ page import="service.ParkingRecordService" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>管理员</title>
    <link rel="stylesheet" href="<%=request.getContextPath()%>/static/css/mainTemplate.css">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/static/css/spot-record.css">

</head>
<%
    session=request.getSession();
    User user=(User)session.getAttribute("user");
    ParkingSpot spot=(ParkingSpot) session.getAttribute("spot");
    List<ParkingRecord>record=(List<ParkingRecord>) session.getAttribute("spot_record");
    request.setCharacterEncoding("UTF-8");
%>
<script>
    function sortRecords() {
        // 获取选定的排序字段和顺序
        var sortField = document.getElementById("sortField").value;
        var sortOrder = document.getElementById("sortOrder").value;

        // 构建带有参数的URL
        var contextPath = "<%=request.getContextPath()%>";
        var url = contextPath + "/main/sort_record?type=" + sortField + "&order=" + sortOrder+"&path="+"/main/user/parking_record.jsp";

        // 导航到新的URL
        window.location.href = url;
    }
</script>
<body>
<div class="top-bar">
    <div class="top-bar-logo">
        <a  href="<%=request.getContextPath()%>/main/user/user-Info.jsp"><img id="logo" src="<%=request.getContextPath()%>/static/images/logo.jpg" alt="" ></a>
        <a id="logo-text" href="#">山东科技大学 作为小组停车场管理系统 <span></span></a>
    </div>
    <div class="top-bar-btn">
    </div>
    <div class="top-bar-right">
        <div class="drop-menu">
            <div class="top-bar-account">
                <span><%=user.getName()%></span>
                <div class="drop"><a href="<%=request.getContextPath()%>/account/exit">退出账户</a></div>
            </div>
        </div>
    </div>
</div>
<div class="container">
    <div class="side-bar">
        <a class="side-bar-button" href="<%=request.getContextPath()%>/main/get_user">用户信息</a>
        <a class="side-bar-button" href="<%=request.getContextPath()%>/main/get_spot">车位情况</a>
        <a class="side-bar-button" href="<%=request.getContextPath()%>/main/get_record">停车记录</a>
        <a class="side-bar-button" href="<%=request.getContextPath()%>/main/get_car_Info">车辆信息</a>
        <a class="side-bar-button" href="<%=request.getContextPath()%>/main/get_IC">IC卡信息</a>
    </div>
    <div class="tasks-content">
        <div class="sort-bar" style="display:flex;">
            <thead>
            <tr>
                <th>
                    排序基准
                    <select id="sortField">
                        <option value="st">开始时间</option>
                        <option value="et">结束时间</option>
                        <option value="fee">停车费用</option>
                        <option value="license">车牌号</option>
                    </select>
                </th>
                <th>
                    排序方式
                    <select id="sortOrder">
                        <option value="asc">升序</option>
                        <option value="desc">降序</option>
                    </select>
                </th>
            </tr>
            </thead>
            <div class="sort" onclick="sortRecords()">确认</div>
        </div>
        <table id="userTable">
            <thead>
            <tr>
                <th>记录号</th>
                <th>开始时间</th>
                <th>结束时间</th>
                <th>车牌号</th>
                <th>消费</th>
            </tr>
            </thead>
            <tbody>
            <%
                int currentPage=1;
                if(request.getParameter("page")!=null){
                    currentPage=Integer.parseInt(request.getParameter("page"));
                }

                for (int i=10*(currentPage-1);i<Math.min(record.size(),10*(currentPage-1)+10);i++) {
                    ParkingRecord re= record.get(i);
            %>
            <tr>
                <td><%= i+1 %></td>
                <td><%= re.getStart_time() %></td>
                <td><%= re.getEnd_time() %></td>
                <td><%= re.getCar_license() %></td>
                <td><%= re.getParking_fee() %></td>
            </tr>
            <% } %>
            </tbody>
        </table>
        <div>
            <div class="pageConfig">
            <a style="margin-left: 32%" href="<%=request.getContextPath()%>/main/user/parking_record.jsp?page=1">首页</a>
            <a href="<%=request.getContextPath()%>/main/user/parking_record.jsp?page=<%=(currentPage > 1) ? (currentPage - 1) : 1 %>">上一页</a>
            <a href="<%=request.getContextPath()%>/main/user/parking_record.jsp?page=<%=currentPage%>">当前:<%=currentPage%>/<%=record.size()/10+1%></a>
            <a href="<%=request.getContextPath()%>/main/user/parking_record.jsp?page=<%= Math.min(currentPage + 1,record.size()/10+1) %>">下一页</a>
            <a href="<%=request.getContextPath()%>/main/user/parking_record.jsp?page=<%=record.size()/10+1%>">尾页</a>
        </div> </div>
    </div>
</div>
</body>
</html>
