Files
servicio_social_front/components/admin/programa/tablaResponsables.vue
T

202 lines
5.1 KiB
Vue
Raw Normal View History

2020-11-19 16:12:38 -06:00
<template>
2020-12-09 14:24:05 -06:00
<div class="container mt-5">
2020-12-27 20:35:46 -06:00
<p class="is-size-2 mb-5">Lista de responsables</p>
2020-12-09 14:24:05 -06:00
<div class="columns">
<div class="column is-3 mb-4 pb-4">
<b-field>
<b-input
type="name"
placeholder="Nombre"
icon="account"
rounded
v-model="nombre"
></b-input>
</b-field>
</div>
<div class="column is-3 mb-0">
2020-12-09 15:32:07 -06:00
<b-field>
2020-11-19 16:12:38 -06:00
<b-input
2020-12-09 14:24:05 -06:00
placeholder="Correo electrónico"
icon="school"
rounded
v-model="correo"
2020-11-19 16:12:38 -06:00
>
2020-12-09 14:24:05 -06:00
</b-input>
</b-field>
</div>
<div class="buttons section pt-3 pl-5">
2020-12-09 15:32:07 -06:00
<b-button type="is-info" @click="obtenerDatos(idStatus)">
Buscar
</b-button>
</div>
2020-12-09 14:24:05 -06:00
</div>
<div class="columns mb-5">
<section class="column is-12">
<b-table
2020-12-09 15:32:07 -06:00
:data="data"
:loading="loading"
hoverable
striped
paginated
backend-pagination
:total="total"
:per-page="perPage"
@page-change="onPageChange"
2020-12-09 14:24:05 -06:00
>
<b-table-column field="nombre" label="Nombre" v-slot="props" centered>
2020-12-27 20:35:46 -06:00
<span @click="verRegistro(props.row)">{{ props.row.nombre }}</span>
2020-12-09 14:24:05 -06:00
</b-table-column>
2020-12-09 15:32:07 -06:00
<b-table-column
field="correo"
label="Correo electrónico"
v-slot="props"
centered
2020-12-08 21:50:16 -06:00
>
2020-12-27 20:35:46 -06:00
<span @click="verRegistro(props.row)">{{ props.row.usuario }}</span>
2020-12-09 14:24:05 -06:00
</b-table-column>
</b-table>
</section>
</div>
</div>
2020-11-19 16:12:38 -06:00
</template>
<script>
2020-12-09 15:32:07 -06:00
import axios from "axios";
2020-11-19 16:12:38 -06:00
export default {
2020-12-08 21:50:16 -06:00
data() {
2020-11-19 16:12:38 -06:00
return {
2020-12-09 15:32:07 -06:00
idUsuario: "",
2020-12-09 14:24:05 -06:00
data: [],
2020-12-09 15:32:07 -06:00
total: "",
2020-12-09 14:24:05 -06:00
loading: false,
2020-11-19 16:12:38 -06:00
page: 1,
2020-12-09 14:24:05 -06:00
perPage: 25,
2020-12-09 15:32:07 -06:00
correo: "",
nombre: "",
idStatus: 1,
2021-01-06 00:10:12 -06:00
token: {
headers: {
token: window.localStorage.getItem("token"),
},
2021-01-06 15:27:23 -06:00
},
2020-12-08 21:50:16 -06:00
};
2020-11-19 16:12:38 -06:00
},
methods: {
2020-12-08 21:50:16 -06:00
onPageChange(page) {
this.page = page;
2020-12-09 15:32:07 -06:00
this.obtenerDatos();
2020-12-09 14:24:05 -06:00
},
2020-12-09 15:32:07 -06:00
obtenerDatos(idStatus) {
this.loading = true;
this.data = [];
axios
.get(
2021-01-06 00:10:12 -06:00
`${process.env.api}/usuario/responsable?pagina=${this.page}&nombre=${this.nombre}&correo=${this.correo}`,
this.token
2020-12-09 15:32:07 -06:00
)
.then((res) => {
const servicios = res.data.servicios;
2020-12-09 14:24:05 -06:00
if (servicios.length !== 0) {
for (let i = 0; i < servicios.length; i++) {
this.data.push({
nombre: servicios[i].nombre,
usuario: servicios[i].usuario,
2020-12-09 15:32:07 -06:00
idUsuario: servicios[i].idUsuario,
});
2020-12-09 14:24:05 -06:00
}
}
2020-12-09 15:32:07 -06:00
let currentTotal = servicios.length;
let contador;
for (let i = 0; i < res.data.registros / this.perPage + 1; i++) {
contador = i;
2020-12-09 14:24:05 -06:00
}
2020-12-09 15:32:07 -06:00
currentTotal = this.perPage * contador;
this.total = currentTotal;
this.loading = false;
2020-12-09 14:24:05 -06:00
})
.catch((err) => {
2020-12-09 15:32:07 -06:00
this.loading = false;
2021-01-06 00:10:12 -06:00
this.error(err.response.data.message);
2020-12-09 15:32:07 -06:00
});
2020-12-09 14:24:05 -06:00
},
2021-01-06 15:27:23 -06:00
error(msj) {
let salir = false;
switch (msj) {
case "invalid signature":
2021-01-06 16:33:56 -06:00
msj = "Tu token no es valido, inicia sesión de nuevo.";
2021-01-06 15:27:23 -06:00
salir = true;
break;
case "jwt expired":
2021-01-06 16:33:56 -06:00
msj = "Tu sesión ha expirado, inicia sesión de nuevo.";
2021-01-06 15:27:23 -06:00
salir = true;
break;
case "jwt malformed":
2021-01-06 17:43:26 -06:00
msj = "No se encontro tu token, inicia sesión de nuevo.";
2021-01-06 15:27:23 -06:00
salir = true;
break;
case "No hay token":
2021-01-06 16:33:56 -06:00
msj = "Ocurrio un error al enviar tu token, inicia sesión de nuevo.";
2021-01-06 15:27:23 -06:00
salir = true;
break;
}
2021-01-06 00:10:12 -06:00
this.$buefy.dialog.alert({
title: "Error",
message: msj,
type: "is-danger",
hasIcon: true,
icon: "alert-circle",
iconPack: "mdi",
ariaRole: "alertdialog",
ariaModal: true,
2021-01-06 15:27:23 -06:00
});
if (salir == true) {
localStorage.clear();
this.$router.push(`/`);
}
2021-01-06 00:10:12 -06:00
},
2020-12-09 15:32:07 -06:00
insertIdLocal() {
this.idUsuario = localStorage.getItem("idUsuario");
},
2020-12-09 16:13:26 -06:00
verRegistro(responsable) {
localStorage.setItem("correo", responsable.usuario);
localStorage.setItem("idResponsable", responsable.idUsuario);
localStorage.setItem("nombre", responsable.nombre);
2021-01-05 15:14:10 -06:00
this.$router.push("/admin/programa/infoResponsable");
2020-12-09 14:24:05 -06:00
},
2020-11-19 16:12:38 -06:00
},
computed: {
2020-12-08 21:50:16 -06:00
busquedaNombreResponsable() {
return this.responsables.filter((responsables) =>
2020-11-19 16:12:38 -06:00
responsables.nombreResp.includes(this.buscarNombreResponsable)
2020-12-08 21:50:16 -06:00
);
},
2020-11-19 16:12:38 -06:00
},
2020-12-09 15:32:07 -06:00
async created() {
await this.obtenerDatos();
this.insertIdLocal();
},
2020-12-08 21:50:16 -06:00
};
2020-11-19 16:12:38 -06:00
</script>
<style scoped>
2020-12-09 15:32:07 -06:00
.b-table {
2020-12-09 14:24:05 -06:00
cursor: pointer;
}
2020-12-09 15:32:07 -06:00
.input:focus {
border: #1b3d70;
2020-12-09 14:24:05 -06:00
box-shadow: 0 0 8px 0 #1b3d70;
}
2020-12-09 15:32:07 -06:00
.select select:focus {
2020-12-09 14:24:05 -06:00
border-color: #1b3d70;
box-shadow: 0 0 8px 0 #1b3d70;
}
2020-12-09 15:32:07 -06:00
.select:not(.is-multiple):not(.is-loading)::after {
2020-12-09 14:24:05 -06:00
border-color: #1b3d70;
}
.pagination-link.is-current {
background-color: #1b3d70;
border-color: #1b3d70;
}
2020-11-19 16:12:38 -06:00
</style>