Update script.js
Browse files13 unmodified lines141516171819202122232425262728293031323334353637383963 unmodified lines1031041051061071081091101111121131141157 unmodified lines12312412512612712812936 unmodified lines1661671681691701711721731741751761771781791801811821831841851861871886 unmodified lines19519619719813 unmodified linesmesaInput.className = 'mesa-input';mesaInput.innerHTML = `<div class="mesa-controls"><button id="decreaseMesa" class="btn btn-outline-secondary">-</button><span id="mesaNumero" class="mesa-number">${mesaNumero}</span><button id="increaseMesa" class="btn btn-outline-secondary">+</button></div><button id="confirmMesa" class="btn btn-primary">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();};63 unmodified lines</div>`;opcionesContainer.appendChild(opcionDiv);});const confirmarButton = document.createElement('button');confirmarButton.textContent = '✔ Confirmar';confirmarButton.className = 'btn btn-success btn-block';confirmarButton.onclick = () => {const cantidadControls = document.querySelectorAll('.cantidad-controls');cantidadControls.forEach(control => {const cantidad = parseInt(control.querySelector('.cantidad').textContent, 10);if (cantidad > 0) {7 unmodified lines};opcionesContainer.appendChild(confirmarButton);app.innerHTML = '';app.appendChild(opcionesContainer);const volverButton = document.createElement('button');36 unmodified linesqrContent += `\nTotal: €${total.toFixed(2)}`;console.log('QR Content:', qrContent); // Para depurar el contenido antes de generar el QR.// Asegúrate de limpiar el contenedor del QR antes de generarloconst qrContainer = document.createElement('div');qrContainer.className = 'text-center';app.appendChild(qrContainer);// Usar la API externa para generar el QRconst qrUrl = `https://api.qrserver.com/v1/create-qr-code/?data=${encodeURIComponent(qrContent)}&size=256x256`;// Crear la imagen del QRconst qrImage = document.createElement('img');qrImage.src = qrUrl;qrImage.alt = 'QR Code';qrContainer.appendChild(qrImage);// Volver a la vista anteriorconst volverButton = document.createElement('button');volverButton.textContent = '← Volver';volverButton.className = 'btn btn-outline-danger btn-block';6 unmodified lines13 unmodified lines14151617181920212223242526272829303132333435363738394063 unmodified lines1041051061071081091101111121131141151161171181191201211221231241251261271281291301311321337 unmodified lines14114214314414514614736 unmodified lines1841851861871881891901911921931941951961971981992002012022032046 unmodified lines21121221313 unmodified linesmesaInput.className = 'mesa-input';mesaInput.innerHTML = `<div class="mesa-controls"><button class="btn btn-outline-secondary decrease-mesa">-</button><span class="mesa-number">${mesaNumero}</span><button class="btn btn-outline-secondary increase-mesa">+</button></div><button class="btn btn-primary confirm-mesa">Confirmar</button>`;app.innerHTML = '';app.appendChild(mesaInput);// Usamos querySelector dentro de mesaInput para encontrar los botonesmesaInput.querySelector('.decrease-mesa').onclick = () => {if (mesaNumero > 1) mesaNumero--;mesaInput.querySelector('.mesa-number').textContent = mesaNumero;};mesaInput.querySelector('.increase-mesa').onclick = () => {mesaNumero++;mesaInput.querySelector('.mesa-number').textContent = mesaNumero;};mesaInput.querySelector('.confirm-mesa').onclick = () => {mesas.push({ numero: mesaNumero, pedidos: [] });render();};63 unmodified lines</div>`;opcionesContainer.appendChild(opcionDiv);// Añadimos los listeners dentro del bucle, para cada grupo de botonesconst cantidadControls = opcionDiv.querySelector('.cantidad-controls');const cantidadSpan = cantidadControls.querySelector('.cantidad');cantidadControls.querySelector('.decrease').onclick = () => {let cantidad = parseInt(cantidadSpan.textContent, 10);if (cantidad > 0) {cantidad--;cantidadSpan.textContent = cantidad;}};cantidadControls.querySelector('.increase').onclick = () => {let cantidad = parseInt(cantidadSpan.textContent, 10);cantidad++;cantidadSpan.textContent = cantidad;};});const confirmarButton = document.createElement('button');confirmarButton.textContent = '✔ Confirmar';confirmarButton.className = 'btn btn-success btn-block';confirmarButton.onclick = () => {const cantidadControls = opcionesContainer.querySelectorAll('.cantidad-controls');cantidadControls.forEach(control => {const cantidad = parseInt(control.querySelector('.cantidad').textContent, 10);if (cantidad > 0) {7 unmodified lines};opcionesContainer.appendChild(confirmarButton);app.innerHTML = '';app.appendChild(opcionesContainer);const volverButton = document.createElement('button');36 unmodified linesqrContent += `\nTotal: €${total.toFixed(2)}`;console.log('QR Content:', qrContent);app.innerHTML = ''; // Limpiamos el contenido antes de generar el QRconst qrContainer = document.createElement('div');qrContainer.className = 'text-center';app.appendChild(qrContainer);const qrUrl = `https://api.qrserver.com/v1/create-qr-code/?data=${encodeURIComponent(qrContent)}&size=256x256`;const qrImage = document.createElement('img');qrImage.src = qrUrl;qrImage.alt = 'QR Code';qrContainer.appendChild(qrImage);const volverButton = document.createElement('button');volverButton.textContent = '← Volver';volverButton.className = 'btn btn-outline-danger btn-block';6 unmodified lines
script.js+32-17