Files

354 lines
9.9 KiB
Vue
Raw Permalink Normal View History

2020-11-11 18:15:05 -06:00
<template>
2021-12-31 21:26:39 -06:00
<div>
<h3 class="title">Editar información del alumno</h3>
2021-11-24 21:02:01 -06:00
2021-12-31 21:26:39 -06:00
<div>
<b-field label="Correo eletrónico del alumno">
2022-01-01 13:50:39 -06:00
<b-input type="email" :placeholder="servicio.correo" v-model="correo" />
2020-11-11 18:15:05 -06:00
</b-field>
2021-11-24 21:02:01 -06:00
2021-12-31 21:26:39 -06:00
<b-field label="Fecha de inicio">
<b-datepicker
icon="calendar-today"
:min-date="minDate1"
2022-01-01 13:50:39 -06:00
v-model="fechaInicio"
2021-12-31 21:26:39 -06:00
/>
</b-field>
2022-01-01 13:50:39 -06:00
<b-field label="Fecha de fin">
<b-datepicker
icon="calendar-today"
:min-date="minDate2"
v-model="fechaFin"
/>
</b-field>
2021-11-24 21:02:01 -06:00
2021-12-31 21:26:39 -06:00
<b-field label="Dirección" v-if="servicio.direccion">
<b-input
type="text"
:placeholder="servicio.direccion"
2022-01-01 13:50:39 -06:00
v-model="direccion"
2021-12-31 21:26:39 -06:00
/>
</b-field>
2021-11-24 21:02:01 -06:00
2021-12-31 21:26:39 -06:00
<b-field label="Teléfono" v-if="servicio.telefono">
<b-input
type="tel"
maxlength="10"
:has-counter="false"
:placeholder="servicio.telefono"
2022-01-01 13:50:39 -06:00
v-model="telefono"
2021-12-31 21:26:39 -06:00
/>
</b-field>
2021-11-24 21:02:01 -06:00
2021-12-31 21:26:39 -06:00
<b-field label="Fecha de nacimiento" v-if="servicio.fechaNacimiento">
<b-datepicker
icon="calendar-today"
:placeholder="fecha(servicio.fechaNacimiento)"
2022-01-01 14:06:34 -06:00
:max-date="new Date()"
2022-01-01 13:50:39 -06:00
v-model="fechaNacimiento"
2021-12-31 21:26:39 -06:00
/>
</b-field>
2021-11-24 21:02:01 -06:00
2021-12-31 21:49:25 -06:00
<b-field label="Carta de aceptación">
2021-12-31 21:26:39 -06:00
<b-upload
accept="application/pdf"
2022-01-01 13:50:39 -06:00
v-model="cartaAceptacion"
2021-12-31 21:26:39 -06:00
drag-drop
expanded
>
2021-12-31 21:49:25 -06:00
<div class="section has-text-centered">
<b-icon icon="upload" size="is-large" class="mb-2" />
<p class="is-size-5">
{{
2022-01-01 13:50:39 -06:00
cartaAceptacion.name ||
2021-12-31 21:49:25 -06:00
'Arrastra aquí tu archivo o da click aquí para buscarlo.'
}}
</p>
<p class="is-size-6">Tamaño máximo 20MB</p>
</div>
2021-12-31 21:26:39 -06:00
</b-upload>
</b-field>
2021-11-24 21:02:01 -06:00
2021-12-31 21:49:25 -06:00
<b-field
label="Carta de término"
v-if="servicio.Status.idStatus > 4 && servicio.Status.idStatus != 7"
>
2021-12-31 21:26:39 -06:00
<b-upload
accept="application/pdf"
2022-01-01 13:50:39 -06:00
v-model="cartaTermino"
2021-12-31 21:26:39 -06:00
drag-drop
expanded
>
2021-12-31 21:49:25 -06:00
<div class="section has-text-centered">
<b-icon icon="upload" size="is-large" class="mb-2" />
<p class="is-size-5">
{{
2022-01-01 13:50:39 -06:00
cartaTermino.name ||
2021-12-31 21:49:25 -06:00
'Arrastra aquí tu archivo o da click aquí para buscarlo.'
}}
</p>
<p class="is-size-6">Tamaño máximo 20MB</p>
</div>
2021-12-31 21:26:39 -06:00
</b-upload>
</b-field>
2021-11-24 21:02:01 -06:00
2021-12-31 21:49:25 -06:00
<b-field
label="Informe global"
v-if="servicio.Status.idStatus > 4 && servicio.Status.idStatus != 7"
>
2021-12-31 21:26:39 -06:00
<b-upload
accept="application/pdf"
2022-01-01 13:50:39 -06:00
v-model="informeGlobal"
2021-12-31 21:26:39 -06:00
drag-drop
expanded
>
2021-12-31 21:49:25 -06:00
<div class="section has-text-centered">
<b-icon icon="upload" size="is-large" class="mb-2" />
<p class="is-size-5">
{{
2022-01-01 13:50:39 -06:00
informeGlobal.name ||
2021-12-31 21:49:25 -06:00
'Arrastra aquí tu archivo o da click aquí para buscarlo.'
}}
</p>
<p class="is-size-6">Tamaño máximo 20MB</p>
</div>
2021-12-31 21:26:39 -06:00
</b-upload>
</b-field>
</div>
2021-11-24 21:02:01 -06:00
2022-01-01 13:50:39 -06:00
<div class="mt-4">
2021-12-31 21:26:39 -06:00
<b-button
class="is-info"
2022-01-01 13:50:39 -06:00
:disabled="mostrar()"
2021-12-31 21:26:39 -06:00
@click="
imprimirWarning(
'¿Seguro(a) que quiere actualizar estos datos?',
actualizar
)
"
>
2021-01-12 20:28:04 -06:00
Actualizar Datos
</b-button>
2021-11-24 21:02:01 -06:00
2021-12-31 21:26:39 -06:00
<b-button
class="is-info"
@click="
imprimirWarning(
2022-01-01 13:50:39 -06:00
'¿Seguro(a) que quieres cambiar/reenviar la contraseña de este alumno?',
2021-12-31 21:26:39 -06:00
password
)
"
2022-01-01 13:50:39 -06:00
:disabled="
servicio.Status.idStatus === 1 || servicio.Status.idStatus === 7
"
2021-12-31 21:26:39 -06:00
>
2022-01-01 13:50:39 -06:00
Cambiar/Reenviar contraseña
2021-01-12 20:28:04 -06:00
</b-button>
2020-11-11 18:15:05 -06:00
</div>
</div>
</template>
<script>
2021-05-13 14:22:56 -05:00
import axios from 'axios'
import moment from 'moment'
import validator from 'validator'
2020-11-13 16:46:50 -06:00
2020-11-11 18:15:05 -06:00
export default {
2021-12-31 21:26:39 -06:00
props: {
admin: { type: Object, required: true },
imprimirError: { type: Function, required: true },
imprimirMensaje: { type: Function, required: true },
imprimirWarning: { type: Function, required: true },
updateIsLoading: { type: Function, required: true },
2021-01-05 02:04:07 -06:00
},
2020-12-08 21:50:16 -06:00
data() {
2020-11-11 18:15:05 -06:00
return {
2022-01-01 13:50:39 -06:00
actualizarFechaFin: false,
2021-12-31 21:26:39 -06:00
idServicio: null,
2022-01-01 13:50:39 -06:00
correo: '',
telefono: '',
direccion: '',
fechaFin: new Date(),
fechaInicio: new Date(),
fechaNacimiento: new Date(),
cartaAceptacion: {},
cartaTermino: {},
informeGlobal: {},
2021-12-31 21:49:25 -06:00
minDate1: new Date('2020-01-01'),
2022-01-01 13:50:39 -06:00
minDate2: new Date(),
servicio: {
Status: {},
fechaFin: new Date(),
fechaInicio: new Date(),
fechaNacimiento: new Date(),
2020-11-13 16:46:50 -06:00
},
2021-05-13 14:22:56 -05:00
}
2020-11-13 16:46:50 -06:00
},
methods: {
2021-06-09 17:34:46 -05:00
fecha(date) {
if (date) {
const fecha = moment(date)
2021-08-04 18:25:24 -05:00
return `${fecha.date() < 10 ? '0' + fecha.date() : fecha.date()}/${
2021-06-09 17:34:46 -05:00
fecha.month() < 9 ? '0' + (fecha.month() + 1) : fecha.month() + 1
}/${fecha.year()}`
}
return ''
},
2020-12-08 21:50:16 -06:00
mostrar() {
2020-11-13 16:46:50 -06:00
if (
2022-01-01 14:06:34 -06:00
this.fechaInicio.toString().substr(0, 15) !==
this.servicio.fechaInicio.toString().substr(0, 15) ||
this.fechaFin.toString().substr(0, 15) !==
this.servicio.fechaFin.toString().substr(0, 15) ||
(this.servicio.fechaNacimiento &&
this.fechaNacimiento.toString().substr(0, 15) !==
this.servicio.fechaNacimiento.toString().substr(0, 15)) ||
2022-01-01 13:50:39 -06:00
(this.correo && validator.isEmail(this.correo)) ||
this.telefono ||
this.direccion ||
this.cartaTermino.name ||
this.cartaAceptacion.name ||
this.informeGlobal.name
)
return false
return true
},
sizeFileValido(file) {
if (file.size >= 20000000) {
this.imprimirError({ message: 'El tamaño del archivo exede los 20MB' })
return false
2020-11-11 18:15:05 -06:00
}
2022-01-01 13:50:39 -06:00
return true
},
updateFechas() {
if (this.actualizarFechaFin) {
this.fechaFin = new Date(
this.fechaInicio.getFullYear(),
this.fechaInicio.getMonth() + 6,
this.fechaInicio.getDate()
)
}
this.minDate2 = new Date(
this.fechaInicio.getFullYear(),
this.fechaInicio.getMonth() + 6,
this.fechaInicio.getDate()
)
this.actualizarFechaFin = true
2020-11-23 15:35:03 -06:00
},
2021-12-31 21:26:39 -06:00
obtenerRegistro() {
this.updateIsLoading(true)
axios
.get(
`${process.env.api}/servicio/admin?idServicio=${this.idServicio}`,
this.admin.token
)
.then((res) => {
this.servicio = res.data
if (
this.servicio.Status.idStatus === 6 ||
this.servicio.Status.idStatus === 10
)
this.$router.push('/admin/servicio')
2022-01-01 13:50:39 -06:00
this.fechaInicio = new Date(this.servicio.fechaInicio)
this.servicio.fechaInicio = new Date(this.servicio.fechaInicio)
this.fechaFin = new Date(this.servicio.fechaFin)
this.servicio.fechaFin = new Date(this.servicio.fechaFin)
if (this.servicio.fechaNacimiento) {
this.fechaNacimiento = new Date(this.servicio.fechaNacimiento)
this.servicio.fechaNacimiento = new Date(
this.servicio.fechaNacimiento
)
}
2021-12-31 21:26:39 -06:00
this.updateIsLoading(false)
})
.catch((err) => {
this.updateIsLoading(false)
this.imprimirError(err.response.data)
})
},
2020-12-08 21:50:16 -06:00
actualizar() {
2021-05-13 14:22:56 -05:00
const formData = new FormData()
const data = { idServicio: this.idServicio }
2021-01-06 21:13:18 -06:00
2021-12-31 21:26:39 -06:00
this.updateIsLoading(true)
2022-01-01 13:50:39 -06:00
if (this.cartaAceptacion)
formData.append('cartaAceptacion', this.cartaAceptacion)
if (this.cartaTermino) formData.append('cartaTermino', this.cartaTermino)
if (this.informeGlobal)
formData.append('informeGlobal', this.informeGlobal)
if (this.direccion) data.direccion = this.direccion
if (this.correo) data.correo = this.correo
if (this.telefono) data.telefono = this.telefono
if (this.fechaInicio) data.fechaInicio = this.fechaInicio
if (this.fechaFin) data.fechaFin = this.fechaFin
if (this.fechaNacimiento) data.fechaNacimiento = this.fechaNacimiento
2021-05-13 14:22:56 -05:00
formData.append('data', JSON.stringify(data))
2020-12-03 17:47:48 -06:00
axios
2021-12-31 21:26:39 -06:00
.put(
`${process.env.api}/servicio/update`,
formData,
this.admin.tokenArchivo
)
2020-12-08 21:50:16 -06:00
.then((res) => {
2021-12-31 21:49:25 -06:00
this.imprimirMensaje(res.data.message)
2021-12-31 21:26:39 -06:00
this.updateIsLoading(false)
2021-05-13 14:22:56 -05:00
this.$router.push('/admin/servicio')
2020-12-03 17:47:48 -06:00
})
2020-12-08 21:50:16 -06:00
.catch((err) => {
2021-12-31 21:26:39 -06:00
this.updateIsLoading(false)
this.imprimirError(err.response.data)
2021-01-12 20:28:04 -06:00
})
},
password() {
2021-05-13 14:22:56 -05:00
const data = { idServicio: this.idServicio }
2021-12-31 21:26:39 -06:00
this.updateIsLoading(true)
2021-01-12 20:28:04 -06:00
axios
2021-12-31 21:26:39 -06:00
.put(
`${process.env.api}/usuario/new_password_alumno`,
data,
this.admin.token
)
2021-01-12 20:28:04 -06:00
.then((res) => {
2021-12-31 21:49:25 -06:00
this.imprimirMensaje(res.data.message)
2021-12-31 21:26:39 -06:00
this.updateIsLoading(false)
2021-05-13 14:22:56 -05:00
this.$router.push('/admin')
2021-01-12 20:28:04 -06:00
})
.catch((err) => {
2021-12-31 21:26:39 -06:00
this.updateIsLoading(false)
this.imprimirError(err.response.data)
2021-05-13 14:22:56 -05:00
})
2021-01-12 20:28:04 -06:00
},
2020-11-13 16:46:50 -06:00
},
watch: {
2022-01-01 13:50:39 -06:00
fechaInicio() {
this.updateFechas()
},
cartaAceptacion() {
if (!this.sizeFileValido(this.cartaAceptacion)) this.cartaAceptacion = {}
2020-11-13 16:46:50 -06:00
},
2022-01-01 13:50:39 -06:00
cartaTermino() {
if (!this.sizeFileValido(this.cartaTermino)) this.cartaAceptacion = {}
2020-12-08 21:50:16 -06:00
},
2022-01-01 13:50:39 -06:00
informeGlobal() {
if (!this.sizeFileValido(this.informeGlobal)) this.informeGlobal = {}
2020-11-13 16:46:50 -06:00
},
2020-12-03 15:34:28 -06:00
},
2020-12-08 21:50:16 -06:00
created() {
2021-12-31 21:26:39 -06:00
this.idServicio = Number(localStorage.getItem('idServicio'))
if (!this.idServicio) this.$router.push('/admin')
else this.obtenerRegistro()
2020-12-08 21:50:16 -06:00
},
2021-05-13 14:22:56 -05:00
}
2020-11-11 18:15:05 -06:00
</script>
2020-11-13 16:46:50 -06:00
2022-01-01 13:50:39 -06:00
<style scoped></style>