159 lines
4.6 KiB
HTML
159 lines
4.6 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Order Information</title>
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
margin: 0;
|
|
padding: 0;
|
|
background-color: #f9f9f9;
|
|
}
|
|
.container {
|
|
width: 80%;
|
|
margin: 20px auto;
|
|
background: #fff;
|
|
padding: 20px;
|
|
border-radius: 8px;
|
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
|
}
|
|
table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
}
|
|
table th, table td {
|
|
border: 1px solid #ddd;
|
|
padding: 8px;
|
|
text-align: left;
|
|
}
|
|
table th {
|
|
background-color: #f2f2f2;
|
|
}
|
|
.pagination {
|
|
margin: 20px 0;
|
|
text-align: center;
|
|
}
|
|
.pagination button {
|
|
margin: 0 5px;
|
|
padding: 10px 20px;
|
|
border: none;
|
|
background-color: #007bff;
|
|
color: white;
|
|
cursor: pointer;
|
|
border-radius: 5px;
|
|
}
|
|
.pagination button[disabled] {
|
|
background-color: #ccc;
|
|
cursor: not-allowed;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h2>Order Information</h2>
|
|
<table id="orderTable">
|
|
<thead>
|
|
<tr>
|
|
<th>Order ID</th>
|
|
<th>Name</th>
|
|
<th>Phone</th>
|
|
<th>Email</th>
|
|
<th>Quantity</th>
|
|
<th>Payment Method</th>
|
|
<th>From Address</th>
|
|
<th>Create Timestamp</th>
|
|
<th>Update Timestamp</th>
|
|
<th>Status</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<!-- Orders will be dynamically inserted here -->
|
|
</tbody>
|
|
</table>
|
|
<div class="pagination">
|
|
<button id="prevPageBtn" disabled>Previous</button>
|
|
<button id="nextPageBtn">Next</button>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const queryParams = JSON.parse(sessionStorage.getItem('queryParams'));
|
|
if (!queryParams) {
|
|
console.error('Query parameters not found.');
|
|
alert('No query parameters found. Please return to the index page.');
|
|
window.location.href = '/index.html';
|
|
}
|
|
queryParams.page = queryParams.page || 1;
|
|
queryParams.pageSize = queryParams.pageSize || 10;
|
|
|
|
// 查询接口
|
|
const apiBaseUrl = 'http://127.0.0.1:5000';
|
|
async function queryOrder() {
|
|
try {
|
|
const response = await fetch(`${apiBaseUrl}/queryOrder`, {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify(queryParams)
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error('Failed to query orders');
|
|
}
|
|
const data = await response.json();
|
|
renderTable(data.orders);
|
|
updatePaginationButtons(data.totalOrders);
|
|
} catch (error) {
|
|
console.error('Network or server error:', error);
|
|
}
|
|
}
|
|
|
|
function renderTable(orders) {
|
|
const tbody = document.querySelector('#orderTable tbody');
|
|
tbody.innerHTML = ''; // 清空表格内容
|
|
orders.forEach(order => {
|
|
const row = `
|
|
<tr>
|
|
<td>${order[0]}</td>
|
|
<td>${order[1]}</td>
|
|
<td>${order[2]}</td>
|
|
<td>${order[3]}</td>
|
|
<td>${order[4]}</td>
|
|
<td>${order[5]}</td>
|
|
<td>${order[6]}</td>
|
|
<td>${order[7]}</td>
|
|
<td>${order[8]}</td>
|
|
<td>${order[9]}</td>
|
|
</tr>
|
|
`;
|
|
tbody.insertAdjacentHTML('beforeend', row);
|
|
});
|
|
}
|
|
|
|
// 更新分页按钮状态
|
|
function updatePaginationButtons(totalOrders) {
|
|
const totalPages = Math.ceil(totalOrders / queryParams.pageSize);
|
|
document.getElementById('prevPageBtn').disabled = queryParams.page <= 1;
|
|
document.getElementById('nextPageBtn').disabled = queryParams.page >= totalPages;
|
|
}
|
|
|
|
// 翻页操作
|
|
document.getElementById('prevPageBtn').addEventListener('click', () => {
|
|
if (queryParams.page > 1) {
|
|
queryParams.page -= 1;
|
|
queryOrder();
|
|
}
|
|
});
|
|
|
|
document.getElementById('nextPageBtn').addEventListener('click', () => {
|
|
queryParams.page += 1;
|
|
queryOrder();
|
|
});
|
|
|
|
// 页面加载时查询第一页
|
|
queryOrder();
|
|
</script>
|
|
</body>
|
|
</html>
|