Upload 3 files
Browse files- Comandero.html +31 -0
- script.js +171 -0
- style.css +51 -28
Comandero.html
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<link rel="stylesheet" type="text/css" href="style.css">
|
| 7 |
+
<title>Gestión de Comandas</title>
|
| 8 |
+
<style>
|
| 9 |
+
body {
|
| 10 |
+
font-family: Arial, sans-serif;
|
| 11 |
+
margin: 20px;
|
| 12 |
+
}
|
| 13 |
+
button {
|
| 14 |
+
margin: 5px;
|
| 15 |
+
padding: 10px;
|
| 16 |
+
background-color: #007BFF;
|
| 17 |
+
color: white;
|
| 18 |
+
border: none;
|
| 19 |
+
border-radius: 5px;
|
| 20 |
+
cursor: pointer;
|
| 21 |
+
}
|
| 22 |
+
button:hover {
|
| 23 |
+
background-color: #0056b3;
|
| 24 |
+
}
|
| 25 |
+
</style>
|
| 26 |
+
</head>
|
| 27 |
+
<body>
|
| 28 |
+
<div id="app"></div>
|
| 29 |
+
<script src="script.js"></script>
|
| 30 |
+
</body>
|
| 31 |
+
</html>
|
script.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Script para gestión de comandas en un bar
|
| 2 |
+
|
| 3 |
+
const app = document.getElementById('app');
|
| 4 |
+
|
| 5 |
+
// Estado global
|
| 6 |
+
let mesas = [];
|
| 7 |
+
|
| 8 |
+
// Generar UI
|
| 9 |
+
function render() {
|
| 10 |
+
app.innerHTML = '';
|
| 11 |
+
|
| 12 |
+
const addButton = document.createElement('button');
|
| 13 |
+
addButton.className = 'add-button';
|
| 14 |
+
addButton.textContent = '+ Añadir Mesa';
|
| 15 |
+
addButton.onclick = () => {
|
| 16 |
+
let mesaNumero = 1;
|
| 17 |
+
const mesaInput = document.createElement('div');
|
| 18 |
+
mesaInput.className = 'mesa-input';
|
| 19 |
+
mesaInput.innerHTML = `
|
| 20 |
+
<div class="mesa-controls">
|
| 21 |
+
<button id="decreaseMesa" class="control-button">-</button>
|
| 22 |
+
<span id="mesaNumero" class="mesa-number">${mesaNumero}</span>
|
| 23 |
+
<button id="increaseMesa" class="control-button">+</button>
|
| 24 |
+
</div>
|
| 25 |
+
<button id="confirmMesa" class="confirm-button">Confirmar</button>
|
| 26 |
+
`;
|
| 27 |
+
app.innerHTML = '';
|
| 28 |
+
app.appendChild(mesaInput);
|
| 29 |
+
|
| 30 |
+
document.getElementById('decreaseMesa').onclick = () => {
|
| 31 |
+
if (mesaNumero > 1) mesaNumero--;
|
| 32 |
+
document.getElementById('mesaNumero').textContent = mesaNumero;
|
| 33 |
+
};
|
| 34 |
+
|
| 35 |
+
document.getElementById('increaseMesa').onclick = () => {
|
| 36 |
+
mesaNumero++;
|
| 37 |
+
document.getElementById('mesaNumero').textContent = mesaNumero;
|
| 38 |
+
};
|
| 39 |
+
|
| 40 |
+
document.getElementById('confirmMesa').onclick = () => {
|
| 41 |
+
mesas.push({ numero: mesaNumero, pedidos: [] });
|
| 42 |
+
render();
|
| 43 |
+
};
|
| 44 |
+
};
|
| 45 |
+
app.appendChild(addButton);
|
| 46 |
+
|
| 47 |
+
const mesasContainer = document.createElement('div');
|
| 48 |
+
mesasContainer.className = 'mesas-container';
|
| 49 |
+
|
| 50 |
+
mesas.forEach((mesa, index) => {
|
| 51 |
+
const mesaDiv = document.createElement('div');
|
| 52 |
+
mesaDiv.className = 'mesa-card';
|
| 53 |
+
mesaDiv.innerHTML = `
|
| 54 |
+
<div class="mesa-card-body">
|
| 55 |
+
<h5 class="mesa-title">Mesa ${mesa.numero}</h5>
|
| 56 |
+
</div>
|
| 57 |
+
`;
|
| 58 |
+
mesaDiv.style.cursor = 'pointer';
|
| 59 |
+
mesaDiv.onclick = () => gestionarMesa(index);
|
| 60 |
+
mesasContainer.appendChild(mesaDiv);
|
| 61 |
+
});
|
| 62 |
+
|
| 63 |
+
app.appendChild(mesasContainer);
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
function gestionarMesa(index) {
|
| 67 |
+
const mesa = mesas[index];
|
| 68 |
+
app.innerHTML = '';
|
| 69 |
+
|
| 70 |
+
const titulo = document.createElement('h1');
|
| 71 |
+
titulo.textContent = `Mesa ${mesa.numero}`;
|
| 72 |
+
titulo.className = 'mesa-heading';
|
| 73 |
+
app.appendChild(titulo);
|
| 74 |
+
|
| 75 |
+
const pedidosContainer = document.createElement('div');
|
| 76 |
+
pedidosContainer.className = 'pedidos-container';
|
| 77 |
+
pedidosContainer.innerHTML = mesa.pedidos.map(p => `${p.item} (${p.opcion || ''}) x${p.cantidad} - €${(p.precio * p.cantidad).toFixed(2)}`).join('<br>');
|
| 78 |
+
app.appendChild(pedidosContainer);
|
| 79 |
+
|
| 80 |
+
const categorias = [
|
| 81 |
+
{ nombre: 'Refresco', precio: 1.5, opciones: ['Cola', 'Cola 0', 'Fanta Limón/Naranja', 'Isotónica', 'Nestea'] },
|
| 82 |
+
{ nombre: 'Cerveza', precio: 2.0, opciones: ['San Miguel', '0 Alcohol', 'Magna', 'Águila', 'Amstel'] },
|
| 83 |
+
{ nombre: 'Vino', precio: 2.0, opciones: ['Tinto', 'Blanco', 'Moscatel', 'Vermuth'] },
|
| 84 |
+
{ nombre: 'Copa', precio: 4.5, opciones: ['Larios', 'Whisky', 'Ron'] },
|
| 85 |
+
{ nombre: 'Pescado Entero', precio: 7.0, opciones: ['Boq.', 'Bacal.', 'Punt.', 'Jurl.', 'Sard.', 'JuPl.'] },
|
| 86 |
+
{ nombre: 'Pescado Media', precio: 4.5, opciones: ['Boq.', 'Bacal.', 'Punt.', 'Jurl.', 'Sard.', 'JuPl.'] },
|
| 87 |
+
{ nombre: 'Otros', precio: 8.0, opciones: ['Queso', 'Gambas'] },
|
| 88 |
+
];
|
| 89 |
+
|
| 90 |
+
categorias.forEach(categoria => {
|
| 91 |
+
const button = document.createElement('button');
|
| 92 |
+
button.className = 'category-button';
|
| 93 |
+
button.textContent = `+ ${categoria.nombre} (€${categoria.precio.toFixed(2)})`;
|
| 94 |
+
button.onclick = () => {
|
| 95 |
+
const opcionesContainer = document.createElement('div');
|
| 96 |
+
opcionesContainer.className = 'opciones-container';
|
| 97 |
+
|
| 98 |
+
categoria.opciones.forEach(opcion => {
|
| 99 |
+
const opcionDiv = document.createElement('div');
|
| 100 |
+
opcionDiv.className = 'opcion-item';
|
| 101 |
+
opcionDiv.innerHTML = `
|
| 102 |
+
<span>${opcion}</span>
|
| 103 |
+
<div class="cantidad-controls" data-opcion="${opcion}">
|
| 104 |
+
<button class="control-button decrease">-</button>
|
| 105 |
+
<span class="cantidad">0</span>
|
| 106 |
+
<button class="control-button increase">+</button>
|
| 107 |
+
<button class="confirm-button confirm">✔</button>
|
| 108 |
+
</div>
|
| 109 |
+
`;
|
| 110 |
+
opcionesContainer.appendChild(opcionDiv);
|
| 111 |
+
});
|
| 112 |
+
|
| 113 |
+
app.innerHTML = '';
|
| 114 |
+
app.appendChild(opcionesContainer);
|
| 115 |
+
|
| 116 |
+
// Delegar eventos en el contenedor principal
|
| 117 |
+
opcionesContainer.onclick = (event) => {
|
| 118 |
+
const target = event.target;
|
| 119 |
+
const cantidadSpan = target.closest('.cantidad-controls')?.querySelector('.cantidad');
|
| 120 |
+
const opcion = target.closest('.cantidad-controls')?.dataset.opcion;
|
| 121 |
+
|
| 122 |
+
if (target.classList.contains('increase')) {
|
| 123 |
+
let cantidad = parseInt(cantidadSpan.textContent, 10);
|
| 124 |
+
cantidad++;
|
| 125 |
+
cantidadSpan.textContent = cantidad;
|
| 126 |
+
} else if (target.classList.contains('decrease')) {
|
| 127 |
+
let cantidad = parseInt(cantidadSpan.textContent, 10);
|
| 128 |
+
if (cantidad > 0) cantidad--;
|
| 129 |
+
cantidadSpan.textContent = cantidad;
|
| 130 |
+
} else if (target.classList.contains('confirm')) {
|
| 131 |
+
const cantidad = parseInt(cantidadSpan.textContent, 10);
|
| 132 |
+
if (cantidad > 0) {
|
| 133 |
+
mesa.pedidos.push({ item: categoria.nombre, opcion, cantidad, precio: categoria.precio });
|
| 134 |
+
render();
|
| 135 |
+
gestionarMesa(index);
|
| 136 |
+
} else {
|
| 137 |
+
alert('Selecciona una cantidad válida.');
|
| 138 |
+
}
|
| 139 |
+
}
|
| 140 |
+
};
|
| 141 |
+
|
| 142 |
+
const volverButton = document.createElement('button');
|
| 143 |
+
volverButton.textContent = '← Volver';
|
| 144 |
+
volverButton.className = 'back-button';
|
| 145 |
+
volverButton.onclick = () => gestionarMesa(index);
|
| 146 |
+
app.appendChild(volverButton);
|
| 147 |
+
};
|
| 148 |
+
app.appendChild(button);
|
| 149 |
+
});
|
| 150 |
+
|
| 151 |
+
const atrasButton = document.createElement('button');
|
| 152 |
+
atrasButton.textContent = '← Atrás';
|
| 153 |
+
atrasButton.className = 'back-button';
|
| 154 |
+
atrasButton.onclick = () => render();
|
| 155 |
+
app.appendChild(atrasButton);
|
| 156 |
+
|
| 157 |
+
const finalizarButton = document.createElement('button');
|
| 158 |
+
finalizarButton.textContent = 'Finalizar';
|
| 159 |
+
finalizarButton.className = 'finalize-button';
|
| 160 |
+
finalizarButton.onclick = () => {
|
| 161 |
+
const total = mesa.pedidos.reduce((sum, p) => sum + p.precio * p.cantidad, 0);
|
| 162 |
+
alert(`Total de la cuenta: €${total.toFixed(2)}`);
|
| 163 |
+
console.log({ fecha: new Date().toISOString(), mesa: mesa.numero, pedidos: mesa.pedidos });
|
| 164 |
+
mesas.splice(index, 1);
|
| 165 |
+
render();
|
| 166 |
+
};
|
| 167 |
+
app.appendChild(finalizarButton);
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
// Inicializar la aplicación
|
| 171 |
+
render();
|
style.css
CHANGED
|
@@ -1,28 +1,51 @@
|
|
| 1 |
-
body {
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
}
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
body {
|
| 2 |
+
font-family: Arial, sans-serif;
|
| 3 |
+
margin: 0;
|
| 4 |
+
padding: 0;
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
#app {
|
| 8 |
+
padding: 20px;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
.add-button, .control-button, .confirm-button, .category-button, .opcion-button, .back-button, .finalize-button {
|
| 12 |
+
display: block;
|
| 13 |
+
margin: 10px auto;
|
| 14 |
+
padding: 10px 20px;
|
| 15 |
+
font-size: 16px;
|
| 16 |
+
cursor: pointer;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
.mesa-input, .mesas-container, .mesa-controls, .pedidos-container, .opciones-container {
|
| 20 |
+
margin-bottom: 20px;
|
| 21 |
+
text-align: center;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
.mesas-container {
|
| 25 |
+
display: grid;
|
| 26 |
+
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
|
| 27 |
+
gap: 15px;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.mesa-card {
|
| 31 |
+
border: 1px solid #ccc;
|
| 32 |
+
border-radius: 8px;
|
| 33 |
+
padding: 15px;
|
| 34 |
+
background: #f9f9f9;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.mesa-title {
|
| 38 |
+
margin: 0;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
.mesa-heading {
|
| 42 |
+
font-size: 24px;
|
| 43 |
+
margin-bottom: 20px;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
.opciones-container {
|
| 47 |
+
display: flex;
|
| 48 |
+
flex-wrap: wrap;
|
| 49 |
+
gap: 10px;
|
| 50 |
+
justify-content: center;
|
| 51 |
+
}
|