Actualizar Interfaz/scripts/BoletosArtista1.js

This commit is contained in:
maria.ruiz 2025-03-09 22:25:28 +00:00
parent ea6ff9746b
commit 7ad5ccbe91
1 changed files with 49 additions and 50 deletions
Interfaz/scripts

View File

@ -1,50 +1,49 @@
const filas = 10;
const filas = 10; const columnas = 12;
const columnas = 12; let diaSeleccionado = 23;
let diaSeleccionado = 23; const asientosVendidos = { 22: new Set(), 23: new Set(), 24: new Set() };
const asientosVendidos = { 22: new Set(), 23: new Set(), 24: new Set() }; let asientosSeleccionados = new Set();
let asientosSeleccionados = new Set();
function seleccionarDia(dia) {
function seleccionarDia(dia) { diaSeleccionado = dia;
diaSeleccionado = dia; asientosSeleccionados.clear();
asientosSeleccionados.clear(); document.querySelectorAll('.dias button').forEach(btn => btn.classList.remove('selected'));
document.querySelectorAll('.dias button').forEach(btn => btn.classList.remove('selected')); event.target.classList.add('selected');
event.target.classList.add('selected'); renderizarAsientos();
renderizarAsientos(); }
}
function toggleAsiento(asiento) {
function toggleAsiento(asiento) { if (asientosVendidos[diaSeleccionado].has(asiento)) return;
if (asientosVendidos[diaSeleccionado].has(asiento)) return; if (asientosSeleccionados.has(asiento)) {
if (asientosSeleccionados.has(asiento)) { asientosSeleccionados.delete(asiento);
asientosSeleccionados.delete(asiento); } else {
} else { asientosSeleccionados.add(asiento);
asientosSeleccionados.add(asiento); }
} renderizarAsientos();
renderizarAsientos(); }
}
function venderAsientos() {
function venderAsientos() { asientosSeleccionados.forEach(asiento => asientosVendidos[diaSeleccionado].add(asiento));
asientosSeleccionados.forEach(asiento => asientosVendidos[diaSeleccionado].add(asiento)); asientosSeleccionados.clear();
asientosSeleccionados.clear(); renderizarAsientos();
renderizarAsientos(); }
}
function renderizarAsientos() {
function renderizarAsientos() { const contenedor = document.getElementById('asientos');
const contenedor = document.getElementById('asientos'); contenedor.innerHTML = '';
contenedor.innerHTML = ''; for (let i = 0; i < filas * columnas; i++) {
for (let i = 0; i < filas * columnas; i++) { const asiento = `${Math.floor(i / columnas) + 1}${String.fromCharCode(65 + (i % columnas))}`;
const asiento = `${Math.floor(i / columnas) + 1}${String.fromCharCode(65 + (i % columnas))}`; const boton = document.createElement('button');
const boton = document.createElement('button'); boton.className = 'asiento';
boton.className = 'asiento'; if (asientosVendidos[diaSeleccionado].has(asiento)) {
if (asientosVendidos[diaSeleccionado].has(asiento)) { boton.classList.add('vendido');
boton.classList.add('vendido'); } else if (asientosSeleccionados.has(asiento)) {
} else if (asientosSeleccionados.has(asiento)) { boton.style.backgroundColor = 'orange';
boton.style.backgroundColor = 'orange'; }
} boton.textContent = asiento;
boton.textContent = asiento; boton.onclick = () => toggleAsiento(asiento);
boton.onclick = () => toggleAsiento(asiento); contenedor.appendChild(boton);
contenedor.appendChild(boton); }
} }
}
renderizarAsientos();
renderizarAsientos();