diff --git a/resources/views/users.html b/resources/views/users.html
index 3b6f21f..184406c 100755
--- a/resources/views/users.html
+++ b/resources/views/users.html
@@ -324,12 +324,13 @@
Id: null,
deleteId: null,
+ users: [],
+ roles: [],
loading: false,
- totalRecords: 0, // Agregar esta línea
+ totalRecords: 0,
+ totalPages: 0,
isLoading: false,
- roles: '',
-
init() {
this.loadRegister();
},
@@ -342,23 +343,22 @@
//this.loading = true;
const search = this.searchQuery ? `&search=${this.searchQuery}` : '';
fetch(`/app/loadusers?page=${page}${search}`)
- .then(response => response.json())
+ .then(response => {
+ if (!response.ok) throw new Error(`HTTP ${response.status}`);
+ return response.json();
+ })
.then(data => {
- this.totalRecords = data.total; // Establece el total de registros aquí
- this.users = data.Users; // Asignar
- this.roles = data.Roles;
- console.log(this.roles);
-
- this.totalPages = data.totalPages; // Asignar total de páginas
+ this.totalRecords = data.total || 0;
+ this.users = data.Users || [];
+ this.roles = data.Roles || [];
+ this.totalPages = data.totalPages || 0;
this.createPagination(this.totalPages, page);
-
- if (data.Users.length != 0) {
- // Lógica de paginación
- const totalPages = Math.ceil(this.totalRecords / data.limit);
- this.createPagination(totalPages, page)
+ if (this.users.length > 0) {
+ const totalPages = Math.ceil(this.totalRecords / (data.limit || 10));
+ this.createPagination(totalPages, page);
}
})
- .catch(error => console.error('Error:', error))
+ .catch(error => console.error('Error cargando usuarios:', error))
.finally(() => {
this.isLoading = false; // Ocultar el GIF de carga
});