Update index.html
Browse files2 unmodified lines34566788910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182831415161784858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286192872 unmodified lines<head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Gestión de Comandas</title> <title>Gestión de Comandas en el Bar</title> <style> /* Aquí van tus estilos CSS */ /* Estilos básicos para la interfaz */ body { font-family: Arial, sans-serif; margin: 0; padding: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; height: 100vh; }
#app { width: 100%; max-width: 600px; padding: 20px; text-align: center; }
button { padding: 10px; margin: 10px; cursor: pointer; font-size: 16px; }
.add-button, .category-button, .confirm-button, .back-button, .finalize-button { background-color: #4CAF50; color: white; border: none; border-radius: 5px; }
.add-button:hover, .category-button:hover, .confirm-button:hover, .back-button:hover, .finalize-button:hover { background-color: #45a049; }
.mesa-card { background-color: #f4f4f4; padding: 15px; margin: 10px 0; border-radius: 5px; cursor: pointer; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
.mesa-card h5 { margin: 0; }
.pedidos-container { text-align: left; margin: 10px 0; }
.cantidad-controls { display: flex; align-items: center; justify-content: center; }
.cantidad { width: 30px; text-align: center; margin: 0 10px; }
#qrcode { margin: 20px 0; } </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script></head><body> <div id="app"></div>
<script src="script.js"></script> <!-- Añadir el script QRCode.js justo antes del cierre de </body> --> <script src="https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script> <script> const app = document.getElementById('app'); let mesas = [];
// Generar UI function render() { app.innerHTML = '';
const addButton = document.createElement('button'); addButton.className = 'add-button'; addButton.textContent = '+ Añadir Mesa'; addButton.onclick = () => { let mesaNumero = 1; const mesaInput = document.createElement('div'); mesaInput.className = 'mesa-input'; mesaInput.innerHTML = ` <div class="mesa-controls"> <button id="decreaseMesa" class="control-button">-</button> <span id="mesaNumero" class="mesa-number">${mesaNumero}</span> <button id="increaseMesa" class="control-button">+</button> </div> <button id="confirmMesa" class="confirm-button">Confirmar</button> `; app.innerHTML = ''; app.appendChild(mesaInput);
document.getElementById('decreaseMesa').onclick = () => { if (mesaNumero > 1) mesaNumero--; document.getElementById('mesaNumero').textContent = mesaNumero; };
document.getElementById('increaseMesa').onclick = () => { mesaNumero++; document.getElementById('mesaNumero').textContent = mesaNumero; };
document.getElementById('confirmMesa').onclick = () => { mesas.push({ numero: mesaNumero, pedidos: [] }); render(); }; }; app.appendChild(addButton);
const mesasContainer = document.createElement('div'); mesasContainer.className = 'mesas-container';
mesas.forEach((mesa, index) => { const mesaDiv = document.createElement('div'); mesaDiv.className = 'mesa-card'; mesaDiv.innerHTML = ` <div class="mesa-card-body"> <h5 class="mesa-title">Mesa ${mesa.numero}</h5> </div> `; mesaDiv.style.cursor = 'pointer'; mesaDiv.onclick = () => gestionarMesa(index); mesasContainer.appendChild(mesaDiv); });
app.appendChild(mesasContainer); }
function gestionarMesa(index) { const mesa = mesas[index]; app.innerHTML = '';
const titulo = document.createElement('h1'); titulo.textContent = `Mesa ${mesa.numero}`; titulo.className = 'mesa-heading'; app.appendChild(titulo);
const pedidosContainer = document.createElement('div'); pedidosContainer.className = 'pedidos-container'; pedidosContainer.innerHTML = mesa.pedidos.map(p => `${p.item} (${p.opcion || ''}) x${p.cantidad} - €${(p.precio * p.cantidad).toFixed(2)}`).join('<br>'); app.appendChild(pedidosContainer);
const categorias = [ { nombre: 'Refresco', precio: 1.5, opciones: ['Cola', 'Cola 0', 'Fanta Limón/Naranja', 'Isotónica', 'Nestea'] }, { nombre: 'Cerveza', precio: 2.0, opciones: ['San Miguel', '0 Alcohol', 'Magna', 'Águila', 'Amstel'] }, { nombre: 'Vino', precio: 2.0, opciones: ['Tinto', 'Blanco', 'Moscatel', 'Vermuth'] }, { nombre: 'Copa', precio: 4.5, opciones: ['Larios', 'Whisky', 'Ron'] }, { nombre: 'Pescado Entero', precio: 7.0, opciones: ['Boq.', 'Bacal.', 'Punt.', 'Jurl.', 'Sard.', 'JuPl.'] }, { nombre: 'Pescado Media', precio: 4.5, opciones: ['Boq.', 'Bacal.', 'Punt.', 'Jurl.', 'Sard.', 'JuPl.'] }, { nombre: 'Otros', precio: 8.0, opciones: ['Queso', 'Gambas'] }, ];
categorias.forEach(categoria => { const button = document.createElement('button'); button.className = 'category-button'; button.textContent = `+ ${categoria.nombre} (€${categoria.precio.toFixed(2)})`; button.onclick = () => { const opcionesContainer = document.createElement('div'); opcionesContainer.className = 'opciones-container';
categoria.opciones.forEach(opcion => { const opcionDiv = document.createElement('div'); opcionDiv.className = 'opcion-item'; opcionDiv.innerHTML = ` <span>${opcion}</span> <div class="cantidad-controls" data-opcion="${opcion}" data-categoria="${categoria.nombre}" data-precio="${categoria.precio}"> <button class="control-button decrease">-</button> <span class="cantidad">0</span> <button class="control-button increase">+</button> </div> `; opcionesContainer.appendChild(opcionDiv);
// Añadir los controladores de cantidad const cantidadControl = opcionDiv.querySelector('.cantidad-controls'); const cantidadSpan = cantidadControl.querySelector('.cantidad'); cantidadControl.querySelector('.increase').onclick = () => { let cantidad = parseInt(cantidadSpan.textContent, 10); cantidad++; cantidadSpan.textContent = cantidad; }; cantidadControl.querySelector('.decrease').onclick = () => { let cantidad = parseInt(cantidadSpan.textContent, 10); if (cantidad > 0) { cantidad--; cantidadSpan.textContent = cantidad; } }; });
const confirmarButton = document.createElement('button'); confirmarButton.textContent = '✔ Confirmar'; confirmarButton.className = 'confirm-button'; confirmarButton.onclick = () => { const cantidadControls = document.querySelectorAll('.cantidad-controls'); cantidadControls.forEach(control => { const cantidad = parseInt(control.querySelector('.cantidad').textContent, 10); if (cantidad > 0) { const opcion = control.dataset.opcion; const categoria = control.dataset.categoria; const precio = parseFloat(control.dataset.precio); mesa.pedidos.push({ item: categoria, opcion, cantidad, precio }); } }); gestionarMesa(index); }; opcionesContainer.appendChild(confirmarButton);
app.innerHTML = ''; app.appendChild(opcionesContainer);
const volverButton = document.createElement('button'); volverButton.textContent = '← Volver'; volverButton.className = 'back-button'; volverButton.onclick = () => gestionarMesa(index); app.appendChild(volverButton); }; app.appendChild(button); });
const atrasButton = document.createElement('button'); atrasButton.textContent = '← Atrás'; atrasButton.className = 'back-button'; atrasButton.onclick = () => render(); app.appendChild(atrasButton);
const finalizarButton = document.createElement('button'); finalizarButton.textContent = 'Finalizar'; finalizarButton.className = 'finalize-button'; finalizarButton.onclick = () => { const total = mesa.pedidos.reduce((sum, p) => sum + p.precio * p.cantidad, 0); app.innerHTML = ` <h2>Total de la cuenta: €${total.toFixed(2)}</h2> <button onclick="generarTicket(${index}, ${total})">Generar Ticket</button> `; }; app.appendChild(finalizarButton); }
function generarTicket(index, total) { const mesa = mesas[index]; const ticketContent = `Mesa ${mesa.numero}\n${mesa.pedidos.map(p => `${p.item} (${p.opcion}) x${p.cantidad} - €${(p.precio * p.cantidad).toFixed(2)}`).join('\n')}\nTotal: €${total.toFixed(2)}`;
const qrCodeContainer = document.createElement('div'); qrCodeContainer.id = 'qrcode'; app.appendChild(qrCodeContainer);
const qrCode = new QRCode(qrCodeContainer, { text: ticketContent, width: 256, height: 256, });
const volverButton = document.createElement('button'); volverButton.textContent = '← Volver'; volverButton.className = 'back-button'; volverButton.onclick = () => render(); app.appendChild(volverButton);
// Eliminar la mesa después de generar el ticket mesas.splice(index, 1); }
// Inicializar la aplicación render(); </script></body></html></html>index.html+275-7