/
ring0
/
RestaurantApp
Обзор
Документация
Войти
/
ring0
/
RestaurantApp
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
static/guest.html
172 строки
8 KB
ring0
feat: guest.html
28 май 2026, 20:54
Верифицирован
28 май 2026, 20:54
5b242e2
Код
Авторство
О чём код?
<!DOCTYPE html> <html lang="ru"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Бронирование столиков</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: Arial, sans-serif; background: #f5f5f5; padding: 20px; } .container { max-width: 1200px; margin: 0 auto; } h1 { color: #333; margin-bottom: 20px; } .filters { background: white; padding: 20px; border-radius: 5px; margin-bottom: 20px; } .filters input, .filters button { padding: 10px; margin-right: 10px; border: 1px solid #ddd; border-radius: 3px; } .filters button { background: #4CAF50; color: white; cursor: pointer; border: none; } .filters button:hover { background: #45a049; } .tables-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 20px; } .table-card { background: white; padding: 20px; border-radius: 5px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); } .table-card h3 { margin-bottom: 10px; color: #333; } .table-card p { color: #666; margin-bottom: 10px; } .status { padding: 5px 10px; border-radius: 3px; font-size: 12px; } .available { background: #4CAF50; color: white; } .reserved { background: #FFC107; color: #333; } .occupied { background: #F44336; color: white; } .book-btn { background: #2196F3; color: white; border: none; padding: 10px 15px; border-radius: 3px; cursor: pointer; } .book-btn:hover { background: #0b7dda; } .modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); } .modal-content { background: white; padding: 20px; border-radius: 5px; max-width: 400px; margin: 100px auto; } .modal input { width: 100%; padding: 10px; margin-bottom: 10px; border: 1px solid #ddd; border-radius: 3px; } .modal button { background: #4CAF50; color: white; border: none; padding: 10px 15px; border-radius: 3px; cursor: pointer; } .modal button.cancel { background: #F44336; margin-right: 10px; } .error { color: #F44336; margin-bottom: 10px; } .success { color: #4CAF50; margin-bottom: 10px; } </style> </head> <body> <div class="container"> <h1>Бронирование столиков в ресторане</h1> <div class="filters"> <input type="date" id="filterDate" /> <input type="time" id="filterTime" /> <button onclick="loadTables()">Найти столики</button> <button onclick="resetFilters()">Сбросить</button> </div> <h2>Доступные столики</h2> <div class="tables-grid" id="tablesGrid"></div> <div class="modal" id="bookingModal"> <div class="modal-content"> <h2>Забронировать столик</h2> <div id="modalError" class="error"></div> <input type="text" id="customerName" placeholder="Ваше имя" /> <input type="date" id="reservationDate" /> <input type="time" id="startTime" placeholder="Время начала" /> <input type="time" id="endTime" placeholder="Время окончания" /> <input type="number" id="guestsCount" placeholder="Количество гостей" /> <button onclick="createBooking()">Забронировать</button> <button class="cancel" onclick="closeModal()">Отмена</button> </div> </div> </div> <script> let currentTableId = null; let currentTableCapacity = null; async function loadTables() { const date = document.getElementById('filterDate').value; const time = document.getElementById('filterTime').value; let url = '/api/tables'; if (date && time) { url += `?date=${date}&time=${time}`; } try { const response = await fetch(url); const tables = await response.json(); displayTables(tables); } catch (error) { console.error('Ошибка загрузки столиков:', error); } } function displayTables(tables) { const grid = document.getElementById('tablesGrid'); grid.innerHTML = ''; tables.forEach(table => { const card = document.createElement('div'); card.className = 'table-card'; card.innerHTML = ` <h3>Столик №${table.number}</h3> <p>Вместимость: ${table.capacity} человек</p> <p>Статус: <span class="status ${table.status}">${table.status}</span></p> <button class="book-btn" onclick="openModal(${table.id}, ${table.capacity})">Забронировать</button> `; grid.appendChild(card); }); } function openModal(tableId, capacity) { currentTableId = tableId; currentTableCapacity = capacity; document.getElementById('bookingModal').style.display = 'block'; document.getElementById('modalError').textContent = ''; } function closeModal() { document.getElementById('bookingModal').style.display = 'none'; currentTableId = null; } async function createBooking() { const customerName = document.getElementById('customerName').value; const reservationDate = document.getElementById('reservationDate').value; const startTime = document.getElementById('startTime').value; const endTime = document.getElementById('endTime').value; const guestsCount = parseInt(document.getElementById('guestsCount').value); if (!customerName || !reservationDate || !startTime || !endTime || !guestsCount) { document.getElementById('modalError').textContent = 'Все поля обязательны для заполнения'; return; } if (guestsCount > currentTableCapacity) { document.getElementById('modalError').textContent = `Количество гостей превышает вместимость столика (${currentTableCapacity})`; return; } const bookingData = { table_id: currentTableId, customer_name: customerName, reservation_date: reservationDate, start_time: startTime, end_time: endTime, guests_count: guestsCount }; try { const response = await fetch('/api/reservations', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(bookingData) }); const result = await response.json(); if (response.ok) { alert('Бронирование успешно создано!'); closeModal(); loadTables(); } else { document.getElementById('modalError').textContent = result.error; } } catch (error) { document.getElementById('modalError').textContent = 'Ошибка при создании бронирования'; } } function resetFilters() { document.getElementById('filterDate').value = ''; document.getElementById('filterTime').value = ''; loadTables(); } // Загрузка столиков при открытии страницы loadTables(); </script> </body> </html>