Actualizar proveedores.html

This commit is contained in:
2026-02-27 22:31:13 +00:00
parent 1ee80177ec
commit 1abe39d5ed

View File

@@ -399,6 +399,7 @@
const addr = raw['Dirección'] || raw['DOMICILIO'] || ""; const addr = raw['Dirección'] || raw['DOMICILIO'] || "";
const pop = raw['Población'] || raw['POBLACION-PROVINCIA'] || ""; const pop = raw['Población'] || raw['POBLACION-PROVINCIA'] || "";
const fullAddr = `${addr} ${pop}`.trim(); const fullAddr = `${addr} ${pop}`.trim();
const cp = raw['Código Postal'] || raw['C.P.'] || "";
const phone = (raw['Teléfono'] || raw['TELEFONOS'] || raw['TELEFONO'] || "").match(/[6789]\d{8}/)?.[0] || ""; const phone = (raw['Teléfono'] || raw['TELEFONOS'] || raw['TELEFONO'] || "").match(/[6789]\d{8}/)?.[0] || "";
let guildName = null; let guildName = null;
@@ -415,6 +416,7 @@
let bgClass = 'bg-white'; let bgClass = 'bg-white';
let isLocked = false; let isLocked = false;
let lockedMsg = ''; let lockedMsg = '';
let showQuickQueueBtn = false; // Variable para saber si mostrar el botón rápido
const autoStatus = (svc.automation_status || '').toLowerCase(); const autoStatus = (svc.automation_status || '').toLowerCase();
const sysStatus = (svc.status || '').toLowerCase(); const sysStatus = (svc.status || '').toLowerCase();
@@ -441,6 +443,8 @@
} else if (autoStatus === 'failed') { } else if (autoStatus === 'failed') {
bgClass = 'bg-red-50/40 border-red-200 hover:border-red-400'; bgClass = 'bg-red-50/40 border-red-200 hover:border-red-400';
isLocked = false; isLocked = false;
// Si ha fallado, pero tiene gremio detectado, le damos la opción de reenviar a la bolsa rápidamente
if (rawGuildId) showQuickQueueBtn = true;
badgeEstado = ` badgeEstado = `
<div class="flex flex-col items-end gap-1"> <div class="flex flex-col items-end gap-1">
<span class="bg-red-100 text-red-700 px-3 py-1 rounded-full text-[10px] font-black uppercase flex items-center gap-1.5 border border-red-200 shadow-sm"> <span class="bg-red-100 text-red-700 px-3 py-1 rounded-full text-[10px] font-black uppercase flex items-center gap-1.5 border border-red-200 shadow-sm">
@@ -452,8 +456,14 @@
// AQUÍ USAMOS EL COLOR Y NOMBRE DEL ESTADO DE LA BASE DE DATOS // AQUÍ USAMOS EL COLOR Y NOMBRE DEL ESTADO DE LA BASE DE DATOS
const cMap = colorMap[dbStatusObj.color] || colorMap['gray']; const cMap = colorMap[dbStatusObj.color] || colorMap['gray'];
bgClass = `${cMap.bg.replace('100', '50')}/40 ${cMap.border} hover:border-${dbStatusObj.color}-400`; bgClass = `${cMap.bg.replace('100', '50')}/40 ${cMap.border} hover:border-${dbStatusObj.color}-400`;
// Si está en un estado que no sea "Pendiente" o "Sin Asignar", se bloquea la edición por aquí
if(!dbStatusObj.name.toLowerCase().includes('pendiente') && !dbStatusObj.name.toLowerCase().includes('desasignado')) {
isLocked = true; isLocked = true;
lockedMsg = `Este servicio ya está en estado: ${dbStatusObj.name}. Ve al Panel Operativo.`; lockedMsg = `Este servicio ya está en estado: ${dbStatusObj.name}. Ve al Panel Operativo.`;
} else if(rawGuildId && !opName) {
showQuickQueueBtn = true; // Si está pendiente, sin técnico y tiene gremio -> Botón rápido
}
badgeEstado = ` badgeEstado = `
<div class="flex flex-col items-end gap-1"> <div class="flex flex-col items-end gap-1">
@@ -486,6 +496,7 @@
</div>`; </div>`;
} else { } else {
bgClass = isUrgent ? 'bg-red-50/20 border-red-300 hover:border-red-50 shadow-[0_0_15px_rgba(239,68,68,0.15)]' : 'bg-white border-slate-200'; bgClass = isUrgent ? 'bg-red-50/20 border-red-300 hover:border-red-50 shadow-[0_0_15px_rgba(239,68,68,0.15)]' : 'bg-white border-slate-200';
if(rawGuildId) showQuickQueueBtn = true; // Si está virgen y tiene gremio -> Botón rápido
badgeEstado = ` badgeEstado = `
<div class="flex flex-col items-end gap-1"> <div class="flex flex-col items-end gap-1">
<span class="bg-slate-100 text-slate-500 px-3 py-1 rounded-full text-[10px] font-black uppercase flex items-center gap-1.5 border border-slate-200"> <span class="bg-slate-100 text-slate-500 px-3 py-1 rounded-full text-[10px] font-black uppercase flex items-center gap-1.5 border border-slate-200">
@@ -521,6 +532,15 @@
} }
}; };
let quickQueueHtml = '';
if (showQuickQueueBtn) {
quickQueueHtml = `
<button onclick="quickSendToQueue(event, '${svc.id}', '${rawGuildId}', '${cp}')" class="bg-emerald-100 hover:bg-emerald-600 text-emerald-700 hover:text-white transition-colors rounded-full p-2" title="Mandar a la bolsa">
<i data-lucide="zap" class="w-4 h-4"></i>
</button>
`;
}
card.innerHTML = ` card.innerHTML = `
<div class="flex items-center gap-4 min-w-0 flex-1"> <div class="flex items-center gap-4 min-w-0 flex-1">
<div class="w-16 h-16 rounded-2xl flex flex-col items-center justify-center shrink-0 shadow-sm border border-slate-100 ${isArchived ? 'bg-gray-200 text-gray-400' : (svc.provider === 'homeserve' ? 'bg-red-50 text-red-600' : 'bg-blue-50 text-blue-600')}"> <div class="w-16 h-16 rounded-2xl flex flex-col items-center justify-center shrink-0 shadow-sm border border-slate-100 ${isArchived ? 'bg-gray-200 text-gray-400' : (svc.provider === 'homeserve' ? 'bg-red-50 text-red-600' : 'bg-blue-50 text-blue-600')}">
@@ -536,9 +556,10 @@
${urgentBadge} ${urgentBadge}
</div> </div>
<p class="text-xs text-slate-400 truncate italic mt-0.5">${fullAddr}</p> <p class="text-xs text-slate-400 truncate italic mt-0.5">${fullAddr}</p>
<div class="flex flex-wrap gap-2 mt-2"> <div class="flex flex-wrap gap-2 mt-2 items-center">
<span class="text-[10px] bg-slate-100 text-slate-500 px-2 py-0.5 rounded-lg font-bold border">#${svc.service_ref}</span> <span class="text-[10px] bg-slate-100 text-slate-500 px-2 py-0.5 rounded-lg font-bold border">#${svc.service_ref}</span>
${guildName ? `<span class="text-[10px] bg-blue-50 text-blue-600 px-2 py-0.5 rounded-lg font-bold border border-blue-100"><i data-lucide="hammer" class="w-2.5 h-2.5 inline mr-1"></i>${guildName}</span>` : ''} ${guildName ? `<span class="text-[10px] bg-blue-50 text-blue-600 px-2 py-0.5 rounded-lg font-bold border border-blue-100"><i data-lucide="hammer" class="w-2.5 h-2.5 inline mr-1"></i>${guildName}</span>` : ''}
${quickQueueHtml}
</div> </div>
</div> </div>
</div> </div>
@@ -748,6 +769,30 @@
finally { btn.disabled = false; } finally { btn.disabled = false; }
} }
// Nueva función para el botón rápido
async function quickSendToQueue(event, id, guildId, cp) {
event.stopPropagation(); // Evita que se abra el modal
if(!guildId) {
showToast("⚠️ Falta el gremio. Ábrelo para asignarlo.", true);
return;
}
try {
showToast("🚀 Iniciando automatismo...");
const res = await fetch(`${API_URL}/providers/automate/${id}`, {
method: 'POST',
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
body: JSON.stringify({ guild_id: guildId, cp: cp })
});
const data = await res.json();
if (data.ok) {
showToast("✅ ¡En cola! Se ha enviado a los operarios.");
loadInbox(); // Refresca la lista sin cerrar modales (ya que no hay)
} else { showToast("❌ " + data.error, true); }
} catch (e) { showToast("❌ Error de conexión", true); }
}
async function sendToQueue() { async function sendToQueue() {
const id = document.getElementById('impScrapedId').value; const id = document.getElementById('impScrapedId').value;
const payload = getFormPayload(); const payload = getFormPayload();