Files

132 lines
3.3 KiB
Vue
Raw Permalink Normal View History

2021-06-08 22:45:32 -05:00
<template>
<div>
<h3 class="title">Editar información del responsable</h3>
<b-field label="Nombre">
<b-input
type="text"
:placeholder="responsable.nombre"
v-model="nuevo.nombre"
2021-11-23 18:38:37 -06:00
/>
2021-06-08 22:45:32 -05:00
</b-field>
<b-field label="Correo eletrónico">
<b-input
type="email"
:placeholder="responsable.usuario"
v-model="nuevo.correo"
2021-11-23 18:38:37 -06:00
/>
2021-06-08 22:45:32 -05:00
</b-field>
2021-06-09 09:14:12 -05:00
<!-- <b-field label="Estado:">
<b-select v-model="nuevo.activo" expanded>
<option :value="true">Activado</option>
<option :value="false">Desactivado</option>
</b-select>
</b-field> -->
<div class="pt-5">
2021-06-08 22:45:32 -05:00
<b-button
2021-06-09 09:14:12 -05:00
type="is-info"
2021-06-08 22:45:32 -05:00
:disabled="mostrarBoton()"
2021-08-05 16:47:56 -05:00
@click="
imprimirWarning(
'¿Seguro(a) que quiere actualizar la información de este usuario?',
actualizar
)
"
2021-06-08 22:45:32 -05:00
>
Guardar Cambios
</b-button>
2021-08-05 16:47:56 -05:00
<b-button
2021-11-28 23:28:05 -06:00
type="is-link"
2021-08-05 16:47:56 -05:00
@click="
imprimirWarning(
'¿Seguro(a) que quiere cambiar la contraseña para este usuario?',
password
)
"
>
2021-06-08 22:45:32 -05:00
Cambiar contraseña
</b-button>
</div>
</div>
</template>
<script>
import axios from 'axios'
2021-11-23 18:38:37 -06:00
import validator from 'validator'
2021-06-08 22:45:32 -05:00
export default {
2021-08-04 17:03:13 -05:00
props: {
admin: { type: Object, required: true },
responsable: { type: Object, required: true },
2021-11-23 18:38:37 -06:00
imprimirError: { type: Function, required: true },
2021-08-04 17:03:13 -05:00
imprimirMensaje: { type: Function, required: true },
imprimirWarning: { type: Function, required: true },
2021-08-05 16:47:56 -05:00
updateIsLoading: { type: Function, required: true },
2021-08-04 17:03:13 -05:00
},
data() {
return {
nuevo: {},
}
},
2021-06-08 22:45:32 -05:00
methods: {
mostrarBoton() {
if (this.nuevo.correo) {
if (!validator.isEmail(this.nuevo.correo)) return true
if (this.nuevo.correo != this.responsable.usuario) return false
}
if (this.nuevo.nombre && this.nuevo.nombre != this.responsable.nombre)
return false
return true
},
actualizar() {
const data = { idUsuario: this.responsable.idUsuario }
2021-06-08 22:45:32 -05:00
2021-08-05 16:47:56 -05:00
this.updateIsLoading(true)
2021-06-08 22:45:32 -05:00
if (this.nuevo.correo) data.correo = this.nuevo.correo
if (this.nuevo.nombre) data.nombre = this.nuevo.nombre
axios
2021-08-04 17:03:13 -05:00
.put(
`${process.env.api}/usuario/responsable/update`,
data,
this.admin.token
)
2021-06-08 22:45:32 -05:00
.then((res) => {
2021-08-05 16:47:56 -05:00
this.updateIsLoading(false)
this.imprimirMensaje(res.data.message)
2021-11-28 23:28:05 -06:00
this.$router.push('/admin/responsables/responsable')
2021-06-08 22:45:32 -05:00
})
.catch((err) => {
2021-08-05 16:47:56 -05:00
this.updateIsLoading(false)
2021-06-08 22:45:32 -05:00
this.imprimirError(err.response.data)
})
},
password() {
const data = { idUsuario: this.responsable.idUsuario }
2021-06-08 22:45:32 -05:00
2021-08-05 16:47:56 -05:00
this.updateIsLoading(true)
2021-06-08 22:45:32 -05:00
axios
.put(
`${process.env.api}/usuario/new_password_responsable`,
data,
2021-08-04 17:03:13 -05:00
this.admin.token
2021-06-08 22:45:32 -05:00
)
.then((res) => {
2021-08-05 16:47:56 -05:00
this.updateIsLoading(false)
this.imprimirMensaje(res.data.message)
2021-11-28 23:28:05 -06:00
this.$router.push('/admin/responsables/responsable')
2021-06-08 22:45:32 -05:00
})
.catch((err) => {
2021-08-05 16:47:56 -05:00
this.updateIsLoading(false)
this.imprimirError(err.response.data)
})
},
2021-06-08 22:45:32 -05:00
},
}
</script>
2021-11-24 22:05:37 -06:00
<style scoped></style>