@@ -152,11 +202,11 @@
document.getElementById('pending-list').innerHTML = pending.length > 0
? pending.map(s => cardTemplate(s, 'blue', 'Asignado')).join('')
- : '
';
document.getElementById('assigned-list').innerHTML = assigned.length > 0
? assigned.map(s => cardTemplate(s, 'emerald', 'En Curso')).join('')
- : '
';
lucide.createIcons();
}
@@ -166,6 +216,14 @@
const addr = raw["Dirección"] || raw["DOMICILIO"] || "---";
const cita = raw.scheduled_date ? `${raw.scheduled_date} | ${raw.scheduled_time}` : 'Pendiente Cita';
+ // Buscar si tiene un estado especial para mostrarlo en la tarjeta
+ const estadoActual = raw.status_operativo || 'citado';
+ let iconEstado = 'calendar';
+ if(estadoActual === 'de_camino') iconEstado = 'car';
+ if(estadoActual === 'trabajando') iconEstado = 'wrench';
+ if(estadoActual === 'incidencia') iconEstado = 'alert-triangle';
+ if(estadoActual === 'terminado') iconEstado = 'check-circle';
+
return `
@@ -174,7 +232,7 @@
${addr}
${s.assigned_name || 'Sin asignar'}
- ${raw.scheduled_date ? `
${cita}
` : ''}
+ ${raw.scheduled_date ? `
${cita}
` : ''}
@@ -187,10 +245,21 @@
const raw = s.raw_data;
document.getElementById('detId').value = s.id;
document.getElementById('detRef').innerText = s.service_ref;
- document.getElementById('detName').innerText = raw["Nombre Cliente"] || raw["CLIENTE"] || "S/N";
- document.getElementById('detPhone').innerText = raw["Teléfono"] || raw["TELEFONO"] || "S/T";
- document.getElementById('detAddr').innerText = raw["Dirección"] || "S/D";
+ document.getElementById('detName').innerText = raw["Nombre Cliente"] || raw["CLIENTE"] || "Asegurado Sin Nombre";
+
+ const phone = raw["Teléfono"] || raw["TELEFONO"] || "Sin Teléfono";
+ document.getElementById('detPhone').innerText = phone;
+ // Extraer solo números para el enlace de llamada
+ const cleanPhone = phone.replace(/\D/g,'');
+ document.getElementById('detPhoneLink').href = cleanPhone ? `tel:${cleanPhone}` : "#";
+
+ document.getElementById('detAddrText').innerText = `${raw["Dirección"] || "Dirección no especificada"} ${raw["Población"] || ""}`;
document.getElementById('detWorker').innerText = s.assigned_name || "Pendiente";
+
+ // Mostrar la descripción completa
+ document.getElementById('detDesc').innerHTML = (raw["Descripción"] || raw["DESCRIPCION"] || "No hay notas adicionales del siniestro.")
+ .replace(/\n/g, '
');
+
document.getElementById('dateInput').value = raw.scheduled_date || "";
document.getElementById('timeInput').value = raw.scheduled_time || "";
@@ -207,14 +276,41 @@
const time = document.getElementById('timeInput').value;
const statusMap = document.getElementById('detStatusMap').value;
- if(!date || !time) return alert("Indica fecha y hora");
+ // BUG SOLUCIONADO: Ya no bloquea obligando a poner la fecha
+ // Solo avisa si no hay fecha porque sin fecha la tarjeta se queda a la izquierda.
+ if(!date && statusMap !== 'incidencia' && statusMap !== 'terminado') {
+ if(!confirm("No has asignado una Fecha de Visita.\n\nEl estado se guardará, pero el expediente seguirá en la columna izquierda hasta que le pongas fecha. ¿Deseas continuar?")) return;
+ }
- const res = await fetch(`${API_URL}/services/set-appointment/${id}`, {
- method: 'PUT',
- headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
- body: JSON.stringify({ date, time, status_operativo: statusMap })
- });
- if(res.ok) { closeDetailModal(); refreshPanel(); }
+ const btn = document.getElementById('btnSaveAppt');
+ const originalContent = btn.innerHTML;
+
+ // Efecto visual de guardando
+ btn.innerHTML = `
Guardando...`;
+ btn.disabled = true;
+ lucide.createIcons();
+
+ try {
+ const res = await fetch(`${API_URL}/services/set-appointment/${id}`, {
+ method: 'PUT',
+ headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
+ body: JSON.stringify({ date, time, status_operativo: statusMap })
+ });
+
+ if(res.ok) {
+ closeDetailModal();
+ refreshPanel();
+ } else {
+ alert("Error al guardar en el servidor");
+ }
+ } catch (e) {
+ alert("Error de conexión");
+ } finally {
+ // Restaurar botón por si acaso
+ btn.innerHTML = originalContent;
+ btn.disabled = false;
+ lucide.createIcons();
+ }
}
async function saveNewService(e) {