Actualizar servicios.html

This commit is contained in:
2026-03-02 22:54:48 +00:00
parent 345abd98d3
commit dd9566f1e1

View File

@@ -130,12 +130,9 @@
<form onsubmit="saveNewService(event)" class="flex-1 overflow-y-auto no-scrollbar p-6 bg-slate-50/50">
<div class="grid grid-cols-1 md:grid-cols-12 gap-6">
<div class="md:col-span-7 space-y-4">
<div class="bg-white p-6 rounded-2xl border border-slate-200 shadow-sm space-y-4">
<h4 class="font-black text-slate-800 uppercase text-[10px] flex items-center gap-2 border-b border-slate-100 pb-2">
<i data-lucide="user" class="w-4 h-4 text-blue-500"></i> Datos del Cliente
</h4>
<h4 class="label-modern border-b pb-2"><i data-lucide="user" class="w-3 h-3 inline mr-1"></i> Datos del Cliente</h4>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<label class="label-modern">Teléfono</label>
@@ -147,83 +144,42 @@
</div>
</div>
<div>
<label class="label-modern">Dirección del Servicio</label>
<input type="text" id="nAddr" placeholder="Dirección completa..." class="input-modern" required>
<div id="addrSuggestions" class="hidden mt-2 p-2 bg-amber-50 border border-amber-200 rounded-lg text-[10px] font-bold text-amber-700">
⚠️ Cliente con direcciones previas registradas.
<label class="label-modern">Dirección</label>
<input type="text" id="nAddr" placeholder="Calle, número, población..." class="input-modern" required>
<div id="addrSuggestions" class="hidden mt-2 p-2 bg-amber-50 border border-amber-200 rounded-lg text-[10px] font-bold text-amber-700">⚠️ Cliente con otras direcciones registradas.</div>
</div>
</div>
<div class="pt-4 border-t border-slate-100">
<label class="flex items-center gap-3 cursor-pointer mb-4">
<input type="checkbox" id="isCompanyCheck" onchange="toggleCompanyFields(this.checked)" class="w-5 h-5 rounded border-slate-300 text-blue-600 focus:ring-blue-500">
<div class="pt-2">
<label class="flex items-center gap-3 cursor-pointer">
<input type="checkbox" id="isCompanyCheck" onchange="toggleCompanyFields(this.checked)" class="w-5 h-5 rounded text-blue-600">
<span class="text-xs font-black text-slate-700 uppercase">¿Es de Compañía de Seguros?</span>
</label>
<div id="companyFields" class="hidden space-y-4 p-4 bg-blue-50/30 rounded-xl border border-blue-100 fade-in">
<div>
<label class="label-modern">Compañía Aseguradora</label>
<select id="nCompanySelect" class="input-modern bg-white">
<option value="">Seleccionar compañía...</option>
</select>
</div>
<div>
<label class="label-modern">Nº Expediente / Referencia</label>
<input type="text" id="nExpRef" onblur="checkDuplicateRef(this.value)" placeholder="Ej: ABC-12345" class="input-modern bg-white uppercase">
<p id="refAlert" class="hidden text-[10px] text-red-600 font-bold mt-1 uppercase">⚠️ Esta referencia ya existe en el sistema</p>
<div id="companyFields" class="hidden mt-4 space-y-4 p-4 bg-blue-50/30 rounded-xl border border-blue-100">
<select id="nCompanySelect" class="input-modern bg-white"><option value="">Seleccionar compañía...</option></select>
<input type="text" id="nExpRef" onblur="checkDuplicateRef(this.value)" placeholder="Nº Expediente" class="input-modern bg-white uppercase">
<p id="refAlert" class="hidden text-[10px] text-red-600 font-bold mt-1 uppercase">⚠️ Referencia ya existente</p>
</div>
</div>
</div>
</div>
<div class="bg-white p-6 rounded-2xl border border-slate-200 shadow-sm">
<label class="label-modern">Descripción detallada de la avería</label>
<textarea id="nDesc" placeholder="Escribe aquí todos los detalles de la reparación..." rows="6" class="input-modern resize-none text-base"></textarea>
<label class="label-modern">Descripción de la Avería</label>
<textarea id="nDesc" placeholder="Detalla el problema..." rows="6" class="input-modern resize-none"></textarea>
</div>
</div>
<div class="md:col-span-5 space-y-4">
<div class="bg-white p-6 rounded-2xl border border-slate-200 shadow-sm space-y-5">
<h4 class="font-black text-slate-800 uppercase text-[10px] flex items-center gap-2 border-b border-slate-100 pb-2">
<i data-lucide="settings" class="w-4 h-4 text-purple-500"></i> Gestión y Tiempo
</h4>
<h4 class="label-modern border-b pb-2"><i data-lucide="settings" class="w-3 h-3 inline mr-1"></i> Asignación y Tiempo</h4>
<select id="nGuild" class="input-modern" onchange="loadOps(this.value, 'nWorker')"><option value="">Gremio...</option></select>
<select id="nWorker" class="input-modern"><option value="">Operario...</option></select>
<div>
<label class="label-modern">Gremio Especialista</label>
<select id="nGuild" class="input-modern" onchange="loadOps(this.value, 'nWorker')">
<option value="">Seleccionar gremio...</option>
</select>
</div>
<div>
<label class="label-modern">Operario Asignado</label>
<select id="nWorker" class="input-modern">
<option value="">(Sin asignar)</option>
</select>
</div>
<div>
<label class="label-modern">Duración Estimada (Nuevas opciones)</label>
<select id="nDuration" class="input-modern font-black text-blue-600">
<option value="15">15 MINUTOS</option>
<option value="30">30 MINUTOS</option>
<option value="60" selected>1 HORA (ESTÁNDAR)</option>
<option value="90">1 HORA Y MEDIA</option>
<option value="120">2 HORAS</option>
<option value="180">3 HORAS</option>
<option value="240">4 HORAS (MEDIA JORNADA)</option>
<label class="label-modern">Duración Estimada</label>
<select id="nDuration" class="input-modern font-black text-blue-600 uppercase">
<option value="15">15 min</option><option value="30">30 min</option><option value="60" selected>1 hora</option>
<option value="90">1.5 horas</option><option value="120">2 horas</option><option value="180">3 horas</option><option value="240">4 horas</option>
</select>
</div>
</div>
<div class="grid grid-cols-1 gap-3">
<button type="submit" name="action" value="manual" class="w-full bg-emerald-600 hover:bg-emerald-500 text-white font-black py-4 rounded-2xl text-xs uppercase tracking-widest shadow-lg transition-all active:scale-95">
Crear y Guardar
</button>
<button type="submit" name="action" value="auto" class="w-full bg-slate-900 hover:bg-slate-800 text-white font-black py-4 rounded-2xl text-xs uppercase tracking-widest transition-all active:scale-95 flex items-center justify-center gap-2">
<i data-lucide="zap" class="w-4 h-4 text-amber-400"></i> Mandar a la Bolsa
</button>
</div>
<button type="submit" name="action" value="manual" class="w-full bg-emerald-600 text-white font-black py-4 rounded-2xl text-xs uppercase shadow-lg">Crear y Guardar</button>
<button type="submit" name="action" value="auto" class="w-full bg-slate-900 text-white font-black py-4 rounded-2xl text-xs uppercase flex items-center justify-center gap-2"><i data-lucide="zap" class="w-4 h-4 text-amber-400"></i> Mandar a la Bolsa</button>
</div>
</div>
</form>
@@ -883,6 +839,8 @@ async function searchClientByPhone(phone) {
async function saveNewService(e) {
e.preventDefault();
const action = e.submitter.value;
const is_company = document.getElementById('isCompanyCheck').checked;
const data = {
phone: document.getElementById('nPhone').value,
name: document.getElementById('nName').value,
@@ -890,16 +848,29 @@ async function searchClientByPhone(phone) {
description: document.getElementById('nDesc').value,
guild_id: document.getElementById('nGuild').value,
assigned_to: document.getElementById('nWorker').value || null,
duration_minutes: document.getElementById('nDuration').value // <--- CAPTURA DE DURACIÓN
duration_minutes: document.getElementById('nDuration').value,
is_company: is_company,
company_name: is_company ? document.getElementById('nCompanySelect').value : 'Particular',
company_ref: is_company ? document.getElementById('nExpRef').value : null,
mode: action
};
try {
const res = await fetch(`${API_URL}/services/manual-high`, {
method: 'POST', headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
body: JSON.stringify({ ...data, mode: action })
method: 'POST',
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
body: JSON.stringify(data)
});
if (res.ok) { closeCreateModal(); refreshPanel(); }
} catch(e) { alert("Error al guardar"); }
if (res.ok) {
showToast("✅ Expediente creado con éxito");
closeCreateModal();
refreshPanel();
} else {
const err = await res.json();
alert("Error: " + (err.error || "No se pudo guardar"));
}
} catch(e) { alert("Error de conexión"); }
}
function closeDetailModal() { document.getElementById('detailModal').classList.add('hidden'); }
// Al abrir el modal, cargamos las compañías configuradas