Actualizar servicios.html

This commit is contained in:
2026-03-07 15:56:48 +00:00
parent d07e7838d0
commit 3291058f7f

View File

@@ -731,11 +731,10 @@
setTimeout(() => { toast.classList.add('hidden'); }, 3500); setTimeout(() => { toast.classList.add('hidden'); }, 3500);
} }
// LA FUNCIÓN CORREGIDA
function openDetail(id, startInEditMode = false) { function openDetail(id, startInEditMode = false) {
const s = localData.find(x => x.id === id); const s = localData.find(x => x.id === id);
if (!s) return; if (!s) return;
const raw = s.raw_data || {}; // Seguridad anti-crashes const raw = s.raw_data || {};
document.getElementById('detId').value = s.id; document.getElementById('detId').value = s.id;
document.getElementById('detRef').innerText = s.service_ref || ""; document.getElementById('detRef').innerText = s.service_ref || "";
@@ -744,7 +743,6 @@
const companyName = raw['Compañía'] || raw['COMPAÑIA'] || raw['Procedencia'] || "Particular"; const companyName = raw['Compañía'] || raw['COMPAÑIA'] || raw['Procedencia'] || "Particular";
if (document.getElementById('detCompany')) document.getElementById('detCompany').innerText = companyName; if (document.getElementById('detCompany')) document.getElementById('detCompany').innerText = companyName;
// RELLENADO DE CAMPOS PARA EL EDITOR Y VISTA (Inputs)
const clientName = raw["Nombre Cliente"] || raw["CLIENTE"] || "Asegurado Sin Nombre"; const clientName = raw["Nombre Cliente"] || raw["CLIENTE"] || "Asegurado Sin Nombre";
if(document.getElementById('editName')) document.getElementById('editName').value = clientName; if(document.getElementById('editName')) document.getElementById('editName').value = clientName;
@@ -753,7 +751,6 @@
const singlePhone = matchPhone ? matchPhone[0] : ""; const singlePhone = matchPhone ? matchPhone[0] : "";
if(document.getElementById('editPhone')) document.getElementById('editPhone').value = singlePhone; if(document.getElementById('editPhone')) document.getElementById('editPhone').value = singlePhone;
// Lógica del botón de llamada dinámico
const callBtn = document.getElementById('btnCallPhone'); const callBtn = document.getElementById('btnCallPhone');
if (callBtn) { if (callBtn) {
if (singlePhone) { if (singlePhone) {
@@ -808,7 +805,8 @@
} else { } else {
cancelEditing(); cancelEditing();
} }
loadChat(id);
loadChat(id); // <---- ESTO ES LO QUE FALTABA
lucide.createIcons(); lucide.createIcons();
} }
@@ -1018,7 +1016,6 @@
} }
async function copyClientPortalLink() { async function copyClientPortalLink() {
// CORRECCIÓN: Leemos los datos desde los inputs usando .value
const phone = document.getElementById('editPhone').value; const phone = document.getElementById('editPhone').value;
const name = document.getElementById('editName').value; const name = document.getElementById('editName').value;
const addr = document.getElementById('editAddr').value; const addr = document.getElementById('editAddr').value;
@@ -1037,7 +1034,6 @@
lucide.createIcons(); lucide.createIcons();
try { try {
// Limpiamos el teléfono de espacios para evitar fallos
const cleanPhone = phone.replace(/\D/g, ""); const cleanPhone = phone.replace(/\D/g, "");
const res = await fetch(`${API_URL}/clients/ensure`, { const res = await fetch(`${API_URL}/clients/ensure`, {
@@ -1054,7 +1050,6 @@
const portalLink = `https://portal.integrarepara.es/?token=${data.client.portal_token}&service=${serviceId}`; const portalLink = `https://portal.integrarepara.es/?token=${data.client.portal_token}&service=${serviceId}`;
// Doble seguro para copiar (el navegador a veces bloquea navigator.clipboard si no hay HTTPS o permiso explícito)
try { try {
await navigator.clipboard.writeText(portalLink); await navigator.clipboard.writeText(portalLink);
showToast("✅ Enlace copiado al portapapeles."); showToast("✅ Enlace copiado al portapapeles.");
@@ -1106,7 +1101,6 @@
} catch (e) { console.error("Error en buscador rápido:", e); } } catch (e) { console.error("Error en buscador rápido:", e); }
} }
// --- MOTOR DE EDICIÓN DE FICHA ---
function enableEditing() { function enableEditing() {
document.getElementById('viewActions').classList.add('hidden'); document.getElementById('viewActions').classList.add('hidden');
document.getElementById('editActions').classList.remove('hidden'); document.getElementById('editActions').classList.remove('hidden');
@@ -1201,7 +1195,6 @@
chatBox.innerHTML += bubbleHtml; chatBox.innerHTML += bubbleHtml;
}); });
// Hacer scroll hasta abajo automáticamente
setTimeout(() => { chatBox.scrollTop = chatBox.scrollHeight; }, 100); setTimeout(() => { chatBox.scrollTop = chatBox.scrollHeight; }, 100);
} }
} catch (e) { } catch (e) {
@@ -1228,7 +1221,7 @@
if (res.ok) { if (res.ok) {
input.value = ''; input.value = '';
document.getElementById('chatInternal').checked = false; document.getElementById('chatInternal').checked = false;
loadChat(serviceId); // Recargar el chat al enviar loadChat(serviceId);
} else { } else {
showToast("Error al enviar mensaje", "warning"); showToast("Error al enviar mensaje", "warning");
} }