fix(admin): eliminar seleccion por defecto en recarga, mostrar aviso vacio y activar solo al escanear QR o buscar

This commit is contained in:
unknown
2026-10-04 22:41:47 -06:00
parent 760db71929
commit 1b7b171a2d
2 changed files with 118 additions and 60 deletions
+36 -14
View File
@@ -10,7 +10,7 @@
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"> <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="apple-mobile-web-app-title" content="RecreoPay"> <meta name="apple-mobile-web-app-title" content="RecreoPay">
<meta name="mobile-web-app-capable" content="yes"> <meta name="mobile-web-app-capable" content="yes">
<link rel="stylesheet" href="/css/styles.css?v=8.7"> <link rel="stylesheet" href="/css/styles.css?v=8.8">
<style> <style>
/* Transiciones suaves */ /* Transiciones suaves */
.fade-enter { animation: fadeIn 0.2s ease-in-out; } .fade-enter { animation: fadeIn 0.2s ease-in-out; }
@@ -263,21 +263,39 @@
</div> </div>
</div> </div>
<!-- FICHA DEL ESTUDIANTE SELECCIONADO --> <!-- ESTADO 1: AVISO VACÍO (NINGÚN ESTUDIANTE SELECCIONADO) -->
<div style="margin-bottom: 6px; display: flex; justify-content: space-between; align-items: center;"> <div id="adminEmptyStudentNotice" style="display: block; text-align: center; padding: 22px 16px; background: #f8fafc; border: 2px dashed #cbd5e1; border-radius: 16px; margin-bottom: 16px;">
<span style="font-size: 0.75rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px;"> <div style="font-size: 2.2rem; margin-bottom: 4px;">📷</div>
Estudiante seleccionado: <strong style="font-size: 0.95rem; color: var(--text-main); display: block;">Ningún estudiante seleccionado</strong>
</span> <p style="font-size: 0.78rem; color: var(--text-muted); margin: 4px 0 12px 0;">
<button type="button" onclick="focusAdminSearch()" style="background: none; border: none; color: #0284c7; font-size: 0.74rem; font-weight: 800; cursor: pointer; text-decoration: underline;"> Escanea el carné QR del alumno o selecciónalo en el buscador de arriba para cargarle saldo.
🔍 Cambiar / Buscar otro </p>
<div style="display: flex; gap: 8px; justify-content: center; flex-wrap: wrap;">
<button type="button" onclick="openAdminScanQrModal()" style="padding: 8px 16px; background: #0284c7; color: white; border: none; border-radius: 8px; font-weight: 800; font-size: 0.8rem; cursor: pointer; display: flex; align-items: center; gap: 5px; box-shadow: 0 2px 6px rgba(2, 132, 199, 0.25);">
<span>📷</span> Escanear Carné QR
</button>
<button type="button" onclick="focusAdminSearch()" style="padding: 8px 14px; background: #ffffff; color: #475569; border: 1.5px solid var(--border); border-radius: 8px; font-weight: 800; font-size: 0.8rem; cursor: pointer; display: flex; align-items: center; gap: 5px;">
<span>🔍</span> Buscar por Nombre
</button> </button>
</div> </div>
<div id="adminSelectedStudentBanner" class="selected-student-banner" style="display: none;"> </div>
<!-- ESTADO 2: FICHA DEL ESTUDIANTE SELECCIONADO TRAS ESCANEO O BÚSQUEDA -->
<div id="adminSelectedStudentWrap" style="display: none; margin-bottom: 16px;">
<div style="margin-bottom: 6px; display: flex; justify-content: space-between; align-items: center;">
<span style="font-size: 0.75rem; font-weight: 800; color: #166534; text-transform: uppercase; letter-spacing: 0.5px; display: flex; align-items: center; gap: 4px;">
<span>✅</span> Estudiante Seleccionado:
</span>
<button type="button" onclick="clearAdminSelectedStudent()" style="background: none; border: none; color: #ef4444; font-size: 0.74rem; font-weight: 800; cursor: pointer; display: flex; align-items: center; gap: 3px;">
✕ Cambiar / Quitar
</button>
</div>
<div id="adminSelectedStudentBanner" class="selected-student-banner" style="display: flex;">
<div style="display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1;"> <div style="display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1;">
<img id="adminSelectedAvatar" src="" style="width: 46px; height: 46px; border-radius: 50%; border: 2.5px solid #0284c7; background: white; flex-shrink: 0; object-fit: cover;"> <img id="adminSelectedAvatar" src="" style="width: 48px; height: 48px; border-radius: 50%; border: 2.5px solid #0284c7; background: white; flex-shrink: 0; object-fit: cover;">
<div style="min-width: 0;"> <div style="min-width: 0;">
<div style="display: flex; align-items: center; gap: 6px; flex-wrap: wrap;"> <div style="display: flex; align-items: center; gap: 6px; flex-wrap: wrap;">
<strong id="adminSelectedName" style="font-size: 0.98rem; color: var(--text-main); word-break: break-word;">Selecciona un alumno</strong> <strong id="adminSelectedName" style="font-size: 1rem; color: var(--text-main); word-break: break-word;">Selecciona un alumno</strong>
<span id="adminSelectedStatusBadge" style="font-size: 0.65rem; font-weight: 800; background: #dcfce7; color: #166534; padding: 2px 6px; border-radius: 4px;">ACTIVA</span> <span id="adminSelectedStatusBadge" style="font-size: 0.65rem; font-weight: 800; background: #dcfce7; color: #166534; padding: 2px 6px; border-radius: 4px;">ACTIVA</span>
</div> </div>
<div id="adminSelectedMeta" style="font-size: 0.75rem; color: var(--text-muted); margin-top: 2px;"> <div id="adminSelectedMeta" style="font-size: 0.75rem; color: var(--text-muted); margin-top: 2px;">
@@ -287,13 +305,16 @@
</div> </div>
<div style="text-align: right; flex-shrink: 0;"> <div style="text-align: right; flex-shrink: 0;">
<div style="font-size: 0.68rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase;">Saldo Actual</div> <div style="font-size: 0.68rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase;">Saldo Actual</div>
<div id="adminSelectedBalance" style="font-size: 1.2rem; font-weight: 900; color: #10b981;">₡0</div> <div id="adminSelectedBalance" style="font-size: 1.25rem; font-weight: 900; color: #10b981;">₡0</div>
</div>
</div> </div>
</div> </div>
<!-- SELECT OCULTO PARA COMPATIBILIDAD CON FUNCIONES JS --> <!-- SELECT OCULTO PARA COMPATIBILIDAD CON FUNCIONES JS -->
<select id="adminRecargaStudentSelect" style="display: none;" onchange="onAdminSelectChange(this.value)"></select> <select id="adminRecargaStudentSelect" style="display: none;" onchange="onAdminSelectChange(this.value)"></select>
<!-- SECCIÓN DE MONTO Y RECARGA (HABILITADA TRAS ESCANEO) -->
<div id="adminRecargaFormFields" style="opacity: 0.45; pointer-events: none; transition: all 0.25s ease;">
<div style="margin-bottom: 12px;"> <div style="margin-bottom: 12px;">
<label style="display: block; font-size: 0.8rem; font-weight: 800; color: var(--text-main); margin-bottom: 5px;"> <label style="display: block; font-size: 0.8rem; font-weight: 800; color: var(--text-main); margin-bottom: 5px;">
Monto a Recargar en Colones: Monto a Recargar en Colones:
@@ -322,6 +343,7 @@
<span>💰</span> Aplicar Recarga Inmediata <span>💰</span> Aplicar Recarga Inmediata
</button> </button>
</div> </div>
</div>
<!-- TAB 4: MOVIMIENTOS Y REVERSIONES --> <!-- TAB 4: MOVIMIENTOS Y REVERSIONES -->
<div id="adminTabContentMovimientos" class="admin-card" style="display: none; max-width: 900px; margin: 0 auto;"> <div id="adminTabContentMovimientos" class="admin-card" style="display: none; max-width: 900px; margin: 0 auto;">
@@ -1211,8 +1233,8 @@
</button> </button>
</nav> </nav>
<script src="/js/sounds.js?v=8.7"></script> <script src="/js/sounds.js?v=8.8"></script>
<script src="/js/jsQR.js"></script> <script src="/js/jsQR.js"></script>
<script src="/js/app.js?v=8.7"></script> <script src="/js/app.js?v=8.8"></script>
</body> </body>
</html> </html>
+47 -11
View File
@@ -2226,6 +2226,10 @@ function switchAdminTab(tabName) {
if (tabName === 'movimientos') { if (tabName === 'movimientos') {
loadAdminMovimientos(); loadAdminMovimientos();
} else if (tabName === 'recarga') {
if (!adminSelectedStudent) {
clearAdminSelectedStudent();
}
} }
if (window.sounds) window.sounds.playTap(); if (window.sounds) window.sounds.playTap();
@@ -2506,23 +2510,20 @@ async function submitNewStudent(event) {
function setupAdminSmartSearch() { function setupAdminSmartSearch() {
if (students && students.length > 0) { if (students && students.length > 0) {
populateAdminRecargaStudents(students); populateAdminRecargaStudents(students);
if (!adminSelectedStudent) {
// Pre-seleccionar pero NO rellenar el input de búsqueda para que el placeholder sea visible
selectAdminStudent(students[0].id, false);
}
} }
} }
function populateAdminRecargaStudents(list) { function populateAdminRecargaStudents(list) {
const sel = document.getElementById('adminRecargaStudentSelect'); const sel = document.getElementById('adminRecargaStudentSelect');
if (sel) { if (sel) {
sel.innerHTML = (list || []).map(s => ` sel.innerHTML = '<option value="">-- Seleccionar estudiante --</option>' + (list || []).map(s => `
<option value="${s.id}">${s.nombre_completo} (Saldo actual: ₡${(s.saldo_colones || 0).toLocaleString('es-CR')})</option> <option value="${s.id}">${s.nombre_completo} (Saldo actual: ₡${(s.saldo_colones || 0).toLocaleString('es-CR')})</option>
`).join(''); `).join('');
if (adminSelectedStudent) {
sel.value = String(adminSelectedStudent.id);
} else {
sel.value = '';
} }
if (list && list.length > 0 && !adminSelectedStudent) {
selectAdminStudent(list[0].id, false);
} }
} }
@@ -2660,6 +2661,32 @@ function onAdminSelectChange(studentId) {
selectAdminStudent(parseInt(studentId, 10), true); selectAdminStudent(parseInt(studentId, 10), true);
} }
function clearAdminSelectedStudent() {
adminSelectedStudent = null;
const sel = document.getElementById('adminRecargaStudentSelect');
if (sel) sel.value = '';
const wrap = document.getElementById('adminSelectedStudentWrap');
const notice = document.getElementById('adminEmptyStudentNotice');
const fields = document.getElementById('adminRecargaFormFields');
const searchInput = document.getElementById('inputAdminSearchStudent');
const btnClear = document.getElementById('btnClearAdminSearch');
if (wrap) wrap.style.display = 'none';
if (notice) notice.style.display = 'block';
if (fields) {
fields.style.opacity = '0.45';
fields.style.pointerEvents = 'none';
}
if (searchInput) searchInput.value = '';
if (btnClear) btnClear.style.display = 'none';
const montoInput = document.getElementById('adminRecargaMonto');
if (montoInput) montoInput.value = '';
const descInput = document.getElementById('adminRecargaDescripcion');
if (descInput) descInput.value = '';
}
function selectAdminStudent(studentId, updateSearchInput = false) { function selectAdminStudent(studentId, updateSearchInput = false) {
const id = parseInt(studentId, 10); const id = parseInt(studentId, 10);
const student = (students || []).find(s => s.id === id); const student = (students || []).find(s => s.id === id);
@@ -2670,7 +2697,17 @@ function selectAdminStudent(studentId, updateSearchInput = false) {
const sel = document.getElementById('adminRecargaStudentSelect'); const sel = document.getElementById('adminRecargaStudentSelect');
if (sel) sel.value = String(student.id); if (sel) sel.value = String(student.id);
const banner = document.getElementById('adminSelectedStudentBanner'); const wrap = document.getElementById('adminSelectedStudentWrap');
const notice = document.getElementById('adminEmptyStudentNotice');
const fields = document.getElementById('adminRecargaFormFields');
if (wrap) wrap.style.display = 'block';
if (notice) notice.style.display = 'none';
if (fields) {
fields.style.opacity = '1';
fields.style.pointerEvents = 'auto';
}
const avatar = document.getElementById('adminSelectedAvatar'); const avatar = document.getElementById('adminSelectedAvatar');
const name = document.getElementById('adminSelectedName'); const name = document.getElementById('adminSelectedName');
const statusBadge = document.getElementById('adminSelectedStatusBadge'); const statusBadge = document.getElementById('adminSelectedStatusBadge');
@@ -2680,7 +2717,6 @@ function selectAdminStudent(studentId, updateSearchInput = false) {
const dropdown = document.getElementById('adminSearchResultsDropdown'); const dropdown = document.getElementById('adminSearchResultsDropdown');
const btnClear = document.getElementById('btnClearAdminSearch'); const btnClear = document.getElementById('btnClearAdminSearch');
if (banner) banner.style.display = 'flex';
if (avatar) avatar.src = student.foto_url || '/img/avatar_default.png'; if (avatar) avatar.src = student.foto_url || '/img/avatar_default.png';
if (name) name.textContent = student.nombre_completo; if (name) name.textContent = student.nombre_completo;
if (statusBadge) { if (statusBadge) {
@@ -2702,7 +2738,6 @@ function selectAdminStudent(studentId, updateSearchInput = false) {
searchInput.value = student.nombre_completo; searchInput.value = student.nombre_completo;
if (btnClear) btnClear.style.display = 'flex'; if (btnClear) btnClear.style.display = 'flex';
} else { } else {
// Mantener vacío para que el placeholder "🔍 Escribe para buscar..." sea completamente visible
searchInput.value = ''; searchInput.value = '';
if (btnClear) btnClear.style.display = 'none'; if (btnClear) btnClear.style.display = 'none';
} }
@@ -2887,6 +2922,7 @@ async function submitAdminManualRecharge() {
await loadAdminData(); await loadAdminData();
populateAdminRecargaStudents(students); populateAdminRecargaStudents(students);
clearAdminSelectedStudent();
} catch (err) { } catch (err) {
if (window.sounds) window.sounds.playError(); if (window.sounds) window.sounds.playError();
alert(`❌ Error al recargar: ${err.message}`); alert(`❌ Error al recargar: ${err.message}`);