This commit is contained in:
Lizandro Guarnizo
2026-05-15 14:26:52 -05:00
parent 70a43597f3
commit b340d29583
8 changed files with 165 additions and 41 deletions
+17 -11
View File
@@ -33,13 +33,13 @@
<td class="px-4 py-3 font-medium text-slate-800" x-text="u.nombre"></td>
<td class="px-4 py-3 text-slate-600" x-text="u.email"></td>
<td class="px-4 py-3">
<span class="badge" :class="u.rol==='partner' ? 'badge-blue' : 'badge-green'" x-text="u.rol"></span>
<span class="badge" :class="(u.role?.es_portal_partner || u.rol==='partner') ? 'badge-blue' : 'badge-green'" x-text="u.role?.name || u.rol"></span>
</td>
<td class="px-4 py-3 text-slate-500 text-xs">
<template x-if="u.rol==='cliente' && u.cliente">
<template x-if="!(u.role?.es_portal_partner || u.rol==='partner') && u.cliente">
<span x-text="u.cliente?.empresa || u.cliente?.nombre"></span>
</template>
<template x-if="u.rol==='partner'">
<template x-if="u.role?.es_portal_partner || u.rol==='partner'">
<div class="flex flex-wrap gap-1">
<template x-for="acc in (u.portal_accesos||[])" :key="acc.ID">
<span class="bg-slate-100 px-2 py-0.5 rounded text-xs flex items-center gap-1">
@@ -82,12 +82,16 @@
</div>
<div>
<label class="label">Rol</label>
<select x-model="form.rol" class="input-field w-full">
<option value="cliente">Cliente</option>
<option value="partner">Partner</option>
<select x-model.number="form.role_id" class="input-field w-full">
<option value="">Sin rol asignado</option>
<template x-for="r in portalRoles" :key="r.ID">
<option :value="r.ID">
<span x-text="r.name + (r.es_portal_partner ? ' (Partner)' : ' (Cliente)')"></span>
</option>
</template>
</select>
</div>
<div x-show="form.rol==='cliente'">
<div x-show="portalRoles.find(r => r.ID === form.role_id)?.es_portal_cliente">
<label class="label">Cliente asignado</label>
<select x-model.number="form.cliente_id" class="input-field w-full">
<option value="">Sin asignar</option>
@@ -146,11 +150,11 @@
<script>
function portalUsuariosApp() {
return {
items: [], clientes: [], loading: false, saving: false,
items: [], clientes: [], portalRoles: [], loading: false, saving: false,
showModal: false, showDelete: false, showAccesoModal: false,
editId: null, deleteId: null, error: '',
accesoUserId: null, accesoClienteId: '',
form: { nombre:'', email:'', password:'', rol:'cliente', cliente_id:'', activo:true, notas:'' },
form: { nombre:'', email:'', password:'', role_id:'', cliente_id:'', activo:true, notas:'' },
async init() { await this.load(); },
@@ -160,23 +164,25 @@ function portalUsuariosApp() {
const r = await axios.get('/app/loadportalusuarios');
this.items = r.data.items || [];
this.clientes = r.data.clientes || [];
this.portalRoles = r.data.portalRoles || [];
} finally { this.loading = false; }
},
openCreate() {
this.editId=null; this.error='';
this.form={nombre:'',email:'',password:'',rol:'cliente',cliente_id:'',activo:true,notas:''};
this.form={nombre:'',email:'',password:'',role_id:'',cliente_id:'',activo:true,notas:''};
this.showModal=true;
},
openEdit(u) {
this.editId=u.ID; this.error='';
this.form={nombre:u.nombre,email:u.email,password:'',rol:u.rol,cliente_id:u.cliente_id||'',activo:u.activo,notas:u.notas||''};
this.form={nombre:u.nombre,email:u.email,password:'',role_id:u.role_id||'',cliente_id:u.cliente_id||'',activo:u.activo,notas:u.notas||''};
this.showModal=true;
},
async save() {
this.saving=true; this.error='';
const payload={...this.form};
if(payload.cliente_id==='') payload.cliente_id=null;
if(payload.role_id==='') payload.role_id=null;
try {
if(this.editId) await axios.put(`/app/portal-usuarios/${this.editId}`, payload);
else await axios.post('/app/portal-usuarios', payload);