pcpuma_unam_operador/components/selects/SelectInstitucion.vue

71 lines
1.7 KiB
Vue
Raw Normal View History

2022-07-26 04:30:07 +00:00
<template>
<b-field class="column mb-0 pb-0" label="Institución" :class="columnSize">
<b-select
icon="school-outline"
: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: {
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
})
},
},
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-07-26 04:30:07 +00:00
this.obtenerInstituciones()
},
}
</script>