pcpuma_unam_operador/components/admin/CrearAdmin.vue

146 lines
3.8 KiB
Vue
Raw Normal View History

2022-07-08 18:23:45 +00:00
<template>
<section class="mb-6">
2022-07-20 16:53:25 +00:00
<h3 class="is-size-4 mb-3">Crear Administradores</h3>
2022-07-08 18:23:45 +00:00
<div class="box">
2022-07-09 20:46:52 +00:00
<div class="columns is-align-items-flex-end pl-0 pb-4">
2022-07-08 18:23:45 +00:00
<InstitucionSelect
2022-07-13 16:30:39 +00:00
:idInstitucion="
typeof idInstitucion === 'undefined' ? 0 : idInstitucion
"
2022-07-08 18:23:45 +00:00
:updateIdInstitucion="updateIdInstitucion"
/>
2022-07-20 01:19:27 +00:00
<b-field class="column mb-0 pb-0" label="Administrador">
2022-07-08 18:23:45 +00:00
<b-input
type="text"
2022-07-20 01:19:27 +00:00
placeholder="Administrador"
2022-07-08 18:23:45 +00:00
icon="account"
@keyup.enter.native="
2022-07-11 14:15:10 +00:00
$alertsGenericos.imprimirWarning(
$buefy,
2022-07-12 23:32:46 +00:00
'¿Esta segur@ de querer crear este admin?',
2022-07-08 18:23:45 +00:00
crearAdmin
)
"
v-model="operador"
rounded
/>
</b-field>
2022-07-12 23:32:46 +00:00
<b-field class="column mb-0 pb-0" label="Correo">
2022-07-08 18:23:45 +00:00
<b-input
2022-07-12 23:32:46 +00:00
icon="mail"
placeholder="Correo"
type="email"
2022-07-08 18:23:45 +00:00
@keyup.enter.native="
2022-07-11 14:15:10 +00:00
$alertsGenericos.imprimirWarning(
$buefy,
2022-07-12 23:32:46 +00:00
'¿Esta segur@ de querer crear este admin?',
2022-07-19 19:40:05 +00:00
crearAdmin
2022-07-12 23:32:46 +00:00
)
"
v-model="correo"
rounded
/>
</b-field>
<b-field class="column mb-0 pb-0" label="Nombre">
<b-input
icon="account"
placeholder="Nombre"
type="text"
@keyup.enter.native="
$alertsGenericos.imprimirWarning(
$buefy,
'¿Esta segur@ de querer crear este admin?',
2022-07-19 19:40:05 +00:00
crearAdmin
2022-07-08 18:23:45 +00:00
)
"
2022-07-12 23:32:46 +00:00
v-model="nombre"
2022-07-08 18:23:45 +00:00
rounded
/>
</b-field>
<b-field class="column">
<b-button
type="is-info"
@click="
2022-07-11 14:15:10 +00:00
$alertsGenericos.imprimirWarning(
$buefy,
2022-07-12 23:32:46 +00:00
'¿Esta segur@ de querer crear este admin?',
2022-07-08 18:23:45 +00:00
crearAdmin
)
"
2022-07-12 23:32:46 +00:00
:disabled="!operador || !idInstitucion || !correo || !nombre"
2022-07-08 18:23:45 +00:00
expanded
rounded
>
Crear
</b-button>
</b-field>
2022-07-09 20:46:52 +00:00
</div>
2022-07-08 18:23:45 +00:00
</div>
</section>
</template>
<script>
import axios from 'axios'
import InstitucionSelect from '@/components/admin/InstitucionSelect'
export default {
components: { InstitucionSelect },
props: {
admin: { type: Object, required: true },
updateActualizarTabla: { type: Function, required: true },
updateIsLoading: { type: Function, required: true },
},
data() {
return {
2022-07-12 23:32:46 +00:00
correo: '',
2022-07-09 20:46:52 +00:00
idInstitucion: 0,
2022-07-12 23:32:46 +00:00
nombre: '',
2022-07-08 18:23:45 +00:00
operador: '',
}
},
methods: {
crearAdmin() {
2022-07-12 23:32:46 +00:00
if (this.operador && this.idInstitucion && this.correo && this.nombre) {
2022-07-11 20:58:10 +00:00
const data = {
2022-07-12 23:32:46 +00:00
correo: this.correo,
2022-07-08 18:23:45 +00:00
id_institucion: this.idInstitucion,
id_tipo_usuario: 3,
2022-07-12 23:32:46 +00:00
nombre: this.nombre,
2022-07-08 18:23:45 +00:00
operador: this.operador,
}
2022-07-19 16:41:33 +00:00
console.log('Hola')
console.log(data)
2022-07-08 18:23:45 +00:00
this.updateIsLoading(true)
axios
2022-07-19 16:41:33 +00:00
.post(`${process.env.api}/operador`, data, this.$getToken.token())
2022-07-08 18:23:45 +00:00
.then((res) => {
2022-07-09 20:46:52 +00:00
this.idInstitucion = 0
2022-07-08 18:23:45 +00:00
this.operador = ''
2022-07-12 23:32:46 +00:00
this.correo = ''
this.nombre = ''
2022-07-08 18:23:45 +00:00
this.updateIsLoading(false)
2022-07-11 14:15:10 +00:00
this.$alertsGenericos.imprimirMensaje(this.$buefy, res.data.message)
2022-07-08 18:23:45 +00:00
this.updateActualizarTabla(true)
})
.catch((err) => {
this.updateIsLoading(false)
2022-07-11 14:15:10 +00:00
this.$alertsGenericos.imprimirError(this.$buefy, err.response.data)
2022-07-08 18:23:45 +00:00
})
}
},
2022-07-09 20:46:52 +00:00
updateIdInstitucion(idInstitucion) {
this.idInstitucion = idInstitucion
},
2022-07-08 18:23:45 +00:00
},
}
</script>
<style></style>