pcpuma_unam_operador/components/selects/SelectInstitucion.vue

92 lines
2.4 KiB
Vue
Raw Normal View History

2022-07-26 04:30:07 +00:00
<template>
2022-08-14 22:23:01 +00:00
<b-field
class="mb-0 pb-0"
label="Institución"
:class="column ? `column ${columnSize}` : ''"
>
2022-07-26 04:30:07 +00:00
<b-select
2022-08-08 02:08:22 +00:00
icon="home"
2022-07-26 04:30:07 +00:00
:loading="isLoadingSelect"
2022-08-03 18:12:27 +00:00
v-model="idInstitucion"
2022-07-26 04:30:07 +00:00
expanded
rounded
>
2022-08-03 18:12:27 +00:00
<option :disabled="deshabilitarOptVacia" :value="0">
2022-07-26 04:30:07 +00:00
Selecciona una opción
</option>
2022-08-03 18:12:27 +00:00
<option
v-for="(i, index) in instituciones"
:key="index"
:value="i.id_institucion"
>
2022-07-26 04:30:07 +00:00
{{ i.institucion }}
</option>
</b-select>
</b-field>
</template>
<script>
import axios from 'axios'
export default {
props: {
2022-08-14 22:23:01 +00:00
activas: { typeof: Boolean, required: false, default: false },
column: { type: Boolean, required: false, default: true },
2022-07-26 04:30:07 +00:00
deshabilitarOptVacia: { typeof: Boolean, required: false, default: true },
columnSize: { typeof: String, required: false, default: '' },
2022-08-03 18:12:27 +00:00
idInstitucionPadre: { type: Number, required: true, default: 0 },
2022-07-26 04:30:07 +00:00
},
data() {
return {
instituciones: [],
isLoadingSelect: false,
2022-08-03 18:12:27 +00:00
idInstitucion: 0,
2022-07-26 04:30:07 +00:00
}
},
methods: {
obtenerInstituciones() {
this.isLoadingSelect = true
this.instituciones = []
axios
.get(`${process.env.api}/institucion`, this.$getToken.token())
.then((res) => {
this.instituciones = res.data
this.$emit('catalogo-instituciones', this.instituciones)
this.isLoadingSelect = false
})
.catch((err) => {
this.isLoadingSelect = false
})
},
2022-08-14 22:23:01 +00:00
obtenerInstitucionesActivas() {
this.isLoadingSelect = true
this.instituciones = []
axios
.get(`${process.env.api}/institucion/instituciones-activas`)
.then((res) => {
this.instituciones = res.data
this.$emit('catalogo-instituciones', this.instituciones)
this.isLoadingSelect = false
})
.catch((err) => {
this.isLoadingSelect = false
})
},
2022-07-26 04:30:07 +00:00
},
watch: {
2022-08-03 18:12:27 +00:00
idInstitucion() {
this.$emit('institucion-seleccionada', this.idInstitucion)
2022-07-26 04:30:07 +00:00
},
2022-08-03 18:12:27 +00:00
idInstitucionPadre(nuevaInstitucion) {
this.idInstitucion = nuevaInstitucion
2022-07-26 04:30:07 +00:00
},
},
created() {
2022-08-03 18:12:27 +00:00
if (this.idInstitucionPadre) this.idInstitucion = this.idInstitucionPadre
2022-08-14 22:23:01 +00:00
if (this.activas) this.obtenerInstitucionesActivas()
else this.obtenerInstituciones()
2022-07-26 04:30:07 +00:00
},
}
</script>