Actualizar asignados.html
This commit is contained in:
152
asignados.html
152
asignados.html
@@ -13,14 +13,12 @@
|
||||
--secondary: #2563eb;
|
||||
--app-bg: #f4f7f9;
|
||||
}
|
||||
|
||||
body { background-color: var(--app-bg); -webkit-tap-highlight-color: transparent; }
|
||||
.fade-in { animation: fadeIn 0.3s ease-out forwards; }
|
||||
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
|
||||
.no-scrollbar::-webkit-scrollbar { display: none; }
|
||||
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
|
||||
.bottom-nav-safe { padding-bottom: env(safe-area-inset-bottom); }
|
||||
|
||||
/* Clases dinámicas */
|
||||
.text-primary-dynamic { color: var(--primary) !important; }
|
||||
.bg-primary-dynamic { background-color: var(--primary) !important; }
|
||||
@@ -30,16 +28,19 @@
|
||||
.day-chip { transition: all 0.2s; border: 2px solid transparent; }
|
||||
.day-chip.active { background-color: var(--primary) !important; color: white !important; border-color: var(--primary) !important; transform: scale(1.05); shadow: 0 4px 6px -1px rgba(0,0,0,0.1); }
|
||||
.day-chip.inactive { background-color: #f8fafc; color: #64748b; border-color: #e2e8f0; }
|
||||
|
||||
/* Chips de Horas */
|
||||
.time-chip { transition: all 0.2s; }
|
||||
.time-chip.active { background-color: var(--primary) !important; color: white !important; font-weight: 900; box-shadow: 0 4px 10px rgba(0,0,0,0.15); border-color: var(--primary) !important; }
|
||||
.time-chip.inactive { background-color: white; color: #475569; border-color: #cbd5e1; }
|
||||
.time-chip:disabled { background-color: #f1f5f9; color: #cbd5e1; border-color: #e2e8f0; text-decoration: line-through; cursor: not-allowed; }
|
||||
|
||||
/* Descripción expandible al tocar */
|
||||
.desc-box { cursor: pointer; }
|
||||
.desc-toggle-icon { transition: transform 0.2s ease; }
|
||||
.desc-toggle-icon.rotate-180 { transform: rotate(180deg); }
|
||||
</style>
|
||||
</head>
|
||||
<body class="text-slate-800 font-sans antialiased h-screen flex flex-col overflow-hidden relative">
|
||||
|
||||
<header class="bg-white px-5 pt-8 pb-4 shadow-sm z-20 shrink-0 border-b border-slate-100 flex justify-between items-center relative">
|
||||
<div>
|
||||
<p class="text-[10px] font-black text-primary-dynamic uppercase tracking-widest mb-0.5">Por Agendar</p>
|
||||
@@ -49,7 +50,6 @@
|
||||
<i data-lucide="arrow-left" class="w-5 h-5"></i>
|
||||
</a>
|
||||
</header>
|
||||
|
||||
<main class="flex-1 overflow-y-auto no-scrollbar p-5 relative z-10" id="mainArea">
|
||||
<div id="loader" class="text-center py-10 opacity-50">
|
||||
<i data-lucide="loader-2" class="w-8 h-8 animate-spin mx-auto text-primary-dynamic mb-2"></i>
|
||||
@@ -57,7 +57,6 @@
|
||||
</div>
|
||||
|
||||
<div id="contentWrapper" class="hidden pb-24 fade-in">
|
||||
|
||||
<div id="searchContainer" class="mb-6 relative">
|
||||
<i data-lucide="search" class="w-5 h-5 absolute left-4 top-1/2 -translate-y-1/2 text-slate-400"></i>
|
||||
<input type="text" id="searchInput" oninput="filterServices()" placeholder="Buscar expediente, cliente, zona o avería..." class="w-full bg-white border border-slate-200 pl-12 pr-4 py-3.5 rounded-2xl text-sm font-bold shadow-sm outline-none focus:ring-2 focus:ring-primary-dynamic transition-all">
|
||||
@@ -74,16 +73,13 @@
|
||||
<div id="requestsList" class="space-y-4">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="noDateSection">
|
||||
<h2 class="text-xs font-black text-slate-400 uppercase tracking-widest mb-3">Pendientes de Fecha</h2>
|
||||
<div id="servicesList" class="space-y-4">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<nav class="bg-white border-t border-slate-200 shrink-0 pb-safe z-20 absolute bottom-0 w-full shadow-[0_-10px_30px_rgba(0,0,0,0.05)] rounded-t-3xl">
|
||||
<div class="flex justify-around items-center p-3 bottom-nav-safe">
|
||||
<a href="menu.html" class="flex flex-col items-center p-2 text-slate-400 hover:text-primary-dynamic transition-transform active:scale-95">
|
||||
@@ -100,7 +96,6 @@
|
||||
</button>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div id="actionModal" class="fixed inset-0 bg-slate-900/60 z-[100] hidden flex-col justify-end transition-opacity duration-300 opacity-0">
|
||||
<div id="modalContent" class="bg-white rounded-t-[2rem] p-6 pb-12 transform translate-y-full transition-transform duration-300 shadow-2xl max-h-[90vh] flex flex-col">
|
||||
|
||||
@@ -111,16 +106,13 @@
|
||||
</div>
|
||||
<button onclick="closeModal('actionModal', 'modalContent')" class="w-8 h-8 bg-slate-100 rounded-full flex items-center justify-center text-slate-500 hover:text-red-500"><i data-lucide="x" class="w-4 h-4"></i></button>
|
||||
</div>
|
||||
|
||||
<div class="overflow-y-auto no-scrollbar flex-1 pb-4">
|
||||
<div class="space-y-1 mb-6 bg-slate-50 p-4 rounded-2xl border border-slate-100">
|
||||
<p class="text-[10px] font-black text-slate-400 uppercase tracking-widest flex items-center gap-1"><i data-lucide="map-pin" class="w-3 h-3"></i> Dirección</p>
|
||||
<p id="detAddress" class="font-bold text-slate-700 text-sm uppercase"></p>
|
||||
</div>
|
||||
|
||||
<input type="hidden" id="detId">
|
||||
<input type="hidden" id="detPhoneRaw">
|
||||
|
||||
<div class="grid grid-cols-2 gap-3 mb-6">
|
||||
<button onclick="callClient()" class="bg-blue-50 border border-blue-100 text-blue-600 font-black py-3 rounded-2xl flex items-center justify-center gap-2 active:scale-95 transition-transform shadow-sm">
|
||||
<i data-lucide="phone" class="w-5 h-5"></i>
|
||||
@@ -131,9 +123,7 @@
|
||||
<span class="text-[10px] uppercase tracking-widest">WhatsApp</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<hr class="border-slate-100 mb-6">
|
||||
|
||||
<div class="bg-white border border-slate-200 rounded-[1.5rem] p-5 shadow-sm space-y-5">
|
||||
<div>
|
||||
<div class="flex justify-between items-center mb-2">
|
||||
@@ -153,12 +143,10 @@
|
||||
<i data-lucide="chevron-down" class="w-5 h-5 absolute right-4 top-1/2 -translate-y-1/2 text-slate-400 pointer-events-none"></i>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p class="text-[10px] font-black text-primary-dynamic uppercase tracking-widest mb-2 flex items-center gap-1.5"><i data-lucide="calendar" class="w-4 h-4"></i> Seleccionar Día</p>
|
||||
<div id="dayCarousel" class="flex overflow-x-auto gap-2 pb-2 no-scrollbar"></div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p class="text-[10px] font-black text-primary-dynamic uppercase tracking-widest mb-2 flex items-center gap-1.5"><i data-lucide="watch" class="w-4 h-4"></i> Huecos Disponibles</p>
|
||||
<div id="timeGrid" class="grid grid-cols-4 gap-2"></div>
|
||||
@@ -168,7 +156,6 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="pt-4 shrink-0 bg-white border-t border-slate-100">
|
||||
<button onclick="saveAppointment()" id="btnSaveAppt" disabled class="w-full bg-slate-300 text-white font-black py-4 rounded-2xl shadow-sm transition-all flex items-center justify-center gap-2 uppercase tracking-widest text-xs cursor-not-allowed">
|
||||
<i data-lucide="calendar-check" class="w-5 h-5"></i> Confirmar Cita
|
||||
@@ -176,7 +163,6 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="approveModal" class="fixed inset-0 bg-slate-900/60 z-[110] hidden flex-col justify-end transition-opacity duration-300 opacity-0">
|
||||
<div id="approveModalContent" class="bg-white rounded-t-[2rem] p-6 pb-12 transform translate-y-full transition-transform duration-300 shadow-2xl">
|
||||
<div class="flex justify-between items-center mb-6">
|
||||
@@ -186,7 +172,6 @@
|
||||
</div>
|
||||
<button onclick="closeModal('approveModal', 'approveModalContent')" class="w-8 h-8 bg-slate-100 rounded-full flex items-center justify-center text-slate-500 hover:text-red-500"><i data-lucide="x" class="w-4 h-4"></i></button>
|
||||
</div>
|
||||
|
||||
<div class="bg-slate-50 border-2 border-primary-dynamic p-5 rounded-2xl mb-6 shadow-inner text-center relative overflow-hidden">
|
||||
<div class="absolute left-0 top-0 bottom-0 w-2 bg-primary-dynamic"></div>
|
||||
<p class="text-[10px] font-black text-primary-dynamic uppercase tracking-widest mb-3">Fecha y Hora de Cita (Modificable)</p>
|
||||
@@ -195,9 +180,7 @@
|
||||
<input type="time" id="appTimeInput" class="bg-white border border-slate-200 px-3 py-2 rounded-xl text-sm font-black text-slate-700 outline-none focus:ring-2 focus:ring-primary-dynamic transition-all">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input type="hidden" id="appId">
|
||||
|
||||
<div class="mb-8">
|
||||
<p class="text-[10px] font-black text-slate-500 uppercase tracking-widest mb-2 ml-1">¿Cuánto tiempo vas a tardar?</p>
|
||||
<div class="relative">
|
||||
@@ -214,7 +197,6 @@
|
||||
<i data-lucide="chevron-down" class="w-5 h-5 absolute right-4 top-1/2 -translate-y-1/2 text-slate-400 pointer-events-none"></i>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<button onclick="rejectRequest()" id="btnReject" class="bg-white border-2 border-rose-200 text-rose-600 font-black py-4 rounded-xl hover:bg-rose-50 flex items-center justify-center gap-2 transition-all text-xs uppercase tracking-widest">
|
||||
<i data-lucide="x" class="w-4 h-4"></i> Rechazar
|
||||
@@ -226,28 +208,23 @@
|
||||
<p class="text-center text-[9px] font-bold text-slate-400 mt-4">Al aceptar, se enviará un WhatsApp al cliente confirmando la cita automáticamente.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="toast" class="fixed top-5 left-1/2 -translate-x-1/2 bg-slate-800 text-white px-5 py-3 rounded-full shadow-2xl z-[200] font-bold text-xs uppercase tracking-widest flex items-center gap-2 transition-all duration-300 opacity-0 pointer-events-none transform -translate-y-10">
|
||||
<i data-lucide="check-circle" class="w-4 h-4 text-emerald-400"></i>
|
||||
<span id="toastMsg">Guardado</span>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const API_URL = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'
|
||||
? 'http://localhost:3000'
|
||||
: 'https://integrarepara-api.integrarepara.es';
|
||||
|
||||
let localServices = [];
|
||||
let globalAllServices = [];
|
||||
let pendingRequests = [];
|
||||
let systemStatuses = [];
|
||||
let systemGuilds = [];
|
||||
let bizHours = { m_start: '09:00', m_end: '14:00', a_start: '16:00', a_end: '19:00' };
|
||||
|
||||
// Variables del Agendador Inteligente
|
||||
let pickerSelectedDate = "";
|
||||
let pickerSelectedTime = "";
|
||||
|
||||
// --- SISTEMA DE TEMA DINÁMICO (VERSIÓN TODOTERRENO DEFINITIVA) ---
|
||||
// --- SISTEMA DE TEMA DINÁMICO (EL BUENO) ---
|
||||
async function applyTheme() {
|
||||
@@ -273,7 +250,6 @@
|
||||
}
|
||||
} catch (e) { console.warn("Usando tema por defecto"); }
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", async () => {
|
||||
if (!localStorage.getItem("token") || (localStorage.getItem("role") !== 'operario' && localStorage.getItem("role") !== 'operario_cerrado')) {
|
||||
window.location.href = "index.html"; return;
|
||||
@@ -283,7 +259,6 @@
|
||||
await loadStatusesAndGuilds();
|
||||
refreshData();
|
||||
});
|
||||
|
||||
async function loadStatusesAndGuilds() {
|
||||
try {
|
||||
const headers = { "Authorization": `Bearer ${localStorage.getItem("token")}` };
|
||||
@@ -297,11 +272,9 @@
|
||||
if (dataG.ok) systemGuilds = dataG.guilds;
|
||||
} catch(e) {}
|
||||
}
|
||||
|
||||
async function refreshData() {
|
||||
document.getElementById('contentWrapper').classList.add('hidden');
|
||||
document.getElementById('loader').classList.remove('hidden');
|
||||
|
||||
try {
|
||||
const headers = { "Authorization": `Bearer ${localStorage.getItem("token")}` };
|
||||
const myUserId = JSON.parse(atob(localStorage.getItem('token').split('.')[1])).sub;
|
||||
@@ -328,7 +301,6 @@
|
||||
|
||||
// 3. SOLO PASAN LOS QUE NO TIENEN FECHA
|
||||
if (raw.scheduled_date && raw.scheduled_date.trim() !== "") return false;
|
||||
|
||||
// 4. Asegurarnos de que no está terminado/anulado
|
||||
if (raw.status_operativo) {
|
||||
const st = systemStatuses.find(x => String(x.id) === String(raw.status_operativo));
|
||||
@@ -348,7 +320,20 @@
|
||||
document.getElementById('contentWrapper').classList.remove('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// EXPANDIR / CONTRAER DESCRIPCIÓN AL TOCAR
|
||||
// ==========================================
|
||||
// Se usa en las tarjetas de "Pendientes de Fecha" y "Citas Solicitadas".
|
||||
// Al tocar el recuadro gris, se quita el recorte de 2 líneas (line-clamp-2)
|
||||
// y se muestra el texto completo; al tocar otra vez, se vuelve a recortar.
|
||||
function toggleDesc(box, evt) {
|
||||
if (evt) evt.stopPropagation(); // Evita que se abra el modal de la tarjeta al tocar la descripción
|
||||
const p = box.querySelector('p');
|
||||
const icon = box.querySelector('.desc-toggle-icon');
|
||||
if (!p) return;
|
||||
p.classList.toggle('line-clamp-2');
|
||||
if (icon) icon.classList.toggle('rotate-180');
|
||||
}
|
||||
// ==========================================
|
||||
// RENDERIZADO DE SOLICITUDES PENDIENTES
|
||||
// ==========================================
|
||||
@@ -356,14 +341,11 @@
|
||||
const reqSection = document.getElementById('requestsSection');
|
||||
const reqList = document.getElementById('requestsList');
|
||||
reqList.innerHTML = '';
|
||||
|
||||
if (pendingRequests.length === 0) {
|
||||
reqSection.classList.add('hidden');
|
||||
return;
|
||||
}
|
||||
|
||||
reqSection.classList.remove('hidden');
|
||||
|
||||
pendingRequests.forEach(req => {
|
||||
const raw = req.raw_data || {};
|
||||
const name = raw["Nombre Cliente"] || raw["CLIENTE"] || "Cliente";
|
||||
@@ -374,12 +356,10 @@
|
||||
const rawPhone = raw["Teléfono"] || raw["TELEFONOS"] || raw["TELEFONO"] || "";
|
||||
const matchPhone = rawPhone.toString().match(/[6789]\d{8}/);
|
||||
const safePhone = matchPhone ? matchPhone[0] : "";
|
||||
|
||||
const addr = raw["Dirección"] || raw["DOMICILIO"] || "Sin dirección";
|
||||
const pop = raw["Población"] || raw["POBLACION-PROVINCIA"] || "";
|
||||
const cp = raw["Código Postal"] || raw["C.P."] || "";
|
||||
const fullAddress = `${addr}, ${cp} ${pop}`.trim().replace(/^,\s*/, '').replace(/,\s*$/, '');
|
||||
|
||||
let guildName = raw["Gremio"] || raw["GREMIO"] || raw["Especialidad"] || "";
|
||||
const idGremio = req.guild_id || raw.guild_id;
|
||||
if (!guildName && idGremio) {
|
||||
@@ -390,7 +370,6 @@
|
||||
guildName = req.guild.name;
|
||||
}
|
||||
guildName = guildName || "Varios";
|
||||
|
||||
reqList.innerHTML += `
|
||||
<div class="bg-white border-2 border-primary-dynamic p-5 rounded-[2rem] flex flex-col shadow-md relative overflow-hidden gap-3">
|
||||
<div class="absolute right-0 top-0 w-24 h-24 bg-primary-dynamic rounded-bl-full opacity-10 z-0"></div>
|
||||
@@ -404,11 +383,10 @@
|
||||
<p class="text-[10px] font-bold text-slate-600 mt-1 flex items-center gap-1"><i data-lucide="calendar" class="w-3 h-3 text-primary-dynamic"></i> ${rDate} | ${raw.requested_time} - ${rTime}</p>
|
||||
<p class="text-[10px] font-bold text-slate-500 mt-1 uppercase flex items-start gap-1"><i data-lucide="map-pin" class="w-3 h-3 text-slate-400 shrink-0 mt-0.5"></i> <span class="leading-tight">${fullAddress}</span></p>
|
||||
</div>
|
||||
|
||||
<div class="relative z-10 bg-slate-50 p-3 rounded-2xl border border-slate-100 mt-1">
|
||||
<p class="text-[10px] font-medium text-slate-600 line-clamp-2 leading-relaxed">${desc}</p>
|
||||
<div class="desc-box relative z-10 bg-slate-50 p-3 rounded-2xl border border-slate-100 mt-1 active:bg-slate-100 transition-colors" onclick="toggleDesc(this, event)">
|
||||
<p class="text-[10px] font-medium text-slate-600 line-clamp-2 leading-relaxed pr-5">${desc}</p>
|
||||
<i data-lucide="chevron-down" class="desc-toggle-icon w-3.5 h-3.5 text-slate-400 absolute right-2.5 top-3 shrink-0"></i>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-2 relative z-10 mt-1">
|
||||
<button onclick="quickCallInline('${safePhone}')" class="flex-1 bg-white border border-primary-dynamic text-primary-dynamic hover:bg-slate-50 font-black py-3 rounded-xl flex items-center justify-center gap-1.5 active:scale-95 transition-transform shadow-sm text-[10px] uppercase tracking-widest">
|
||||
<i data-lucide="phone" class="w-4 h-4"></i> Llamar
|
||||
@@ -422,17 +400,14 @@
|
||||
});
|
||||
lucide.createIcons();
|
||||
}
|
||||
|
||||
function quickCallInline(phone) {
|
||||
if (phone) window.location.href = `tel:+34${phone}`;
|
||||
else alert("No hay un teléfono válido guardado.");
|
||||
}
|
||||
|
||||
function openApproveModal(id) {
|
||||
const req = pendingRequests.find(r => r.id === id);
|
||||
if(!req) return;
|
||||
const raw = req.raw_data || {};
|
||||
|
||||
document.getElementById('appId').value = id;
|
||||
document.getElementById('appRef').innerText = `Exp. #${req.service_ref || "S/R"}`;
|
||||
document.getElementById('appName').innerText = raw["Nombre Cliente"] || "Cliente";
|
||||
@@ -440,7 +415,6 @@
|
||||
document.getElementById('appDateInput').value = raw.requested_date || "";
|
||||
document.getElementById('appTimeInput').value = raw.requested_time || "";
|
||||
document.getElementById('appDurationInput').value = "60";
|
||||
|
||||
const modal = document.getElementById('approveModal');
|
||||
const content = document.getElementById('approveModalContent');
|
||||
modal.classList.remove('hidden');
|
||||
@@ -448,7 +422,6 @@
|
||||
modal.classList.remove('opacity-0');
|
||||
content.classList.remove('translate-y-full');
|
||||
}
|
||||
|
||||
async function approveRequest() {
|
||||
const id = document.getElementById('appId').value;
|
||||
const duration = document.getElementById('appDurationInput').value;
|
||||
@@ -458,7 +431,6 @@
|
||||
const originalContent = btn.innerHTML;
|
||||
btn.innerHTML = `<i data-lucide="loader-2" class="w-4 h-4 animate-spin"></i>`;
|
||||
btn.disabled = true;
|
||||
|
||||
try {
|
||||
const res = await fetch(`${API_URL}/agenda/requests/${id}/approve`, {
|
||||
method: 'POST',
|
||||
@@ -473,7 +445,6 @@
|
||||
} catch (e) { alert("Error de conexión"); }
|
||||
finally { btn.innerHTML = originalContent; btn.disabled = false; lucide.createIcons(); }
|
||||
}
|
||||
|
||||
async function rejectRequest() {
|
||||
if(!confirm("¿Seguro que quieres rechazar este horario? El cliente recibirá un mensaje para elegir otro.")) return;
|
||||
const id = document.getElementById('appId').value;
|
||||
@@ -481,7 +452,6 @@
|
||||
const originalContent = btn.innerHTML;
|
||||
btn.innerHTML = `<i data-lucide="loader-2" class="w-4 h-4 animate-spin"></i>`;
|
||||
btn.disabled = true;
|
||||
|
||||
try {
|
||||
const res = await fetch(`${API_URL}/agenda/requests/${id}/reject`, {
|
||||
method: 'POST',
|
||||
@@ -495,7 +465,6 @@
|
||||
} catch (e) { alert("Error de conexión"); }
|
||||
finally { btn.innerHTML = originalContent; btn.disabled = false; lucide.createIcons(); }
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// RENDERIZADO DE LISTADO NORMAL (SIN CITA)
|
||||
// ==========================================
|
||||
@@ -507,7 +476,6 @@
|
||||
const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24));
|
||||
return diffDays;
|
||||
}
|
||||
|
||||
// 🔥 FUNCIÓN DE FILTRADO (BUSCADOR) 🔥
|
||||
function filterServices() {
|
||||
const query = document.getElementById('searchInput').value.toLowerCase().trim();
|
||||
@@ -516,7 +484,6 @@
|
||||
renderServices(localServices); // Si borramos el texto, pinta todos
|
||||
return;
|
||||
}
|
||||
|
||||
const filtered = localServices.filter(s => {
|
||||
const raw = s.raw_data || {};
|
||||
|
||||
@@ -530,13 +497,10 @@
|
||||
${raw["Descripción"] || raw["DESCRIPCION"] || raw["Averia"] || ""}
|
||||
${raw["Compañía"] || raw["Procedencia"] || ""}
|
||||
`.toLowerCase();
|
||||
|
||||
return searchString.includes(query);
|
||||
});
|
||||
|
||||
renderServices(filtered);
|
||||
}
|
||||
|
||||
function renderServices(servicesToRender = localServices) {
|
||||
const container = document.getElementById('servicesList');
|
||||
const noDateSec = document.getElementById('noDateSection');
|
||||
@@ -558,10 +522,8 @@ function renderServices(servicesToRender = localServices) {
|
||||
else noDateSec.classList.add('hidden');
|
||||
return;
|
||||
}
|
||||
|
||||
noDateSec.classList.remove('hidden');
|
||||
noDateSec.querySelector('h2').classList.remove('hidden');
|
||||
|
||||
container.innerHTML = servicesToRender.map(s => {
|
||||
const raw = s.raw_data || {};
|
||||
const name = raw["Nombre Cliente"] || raw["CLIENTE"] || "Asegurado";
|
||||
@@ -599,9 +561,7 @@ function renderServices(servicesToRender = localServices) {
|
||||
// Ponemos la primera letra en mayúscula. Si nos pasamos borrando, devolvemos el texto original por seguridad.
|
||||
return res.length > 5 ? res.charAt(0).toUpperCase() + res.slice(1) : texto;
|
||||
}
|
||||
|
||||
let desc = limpiarPaja(raw["Descripción"] || raw["DESCRIPCION"] || raw["Averia"]);
|
||||
|
||||
const calledTimes = parseInt(raw.called_times || 0);
|
||||
const delayDays = calculateDelayDays(s.created_at);
|
||||
|
||||
@@ -609,7 +569,6 @@ function renderServices(servicesToRender = localServices) {
|
||||
if (delayDays > 1) {
|
||||
delayHtml = `<span class="bg-rose-100 text-rose-600 text-[8px] font-black px-2 py-0.5 rounded uppercase tracking-widest ml-2">Retraso: ${delayDays} días</span>`;
|
||||
}
|
||||
|
||||
let guildName = raw["Gremio"] || raw["GREMIO"] || raw["Especialidad"] || "";
|
||||
|
||||
// ¡AQUÍ ESTÁ LA CLAVE! El ID viene dentro del JSON (raw) o en el servicio (s)
|
||||
@@ -625,7 +584,6 @@ function renderServices(servicesToRender = localServices) {
|
||||
}
|
||||
|
||||
guildName = guildName || "Varios";
|
||||
|
||||
return `
|
||||
<div class="bg-white p-5 rounded-3xl border border-slate-200 shadow-sm relative overflow-hidden mb-4">
|
||||
${isUrgent ? '<div class="absolute top-0 right-0 bg-red-500 text-white text-[8px] font-black px-3 py-1 rounded-bl-xl uppercase tracking-widest shadow-sm z-10">Urgente</div>' : ''}
|
||||
@@ -641,9 +599,9 @@ function renderServices(servicesToRender = localServices) {
|
||||
<i data-lucide="map-pin" class="w-3 h-3"></i> ${addr}, ${pop}
|
||||
</p>
|
||||
|
||||
<div class="mt-2.5 bg-slate-50 border border-slate-100 rounded-xl p-2.5 relative">
|
||||
<p class="text-[10px] text-slate-600 font-medium leading-relaxed line-clamp-2 pr-4">${desc}</p>
|
||||
<i data-lucide="info" class="w-3 h-3 text-slate-300 absolute right-2 top-2.5"></i>
|
||||
<div class="desc-box mt-2.5 bg-slate-50 border border-slate-100 rounded-xl p-2.5 relative active:bg-slate-100 transition-colors" onclick="toggleDesc(this, event)">
|
||||
<p class="text-[10px] text-slate-600 font-medium leading-relaxed line-clamp-2 pr-5">${desc}</p>
|
||||
<i data-lucide="chevron-down" class="desc-toggle-icon w-3.5 h-3.5 text-slate-400 absolute right-2 top-2.5 shrink-0"></i>
|
||||
</div>
|
||||
</div>
|
||||
<div class="shrink-0 pr-2 self-center flex flex-col items-end justify-center gap-1.5 pl-2">
|
||||
@@ -651,7 +609,6 @@ function renderServices(servicesToRender = localServices) {
|
||||
<i data-lucide="chevron-right" class="text-slate-300"></i>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 pt-4 border-t border-slate-100">
|
||||
<button onclick="markClientNotFound(${s.id}, ${calledTimes})" class="w-full bg-orange-50 border border-orange-100 hover:bg-orange-100 text-orange-600 font-black py-2.5 rounded-xl flex items-center justify-center gap-2 transition-colors text-[10px] uppercase tracking-widest">
|
||||
<i data-lucide="bell-ring" class="w-4 h-4"></i> No Localizado (${calledTimes})
|
||||
@@ -660,10 +617,8 @@ function renderServices(servicesToRender = localServices) {
|
||||
</div>
|
||||
`;
|
||||
}).join('');
|
||||
|
||||
lucide.createIcons();
|
||||
}
|
||||
|
||||
// 🔥 MEJORA MATA-FANTASMAS
|
||||
async function openActionModal(id) {
|
||||
let s = localServices.find(x => x.id === id);
|
||||
@@ -680,16 +635,13 @@ function renderServices(servicesToRender = localServices) {
|
||||
}
|
||||
} catch(e) {}
|
||||
}
|
||||
|
||||
// Si definitivamente el aviso fue borrado/reasignado por la oficina
|
||||
if (!s) {
|
||||
showToast("Este aviso ya no está en tu bandeja", true);
|
||||
refreshData(); // Limpiamos la pantalla para que desaparezca visualmente
|
||||
return;
|
||||
}
|
||||
|
||||
const raw = s.raw_data;
|
||||
|
||||
document.getElementById('detId').value = s.id;
|
||||
document.getElementById('detRef').innerText = `Exp. #${s.service_ref || "S/R"}`;
|
||||
document.getElementById('detName').innerText = raw["Nombre Cliente"] || "Asegurado";
|
||||
@@ -698,13 +650,11 @@ function renderServices(servicesToRender = localServices) {
|
||||
const rawPhone = raw["Teléfono"] || raw["TELEFONOS"] || raw["TELEFONO"] || "";
|
||||
const matchPhone = String(rawPhone).match(/[6789]\d{8}/);
|
||||
document.getElementById('detPhoneRaw').value = matchPhone ? matchPhone[0] : "";
|
||||
|
||||
document.getElementById('durationInput').value = "60";
|
||||
pickerSelectedDate = "";
|
||||
pickerSelectedTime = "";
|
||||
buildDayCarousel();
|
||||
checkSaveButton();
|
||||
|
||||
const modal = document.getElementById('actionModal');
|
||||
const content = document.getElementById('modalContent');
|
||||
modal.classList.remove('hidden');
|
||||
@@ -712,13 +662,11 @@ function renderServices(servicesToRender = localServices) {
|
||||
modal.classList.remove('opacity-0');
|
||||
content.classList.remove('translate-y-full');
|
||||
}
|
||||
|
||||
async function markClientNotFound(serviceId, currentTimes) {
|
||||
const btn = event.currentTarget;
|
||||
const originalHtml = btn.innerHTML;
|
||||
btn.innerHTML = `<i data-lucide="loader-2" class="w-4 h-4 animate-spin"></i> Enviando...`;
|
||||
btn.disabled = true;
|
||||
|
||||
try {
|
||||
const res = await fetch(`${API_URL}/services/not-found/${serviceId}`, {
|
||||
method: 'POST',
|
||||
@@ -740,7 +688,6 @@ function renderServices(servicesToRender = localServices) {
|
||||
btn.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// LÓGICA DEL MOTOR DE AGENDAMIENTO INTELIGENTE
|
||||
// ==========================================
|
||||
@@ -750,7 +697,6 @@ function renderServices(servicesToRender = localServices) {
|
||||
const d = String(dateObj.getDate()).padStart(2, '0');
|
||||
return `${y}-${m}-${d}`;
|
||||
}
|
||||
|
||||
function timeToMins(t) { let [h, m] = t.split(':').map(Number); return h * 60 + m; }
|
||||
function minsToTime(m) { let h = Math.floor(m / 60).toString().padStart(2, '0'); let min = (m % 60).toString().padStart(2, '0'); return `${h}:${min}`; }
|
||||
function addOneHour(timeStr) {
|
||||
@@ -771,7 +717,6 @@ function renderServices(servicesToRender = localServices) {
|
||||
return d.toLocaleDateString('es-ES', opciones);
|
||||
} catch(e) { return dateStr; }
|
||||
}
|
||||
|
||||
function buildDayCarousel() {
|
||||
const container = document.getElementById('dayCarousel');
|
||||
container.innerHTML = "";
|
||||
@@ -797,7 +742,6 @@ function renderServices(servicesToRender = localServices) {
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
function selectPickerDate(isoDate) {
|
||||
pickerSelectedDate = isoDate;
|
||||
pickerSelectedTime = "";
|
||||
@@ -805,13 +749,11 @@ function renderServices(servicesToRender = localServices) {
|
||||
renderTimeSlots();
|
||||
checkSaveButton();
|
||||
}
|
||||
|
||||
function selectPickerTime(timeStr) {
|
||||
pickerSelectedTime = timeStr;
|
||||
renderTimeSlots();
|
||||
checkSaveButton();
|
||||
}
|
||||
|
||||
function checkSaveButton() {
|
||||
const btn = document.getElementById('btnSaveAppt');
|
||||
if (pickerSelectedDate && pickerSelectedTime) {
|
||||
@@ -824,7 +766,6 @@ function renderServices(servicesToRender = localServices) {
|
||||
btn.classList.remove('bg-primary-dynamic', 'active:scale-95', 'shadow-lg');
|
||||
}
|
||||
}
|
||||
|
||||
function getOccupiedRanges(dateStr) {
|
||||
let ranges = [];
|
||||
globalAllServices.forEach(s => {
|
||||
@@ -837,14 +778,12 @@ function renderServices(servicesToRender = localServices) {
|
||||
});
|
||||
return ranges;
|
||||
}
|
||||
|
||||
function isOverlapping(startMins, endMins, occupiedRanges) {
|
||||
for(let r of occupiedRanges) {
|
||||
if(startMins < r.end && endMins > r.start) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function renderTimeSlots() {
|
||||
const grid = document.getElementById('timeGrid');
|
||||
const msg = document.getElementById('noSlotsMsg');
|
||||
@@ -853,7 +792,6 @@ function renderServices(servicesToRender = localServices) {
|
||||
|
||||
grid.innerHTML = "";
|
||||
let slotsGenerated = 0;
|
||||
|
||||
const genSlotsForPeriod = (startStr, endStr) => {
|
||||
let startMins = timeToMins(startStr);
|
||||
let endMins = timeToMins(endStr);
|
||||
@@ -871,10 +809,8 @@ function renderServices(servicesToRender = localServices) {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Cambiamos el horario comercial por una franja completa de 08:00 a 24:00
|
||||
genSlotsForPeriod('08:00', '24:00');
|
||||
|
||||
if (slotsGenerated === 0) {
|
||||
msg.classList.remove('hidden');
|
||||
grid.classList.add('hidden');
|
||||
@@ -887,38 +823,8 @@ function renderServices(servicesToRender = localServices) {
|
||||
if (pickerSelectedTime && !grid.innerHTML.includes(`'${pickerSelectedTime}'`)) {
|
||||
pickerSelectedTime = "";
|
||||
}
|
||||
|
||||
checkSaveButton();
|
||||
}
|
||||
|
||||
function openActionModal(id) {
|
||||
const s = localServices.find(x => x.id === id);
|
||||
if (!s) return;
|
||||
const raw = s.raw_data;
|
||||
|
||||
document.getElementById('detId').value = s.id;
|
||||
document.getElementById('detRef').innerText = `Exp. #${s.service_ref || "S/R"}`;
|
||||
document.getElementById('detName').innerText = raw["Nombre Cliente"] || "Asegurado";
|
||||
document.getElementById('detAddress').innerText = `${raw["Dirección"] || ""}, ${raw["Población"] || ""}`;
|
||||
|
||||
const rawPhone = raw["Teléfono"] || raw["TELEFONOS"] || raw["TELEFONO"] || "";
|
||||
const matchPhone = rawPhone.toString().match(/[6789]\d{8}/);
|
||||
document.getElementById('detPhoneRaw').value = matchPhone ? matchPhone[0] : "";
|
||||
|
||||
document.getElementById('durationInput').value = "60";
|
||||
pickerSelectedDate = "";
|
||||
pickerSelectedTime = "";
|
||||
buildDayCarousel();
|
||||
checkSaveButton();
|
||||
|
||||
const modal = document.getElementById('actionModal');
|
||||
const content = document.getElementById('modalContent');
|
||||
modal.classList.remove('hidden');
|
||||
void modal.offsetWidth;
|
||||
modal.classList.remove('opacity-0');
|
||||
content.classList.remove('translate-y-full');
|
||||
}
|
||||
|
||||
function closeModal(modalId, contentId) {
|
||||
const modal = document.getElementById(modalId);
|
||||
const content = document.getElementById(contentId);
|
||||
@@ -926,33 +832,26 @@ function renderServices(servicesToRender = localServices) {
|
||||
content.classList.add('translate-y-full');
|
||||
setTimeout(() => { modal.classList.add('hidden'); }, 300);
|
||||
}
|
||||
|
||||
function callClient() {
|
||||
const phone = document.getElementById('detPhoneRaw').value;
|
||||
if (phone) window.location.href = `tel:+34${phone}`;
|
||||
else alert("No hay un teléfono válido guardado.");
|
||||
}
|
||||
|
||||
function openWhatsApp() {
|
||||
const phone = document.getElementById('detPhoneRaw').value;
|
||||
if (phone) window.open(`https://wa.me/34${phone}`, '_blank');
|
||||
else alert("No hay un teléfono válido guardado.");
|
||||
}
|
||||
|
||||
async function saveAppointment() {
|
||||
const id = document.getElementById('detId').value;
|
||||
const duration = document.getElementById('durationInput').value;
|
||||
|
||||
if (!pickerSelectedDate || !pickerSelectedTime) return alert("Selecciona un hueco disponible.");
|
||||
|
||||
const btn = document.getElementById('btnSaveAppt');
|
||||
const originalContent = btn.innerHTML;
|
||||
btn.innerHTML = `<i data-lucide="loader-2" class="w-5 h-5 animate-spin"></i> Agendando...`;
|
||||
btn.disabled = true;
|
||||
|
||||
const citadoStatus = systemStatuses.find(st => st.name.toLowerCase().includes('citado'));
|
||||
const statusToSave = citadoStatus ? String(citadoStatus.id) : null;
|
||||
|
||||
try {
|
||||
const res = await fetch(`${API_URL}/services/set-appointment/${id}`, {
|
||||
method: 'PUT',
|
||||
@@ -980,7 +879,6 @@ function renderServices(servicesToRender = localServices) {
|
||||
lucide.createIcons();
|
||||
}
|
||||
}
|
||||
|
||||
function showToast(msg) {
|
||||
const t = document.getElementById('toast');
|
||||
document.getElementById('toastMsg').innerText = msg;
|
||||
|
||||
Reference in New Issue
Block a user