Actualizar solicitar.html
This commit is contained in:
158
solicitar.html
158
solicitar.html
@@ -12,14 +12,12 @@
|
|||||||
--secondary: #2563eb;
|
--secondary: #2563eb;
|
||||||
--app-bg: #f4f7f9;
|
--app-bg: #f4f7f9;
|
||||||
}
|
}
|
||||||
|
|
||||||
body { background-color: var(--app-bg); -webkit-tap-highlight-color: transparent; }
|
body { background-color: var(--app-bg); -webkit-tap-highlight-color: transparent; }
|
||||||
.fade-in { animation: fadeIn 0.3s ease-out forwards; }
|
.fade-in { animation: fadeIn 0.3s ease-out forwards; }
|
||||||
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
|
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
|
||||||
.no-scrollbar::-webkit-scrollbar { display: none; }
|
.no-scrollbar::-webkit-scrollbar { display: none; }
|
||||||
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
|
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
|
||||||
.bottom-nav-safe { padding-bottom: env(safe-area-inset-bottom); }
|
.bottom-nav-safe { padding-bottom: env(safe-area-inset-bottom); }
|
||||||
|
|
||||||
.text-primary-dynamic { color: var(--primary) !important; }
|
.text-primary-dynamic { color: var(--primary) !important; }
|
||||||
.bg-primary-dynamic { background-color: var(--primary) !important; }
|
.bg-primary-dynamic { background-color: var(--primary) !important; }
|
||||||
.border-primary-dynamic { border-color: var(--primary) !important; }
|
.border-primary-dynamic { border-color: var(--primary) !important; }
|
||||||
@@ -27,7 +25,6 @@
|
|||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body class="text-slate-800 font-sans antialiased h-screen flex flex-col overflow-hidden relative">
|
<body class="text-slate-800 font-sans antialiased h-screen flex flex-col overflow-hidden relative">
|
||||||
|
|
||||||
<header class="bg-white px-5 pt-8 pb-4 shadow-sm z-20 shrink-0 border-b border-slate-100 flex justify-between items-center">
|
<header class="bg-white px-5 pt-8 pb-4 shadow-sm z-20 shrink-0 border-b border-slate-100 flex justify-between items-center">
|
||||||
<div>
|
<div>
|
||||||
<p class="text-[10px] font-black text-primary-dynamic uppercase tracking-widest mb-0.5">Bolsa de Trabajo</p>
|
<p class="text-[10px] font-black text-primary-dynamic uppercase tracking-widest mb-0.5">Bolsa de Trabajo</p>
|
||||||
@@ -37,7 +34,6 @@
|
|||||||
<i data-lucide="arrow-left" class="w-5 h-5"></i>
|
<i data-lucide="arrow-left" class="w-5 h-5"></i>
|
||||||
</a>
|
</a>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<main class="flex-1 overflow-y-auto no-scrollbar p-5 relative z-10" id="mainArea">
|
<main class="flex-1 overflow-y-auto no-scrollbar p-5 relative z-10" id="mainArea">
|
||||||
|
|
||||||
<div id="searchContainer" class="hidden mb-6 flex gap-2">
|
<div id="searchContainer" class="hidden mb-6 flex gap-2">
|
||||||
@@ -55,7 +51,6 @@
|
|||||||
<i data-lucide="arrow-up-down" class="w-4 h-4 absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 pointer-events-none"></i>
|
<i data-lucide="arrow-up-down" class="w-4 h-4 absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 pointer-events-none"></i>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="loader" class="text-center py-10 opacity-50">
|
<div id="loader" class="text-center py-10 opacity-50">
|
||||||
<i data-lucide="loader-2" class="w-8 h-8 animate-spin mx-auto text-primary-dynamic mb-2"></i>
|
<i data-lucide="loader-2" class="w-8 h-8 animate-spin mx-auto text-primary-dynamic mb-2"></i>
|
||||||
<p class="text-xs font-bold uppercase tracking-widest mt-2 text-slate-400">Rastreando tu zona...</p>
|
<p class="text-xs font-bold uppercase tracking-widest mt-2 text-slate-400">Rastreando tu zona...</p>
|
||||||
@@ -73,7 +68,6 @@
|
|||||||
<a href="asignados.html" class="inline-block mt-6 bg-slate-900 text-white text-xs font-black uppercase tracking-widest px-6 py-3 rounded-xl shadow-lg active:scale-95 transition-transform">Ver Mis Asignados</a>
|
<a href="asignados.html" class="inline-block mt-6 bg-slate-900 text-white text-xs font-black uppercase tracking-widest px-6 py-3 rounded-xl shadow-lg active:scale-95 transition-transform">Ver Mis Asignados</a>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<nav class="bg-white border-t border-slate-200 shrink-0 pb-safe z-20 absolute bottom-0 w-full shadow-[0_-10px_30px_rgba(0,0,0,0.05)] rounded-t-3xl">
|
<nav class="bg-white border-t border-slate-200 shrink-0 pb-safe z-20 absolute bottom-0 w-full shadow-[0_-10px_30px_rgba(0,0,0,0.05)] rounded-t-3xl">
|
||||||
<div class="flex justify-around items-center p-3 bottom-nav-safe">
|
<div class="flex justify-around items-center p-3 bottom-nav-safe">
|
||||||
<a href="menu.html" class="flex flex-col items-center p-2 text-slate-400 hover:text-primary-dynamic transition-transform active:scale-95">
|
<a href="menu.html" class="flex flex-col items-center p-2 text-slate-400 hover:text-primary-dynamic transition-transform active:scale-95">
|
||||||
@@ -86,7 +80,6 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div id="actionModal" class="fixed inset-0 bg-slate-900/60 z-[100] hidden flex-col justify-end transition-opacity duration-300 opacity-0">
|
<div id="actionModal" class="fixed inset-0 bg-slate-900/60 z-[100] hidden flex-col justify-end transition-opacity duration-300 opacity-0">
|
||||||
<div id="modalContent" class="bg-white rounded-t-[2rem] p-6 pb-12 transform translate-y-full transition-transform duration-300 shadow-2xl">
|
<div id="modalContent" class="bg-white rounded-t-[2rem] p-6 pb-12 transform translate-y-full transition-transform duration-300 shadow-2xl">
|
||||||
|
|
||||||
@@ -98,22 +91,27 @@
|
|||||||
</div>
|
</div>
|
||||||
<button onclick="closeModal()" class="w-8 h-8 bg-slate-100 rounded-full flex items-center justify-center text-slate-500 hover:text-red-500"><i data-lucide="x" class="w-4 h-4"></i></button>
|
<button onclick="closeModal()" class="w-8 h-8 bg-slate-100 rounded-full flex items-center justify-center text-slate-500 hover:text-red-500"><i data-lucide="x" class="w-4 h-4"></i></button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="space-y-4 mb-6">
|
<div class="space-y-4 mb-6">
|
||||||
<div class="bg-slate-50 p-4 rounded-2xl border border-slate-100">
|
<div class="bg-slate-50 p-4 rounded-2xl border border-slate-100">
|
||||||
<p class="text-[10px] font-black text-slate-400 uppercase tracking-widest flex items-center gap-1 mb-1"><i data-lucide="map-pin" class="w-3 h-3"></i> Zona / Dirección</p>
|
<p class="text-[10px] font-black text-slate-400 uppercase tracking-widest flex items-center gap-1 mb-1"><i data-lucide="map-pin" class="w-3 h-3"></i> Zona / Dirección</p>
|
||||||
<p id="detAddress" class="font-bold text-slate-700 text-sm uppercase"></p>
|
<p id="detAddress" class="font-bold text-slate-700 text-sm uppercase"></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<p class="text-[10px] font-black text-slate-400 uppercase tracking-widest flex items-center gap-1 mb-1 ml-1"><i data-lucide="align-left" class="w-3 h-3"></i> Descripción</p>
|
<p class="text-[10px] font-black text-slate-400 uppercase tracking-widest flex items-center gap-1 mb-1 ml-1"><i data-lucide="align-left" class="w-3 h-3"></i> Descripción</p>
|
||||||
<div class="bg-white p-4 rounded-2xl border border-slate-100 text-sm text-slate-600 max-h-32 overflow-y-auto no-scrollbar" id="detDesc">
|
<div class="bg-white p-4 rounded-2xl border border-slate-100 text-sm text-slate-600 max-h-32 overflow-y-auto no-scrollbar" id="detDesc">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="guildPickerWrap" class="hidden">
|
||||||
|
<p class="text-[10px] font-black text-amber-600 uppercase tracking-widest flex items-center gap-1 mb-2 ml-1"><i data-lucide="alert-triangle" class="w-3 h-3"></i> Este aviso no tiene gremio. Asígnalo antes de cogerlo:</p>
|
||||||
|
<div class="relative">
|
||||||
|
<select id="guildPickerSelect" onchange="checkClaimReady()" class="w-full bg-amber-50 border border-amber-200 p-3.5 rounded-xl text-sm font-black text-slate-700 outline-none focus:ring-2 focus:ring-amber-400 transition-all appearance-none pr-10 cursor-pointer">
|
||||||
|
<option value="">-- Selecciona un gremio --</option>
|
||||||
|
</select>
|
||||||
|
<i data-lucide="chevron-down" class="w-5 h-5 absolute right-4 top-1/2 -translate-y-1/2 text-amber-400 pointer-events-none"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input type="hidden" id="detId">
|
<input type="hidden" id="detId">
|
||||||
|
|
||||||
<button onclick="claimService()" id="btnClaim" class="w-full bg-primary-dynamic text-white font-black py-4 rounded-2xl shadow-xl active:scale-95 transition-transform flex items-center justify-center gap-2 uppercase tracking-widest text-xs">
|
<button onclick="claimService()" id="btnClaim" class="w-full bg-primary-dynamic text-white font-black py-4 rounded-2xl shadow-xl active:scale-95 transition-transform flex items-center justify-center gap-2 uppercase tracking-widest text-xs">
|
||||||
<i data-lucide="hand" class="w-5 h-5"></i> ¡Me lo quedo!
|
<i data-lucide="hand" class="w-5 h-5"></i> ¡Me lo quedo!
|
||||||
</button>
|
</button>
|
||||||
@@ -121,17 +119,14 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="toast" class="fixed top-5 left-1/2 -translate-x-1/2 bg-slate-800 text-white px-5 py-3 rounded-full shadow-2xl z-[200] font-bold text-xs uppercase tracking-widest flex items-center gap-2 transition-all duration-300 opacity-0 pointer-events-none transform -translate-y-10">
|
<div id="toast" class="fixed top-5 left-1/2 -translate-x-1/2 bg-slate-800 text-white px-5 py-3 rounded-full shadow-2xl z-[200] font-bold text-xs uppercase tracking-widest flex items-center gap-2 transition-all duration-300 opacity-0 pointer-events-none transform -translate-y-10">
|
||||||
<i data-lucide="check-circle" class="w-4 h-4 text-emerald-400"></i>
|
<i data-lucide="check-circle" class="w-4 h-4 text-emerald-400"></i>
|
||||||
<span id="toastMsg">Servicio Asignado</span>
|
<span id="toastMsg">Servicio Asignado</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const API_URL = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'
|
const API_URL = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'
|
||||||
? 'http://localhost:3000'
|
? 'http://localhost:3000'
|
||||||
: 'https://integrarepara-api.integrarepara.es';
|
: 'https://integrarepara-api.integrarepara.es';
|
||||||
|
|
||||||
let availableServices = [];
|
let availableServices = [];
|
||||||
let systemStatuses = [];
|
let systemStatuses = [];
|
||||||
let systemGuilds = [];
|
let systemGuilds = [];
|
||||||
@@ -140,7 +135,6 @@
|
|||||||
let myUserId = null;
|
let myUserId = null;
|
||||||
let myUserName = "";
|
let myUserName = "";
|
||||||
let isRestricted = false;
|
let isRestricted = false;
|
||||||
|
|
||||||
// --- SISTEMA DE TEMA DINÁMICO ---
|
// --- SISTEMA DE TEMA DINÁMICO ---
|
||||||
async function applyTheme() {
|
async function applyTheme() {
|
||||||
try {
|
try {
|
||||||
@@ -161,7 +155,6 @@
|
|||||||
}
|
}
|
||||||
} catch (e) { console.warn("Usando tema por defecto"); }
|
} catch (e) { console.warn("Usando tema por defecto"); }
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", async () => {
|
document.addEventListener("DOMContentLoaded", async () => {
|
||||||
if (!localStorage.getItem("token")) {
|
if (!localStorage.getItem("token")) {
|
||||||
window.location.href = "index.html"; return;
|
window.location.href = "index.html"; return;
|
||||||
@@ -172,7 +165,6 @@
|
|||||||
if (currentRole !== 'operario' && currentRole !== 'operario_cerrado') {
|
if (currentRole !== 'operario' && currentRole !== 'operario_cerrado') {
|
||||||
window.location.href = "index.html"; return;
|
window.location.href = "index.html"; return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await applyTheme();
|
await applyTheme();
|
||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
|
|
||||||
@@ -185,13 +177,11 @@
|
|||||||
document.getElementById('btnRecargar').style.display = 'none'; // Quitamos el botón de recargar
|
document.getElementById('btnRecargar').style.display = 'none'; // Quitamos el botón de recargar
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si está libre, cargamos la bolsa
|
// Si está libre, cargamos la bolsa
|
||||||
await loadStatuses();
|
await loadStatuses();
|
||||||
await loadGuilds();
|
await loadGuilds();
|
||||||
loadAvailableServices();
|
loadAvailableServices();
|
||||||
});
|
});
|
||||||
|
|
||||||
async function fetchUserData() {
|
async function fetchUserData() {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_URL}/auth/me`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
const res = await fetch(`${API_URL}/auth/me`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
||||||
@@ -202,7 +192,6 @@
|
|||||||
if (data.user.role === 'operario_cerrado') {
|
if (data.user.role === 'operario_cerrado') {
|
||||||
isRestricted = true;
|
isRestricted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
myUserId = data.user.id;
|
myUserId = data.user.id;
|
||||||
myUserName = data.user.full_name;
|
myUserName = data.user.full_name;
|
||||||
userZones = Array.isArray(data.user.zones) ? data.user.zones.map(z => z.cps) : [];
|
userZones = Array.isArray(data.user.zones) ? data.user.zones.map(z => z.cps) : [];
|
||||||
@@ -216,7 +205,6 @@
|
|||||||
}
|
}
|
||||||
} catch(e) { console.error("Error perfil", e); }
|
} catch(e) { console.error("Error perfil", e); }
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadStatuses() {
|
async function loadStatuses() {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_URL}/statuses`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
const res = await fetch(`${API_URL}/statuses`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
||||||
@@ -232,15 +220,12 @@
|
|||||||
if(data.ok) systemGuilds = data.guilds;
|
if(data.ok) systemGuilds = data.guilds;
|
||||||
} catch(e){}
|
} catch(e){}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadAvailableServices() {
|
async function loadAvailableServices() {
|
||||||
if (isRestricted) return; // Doble seguridad
|
if (isRestricted) return; // Doble seguridad
|
||||||
|
|
||||||
document.getElementById('servicesList').classList.add('hidden');
|
document.getElementById('servicesList').classList.add('hidden');
|
||||||
document.getElementById('searchContainer').classList.add('hidden');
|
document.getElementById('searchContainer').classList.add('hidden');
|
||||||
document.getElementById('loader').classList.remove('hidden');
|
document.getElementById('loader').classList.remove('hidden');
|
||||||
document.getElementById('searchInput').value = ""; // Limpiamos el buscador al recargar
|
document.getElementById('searchInput').value = ""; // Limpiamos el buscador al recargar
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_URL}/providers/scraped`, {
|
const res = await fetch(`${API_URL}/providers/scraped`, {
|
||||||
headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` }
|
headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` }
|
||||||
@@ -259,14 +244,18 @@
|
|||||||
if(s.status === 'archived' || (dbStatus && ['anulado', 'terminado', 'finalizado'].includes(dbStatus.toLowerCase()))) return false;
|
if(s.status === 'archived' || (dbStatus && ['anulado', 'terminado', 'finalizado'].includes(dbStatus.toLowerCase()))) return false;
|
||||||
|
|
||||||
// 3. Filtrar por Gremio y Zona del operario
|
// 3. Filtrar por Gremio y Zona del operario
|
||||||
const sGuild = String(s.guild_id || raw.guild_id);
|
const rawGuildId = s.guild_id ?? raw.guild_id;
|
||||||
|
// 🆕 ¿Este aviso tiene gremio asignado de verdad? (no vacío, no null, no 0)
|
||||||
|
const hasGuild = rawGuildId !== undefined && rawGuildId !== null && String(rawGuildId).trim() !== "" && String(rawGuildId) !== "0";
|
||||||
|
const sGuild = String(rawGuildId);
|
||||||
const sCp = String(raw['Código Postal'] || raw['CP'] || "").trim();
|
const sCp = String(raw['Código Postal'] || raw['CP'] || "").trim();
|
||||||
|
const matchGuild = hasGuild && (userGuilds.includes(Number(sGuild)) || userGuilds.includes(String(sGuild)));
|
||||||
const matchGuild = userGuilds.includes(Number(sGuild)) || userGuilds.includes(String(sGuild));
|
|
||||||
const matchZone = userZones.some(z => sCp.startsWith(z));
|
const matchZone = userZones.some(z => sCp.startsWith(z));
|
||||||
|
// 🆕 REGLA NUEVA: si el aviso NO tiene gremio asignado, dejamos que cualquiera lo vea
|
||||||
// Si el operario no tiene filtros, lo ve todo. Si tiene, debe coincidir.
|
// (antes se quedaba invisible para siempre). Se pinta en otro color en la tarjeta.
|
||||||
if((userGuilds.length === 0 || matchGuild) && (userZones.length === 0 || matchZone)) {
|
const guildOk = !hasGuild || userGuilds.length === 0 || matchGuild;
|
||||||
|
// Si el operario no tiene filtros de zona, lo ve todo. Si tiene, debe coincidir.
|
||||||
|
if(guildOk && (userZones.length === 0 || matchZone)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -285,35 +274,6 @@
|
|||||||
document.getElementById('servicesList').classList.remove('hidden');
|
document.getElementById('servicesList').classList.remove('hidden');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 🔥 FUNCIÓN DE FILTRADO (BUSCADOR) 🔥
|
|
||||||
function filterServices() {
|
|
||||||
const query = document.getElementById('searchInput').value.toLowerCase().trim();
|
|
||||||
|
|
||||||
if (query === "") {
|
|
||||||
renderServices(availableServices); // Si está vacío, pinta todos
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const filtered = availableServices.filter(s => {
|
|
||||||
const raw = s.raw_data || {};
|
|
||||||
|
|
||||||
const searchString = `
|
|
||||||
${s.service_ref || ""}
|
|
||||||
${raw["Nombre Cliente"] || raw["CLIENTE"] || ""}
|
|
||||||
${raw["Dirección"] || raw["DOMICILIO"] || ""}
|
|
||||||
${raw["Población"] || raw["POBLACION-PROVINCIA"] || ""}
|
|
||||||
${raw["Código Postal"] || raw["C.P."] || ""}
|
|
||||||
${raw["Descripción"] || raw["DESCRIPCION"] || raw["Averia"] || ""}
|
|
||||||
${raw["Compañía"] || raw["Procedencia"] || ""}
|
|
||||||
`.toLowerCase();
|
|
||||||
|
|
||||||
return searchString.includes(query);
|
|
||||||
});
|
|
||||||
|
|
||||||
renderServices(filtered);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Se ha modificado para que reciba el array a pintar (filtered o full)
|
// Se ha modificado para que reciba el array a pintar (filtered o full)
|
||||||
function renderServices(servicesToRender) {
|
function renderServices(servicesToRender) {
|
||||||
const container = document.getElementById('servicesList');
|
const container = document.getElementById('servicesList');
|
||||||
@@ -331,7 +291,6 @@
|
|||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
container.innerHTML = servicesToRender.map(s => {
|
container.innerHTML = servicesToRender.map(s => {
|
||||||
const raw = s.raw_data || {};
|
const raw = s.raw_data || {};
|
||||||
const name = raw["Nombre Cliente"] || raw["CLIENTE"] || "Asegurado";
|
const name = raw["Nombre Cliente"] || raw["CLIENTE"] || "Asegurado";
|
||||||
@@ -340,16 +299,18 @@
|
|||||||
const isUrgent = s.is_urgent;
|
const isUrgent = s.is_urgent;
|
||||||
const company = raw["Compañía"] || raw["Procedencia"] || "Particular";
|
const company = raw["Compañía"] || raw["Procedencia"] || "Particular";
|
||||||
const guildObj = systemGuilds.find(g => String(g.id) === String(s.guild_id || raw.guild_id));
|
const guildObj = systemGuilds.find(g => String(g.id) === String(s.guild_id || raw.guild_id));
|
||||||
|
// 🆕 Si no encontramos un gremio válido para este aviso, lo marcamos visualmente en ámbar
|
||||||
|
const sinGremio = !guildObj;
|
||||||
return `
|
return `
|
||||||
<div onclick="openActionModal(${s.id})" class="bg-white p-5 rounded-3xl border border-slate-200 shadow-sm active:scale-95 transition-transform flex flex-col gap-3 relative overflow-hidden cursor-pointer">
|
<div onclick="openActionModal(${s.id})" class="bg-white p-5 rounded-3xl border ${sinGremio ? 'border-amber-300' : 'border-slate-200'} shadow-sm active:scale-95 transition-transform flex flex-col gap-3 relative overflow-hidden cursor-pointer">
|
||||||
${isUrgent ? '<div class="absolute top-0 right-0 bg-red-500 text-white text-[8px] font-black px-3 py-1 rounded-bl-xl uppercase tracking-widest shadow-sm z-10">Urgente</div>' : ''}
|
${isUrgent ? '<div class="absolute top-0 right-0 bg-red-500 text-white text-[8px] font-black px-3 py-1 rounded-bl-xl uppercase tracking-widest shadow-sm z-10">Urgente</div>' : ''}
|
||||||
|
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<span class="bg-slate-100 text-slate-500 text-[9px] font-black px-2 py-0.5 rounded uppercase">#${s.service_ref}</span>
|
<span class="bg-slate-100 text-slate-500 text-[9px] font-black px-2 py-0.5 rounded uppercase">#${s.service_ref}</span>
|
||||||
<span class="bg-blue-50 text-primary-dynamic text-[9px] font-black px-2 py-0.5 rounded uppercase border border-blue-100">${guildObj ? guildObj.name : 'Reparación'}</span>
|
<span class="${sinGremio ? 'bg-amber-50 text-amber-600 border-amber-200' : 'bg-blue-50 text-primary-dynamic border-blue-100'} text-[9px] font-black px-2 py-0.5 rounded uppercase border flex items-center gap-1">
|
||||||
|
${sinGremio ? '<i data-lucide="alert-triangle" class="w-2.5 h-2.5"></i> Sin Gremio' : guildObj.name}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<p class="text-[9px] font-black text-slate-400 uppercase tracking-widest mb-0.5">${company}</p>
|
<p class="text-[9px] font-black text-slate-400 uppercase tracking-widest mb-0.5">${company}</p>
|
||||||
<h3 class="font-black text-slate-800 text-base uppercase leading-tight truncate">${name}</h3>
|
<h3 class="font-black text-slate-800 text-base uppercase leading-tight truncate">${name}</h3>
|
||||||
@@ -357,21 +318,18 @@
|
|||||||
|
|
||||||
<div class="bg-slate-50 p-2.5 rounded-xl border border-slate-100">
|
<div class="bg-slate-50 p-2.5 rounded-xl border border-slate-100">
|
||||||
<p class="text-[10px] font-bold text-slate-600 uppercase flex items-center gap-1.5 truncate">
|
<p class="text-[10px] font-bold text-slate-600 uppercase flex items-center gap-1.5 truncate">
|
||||||
<i data-lucide="map-pin" class="w-3.5 h-3.5 text-primary-dynamic shrink-0"></i> ${pop} - ${addr}
|
<i data-lucide="map-pin" class="w-3.5 h-3.5 ${sinGremio ? 'text-amber-500' : 'text-primary-dynamic'} shrink-0"></i> ${pop} - ${addr}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}).join('');
|
}).join('');
|
||||||
|
|
||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
}
|
}
|
||||||
|
|
||||||
function openActionModal(id) {
|
function openActionModal(id) {
|
||||||
const s = availableServices.find(x => x.id === id);
|
const s = availableServices.find(x => x.id === id);
|
||||||
if (!s) return;
|
if (!s) return;
|
||||||
const raw = s.raw_data;
|
const raw = s.raw_data;
|
||||||
|
|
||||||
document.getElementById('detId').value = s.id;
|
document.getElementById('detId').value = s.id;
|
||||||
document.getElementById('detRef').innerText = `Exp. #${s.service_ref || "S/R"}`;
|
document.getElementById('detRef').innerText = `Exp. #${s.service_ref || "S/R"}`;
|
||||||
document.getElementById('detName').innerText = raw["Nombre Cliente"] || "Asegurado";
|
document.getElementById('detName').innerText = raw["Nombre Cliente"] || "Asegurado";
|
||||||
@@ -379,6 +337,21 @@
|
|||||||
document.getElementById('detAddress').innerText = `${raw["Dirección"] || ""}, ${raw["Código Postal"] || ""} ${raw["Población"] || ""}`;
|
document.getElementById('detAddress').innerText = `${raw["Dirección"] || ""}, ${raw["Código Postal"] || ""} ${raw["Población"] || ""}`;
|
||||||
document.getElementById('detDesc').innerHTML = (raw["Descripción"] || raw["DESCRIPCION"] || "Sin descripción proporcionada.").replace(/\n/g, '<br>');
|
document.getElementById('detDesc').innerHTML = (raw["Descripción"] || raw["DESCRIPCION"] || "Sin descripción proporcionada.").replace(/\n/g, '<br>');
|
||||||
|
|
||||||
|
// 🆕 Si el aviso no tiene un gremio reconocido, mostramos el selector para que el operario lo asigne antes de cogerlo
|
||||||
|
const guildObj = systemGuilds.find(g => String(g.id) === String(s.guild_id || raw.guild_id));
|
||||||
|
const guildWrap = document.getElementById('guildPickerWrap');
|
||||||
|
const guildSelect = document.getElementById('guildPickerSelect');
|
||||||
|
if (!guildObj) {
|
||||||
|
guildSelect.innerHTML = '<option value="">-- Selecciona un gremio --</option>' +
|
||||||
|
systemGuilds.map(g => `<option value="${g.id}">${g.name}</option>`).join('');
|
||||||
|
guildSelect.value = "";
|
||||||
|
guildWrap.classList.remove('hidden');
|
||||||
|
} else {
|
||||||
|
guildWrap.classList.add('hidden');
|
||||||
|
guildSelect.innerHTML = "";
|
||||||
|
}
|
||||||
|
checkClaimReady();
|
||||||
|
|
||||||
// Mostrar modal con animación
|
// Mostrar modal con animación
|
||||||
const modal = document.getElementById('actionModal');
|
const modal = document.getElementById('actionModal');
|
||||||
const content = document.getElementById('modalContent');
|
const content = document.getElementById('modalContent');
|
||||||
@@ -387,7 +360,22 @@
|
|||||||
modal.classList.remove('opacity-0');
|
modal.classList.remove('opacity-0');
|
||||||
content.classList.remove('translate-y-full');
|
content.classList.remove('translate-y-full');
|
||||||
}
|
}
|
||||||
|
// 🆕 Activa/desactiva el botón "¡Me lo quedo!" según si hace falta elegir gremio primero
|
||||||
|
function checkClaimReady() {
|
||||||
|
const btn = document.getElementById('btnClaim');
|
||||||
|
const guildWrap = document.getElementById('guildPickerWrap');
|
||||||
|
const needsGuild = !guildWrap.classList.contains('hidden');
|
||||||
|
const guildChosen = document.getElementById('guildPickerSelect').value !== "";
|
||||||
|
if (needsGuild && !guildChosen) {
|
||||||
|
btn.disabled = true;
|
||||||
|
btn.classList.add('bg-slate-300', 'cursor-not-allowed');
|
||||||
|
btn.classList.remove('bg-primary-dynamic', 'active:scale-95', 'shadow-xl');
|
||||||
|
} else {
|
||||||
|
btn.disabled = false;
|
||||||
|
btn.classList.remove('bg-slate-300', 'cursor-not-allowed');
|
||||||
|
btn.classList.add('bg-primary-dynamic', 'active:scale-95', 'shadow-xl');
|
||||||
|
}
|
||||||
|
}
|
||||||
function closeModal() {
|
function closeModal() {
|
||||||
const modal = document.getElementById('actionModal');
|
const modal = document.getElementById('actionModal');
|
||||||
const content = document.getElementById('modalContent');
|
const content = document.getElementById('modalContent');
|
||||||
@@ -397,21 +385,24 @@
|
|||||||
|
|
||||||
setTimeout(() => { modal.classList.add('hidden'); }, 300);
|
setTimeout(() => { modal.classList.add('hidden'); }, 300);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function claimService() {
|
async function claimService() {
|
||||||
const id = document.getElementById('detId').value;
|
const id = document.getElementById('detId').value;
|
||||||
const btn = document.getElementById('btnClaim');
|
const btn = document.getElementById('btnClaim');
|
||||||
|
// 🆕 Si hacía falta elegir gremio, comprobamos que lo haya seleccionado
|
||||||
|
const guildWrap = document.getElementById('guildPickerWrap');
|
||||||
|
const needsGuild = !guildWrap.classList.contains('hidden');
|
||||||
|
const selectedGuild = document.getElementById('guildPickerSelect').value;
|
||||||
|
if (needsGuild && !selectedGuild) {
|
||||||
|
return alert("Selecciona un gremio para este aviso antes de cogerlo.");
|
||||||
|
}
|
||||||
|
|
||||||
if(!myUserId) return alert("Error de sesión. Vuelve a entrar.");
|
if(!myUserId) return alert("Error de sesión. Vuelve a entrar.");
|
||||||
|
|
||||||
const originalContent = btn.innerHTML;
|
const originalContent = btn.innerHTML;
|
||||||
btn.innerHTML = `<i data-lucide="loader-2" class="w-5 h-5 animate-spin"></i> Asignando...`;
|
btn.innerHTML = `<i data-lucide="loader-2" class="w-5 h-5 animate-spin"></i> Asignando...`;
|
||||||
btn.disabled = true;
|
btn.disabled = true;
|
||||||
|
|
||||||
// Buscamos el estado "Asignado" para ponerlo automáticamente
|
// Buscamos el estado "Asignado" para ponerlo automáticamente
|
||||||
const estadoAsignado = systemStatuses.find(st => st.name.toLowerCase() === 'asignado') || systemStatuses[1];
|
const estadoAsignado = systemStatuses.find(st => st.name.toLowerCase() === 'asignado') || systemStatuses[1];
|
||||||
const statusToSave = estadoAsignado ? String(estadoAsignado.id) : 'asignado_operario';
|
const statusToSave = estadoAsignado ? String(estadoAsignado.id) : 'asignado_operario';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Primero paramos el robot por si estaba buscando a alguien
|
// Primero paramos el robot por si estaba buscando a alguien
|
||||||
await fetch(`${API_URL}/providers/scraped/${id}`, {
|
await fetch(`${API_URL}/providers/scraped/${id}`, {
|
||||||
@@ -419,16 +410,19 @@
|
|||||||
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
|
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
|
||||||
body: JSON.stringify({ automation_status: 'completed' })
|
body: JSON.stringify({ automation_status: 'completed' })
|
||||||
});
|
});
|
||||||
|
// Luego nos asignamos el servicio (y le dejamos puesto el gremio, si hacía falta)
|
||||||
// Luego nos asignamos el servicio
|
const claimPayload = {
|
||||||
|
assigned_to: myUserId,
|
||||||
|
assigned_to_name: myUserName,
|
||||||
|
status_operativo: statusToSave
|
||||||
|
};
|
||||||
|
if (needsGuild && selectedGuild) {
|
||||||
|
claimPayload.guild_id = selectedGuild;
|
||||||
|
}
|
||||||
const res = await fetch(`${API_URL}/providers/scraped/${id}`, {
|
const res = await fetch(`${API_URL}/providers/scraped/${id}`, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
|
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify(claimPayload)
|
||||||
assigned_to: myUserId,
|
|
||||||
assigned_to_name: myUserName,
|
|
||||||
status_operativo: statusToSave
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
@@ -446,7 +440,6 @@
|
|||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 🔥 FUNCIÓN DE FILTRADO Y ORDENACIÓN 🔥
|
// 🔥 FUNCIÓN DE FILTRADO Y ORDENACIÓN 🔥
|
||||||
function filterServices() {
|
function filterServices() {
|
||||||
const query = document.getElementById('searchInput').value.toLowerCase().trim();
|
const query = document.getElementById('searchInput').value.toLowerCase().trim();
|
||||||
@@ -469,7 +462,6 @@
|
|||||||
return searchString.includes(query);
|
return searchString.includes(query);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Luego ordenamos el resultado
|
// 2. Luego ordenamos el resultado
|
||||||
filtered.sort((a, b) => {
|
filtered.sort((a, b) => {
|
||||||
const rawA = a.raw_data || {};
|
const rawA = a.raw_data || {};
|
||||||
@@ -498,11 +490,9 @@
|
|||||||
return new Date(b.created_at || 0) - new Date(a.created_at || 0);
|
return new Date(b.created_at || 0) - new Date(a.created_at || 0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 3. Pintamos la pantalla
|
// 3. Pintamos la pantalla
|
||||||
renderServices(filtered);
|
renderServices(filtered);
|
||||||
}
|
}
|
||||||
|
|
||||||
function showToast(msg) {
|
function showToast(msg) {
|
||||||
const t = document.getElementById('toast');
|
const t = document.getElementById('toast');
|
||||||
document.getElementById('toastMsg').innerText = msg;
|
document.getElementById('toastMsg').innerText = msg;
|
||||||
|
|||||||
Reference in New Issue
Block a user