Tạo trang web quản lý ky túc xá
- User
Tạo trang web quản lý ky túc xá
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Tạo trang web quản lý ky túc xá
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Tôi sẽ tạo cho bạn một hệ thống quản lý ký túc xá đầy đủ với HTML, CSS và JavaScript. Hệ thống này bao gồm các chức năng quản lý sinh viên, phòng, thanh toán và báo cáo.
<!DOCTYPE html>
<html lang="vi">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hệ Thống Quản Lý Ký Túc Xá</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f5f5f5;
color: #333;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
header {
background-color: #2c3e50;
color: white;
padding: 20px 0;
margin-bottom: 30px;
}
header h1 {
text-align: center;
font-size: 2.5em;
}
nav {
background-color: #34495e;
padding: 0;
margin-bottom: 30px;
border-radius: 5px;
overflow: hidden;
}
nav ul {
list-style: none;
display: flex;
justify-content: center;
}
nav li {
flex: 1;
}
nav a {
display: block;
color: white;
text-decoration: none;
padding: 15px 20px;
text-align: center;
transition: background-color 0.3s;
}
nav a:hover, nav a.active {
background-color: #2c3e50;
}
.content-section {
display: none;
background-color: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.content-section.active {
display: block;
}
h2 {
color: #2c3e50;
margin-bottom: 20px;
font-size: 2em;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #555;
}
input, select, textarea {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
font-size: 16px;
}
button {
background-color: #3498db;
color: white;
padding: 12px 30px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s;
}
button:hover {
background-color: #2980b9;
}
.btn-secondary {
background-color: #95a5a6;
}
.btn-secondary:hover {
background-color: #7f8c8d;
}
.btn-danger {
background-color: #e74c3c;
}
.btn-danger:hover {
background-color: #c0392b;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
padding: 12px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #34495e;
color: white;
font-weight: bold;
}
tr:hover {
background-color: #f5f5f5;
}
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 20px;
margin-bottom: 30px;
}
.stat-card {
background-color: #f8f9fa;
padding: 20px;
border-radius: 10px;
text-align: center;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.stat-card h3 {
color: #34495e;
margin-bottom: 10px;
}
.stat-card p {
font-size: 2em;
font-weight: bold;
color: #3498db;
}
.room-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
gap: 15px;
margin-top: 20px;
}
.room-card {
background-color: #f8f9fa;
padding: 15px;
border-radius: 8px;
text-align: center;
cursor: pointer;
transition: transform 0.2s;
border: 2px solid transparent;
}
.room-card:hover {
transform: translateY(-3px);
box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
.room-card.occupied {
background-color: #e74c3c;
color: white;
}
.room-card.available {
background-color: #27ae60;
color: white;
}
.modal {
display: none;
position: fixed;
z-index: 1000;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.5);
}
.modal-content {
background-color: white;
margin: 10% auto;
padding: 30px;
border-radius: 10px;
width: 80%;
max-width: 500px;
}
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
cursor: pointer;
}
.close:hover {
color: #000;
}
@media (max-width: 768px) {
nav ul {
flex-direction: column;
}
.stats-grid {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<header>
<h1>HỆ THỐNG QUẢN LÝ KÝ TÚC XÁ</h1>
</header>
<div class="container">
<nav>
<ul>
<li><a href="#" class="nav-link active" data-section="dashboard">Tổng quan</a></li>
<li><a href="#" class="nav-link" data-section="students">Sinh viên</a></li>
<li><a href="#" class="nav-link" data-section="rooms">Phòng</a></li>
<li><a href="#" class="nav-link" data-section="payments">Thanh toán</a></li>
<li><a href="#" class="nav-link" data-section="reports">Báo cáo</a></li>
</ul>
</nav>
<!-- Tổng quan -->
<section id="dashboard" class="content-section active">
<h2>Tổng quan</h2>
<div class="stats-grid">
<div class="stat-card">
<h3>Tổng số phòng</h3>
<p id="totalRooms">20</p>
</div>
<div class="stat-card">
<h3>Phòng đã thuê</h3>
<p id="occupiedRooms">0</p>
</div>
<div class="stat-card">
<h3>Phòng trống</h3>
<p id="availableRooms">20</p>
</div>
<div class="stat-card">
<h3>Tổng sinh viên</h3>
<p id="totalStudents">0</p>
</div>
</div>
<h3>Sơ đồ phòng</h3>
<div class="room-grid" id="roomMap"></div>
</section>
<!-- Quản lý sinh viên -->
<section id="students" class="content-section">
<h2>Quản lý sinh viên</h2>
<button onclick="showAddStudentForm()">Thêm sinh viên mới</button>
<table id="studentsTable">
<thead>
<tr>
<th>MSSV</th>
<th>Họ tên</th>
<th>Phòng</th>
<th>Số điện thoại</th>
<th>Email</th>
<th>Hành động</th>
</tr>
</thead>
<tbody id="studentsTableBody">
</tbody>
</table>
</section>
<!-- Quản lý phòng -->
<section id="rooms" class="content-section">
<h2>Quản lý phòng</h2>
<table id="roomsTable">
<thead>
<tr>
<th>Số phòng</th>
<th>Tầng</th>
<th>Loại phòng</th>
<th>Sức chứa</th>
<th>Đã ở</th>
<th>Trạng thái</th>
<th>Giá thuê/tháng</th>
</tr>
</thead>
<tbody id="roomsTableBody">
</tbody>
</table>
</section>
<!-- Quản lý thanh toán -->
<section id="payments" class="content-section">
<h2>Quản lý thanh toán</h2>
<button onclick="showAddPaymentForm()">Thêm thanh toán</button>
<table id="paymentsTable">
<thead>
<tr>
<th>Mã thanh toán</th>
<th>MSSV</th>
<th>Họ tên</th>
<th>Phòng</th>
<th>Số tiền</th>
<th>Ngày thanh toán</th>
<th>Trạng thái</th>
</tr>
</thead>
<tbody id="paymentsTableBody">
</tbody>
</table>
</section>
<!-- Báo cáo -->
<section id="reports" class="content-section">
<h2>Báo cáo thống kê</h2>
<div class="stats-grid">
<div class="stat-card">
<h3>Doanh thu tháng này</h3>
<p id="monthlyRevenue">0 VNĐ</p>
</div>
<div class="stat-card">
<h3>Sinh viên nợ phí</h3>
<p id="unpaidStudents">0</p>
</div>
<div class="stat-card">
<h3>Tỷ lệ lấp đầy</h3>
<p id="occupancyRate">0%</p>
</div>
</div>
<h3>Danh sách sinh viên chưa thanh toán</h3>
<table id="unpaidTable">
<thead>
<tr>
<th>MSSV</th>
<th>Họ tên</th>
<th>Phòng</th>
<th>Số tiền nợ</th>
<th>Số tháng nợ</th>
</tr>
</thead>
<tbody id="unpaidTableBody">
</tbody>
</table>
</section>
</div>
<!-- Modal thêm sinh viên -->
<div id="studentModal" class="modal">
<div class="modal-content">
<span class="close" onclick="closeModal('studentModal')">×</span>
<h2>Thêm sinh viên mới</h2>
<form id="studentForm">
<div class="form-group">
<label>MSSV:</label>
<input type="text" id="studentId" required>
</div>
<div class="form-group">
<label>Họ tên:</label>
<input type="text" id="studentName" required>
</div>
<div class="form-group">
<label>Số điện thoại:</label>
<input type="tel" id="studentPhone" required>
</div>
<div class="form-group">
<label>Email:</label>
<input type="email" id="studentEmail" required>
</div>
<div class="form-group">
<label>Phòng:</label>
<select id="studentRoom" required>
<option value="">Chọn phòng</option>
</select>
</div>
<button type="submit">Lưu</button>
<button type="button" class="btn-secondary" onclick="closeModal('studentModal')">Hủy</button>
</form>
</div>
</div>
<!-- Modal thêm thanh toán -->
<div id="paymentModal" class="modal">
<div class="modal-content">
<span class="close" onclick="closeModal('paymentModal')">×</span>
<h2>Thêm thanh toán</h2>
<form id="paymentForm">
<div class="form-group">
<label>Sinh viên:</label>
<select id="paymentStudent" required>
<option value="">Chọn sinh viên</option>
</select>
</div>
<div class="form-group">
<label>Số tiền:</label>
<input type="number" id="paymentAmount" required>
</div>
<div class="form-group">
<label>Ngày thanh toán:</label>
<input type="date" id="paymentDate" required>
</div>
<button type="submit">Lưu</button>
<button type="button" class="btn-secondary" onclick="closeModal('paymentModal')">Hủy</button>
</form>
</div>
</div>
<script>
// Dữ liệu mẫu
let students = [];
let payments = [];
let rooms = [];
// Khởi tạo phòng
function initializeRooms() {
for (let floor = 1; floor <= 4; floor++) {
for (let room = 1; room <= 5; room++) {
rooms.push({
id: `${floor}0${room}`,
floor: floor,
type: room <= 3 ? '4 người' : '2 người',
capacity: room <= 3 ? 4 : 2,
occupied: 0,
price: room <= 3 ? 800000 : 1200000
});
}
}
updateRoomDisplay();
}
// Chuyển đổi giữa các tab
document.querySelectorAll('.nav-link').forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
document.querySelectorAll('.nav-link').forEach(l => l.classList.remove('active'));
document.querySelectorAll('.content-section').forEach(s => s.classList.remove('active'));
this.classList.add('active');
const sectionId = this.getAttribute('data-section');
document.getElementById(sectionId).classList.add('active');
updateDashboard();
});
});
// Cập nhật dashboard
function updateDashboard() {
const occupiedCount = rooms.filter(r => r.occupied > 0).length;
const availableCount = rooms.length - occupiedCount;
document.getElementById('totalRooms').textContent = rooms.length;
document.getElementById('occupiedRooms').textContent = occupiedCount;
document.getElementById('availableRooms').textContent = availableCount;
document.getElementById('totalStudents').textContent = students.length;
// Cập nhật sơ đồ phòng
const roomMap = document.getElementById('roomMap');
roomMap.innerHTML = '';
rooms.forEach(room => {
const roomCard = document.createElement('div');
roomCard.className = `room-card ${room.occupied > 0 ? 'occupied' : 'available'}`;
roomCard.innerHTML = `
<h4>Phòng ${room.id}</h4>
<p>${room.occupied}/${room.capacity}</p>
`;
roomMap.appendChild(roomCard);
});
// Cập nhật báo cáo
updateReports();
}
// Hiển thị danh sách phòng
function updateRoomDisplay() {
const tbody = document.getElementById('roomsTableBody');
tbody.innerHTML = '';
rooms.forEach(room => {
const tr = document.createElement('tr');
tr.innerHTML = `
<td>${room.id}</td>
<td>Tầng ${room.floor}</td>
<td>${room.type}</td>
<td>${room.capacity}</td>
<td>${room.occupied}</td>
<td>${room.occupied < room.capacity ? 'Còn chỗ' : 'Đầy'}</td>
<td>${room.price.toLocaleString()} VNĐ</td>
`;
tbody.appendChild(tr);
});
}
// Hiển thị form thêm sinh viên
function showAddStudentForm() {
const select = document.getElementById('studentRoom');
select.innerHTML = '<option value="">Chọn phòng</option>';
rooms.filter(r => r.occupied < r.capacity).forEach(room => {
const option = document.createElement('option');
option.value = room.id;
option.textContent = `Phòng ${room.id} (${room.occupied}/${room.capacity})`;
select.appendChild(option);
});
document.getElementById('studentModal').style.display = 'block';
}
// Xử lý thêm sinh viên
document.getElementById('studentForm').addEventListener('submit', function(e) {
e.preventDefault();
const student = {
id: document.getElementById('studentId').value,
name: document.getElementById('studentName').value,
phone: document.getElementById('studentPhone').value,
email: document.getElementById('studentEmail').value,
room: document.getElementById('studentRoom').value
};
students.push(student);
// Cập nhật số lượng người trong phòng
const room = rooms.find(r => r.id === student.room);
if (room) {
room.occupied++;
}
updateStudentDisplay();
updateRoomDisplay();
updateDashboard();
closeModal('studentModal');
this.reset();
});
// Hiển thị danh sách sinh viên
function updateStudentDisplay() {
const tbody = document.getElementById('studentsTableBody');
tbody.innerHTML = '';
students.forEach(student => {
const tr = document.createElement('tr');
tr.innerHTML = `
<td>${student.id}</td>
<td>${student.name}</td>
<td>${student.room}</td>
<td>${student.phone}</td>
<td>${student.email}</td>
<td>
<button class="btn-danger" onclick="removeStudent('${student.id}')">Xóa</button>
</td>
`;
tbody.appendChild(tr);
});
}
// Xóa sinh viên
function removeStudent(studentId) {
const student = students.find(s => s.id === studentId);
if (student && confirm('Bạn có chắc muốn xóa sinh viên này?')) {
const room = rooms.find(r => r.id === student.room);
if (room) {
room.occupied--;
}
students = students.filter(s => s.id !== studentId);
updateStudentDisplay();
updateRoomDisplay();
updateDashboard();
}
}
// Hiển thị form thêm thanh toán
function showAddPaymentForm() {
const select = document.getElementById('paymentStudent');
select.innerHTML = '<option value="">Chọn sinh viên</option>';
students.forEach(student => {
const option = document.createElement('option');
option.value = student.id;
option.textContent = `${student.id} - ${student.name}`;
select.appendChild(option);
});
document.getElementById('paymentDate').valueAsDate = new Date();
document.getElementById('paymentModal').style.display = 'block';
}
// Xử lý thêm thanh toán
document.getElementById('paymentForm').addEventListener('submit', function(e) {
e.preventDefault();
const studentId = document.getElementById('paymentStudent').value;
const student = students.find(s => s.id === studentId);
if (student) {
const payment = {
id: 'PAY' + Date.now(),
studentId: studentId,
studentName: student.name,
room: student.room,
amount: parseInt(document.getElementById('paymentAmount').value),
date: document.getElementById('paymentDate').value,
status: 'Đã thanh toán'
};
payments.push(payment);
updatePaymentDisplay();
updateReports();
closeModal('paymentModal');
this.reset();
}
});
// Hiển thị danh sách thanh toán
function updatePaymentDisplay() {
const tbody = document.getElementById('paymentsTableBody');
tbody.innerHTML = '';
payments.forEach(payment => {
const tr = document.createElement('tr');
tr.innerHTML = `
<td>${payment.id}</td>
<td>${payment.studentId}</td>
<td>${payment.studentName}</td>
<td>${payment.room}</td>
<td>${payment.amount.toLocaleString()} VNĐ</td>
<td>${payment.date}</td>
<td>${payment.status}</td>
`;
tbody.appendChild(tr);
});
}
// Cập nhật báo cáo
function updateReports() {
// Tính doanh thu tháng này
const currentMonth = new Date().getMonth();
const currentYear = new Date().getFullYear();
const monthlyRevenue = payments
.filter(p => {
const pDate = new Date(p.date);
return pDate.getMonth() === currentMonth && pDate.getFullYear() === currentYear;
})
.reduce((sum, p) => sum + p.amount, 0);
document.getElementById('monthlyRevenue').textContent = monthlyRevenue.toLocaleString() + ' VNĐ';
// Tính tỷ lệ lấp đầy
const totalCapacity = rooms.reduce((sum, r) => sum + r.capacity, 0);
const totalOccupied = rooms.reduce((sum, r) => sum + r.occupied, 0);
const occupancyRate = totalCapacity > 0 ? (totalOccupied / totalCapacity * 100).toFixed(1) : 0;
document.getElementById('occupancyRate').textContent = occupancyRate + '%';
}
// Đóng modal
function closeModal(modalId) {
document.getElementById(modalId).style.display = 'none';
}
// Đóng modal khi click bên ngoài
window.onclick = function(event) {
if (event.target.classList.contains('modal')) {
event.target.style.display = 'none';
}
}
// Khởi tạo
initializeRooms();
updateDashboard();
</script>
</body>
</html>
Hệ thống quản lý ký túc xá này bao gồm các tính năng:
1. Tổng quan (Dashboard):
2. Quản lý sinh viên:
3. Quản lý phòng:
4. Quản lý thanh toán:
5. Báo cáo thống kê:
Tính năng nổi bật:
Bạn có thể sử dụng và tùy chỉnh hệ thống này theo nhu cầu cụ thể của ký túc xá. Nếu cần thêm tính năng như xuất báo cáo Excel, tìm kiếm, hoặc tích hợp database, hãy cho tôi biết!