pcpuma_unam_operador/components/admin/Institucion.vue

161 lines
4.3 KiB
Vue
Raw Normal View History

2022-07-11 08:23:33 +00:00
<template>
2022-07-19 20:27:58 +00:00
<div>
<div class="box">
<div
class="columns is-align-items-flex-end"
v-if="admin.tipoUsuario.id_tipo_usuario === 2"
>
<InstitucionSelect
:updateIdInstitucion="updateIdInstitucion"
:idInstitucion="
typeof idInstitucion === 'undefined' ? 0 : idInstitucion
"
/>
2022-07-11 16:56:17 +00:00
2022-07-19 20:27:58 +00:00
<b-field class="column">
<b-button
type="is-success"
:disabled="!idInstitucion"
@click="buscar()"
rounded
expanded
>
Buscar
</b-button>
</b-field>
</div>
2022-07-11 16:56:17 +00:00
2022-07-19 20:27:58 +00:00
<div class="columns">
<AdminInstitucion
:buscar="buscar"
:updateIsLoading="updateIsLoading"
:admin="admin"
:institucion="institucion"
/>
2022-07-11 23:54:56 +00:00
2022-07-19 20:27:58 +00:00
<InfoInstitucion
:admin="admin"
:institucion="institucion"
:updateIsLoading="updateIsLoading"
:buscar="buscar"
/>
</div>
2022-07-11 16:56:17 +00:00
</div>
2022-07-19 20:27:58 +00:00
<b-table
:data="data"
:total="total"
:current-page="page"
:per-page="25"
:loading="isLoadingTable"
@page-change="onPageChange"
class="mb-6"
backend-pagination
hoverable
paginated
striped
>
<b-table-column field="operador" label="Admin" v-slot="props" centered>
<span>{{ props.row.operador }}</span>
</b-table-column>
<b-table-column field="nombre" label="Nombre" v-slot="props" centered>
<span>{{ props.row.nombre }}</span>
</b-table-column>
<b-table-column field="correo" label="Correo" v-slot="props" centered>
<span>{{ props.row.correo }}</span>
</b-table-column>
</b-table>
2022-07-11 08:23:33 +00:00
</div>
</template>
<script>
2022-07-11 16:56:17 +00:00
import axios from 'axios'
import AdminInstitucion from '@/components/admin/AdminInstitucion'
import InstitucionSelect from '@/components/admin/InstitucionSelect'
import InfoInstitucion from '@/components/admin/InfoInstitucion'
2022-07-11 08:23:33 +00:00
export default {
2022-07-11 16:56:17 +00:00
components: { AdminInstitucion, InstitucionSelect, InfoInstitucion },
2022-07-11 08:23:33 +00:00
props: {
admin: { type: Object, required: true },
updateIsLoading: { type: Function, required: true },
},
data() {
2022-07-19 20:27:58 +00:00
return {
institucion: {},
idInstitucion: 0,
data: [],
isLoadingTable: false,
page: 1,
total: 0,
lastSearch: {},
search: { idInstitucion: 0 },
}
2022-07-11 16:56:17 +00:00
},
methods: {
updateIdInstitucion(idInstitucion) {
this.idInstitucion = idInstitucion
},
2022-07-19 20:27:58 +00:00
onPageChange(page) {
this.page = page
this.obtenerAdmins()
},
2022-07-11 16:56:17 +00:00
buscar() {
this.updateIsLoading(true)
axios
.get(
2022-07-19 16:41:33 +00:00
`${process.env.api}/institucion/institucion?id_institucion=${this.idInstitucion}`,
this.$getToken.token()
2022-07-11 16:56:17 +00:00
)
.then((res) => {
this.institucion = res.data
this.updateIsLoading(false)
if (this.admin.tipoUsuario.id_tipo_usuario === 2)
2022-07-13 19:10:31 +00:00
this.$router.push(
`/admin/configuracion/instituciones/${this.idInstitucion}`
)
2022-07-19 20:27:58 +00:00
return this.obtenerAdmins()
2022-07-11 16:56:17 +00:00
})
.catch((err) => {
this.updateIsLoading(false)
this.$alertsGenericos.imprimirError(this.$buefy, err.response.data)
})
},
2022-07-19 20:27:58 +00:00
obtenerAdmins() {
let data = ''
this.isLoadingTable = true
if (this.search.idInstitucion != this.lastSearch.idInstitucion) {
this.page = 1
this.lastSearch.idInstitucion = this.search.idInstitucion
}
if (this.search.idInstitucion)
data = `&id_institucion=${this.search.idInstitucion}`
axios
.get(
`${process.env.api}/operador/operadores?pagina=${this.page}&id_tipo_usuario=3${data}`,
this.$getToken.token()
)
.then((res) => {
this.data = res.data[0]
this.total = res.data[1]
this.isLoadingTable = false
})
.catch((err) => {
this.isLoadingTable = false
this.$alertsGenericos.imprimirError(this.$buefy, err.response.data)
})
},
2022-07-11 16:56:17 +00:00
},
created() {
if (this.$route.params.institucion)
this.idInstitucion = parseInt(this.$route.params.institucion)
2022-07-13 19:10:31 +00:00
else if (this.admin.institucion)
this.idInstitucion = this.admin.institucion.id_institucion
2022-07-11 16:56:17 +00:00
if (this.idInstitucion) this.buscar()
2022-07-11 08:23:33 +00:00
},
}
</script>