Update script.js
Browse files
script.js
CHANGED
|
@@ -14,26 +14,27 @@ function render() {
|
|
| 14 |
mesaInput.className = 'mesa-input';
|
| 15 |
mesaInput.innerHTML = `
|
| 16 |
<div class="mesa-controls">
|
| 17 |
-
<button
|
| 18 |
-
<span
|
| 19 |
-
<button
|
| 20 |
</div>
|
| 21 |
-
<button
|
| 22 |
`;
|
| 23 |
app.innerHTML = '';
|
| 24 |
app.appendChild(mesaInput);
|
| 25 |
|
| 26 |
-
|
|
|
|
| 27 |
if (mesaNumero > 1) mesaNumero--;
|
| 28 |
-
|
| 29 |
};
|
| 30 |
|
| 31 |
-
|
| 32 |
mesaNumero++;
|
| 33 |
-
|
| 34 |
};
|
| 35 |
|
| 36 |
-
|
| 37 |
mesas.push({ numero: mesaNumero, pedidos: [] });
|
| 38 |
render();
|
| 39 |
};
|
|
@@ -103,13 +104,30 @@ function gestionarMesa(index) {
|
|
| 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 =
|
| 113 |
cantidadControls.forEach(control => {
|
| 114 |
const cantidad = parseInt(control.querySelector('.cantidad').textContent, 10);
|
| 115 |
if (cantidad > 0) {
|
|
@@ -123,7 +141,7 @@ function gestionarMesa(index) {
|
|
| 123 |
};
|
| 124 |
opcionesContainer.appendChild(confirmarButton);
|
| 125 |
|
| 126 |
-
app.innerHTML = '';
|
| 127 |
app.appendChild(opcionesContainer);
|
| 128 |
|
| 129 |
const volverButton = document.createElement('button');
|
|
@@ -166,23 +184,21 @@ function generarTicket(index, total) {
|
|
| 166 |
|
| 167 |
qrContent += `\nTotal: €${total.toFixed(2)}`;
|
| 168 |
|
| 169 |
-
console.log('QR Content:', qrContent);
|
|
|
|
|
|
|
| 170 |
|
| 171 |
-
// Asegúrate de limpiar el contenedor del QR antes de generarlo
|
| 172 |
const qrContainer = document.createElement('div');
|
| 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');
|
| 187 |
volverButton.textContent = '← Volver';
|
| 188 |
volverButton.className = 'btn btn-outline-danger btn-block';
|
|
@@ -195,4 +211,3 @@ render();
|
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
-
|
|
|
|
| 14 |
mesaInput.className = 'mesa-input';
|
| 15 |
mesaInput.innerHTML = `
|
| 16 |
<div class="mesa-controls">
|
| 17 |
+
<button class="btn btn-outline-secondary decrease-mesa">-</button>
|
| 18 |
+
<span class="mesa-number">${mesaNumero}</span>
|
| 19 |
+
<button class="btn btn-outline-secondary increase-mesa">+</button>
|
| 20 |
</div>
|
| 21 |
+
<button class="btn btn-primary confirm-mesa">Confirmar</button>
|
| 22 |
`;
|
| 23 |
app.innerHTML = '';
|
| 24 |
app.appendChild(mesaInput);
|
| 25 |
|
| 26 |
+
// Usamos querySelector dentro de mesaInput para encontrar los botones
|
| 27 |
+
mesaInput.querySelector('.decrease-mesa').onclick = () => {
|
| 28 |
if (mesaNumero > 1) mesaNumero--;
|
| 29 |
+
mesaInput.querySelector('.mesa-number').textContent = mesaNumero;
|
| 30 |
};
|
| 31 |
|
| 32 |
+
mesaInput.querySelector('.increase-mesa').onclick = () => {
|
| 33 |
mesaNumero++;
|
| 34 |
+
mesaInput.querySelector('.mesa-number').textContent = mesaNumero;
|
| 35 |
};
|
| 36 |
|
| 37 |
+
mesaInput.querySelector('.confirm-mesa').onclick = () => {
|
| 38 |
mesas.push({ numero: mesaNumero, pedidos: [] });
|
| 39 |
render();
|
| 40 |
};
|
|
|
|
| 104 |
</div>
|
| 105 |
`;
|
| 106 |
opcionesContainer.appendChild(opcionDiv);
|
| 107 |
+
|
| 108 |
+
// Añadimos los listeners dentro del bucle, para cada grupo de botones
|
| 109 |
+
const cantidadControls = opcionDiv.querySelector('.cantidad-controls');
|
| 110 |
+
const cantidadSpan = cantidadControls.querySelector('.cantidad');
|
| 111 |
+
cantidadControls.querySelector('.decrease').onclick = () => {
|
| 112 |
+
let cantidad = parseInt(cantidadSpan.textContent, 10);
|
| 113 |
+
if (cantidad > 0) {
|
| 114 |
+
cantidad--;
|
| 115 |
+
cantidadSpan.textContent = cantidad;
|
| 116 |
+
}
|
| 117 |
+
};
|
| 118 |
+
|
| 119 |
+
cantidadControls.querySelector('.increase').onclick = () => {
|
| 120 |
+
let cantidad = parseInt(cantidadSpan.textContent, 10);
|
| 121 |
+
cantidad++;
|
| 122 |
+
cantidadSpan.textContent = cantidad;
|
| 123 |
+
};
|
| 124 |
});
|
| 125 |
|
| 126 |
const confirmarButton = document.createElement('button');
|
| 127 |
confirmarButton.textContent = '✔ Confirmar';
|
| 128 |
confirmarButton.className = 'btn btn-success btn-block';
|
| 129 |
confirmarButton.onclick = () => {
|
| 130 |
+
const cantidadControls = opcionesContainer.querySelectorAll('.cantidad-controls');
|
| 131 |
cantidadControls.forEach(control => {
|
| 132 |
const cantidad = parseInt(control.querySelector('.cantidad').textContent, 10);
|
| 133 |
if (cantidad > 0) {
|
|
|
|
| 141 |
};
|
| 142 |
opcionesContainer.appendChild(confirmarButton);
|
| 143 |
|
| 144 |
+
app.innerHTML = '';
|
| 145 |
app.appendChild(opcionesContainer);
|
| 146 |
|
| 147 |
const volverButton = document.createElement('button');
|
|
|
|
| 184 |
|
| 185 |
qrContent += `\nTotal: €${total.toFixed(2)}`;
|
| 186 |
|
| 187 |
+
console.log('QR Content:', qrContent);
|
| 188 |
+
|
| 189 |
+
app.innerHTML = ''; // Limpiamos el contenido antes de generar el QR
|
| 190 |
|
|
|
|
| 191 |
const qrContainer = document.createElement('div');
|
| 192 |
qrContainer.className = 'text-center';
|
| 193 |
app.appendChild(qrContainer);
|
| 194 |
|
|
|
|
| 195 |
const qrUrl = `https://api.qrserver.com/v1/create-qr-code/?data=${encodeURIComponent(qrContent)}&size=256x256`;
|
| 196 |
|
|
|
|
| 197 |
const qrImage = document.createElement('img');
|
| 198 |
qrImage.src = qrUrl;
|
| 199 |
qrImage.alt = 'QR Code';
|
| 200 |
qrContainer.appendChild(qrImage);
|
| 201 |
|
|
|
|
| 202 |
const volverButton = document.createElement('button');
|
| 203 |
volverButton.textContent = '← Volver';
|
| 204 |
volverButton.className = 'btn btn-outline-danger btn-block';
|
|
|
|
| 211 |
|
| 212 |
|
| 213 |
|
|
|