Update script.js
Browse files
script.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
| 1 |
const app = document.getElementById('app');
|
| 2 |
let mesas = [];
|
| 3 |
|
| 4 |
-
//
|
| 5 |
function render() {
|
| 6 |
app.innerHTML = '';
|
| 7 |
|
| 8 |
const addButton = document.createElement('button');
|
| 9 |
-
addButton.className = 'btn btn-success';
|
| 10 |
addButton.textContent = '+ Añadir Mesa';
|
| 11 |
addButton.onclick = () => {
|
| 12 |
let mesaNumero = 1;
|
|
@@ -14,9 +14,9 @@ function render() {
|
|
| 14 |
mesaInput.className = 'mesa-input';
|
| 15 |
mesaInput.innerHTML = `
|
| 16 |
<div class="mesa-controls">
|
| 17 |
-
<button id="decreaseMesa" class="btn btn-outline-
|
| 18 |
<span id="mesaNumero" class="mesa-number">${mesaNumero}</span>
|
| 19 |
-
<button id="increaseMesa" class="btn btn-outline-
|
| 20 |
</div>
|
| 21 |
<button id="confirmMesa" class="btn btn-primary">Confirmar</button>
|
| 22 |
`;
|
|
@@ -47,10 +47,8 @@ function render() {
|
|
| 47 |
const mesaDiv = document.createElement('div');
|
| 48 |
mesaDiv.className = 'mesa-card';
|
| 49 |
mesaDiv.innerHTML = `
|
| 50 |
-
<div class="card">
|
| 51 |
-
<
|
| 52 |
-
<h5 class="card-title">Mesa ${mesa.numero}</h5>
|
| 53 |
-
</div>
|
| 54 |
</div>
|
| 55 |
`;
|
| 56 |
mesaDiv.style.cursor = 'pointer';
|
|
@@ -61,18 +59,17 @@ function render() {
|
|
| 61 |
app.appendChild(mesasContainer);
|
| 62 |
}
|
| 63 |
|
| 64 |
-
// Función para gestionar los pedidos de una mesa
|
| 65 |
function gestionarMesa(index) {
|
| 66 |
const mesa = mesas[index];
|
| 67 |
app.innerHTML = '';
|
| 68 |
|
| 69 |
const titulo = document.createElement('h1');
|
| 70 |
titulo.textContent = `Mesa ${mesa.numero}`;
|
| 71 |
-
titulo.className = '
|
| 72 |
app.appendChild(titulo);
|
| 73 |
|
| 74 |
const pedidosContainer = document.createElement('div');
|
| 75 |
-
pedidosContainer.className = 'pedidos-container
|
| 76 |
pedidosContainer.innerHTML = mesa.pedidos.map(p => `${p.item} (${p.opcion || ''}) x${p.cantidad} - €${(p.precio * p.cantidad).toFixed(2)}`).join('<br>');
|
| 77 |
app.appendChild(pedidosContainer);
|
| 78 |
|
|
@@ -106,28 +103,11 @@ function gestionarMesa(index) {
|
|
| 106 |
</div>
|
| 107 |
`;
|
| 108 |
opcionesContainer.appendChild(opcionDiv);
|
| 109 |
-
|
| 110 |
-
const cantidadControl = opcionDiv.querySelector('.cantidad-controls');
|
| 111 |
-
const cantidadSpan = cantidadControl.querySelector('.cantidad');
|
| 112 |
-
|
| 113 |
-
cantidadControl.querySelector('.increase').onclick = () => {
|
| 114 |
-
let cantidad = parseInt(cantidadSpan.textContent, 10);
|
| 115 |
-
cantidad++;
|
| 116 |
-
cantidadSpan.textContent = cantidad;
|
| 117 |
-
};
|
| 118 |
-
|
| 119 |
-
cantidadControl.querySelector('.decrease').onclick = () => {
|
| 120 |
-
let cantidad = parseInt(cantidadSpan.textContent, 10);
|
| 121 |
-
if (cantidad > 0) {
|
| 122 |
-
cantidad--;
|
| 123 |
-
cantidadSpan.textContent = cantidad;
|
| 124 |
-
}
|
| 125 |
-
};
|
| 126 |
});
|
| 127 |
|
| 128 |
const confirmarButton = document.createElement('button');
|
| 129 |
confirmarButton.textContent = '✔ Confirmar';
|
| 130 |
-
confirmarButton.className = 'btn btn-
|
| 131 |
confirmarButton.onclick = () => {
|
| 132 |
const cantidadControls = document.querySelectorAll('.cantidad-controls');
|
| 133 |
cantidadControls.forEach(control => {
|
|
@@ -148,7 +128,7 @@ function gestionarMesa(index) {
|
|
| 148 |
|
| 149 |
const volverButton = document.createElement('button');
|
| 150 |
volverButton.textContent = '← Volver';
|
| 151 |
-
volverButton.className = 'btn btn-danger btn-block';
|
| 152 |
volverButton.onclick = () => gestionarMesa(index);
|
| 153 |
app.appendChild(volverButton);
|
| 154 |
};
|
|
@@ -157,7 +137,7 @@ function gestionarMesa(index) {
|
|
| 157 |
|
| 158 |
const atrasButton = document.createElement('button');
|
| 159 |
atrasButton.textContent = '← Atrás';
|
| 160 |
-
atrasButton.className = 'btn btn-outline-
|
| 161 |
atrasButton.onclick = () => render();
|
| 162 |
app.appendChild(atrasButton);
|
| 163 |
|
|
@@ -175,7 +155,7 @@ function gestionarMesa(index) {
|
|
| 175 |
app.appendChild(finalizarButton);
|
| 176 |
}
|
| 177 |
|
| 178 |
-
// Generación del QR
|
| 179 |
function generarTicket(index, total) {
|
| 180 |
const mesa = mesas[index];
|
| 181 |
let qrContent = `Mesa ${mesa.numero}\n`;
|
|
@@ -193,15 +173,14 @@ function generarTicket(index, total) {
|
|
| 193 |
qrContainer.className = 'text-center';
|
| 194 |
app.appendChild(qrContainer);
|
| 195 |
|
| 196 |
-
//
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
});
|
| 205 |
|
| 206 |
// Volver a la vista anterior
|
| 207 |
const volverButton = document.createElement('button');
|
|
@@ -210,8 +189,10 @@ function generarTicket(index, total) {
|
|
| 210 |
volverButton.onclick = () => render();
|
| 211 |
app.appendChild(volverButton);
|
| 212 |
}
|
|
|
|
| 213 |
// Inicializar la aplicación
|
| 214 |
render();
|
| 215 |
|
| 216 |
|
| 217 |
|
|
|
|
|
|
| 1 |
const app = document.getElementById('app');
|
| 2 |
let mesas = [];
|
| 3 |
|
| 4 |
+
// Generar UI
|
| 5 |
function render() {
|
| 6 |
app.innerHTML = '';
|
| 7 |
|
| 8 |
const addButton = document.createElement('button');
|
| 9 |
+
addButton.className = 'btn btn-success btn-block';
|
| 10 |
addButton.textContent = '+ Añadir Mesa';
|
| 11 |
addButton.onclick = () => {
|
| 12 |
let mesaNumero = 1;
|
|
|
|
| 14 |
mesaInput.className = 'mesa-input';
|
| 15 |
mesaInput.innerHTML = `
|
| 16 |
<div class="mesa-controls">
|
| 17 |
+
<button id="decreaseMesa" class="btn btn-outline-secondary">-</button>
|
| 18 |
<span id="mesaNumero" class="mesa-number">${mesaNumero}</span>
|
| 19 |
+
<button id="increaseMesa" class="btn btn-outline-secondary">+</button>
|
| 20 |
</div>
|
| 21 |
<button id="confirmMesa" class="btn btn-primary">Confirmar</button>
|
| 22 |
`;
|
|
|
|
| 47 |
const mesaDiv = document.createElement('div');
|
| 48 |
mesaDiv.className = 'mesa-card';
|
| 49 |
mesaDiv.innerHTML = `
|
| 50 |
+
<div class="mesa-card-body">
|
| 51 |
+
<h5 class="mesa-title">Mesa ${mesa.numero}</h5>
|
|
|
|
|
|
|
| 52 |
</div>
|
| 53 |
`;
|
| 54 |
mesaDiv.style.cursor = 'pointer';
|
|
|
|
| 59 |
app.appendChild(mesasContainer);
|
| 60 |
}
|
| 61 |
|
|
|
|
| 62 |
function gestionarMesa(index) {
|
| 63 |
const mesa = mesas[index];
|
| 64 |
app.innerHTML = '';
|
| 65 |
|
| 66 |
const titulo = document.createElement('h1');
|
| 67 |
titulo.textContent = `Mesa ${mesa.numero}`;
|
| 68 |
+
titulo.className = 'mesa-heading';
|
| 69 |
app.appendChild(titulo);
|
| 70 |
|
| 71 |
const pedidosContainer = document.createElement('div');
|
| 72 |
+
pedidosContainer.className = 'pedidos-container';
|
| 73 |
pedidosContainer.innerHTML = mesa.pedidos.map(p => `${p.item} (${p.opcion || ''}) x${p.cantidad} - €${(p.precio * p.cantidad).toFixed(2)}`).join('<br>');
|
| 74 |
app.appendChild(pedidosContainer);
|
| 75 |
|
|
|
|
| 103 |
</div>
|
| 104 |
`;
|
| 105 |
opcionesContainer.appendChild(opcionDiv);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
});
|
| 107 |
|
| 108 |
const confirmarButton = document.createElement('button');
|
| 109 |
confirmarButton.textContent = '✔ Confirmar';
|
| 110 |
+
confirmarButton.className = 'btn btn-success btn-block';
|
| 111 |
confirmarButton.onclick = () => {
|
| 112 |
const cantidadControls = document.querySelectorAll('.cantidad-controls');
|
| 113 |
cantidadControls.forEach(control => {
|
|
|
|
| 128 |
|
| 129 |
const volverButton = document.createElement('button');
|
| 130 |
volverButton.textContent = '← Volver';
|
| 131 |
+
volverButton.className = 'btn btn-outline-danger btn-block';
|
| 132 |
volverButton.onclick = () => gestionarMesa(index);
|
| 133 |
app.appendChild(volverButton);
|
| 134 |
};
|
|
|
|
| 137 |
|
| 138 |
const atrasButton = document.createElement('button');
|
| 139 |
atrasButton.textContent = '← Atrás';
|
| 140 |
+
atrasButton.className = 'btn btn-outline-secondary btn-block';
|
| 141 |
atrasButton.onclick = () => render();
|
| 142 |
app.appendChild(atrasButton);
|
| 143 |
|
|
|
|
| 155 |
app.appendChild(finalizarButton);
|
| 156 |
}
|
| 157 |
|
| 158 |
+
// Generación del QR usando la API externa
|
| 159 |
function generarTicket(index, total) {
|
| 160 |
const mesa = mesas[index];
|
| 161 |
let qrContent = `Mesa ${mesa.numero}\n`;
|
|
|
|
| 173 |
qrContainer.className = 'text-center';
|
| 174 |
app.appendChild(qrContainer);
|
| 175 |
|
| 176 |
+
// Usar la API externa para generar el QR
|
| 177 |
+
const qrUrl = `https://api.qrserver.com/v1/create-qr-code/?data=${encodeURIComponent(qrContent)}&size=256x256`;
|
| 178 |
+
|
| 179 |
+
// Crear la imagen del QR
|
| 180 |
+
const qrImage = document.createElement('img');
|
| 181 |
+
qrImage.src = qrUrl;
|
| 182 |
+
qrImage.alt = 'QR Code';
|
| 183 |
+
qrContainer.appendChild(qrImage);
|
|
|
|
| 184 |
|
| 185 |
// Volver a la vista anterior
|
| 186 |
const volverButton = document.createElement('button');
|
|
|
|
| 189 |
volverButton.onclick = () => render();
|
| 190 |
app.appendChild(volverButton);
|
| 191 |
}
|
| 192 |
+
|
| 193 |
// Inicializar la aplicación
|
| 194 |
render();
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
+
|