53 lines
1.7 KiB
HTML
53 lines
1.7 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="ru" data-title="Клиенты" data-description="Список клиентов гостиницы">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<link rel="stylesheet" href="style.css">
|
|
</head>
|
|
<body>
|
|
<header></header>
|
|
<main>
|
|
<h1>Клиенты</h1>
|
|
<input type="text" id="searchClient" placeholder="Поиск по имени или телефону">
|
|
<button id="searchClientBtn">Найти</button>
|
|
<table id="clientsTable">
|
|
<thead>
|
|
<tr><th>ID</th><th>Телефон</th><th>Имя</th><th>Действия</th></tr>
|
|
</thead>
|
|
<tbody></tbody>
|
|
</table>
|
|
</main>
|
|
<script src="nav.js"></script>
|
|
<script src="seo.js"></script>
|
|
<script>
|
|
fetch('/api/me').then(r => r.json()).then(data => {
|
|
if (!data.isAdmin) window.location.href = '/login.html';
|
|
});
|
|
|
|
const tbody = document.querySelector('#clientsTable tbody');
|
|
|
|
async function loadClients() {
|
|
const search = document.getElementById('searchClient').value;
|
|
let url = '/api/clients?';
|
|
if (search) url += `search=${encodeURIComponent(search)}`;
|
|
const res = await fetch(url);
|
|
const clients = await res.json();
|
|
tbody.innerHTML = '';
|
|
clients.forEach(c => {
|
|
const tr = document.createElement('tr');
|
|
tr.innerHTML = `
|
|
<td>${c.id}</td>
|
|
<td>${c.phone}</td>
|
|
<td>${c.name || '—'}</td>
|
|
<td><a href="client.html?id=${c.id}">Профиль</a></td>
|
|
`;
|
|
tbody.appendChild(tr);
|
|
});
|
|
}
|
|
|
|
document.getElementById('searchClientBtn').addEventListener('click', loadClients);
|
|
loadClients();
|
|
</script>
|
|
</body>
|
|
</html> |