Actualizar proveedores.html

This commit is contained in:
2026-02-15 19:00:45 +00:00
parent 23e1d8f6fb
commit 6d9e9b4fd5

View File

@@ -82,9 +82,9 @@
</div>
</div>
<div id="importModal" class="fixed inset-0 bg-slate-900/75 hidden z-[100] flex items-center justify-center backdrop-blur-md p-2">
<div id="importModal" class="fixed inset-0 bg-slate-900/75 hidden z-[100] flex items-center justify-center backdrop-blur-md p-2 text-left">
<div class="bg-white rounded-[2.5rem] shadow-2xl w-full max-w-4xl flex flex-col max-h-[95vh] overflow-hidden border border-slate-200 fade-in text-left">
<div class="px-8 pt-6 pb-4 flex justify-between items-center border-b border-slate-50">
<div class="px-8 pt-6 pb-4 flex justify-between items-center border-b border-slate-50 text-left">
<div class="flex items-center gap-4 text-left">
<div id="modalCompanyLogo" class="w-12 h-12 rounded-xl bg-slate-50 border border-slate-100 p-2 flex items-center justify-center shadow-sm overflow-hidden"></div>
<div>
@@ -106,7 +106,7 @@
<option value="true">🚨 MUY URGENTE</option>
</select>
</div>
<button onclick="closeModal()" class="bg-slate-50 p-2 rounded-full hover:bg-red-50 hover:text-red-500 transition-all">
<button onclick="closeModal()" class="bg-slate-50 p-2 rounded-full hover:bg-red-50 hover:text-red-500 transition-all text-left">
<i data-lucide="x" class="w-5 h-5"></i>
</button>
</div>
@@ -115,39 +115,39 @@
<input type="hidden" id="impScrapedId">
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="bg-slate-50/50 p-3 rounded-2xl border border-slate-100 flex items-center gap-3 text-left">
<div class="bg-white p-2 rounded-xl shadow-sm text-slate-400"><i data-lucide="user" class="w-4 h-4"></i></div>
<div class="bg-white p-2 rounded-xl shadow-sm text-slate-400 text-left"><i data-lucide="user" class="w-4 h-4"></i></div>
<div class="flex flex-col min-w-0 w-full text-left">
<span class="text-[9px] font-black text-slate-400 uppercase mb-0.5">Asegurado</span>
<input type="text" id="impName" readonly class="bg-transparent border-none p-0 text-sm font-bold text-slate-700 outline-none w-full">
<span class="text-[9px] font-black text-slate-400 uppercase mb-0.5 text-left">Asegurado</span>
<input type="text" id="impName" readonly class="bg-transparent border-none p-0 text-sm font-bold text-slate-700 outline-none w-full text-left">
</div>
</div>
<div class="bg-slate-50/50 p-3 rounded-2xl border border-slate-100 flex items-center gap-3 text-left">
<div class="bg-white p-2 rounded-xl shadow-sm text-emerald-500"><i data-lucide="phone" class="w-4 h-4"></i></div>
<div class="bg-white p-2 rounded-xl shadow-sm text-emerald-500 text-left"><i data-lucide="phone" class="w-4 h-4 text-left"></i></div>
<div class="flex flex-col min-w-0 w-full text-left">
<span class="text-[9px] font-black text-slate-400 uppercase mb-0.5">Teléfono</span>
<input type="text" id="impPhone" readonly class="bg-transparent border-none p-0 text-sm font-black text-emerald-600 outline-none w-full">
<span class="text-[9px] font-black text-slate-400 uppercase mb-0.5 text-left">Teléfono</span>
<input type="text" id="impPhone" readonly class="bg-transparent border-none p-0 text-sm font-black text-emerald-600 outline-none w-full text-left">
</div>
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-5 gap-3 text-left">
<div class="md:col-span-4 space-y-1 text-left">
<label class="text-[9px] font-black text-blue-600 uppercase tracking-widest ml-2 flex items-center gap-1 text-left"><i data-lucide="map-pin" class="w-3 h-3"></i> Dirección</label>
<input type="text" id="impAddress" required class="w-full border-2 border-slate-100 bg-white px-4 py-2.5 rounded-2xl text-sm font-medium outline-none focus:border-blue-500 shadow-sm">
<label class="text-[9px] font-black text-blue-600 uppercase tracking-widest ml-2 flex items-center gap-1 text-left"><i data-lucide="map-pin" class="w-3 h-3 text-left"></i> Dirección</label>
<input type="text" id="impAddress" required class="w-full border-2 border-slate-100 bg-white px-4 py-2.5 rounded-2xl text-sm font-medium outline-none focus:border-blue-500 shadow-sm text-left">
</div>
<div class="space-y-1 text-center">
<label class="text-[9px] font-black text-blue-600 uppercase tracking-widest block">C.P.</label>
<label class="text-[9px] font-black text-blue-600 uppercase tracking-widest block text-left ml-2">C.P.</label>
<input type="text" id="impCP" required class="w-full border-2 border-slate-100 bg-white py-2.5 rounded-2xl text-sm font-black text-center outline-none focus:border-blue-500 shadow-sm">
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 p-5 rounded-[1.8rem] border-2 border-blue-50 bg-blue-50/30 text-left">
<div class="space-y-1 text-left">
<label class="text-[9px] font-black text-blue-600 uppercase tracking-widest ml-2">Gremio Especialista *</label>
<label class="text-[9px] font-black text-blue-600 uppercase tracking-widest ml-2 text-left">Gremio Especialista *</label>
<select id="impGuild" required onchange="loadOpsForGuild(this.value)" class="w-full border border-blue-100 bg-white px-3 py-2 rounded-xl text-sm font-bold shadow-sm outline-none focus:ring-2 focus:ring-blue-400 text-left">
<option value="">-- Seleccionar Gremio --</option>
</select>
</div>
<div class="space-y-1 text-left">
<label class="text-[9px] font-black text-slate-400 uppercase tracking-widest ml-2">Asignación Operario</label>
<label class="text-[9px] font-black text-slate-400 uppercase tracking-widest ml-2 text-left">Asignación Operario</label>
<select id="impOperator" class="w-full border border-blue-100 bg-white px-3 py-2 rounded-xl text-sm font-bold shadow-sm outline-none focus:ring-2 focus:ring-blue-400 text-left">
<option value="">-- Automática --</option>
</select>
@@ -155,33 +155,36 @@
</div>
<div class="space-y-3 text-left">
<div class="space-y-1 text-left">
<label class="text-[9px] font-black text-slate-400 uppercase tracking-widest ml-2">Avería Detectada</label>
<label class="text-[9px] font-black text-slate-400 uppercase tracking-widest ml-2 text-left">Avería Detectada</label>
<textarea id="impDesc" rows="2" class="w-full border border-slate-200 bg-white px-4 py-2 rounded-2xl text-sm font-medium text-slate-600 outline-none focus:border-blue-400 resize-none shadow-sm text-left"></textarea>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 text-left">
<div class="text-left">
<label class="text-[9px] font-black text-amber-600 uppercase ml-2 mb-1 block">Notas Oficina</label>
<label class="text-[9px] font-black text-amber-600 uppercase ml-2 mb-1 block text-left">Notas Oficina</label>
<textarea id="impNotesInt" rows="1" class="w-full border border-amber-100 bg-amber-50/30 px-3 py-2 rounded-xl text-xs outline-none focus:bg-white text-left"></textarea>
</div>
<div class="text-left">
<label class="text-[9px] font-black text-blue-500 uppercase ml-2 mb-1 block">Instrucciones Operario</label>
<label class="text-[9px] font-black text-blue-500 uppercase ml-2 mb-1 block text-left">Instrucciones Operario</label>
<textarea id="impNotesExt" rows="1" class="w-full border border-blue-100 bg-blue-50/30 px-3 py-2 rounded-xl text-xs outline-none focus:bg-white text-left"></textarea>
</div>
</div>
</div>
<div class="flex items-center gap-3 pt-4 border-t text-left">
<button type="button" onclick="saveDraftChanges(event)" class="bg-slate-100 hover:bg-slate-200 text-slate-600 font-black px-6 py-5 rounded-[1.8rem] transition-all flex items-center justify-center gap-2 active:scale-95 text-xs uppercase tracking-widest">
<i data-lucide="save" class="w-4 h-4 text-left"></i> <span>Guardar Borrador</span>
<div class="flex flex-wrap items-center gap-3 pt-4 border-t text-left">
<button type="button" onclick="saveDraftChanges(event)" class="bg-slate-100 hover:bg-slate-200 text-slate-600 font-black px-4 py-4 rounded-[1.5rem] transition-all flex items-center justify-center gap-2 active:scale-95 text-[10px] uppercase tracking-widest">
<i data-lucide="save" class="w-4 h-4"></i> <span>Guardar</span>
</button>
<button type="submit" class="flex-1 bg-slate-900 hover:bg-emerald-600 text-white font-black py-5 rounded-[1.8rem] shadow-xl transition-all flex items-center justify-center gap-3 active:scale-95 text-sm uppercase tracking-[0.2em]">
<span>TRASPASAR A CRM</span> <i data-lucide="send" class="w-5 h-5 text-left"></i>
<button type="submit" class="bg-blue-600 hover:bg-blue-700 text-white font-black px-6 py-4 rounded-[1.5rem] shadow-lg transition-all flex items-center justify-center gap-2 active:scale-95 text-[10px] uppercase tracking-widest">
<i data-lucide="send" class="w-4 h-4"></i> <span>Traspaso Manual</span>
</button>
<button type="button" onclick="sendToQueue()" class="flex-1 bg-emerald-600 hover:bg-emerald-700 text-white font-black py-4 rounded-[1.5rem] shadow-xl shadow-emerald-200 transition-all flex items-center justify-center gap-3 active:scale-95 text-xs uppercase tracking-[0.15em]">
<i data-lucide="zap" class="w-5 h-5"></i> <span>MANDAR A LA COLA (AUTO)</span>
</button>
</div>
</form>
</div>
</div>
<div id="toast" class="fixed bottom-8 right-8 bg-slate-900 text-white px-8 py-4 rounded-2xl shadow-2xl hidden z-[200] border border-white/10"><span id="toastMsg" class="font-bold text-sm text-left"></span></div>
<div id="toast" class="fixed bottom-8 right-8 bg-slate-900 text-white px-8 py-4 rounded-2xl shadow-2xl hidden z-[200] border border-white/10 text-left"><span id="toastMsg" class="font-bold text-sm text-left"></span></div>
<script src="js/layout.js"></script>
<script>
@@ -244,7 +247,6 @@
async function loadInbox() {
const container = document.getElementById('inboxContainer');
try {
// MODIFICACIÓN: Ya no solicitamos solo 'pending', traemos todo para el filtrado reactivo
const resSvc = await fetch(`${API_URL}/providers/scraped`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
const dataSvc = await resSvc.json();
scrapedData = dataSvc.services || [];
@@ -258,7 +260,6 @@
compSelect.innerHTML = '<option value="ALL">COMPAÑÍAS</option>';
uniqueCompanies.forEach(c => compSelect.innerHTML += `<option value="${c}">${c}</option>`);
// ACTUALIZAR ESTADÍSTICAS
const active = scrapedData.filter(s => s.status === 'pending').length;
const archived = scrapedData.filter(s => s.status === 'archived').length;
document.getElementById('countActive').innerText = active;
@@ -274,7 +275,7 @@
const search = document.getElementById('searchBox').value.toUpperCase();
const provider = document.getElementById('filterProvider').value;
const company = document.getElementById('filterCompany').value;
const status = document.getElementById('filterStatus').value; // FILTRO DE ESTADO
const status = document.getElementById('filterStatus').value;
const filtered = scrapedData.filter(svc => {
const raw = svc.raw_data || {};
@@ -287,7 +288,7 @@
const matchesSearch = name.includes(search) || ref.includes(search) || addr.includes(search) || phone.includes(search);
const matchesProvider = provider === 'ALL' || svc.provider === provider;
const matchesCompany = company === 'ALL' || comp === company;
const matchesStatus = status === 'ALL' || svc.status === status; // CORRECCIÓN VISIBILIDAD
const matchesStatus = status === 'ALL' || svc.status === status;
return matchesSearch && matchesProvider && matchesCompany && matchesStatus;
});
@@ -303,25 +304,21 @@
const isArchived = svc.status === 'archived';
const statusLabel = isArchived ? 'ARCHIVADO' : 'SERVICIO ACTIVO';
const statusClass = isArchived ? 'bg-gray-100 text-gray-500 border-gray-200' : 'bg-emerald-50 text-emerald-600 border-emerald-100';
const name = raw['Nombre Cliente'] || raw['CLIENTE'] || "S/N";
const addr = raw['Dirección'] || raw['DOMICILIO'] || "";
const pop = raw['Población'] || raw['POBLACION-PROVINCIA'] || "";
const fullAddr = `${addr} ${pop}`.trim();
const phone = (raw['Teléfono'] || raw['TELEFONOS'] || raw['TELEFONO'] || "").match(/[6789]\d{8}/)?.[0] || "";
const guildName = allGuilds.find(g => g.id == raw['guild_id'])?.name || null;
const opName = raw['assigned_to_name'] || null;
const card = document.createElement('div');
card.className = `service-card bg-white p-5 rounded-2xl border ${isArchived ? 'archived' : 'shadow-sm'} flex items-center justify-between transition-all group fade-in text-left`;
card.onclick = (e) => {
if (e.target.closest('a') || e.target.closest('button')) return;
if (isArchived) showToast("⚠️ Este servicio está ARCHIVADO (ya no aparece en la web de compañía).", true);
if (isArchived) showToast("⚠️ Este servicio está ARCHIVADO.", true);
else openEditor(svc.id);
};
card.innerHTML = `
<div class="flex items-center gap-4 min-w-0 text-left">
<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')}">
@@ -365,7 +362,7 @@
document.getElementById('modalCompanyLogo').innerHTML = `<img src="${getLogoUrl(companyName)}" class="max-w-full max-h-full object-contain">`;
document.getElementById('displayRef').innerText = `REF: ${svc.service_ref}`;
document.getElementById('displayCompany').innerText = companyName;
document.getElementById('modalStatusBadge').innerHTML = `<span class="text-[9px] bg-emerald-50 text-emerald-600 px-3 py-1 rounded-full font-black border border-emerald-100">SERVICIO ACTIVO</span>`;
document.getElementById('modalStatusBadge').innerHTML = `<span class="text-[9px] bg-emerald-50 text-emerald-600 px-3 py-1 rounded-full font-black border border-emerald-100 text-left">SERVICIO ACTIVO</span>`;
document.getElementById('impScrapedId').value = id;
document.getElementById('impName').value = raw['Nombre Cliente'] || raw['CLIENTE'] || "S/N";
@@ -376,13 +373,10 @@
document.getElementById('impAddress').value = `${addr} ${pop}`.trim();
document.getElementById('impCP').value = raw['Código Postal'] || raw['C.P.'] || "";
document.getElementById('impDesc').value = raw['Descripción'] || "";
const isUrgent = raw['Urgente'] === 'Sí' || raw['Urgente'] === 'true' || raw['URGENTE'] === 'SI';
document.getElementById('impUrgent').value = isUrgent.toString();
document.getElementById('impNotesInt').value = raw['internal_notes'] || "";
document.getElementById('impNotesExt').value = raw['client_notes'] || "";
const savedGuild = raw['guild_id'] || "";
document.getElementById('impGuild').value = savedGuild;
@@ -403,7 +397,6 @@
const id = document.getElementById('impScrapedId').value;
const btn = e.currentTarget;
btn.disabled = true;
const opSelect = document.getElementById('impOperator');
const opName = opSelect.options[opSelect.selectedIndex]?.text.includes('--') ? null : opSelect.options[opSelect.selectedIndex]?.text;
@@ -427,7 +420,7 @@
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${localStorage.getItem("token")}` },
body: JSON.stringify(payload)
});
if(res.ok) { showToast("✅ Borrador guardado correctamente"); loadInbox(); }
if(res.ok) { showToast("✅ Borrador guardado"); loadInbox(); }
else { showToast("❌ Error al guardar", true); }
} catch (e) { showToast("❌ Error de red", true); }
finally { btn.disabled = false; }
@@ -464,6 +457,40 @@
finally { btn.disabled = false; }
}
// NUEVA FUNCIÓN: MANDAR A LA COLA
async function sendToQueue() {
const id = document.getElementById('impScrapedId').value;
const guild_id = document.getElementById('impGuild').value;
const cp = document.getElementById('impCP').value;
if (!guild_id) {
showToast("⚠️ Selecciona un gremio para el automatismo", 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, cp })
});
const data = await res.json();
if (data.ok) {
showToast("✅ ¡En cola! Se ha enviado el primer WhatsApp.");
closeModal();
loadInbox();
} else {
showToast("❌ " + data.error, true);
}
} catch (e) {
showToast("❌ Error de conexión", true);
}
}
function showToast(msg, isError = false) {
const t = document.getElementById('toast'), m = document.getElementById('toastMsg');
t.className = `fixed bottom-8 right-8 px-8 py-4 rounded-2xl shadow-2xl z-[200] flex items-center gap-3 transition-all ${isError ? 'bg-red-600' : 'bg-slate-900'} text-white text-left`;