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>
2021-05-13 14:22:56 -05: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 {
2021-05-13 14:22:56 -05:00
idUsuario: '',
2020-12-09 14:24:05 -06:00
data: [],
2021-05-13 14:22:56 -05: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,
2021-05-13 14:22:56 -05:00
correo: '',
nombre: '',
2020-12-09 15:32:07 -06:00
idStatus: 1,
2021-01-06 00:10:12 -06:00
token: {
headers: {
2021-05-13 14:22:56 -05:00
token: window.localStorage.getItem('token'),
2021-01-06 00:10:12 -06:00
},
2021-01-06 15:27:23 -06:00
},
2021-05-13 14:22:56 -05:00
}
2020-11-19 16:12:38 -06:00
},
methods: {
2020-12-08 21:50:16 -06:00
onPageChange(page) {
2021-05-13 14:22:56 -05:00
this.page = page
this.obtenerDatos()
2020-12-09 14:24:05 -06:00
},
2020-12-09 15:32:07 -06:00
obtenerDatos(idStatus) {
2021-05-13 14:22:56 -05:00
this.loading = true
this.data = []
2020-12-09 15:32:07 -06:00
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) => {
2021-05-13 14:22:56 -05:00
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,
2021-05-13 14:22:56 -05:00
})
2020-12-09 14:24:05 -06:00
}
}
2021-05-13 14:22:56 -05:00
let currentTotal = servicios.length
let contador
2020-12-09 15:32:07 -06:00
for (let i = 0; i < res.data.registros / this.perPage + 1; i++) {
2021-05-13 14:22:56 -05:00
contador = i
2020-12-09 14:24:05 -06:00
}
2021-05-13 14:22:56 -05:00
currentTotal = this.perPage * contador
this.total = currentTotal
this.loading = false
2020-12-09 14:24:05 -06:00
})
.catch((err) => {
2021-05-13 14:22:56 -05:00
this.loading = false
this.error(err.response.data.message)
})
2020-12-09 14:24:05 -06:00
},
2021-01-06 15:27:23 -06:00
error(msj) {
2021-05-13 14:22:56 -05:00
let salir = false
2021-01-06 15:27:23 -06:00
switch (msj) {
2021-05-13 14:22:56 -05:00
case 'invalid signature':
msj = 'Tu token no es valido, inicia sesión de nuevo.'
salir = true
break
case 'jwt expired':
msj = 'Tu sesión ha expirado, inicia sesión de nuevo.'
salir = true
break
case 'jwt malformed':
msj = 'No se encontro tu token, inicia sesión de nuevo.'
salir = true
break
case 'No hay token':
msj = 'Ocurrio un error al enviar tu token, inicia sesión de nuevo.'
salir = true
break
2021-01-06 15:27:23 -06:00
}
2021-01-06 00:10:12 -06:00
this.$buefy.dialog.alert({
2021-05-13 14:22:56 -05:00
title: 'Error',
2021-01-06 00:10:12 -06:00
message: msj,
2021-05-13 14:22:56 -05:00
type: 'is-danger',
2021-01-06 00:10:12 -06:00
hasIcon: true,
2021-05-13 14:22:56 -05:00
icon: 'alert-circle',
iconPack: 'mdi',
ariaRole: 'alertdialog',
2021-01-06 00:10:12 -06:00
ariaModal: true,
2021-05-13 14:22:56 -05:00
})
2021-01-06 15:27:23 -06:00
if (salir == true) {
2021-05-13 14:22:56 -05:00
localStorage.clear()
this.$router.push(`/`)
2021-01-06 15:27:23 -06:00
}
2021-01-06 00:10:12 -06:00
},
2020-12-09 15:32:07 -06:00
insertIdLocal() {
2021-05-13 14:22:56 -05:00
this.idUsuario = localStorage.getItem('idUsuario')
2020-12-09 15:32:07 -06:00
},
2020-12-09 16:13:26 -06:00
verRegistro(responsable) {
2021-05-13 14:22:56 -05:00
localStorage.setItem('correo', responsable.usuario)
localStorage.setItem('idResponsable', responsable.idUsuario)
localStorage.setItem('nombre', responsable.nombre)
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)
2021-05-13 14:22:56 -05:00
)
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() {
2021-05-13 14:22:56 -05:00
await this.obtenerDatos()
this.insertIdLocal()
2020-12-09 15:32:07 -06:00
},
2021-05-13 14:22:56 -05: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>