diff --git a/asignados.html b/asignados.html index 3be1d3d..ab30936 100644 --- a/asignados.html +++ b/asignados.html @@ -120,6 +120,7 @@ +
`; + }).join(''); + row.classList.remove('hidden'); + lucide.createIcons(); + } + function selectPhone(number) { + document.getElementById('detPhoneRaw').value = number; + const s = localServices.find(x => String(x.id) === String(document.getElementById('detId').value)); + renderPhoneSelector(Array.isArray(s?.phones) && s.phones.length > 0 ? s.phones : [{number, isMobile:/^[67]/.test(number)}]); + } async function saveAppointment() { const id = document.getElementById('detId').value; const duration = document.getElementById('durationInput').value; @@ -981,7 +1012,9 @@ function renderServices(servicesToRender = localServices) { id: s.id, type: 'sin_cita', address, name: raw["Nombre Cliente"] || raw["CLIENTE"] || "Asegurado", company: raw["Compañía"] || raw["Procedencia"] || "Particular", - phone: extractPhone(raw), isUrgent: !!s.is_urgent + // 📞 Preferimos el teléfono ya priorizado (móvil primero) que manda la API; + // si no vino (caché vieja), caemos al match simple de siempre. + phone: (Array.isArray(s.phones) && s.phones[0]?.number) || extractPhone(raw), isUrgent: !!s.is_urgent }); }); pendingRequests.forEach(req => { @@ -1124,6 +1157,7 @@ function renderServices(servicesToRender = localServices) {
${dirUrl ? `` : ''} ${r.phone ? `` : ''} + ${r.phone ? `` : ''}
`; diff --git a/calendario.html b/calendario.html index 1664c73..5407def 100644 --- a/calendario.html +++ b/calendario.html @@ -169,8 +169,10 @@ - + + + + @@ -1010,9 +1012,16 @@ const fullAddress = `${raw["Dirección"] || ""}, ${raw["Código Postal"] || ""} ${raw["Población"] || ""}`; document.getElementById('detAddress').innerText = fullAddress; + // 📞 Usamos los teléfonos ya extraídos y priorizados (móvil primero) por la API. + // Si por caché no vinieran, caemos al match simple de siempre. const rawPhone = raw["Teléfono"] || raw["TELEFONOS"] || raw["TELEFONO"] || ""; const matchPhone = String(rawPhone).match(/[6789]\d{8}/); - document.getElementById('detPhoneRaw').value = matchPhone ? matchPhone[0] : ""; + const fallbackPhone = matchPhone ? matchPhone[0] : ""; + const detailPhones = Array.isArray(s.phones) && s.phones.length > 0 + ? s.phones + : (fallbackPhone ? [{ number: fallbackPhone, isMobile: /^[67]/.test(fallbackPhone), horario: '', contacto: '' }] : []); + document.getElementById('detPhoneRaw').value = detailPhones[0]?.number || ""; + renderPhoneSelector(detailPhones); const banner = document.getElementById('urgentBanner'); if (s.is_urgent) banner.classList.remove('hidden'); @@ -1386,13 +1395,37 @@ } else { alert("Sin teléfono"); } } - function openWhatsApp() { - const p = document.getElementById('detPhoneRaw').value; + function openWhatsApp() { + const p = document.getElementById('detPhoneRaw').value; if (p) { sendLog("WhatsApp Abierto", "El operario ha abierto el chat de WhatsApp con el cliente."); - window.open(`https://wa.me/34${p}`, '_blank'); + window.open(`https://wa.me/34${p}`, '_blank'); } else { alert("Sin teléfono"); } } + + // 📞 Cuando el servicio trae más de un teléfono (típico de HomeServe), pintamos un + // selector de chips para que el operario elija cuál usar antes de Llamar/WhatsApp. + // Con un solo teléfono no mostramos nada (para no añadir ruido visual de más). + function renderPhoneSelector(phones) { + const row = document.getElementById('phoneSelectorRow'); + if (!row) return; + if (!phones || phones.length <= 1) { row.innerHTML = ''; row.classList.add('hidden'); return; } + const active = document.getElementById('detPhoneRaw').value; + row.innerHTML = phones.map(p => { + const isActive = p.number === active; + return ` + `; + }).join(''); + row.classList.remove('hidden'); + lucide.createIcons(); + } + function selectPhone(number) { + document.getElementById('detPhoneRaw').value = number; + const s = localServices.find(x => String(x.id) === String(document.getElementById('detId').value)); + renderPhoneSelector(Array.isArray(s?.phones) && s.phones.length > 0 ? s.phones : [{number, isMobile:/^[67]/.test(number)}]); + } async function copyAndOpenPortal() { const btn = document.getElementById('btnPortal');