diff --git a/servicios.html b/servicios.html index f6f1b8e..6c4fe21 100644 --- a/servicios.html +++ b/servicios.html @@ -329,18 +329,20 @@ -
+
- +
+
+
@@ -901,6 +903,44 @@ setTimeout(() => { toast.classList.add('hidden'); }, 3500); } + // 馃摓 Pinta un chip por cada tel茅fono detectado (m贸viles primero), con bot贸n de llamar, + // bot贸n de WhatsApp, y un bot贸n para usarlo como el tel茅fono "oficial" del expediente + // (rellena editPhone, que es el que se guarda en la base de datos al Guardar). + function renderPhoneChips(phones, activePhone) { + const cont = document.getElementById('phoneChips'); + if (!cont) return; + if (!phones || phones.length === 0) { cont.innerHTML = ''; return; } + if (phones.length === 1 && phones[0].number === activePhone) { cont.innerHTML = ''; return; } + + cont.innerHTML = phones.map(p => { + const isActive = p.number === activePhone; + const label = p.isMobile ? 'M贸vil' : 'Fijo'; + const icon = p.isMobile ? 'smartphone' : 'phone'; + const extra = [p.contacto, p.horario].filter(Boolean).join(' 路 '); + return ` +
+ + + ${label} + + +
`; + }).join(''); + lucide.createIcons(); + } + + // Marca un tel茅fono concreto (elegido entre los detectados) como el oficial del + // expediente: actualiza el campo editable y el bot贸n de llamada principal. + function usePhoneAsOfficial(number) { + const input = document.getElementById('editPhone'); + if (input) input.value = number; + const callBtn = document.getElementById('btnCallPhone'); + if (callBtn) { callBtn.href = `tel:+34${number}`; callBtn.classList.remove('hidden'); } + const s = localData.find(x => x.id === Number(document.getElementById('detId').value)); + const allPhones = (s && Array.isArray(s.phones) && s.phones.length > 0) ? s.phones : []; + renderPhoneChips(allPhones, number); + } + function openDetail(id, startInEditMode = false) { const s = localData.find(x => x.id === id); if (!s) return; @@ -923,17 +963,30 @@ const clientName = raw["Nombre Cliente"] || raw["CLIENTE"] || "Asegurado Sin Nombre"; if(document.getElementById('editName')) document.getElementById('editName').value = clientName; + // 馃摓 Todos los tel茅fonos detectados para este servicio (m贸viles primero, ya vienen + // as铆 ordenados desde la API). Si por lo que sea la API a煤n no los env铆a (cach茅 vieja), + // recurrimos al match simple de siempre como red de seguridad. const rawPhone = raw["Tel茅fono"] || raw["TELEFONOS"] || raw["TELEFONO"] || ""; const matchPhone = rawPhone.toString().match(/[6789]\d{8}/); const singlePhone = matchPhone ? matchPhone[0] : ""; - if(document.getElementById('editPhone')) document.getElementById('editPhone').value = singlePhone; + const allPhones = Array.isArray(s.phones) && s.phones.length > 0 + ? s.phones + : (singlePhone ? [{ number: singlePhone, isMobile: /^[67]/.test(singlePhone), horario: '', contacto: '' }] : []); + + // El campo "editPhone" sigue siendo el tel茅fono "oficial" del expediente (editable + // manualmente y el que se guarda al pulsar Guardar); lo rellenamos con el mejor + // candidato (m贸vil si lo hay) pero el admin puede elegir otro con los chips de abajo. + const bestPhone = allPhones[0]?.number || singlePhone || ""; + if(document.getElementById('editPhone')) document.getElementById('editPhone').value = bestPhone; const callBtn = document.getElementById('btnCallPhone'); if (callBtn) { - if (singlePhone) { callBtn.href = `tel:+34${singlePhone}`; callBtn.classList.remove('hidden'); } + if (bestPhone) { callBtn.href = `tel:+34${bestPhone}`; callBtn.classList.remove('hidden'); } else { callBtn.classList.add('hidden'); } } + renderPhoneChips(allPhones, bestPhone); + const fullAddr = `${raw["Direcci贸n"] || ""} ${raw["Poblaci贸n"] || ""}`.trim(); if(document.getElementById('editAddr')) document.getElementById('editAddr').value = fullAddr;