pcpuma_unam_operador/components/crear/CrearInfraccion.vue

119 lines
3.0 KiB
Vue
Raw Normal View History

2022-07-26 05:44:07 +00:00
<template>
2022-07-26 13:35:38 +00:00
<section class="mb-6">
<h3 class="is-size-4 mb-3">Crear Infracción</h3>
<div class="box">
<div class="columns is-align-items-flex-end pl-0 pb-4">
<b-field class="column mb-0 pb-0" label="Infracción">
<b-input
placeholder="Nombre de la infracción"
type="text"
@keyup.enter.native="warning()"
v-model="infraccion"
rounded
/>
</b-field>
2022-07-26 05:44:07 +00:00
2022-07-26 13:35:38 +00:00
<BotonCrear :disabled="!infraccion" :crear="warning" />
</div>
<b-collapse
animation="slide"
aria-id="contentIdForA11y3"
class="card"
v-model="activo"
2022-07-26 05:44:07 +00:00
>
2022-07-26 13:35:38 +00:00
<template #trigger>
<div
aria-controls="contentIdForA11y3"
class="card-header"
role="button"
:aria-expanded="activo"
>
<p class="card-header-title">Tabla de infracciones</p>
2022-07-26 05:44:07 +00:00
2022-07-26 13:35:38 +00:00
<a class="card-header-icon">
<b-icon :icon="activo ? 'menu-down' : 'menu-up'" />
</a>
</div>
</template>
2022-07-26 05:44:07 +00:00
2022-07-26 13:35:38 +00:00
<TablaOpcionesCreadas
v-if="activo"
:data="infracciones"
:columnaInfraccion="true"
/>
</b-collapse>
</div>
</section>
2022-07-26 05:44:07 +00:00
</template>
<script>
import axios from 'axios'
2022-07-26 13:35:38 +00:00
import BotonCrear from '@/components/botones/BotonCrear'
2022-07-26 05:44:07 +00:00
import TablaOpcionesCreadas from '@/components/admin/TablaOpcionesCreadas'
2022-07-26 13:35:38 +00:00
2022-07-26 05:44:07 +00:00
export default {
2022-07-26 13:35:38 +00:00
components: { BotonCrear, TablaOpcionesCreadas },
2022-07-26 05:44:07 +00:00
props: {
updateIsLoading: { type: Function, required: true },
},
data() {
return {
infracciones: [],
2022-07-26 13:35:38 +00:00
activo: false,
2022-07-26 05:44:07 +00:00
infraccion: '',
}
},
methods: {
obtenerCatalogoInfracciones() {
axios
.get(
`${process.env.api}/institucion-infraccion/`,
this.$getToken.token()
)
.then((res) => {
this.infracciones = res.data
})
.catch((err) => {
this.$alertsGenericos.imprimirError(this.$buefy, err.response.data)
})
},
crearInfraccion() {
const data = {
infraccion: this.infraccion,
}
2022-07-26 13:35:38 +00:00
2022-07-26 05:44:07 +00:00
this.updateIsLoading(true)
axios
.post(
`${process.env.api}/institucion-infraccion/`,
data,
this.$getToken.token()
)
.then((res) => {
2022-07-26 13:35:38 +00:00
this.infraccion = ''
this.obtenerCatalogoInfracciones()
2022-07-26 05:44:07 +00:00
this.updateIsLoading(false)
this.$alertsGenericos.imprimirMensaje(this.$buefy, res.data.message)
})
.catch((err) => {
this.updateIsLoading(false)
this.$alertsGenericos.imprimirError(this.$buefy, err.response.data)
})
},
2022-07-26 13:35:38 +00:00
warning() {
if (this.infraccion)
this.$alertsGenericos.imprimirWarning(
this.$buefy,
'¿Esta segur@ de querer crear esta infracción?',
this.crearInfraccion
)
},
2022-07-26 05:44:07 +00:00
},
created() {
this.obtenerCatalogoInfracciones()
},
}
</script>