pcpuma_unam_operador/components/admin/TablaInstiDia.vue

161 lines
4.3 KiB
Vue
Raw Normal View History

2022-06-28 06:41:38 +00:00
<template>
<section>
2022-07-06 06:57:55 +00:00
<b-table :data="data" detailed>
2022-06-28 06:41:38 +00:00
<b-table-column field="dia" label="Día" centered v-slot="props">
{{ props.row.dia.dia }}
</b-table-column>
<b-table-column
field="hora_inicio"
label="Hora Inicio"
centered
v-slot="props"
>
{{ props.row.hora_inicio }}
</b-table-column>
<b-table-column field="hora_fin" label="Hora Fin" centered v-slot="props">
{{ props.row.hora_fin }}
</b-table-column>
<b-table-column field="editar" label="Editar" v-slot="props"
><b-button type="is-primary" @click="editarHora(props.row)">
<b-icon icon="pencil" size="is-small" />
</b-button>
</b-table-column>
2022-07-12 20:47:47 +00:00
<b-table-column field="activar" label="Activar" centered v-slot="props">
<BotonDesactivar
:admin="admin"
:data="props.row"
tipo="día"
:cambiarStatus="cambiarStatus"
/>
</b-table-column>
2022-07-06 06:57:55 +00:00
<template #detail="props">
<HorasExcepcion
:horasExcepcion="props.row"
2022-07-06 19:52:10 +00:00
:updateIsLoading="updateIsLoading"
:actualizarTabla="actualizarTabla"
:updateActualizarTabla="updateActualizarTabla"
2022-07-06 06:57:55 +00:00
/>
</template>
</b-table>
2022-06-28 06:41:38 +00:00
2022-07-06 06:57:55 +00:00
<div v-if="mostrar">
2022-07-22 04:02:08 +00:00
<Reloj
2022-07-06 06:57:55 +00:00
:cambiarHora="cambiarHora"
:diaSeleccion="diaSeleccion"
tipo="cambiarHora"
/>
2022-06-28 06:41:38 +00:00
</div>
</section>
</template>
<script>
import axios from 'axios'
2022-07-12 20:47:47 +00:00
import BotonDesactivar from '@/components/operador/BotonDesactivar'
2022-07-06 06:57:55 +00:00
import HorasExcepcion from '@/components/admin/HorasExcepcion'
2022-07-22 04:02:08 +00:00
import Reloj from '@/components/admin/Reloj'
2022-07-06 06:57:55 +00:00
2022-06-28 06:41:38 +00:00
export default {
2022-07-06 06:57:55 +00:00
components: {
2022-07-12 20:47:47 +00:00
BotonDesactivar,
2022-07-06 06:57:55 +00:00
HorasExcepcion,
2022-07-22 04:02:08 +00:00
Reloj,
2022-07-06 06:57:55 +00:00
},
2022-06-28 06:41:38 +00:00
props: {
admin: { type: Object, require: true },
2022-07-01 05:42:16 +00:00
updateIsLoading: { type: Function, required: true },
2022-06-28 17:20:39 +00:00
actualizarTabla: { type: Boolean, required: true },
updateActualizarTabla: { type: Function, required: true },
2022-06-28 06:41:38 +00:00
},
data() {
return {
data: [],
mostrar: false,
diaSeleccion: {},
}
},
methods: {
2022-07-12 20:47:47 +00:00
cambiarStatus(dataSelect, status) {
const data = {
id_institucion_dia: dataSelect.id_institucion_dia,
activo: status,
}
this.updateIsLoading(true)
axios
2022-07-19 16:41:33 +00:00
.put(
`${process.env.api}/institucion-dia/`,
data,
this.$getToken.token()
)
2022-07-12 20:47:47 +00:00
.then((res) => {
this.obtenerDias()
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-06-28 06:41:38 +00:00
obtenerDias() {
this.updateIsLoading(true)
axios
.get(
2022-07-19 16:41:33 +00:00
`${process.env.api}/institucion-dia/?id_institucion=${this.admin.institucion.id_institucion}`,
this.$getToken.token()
2022-06-28 06:41:38 +00:00
)
.then((res) => {
this.data = res.data
2022-07-01 05:14:19 +00:00
this.updateIsLoading(false)
2022-06-28 06:41:38 +00:00
})
.catch((err) => {
2022-07-01 05:14:19 +00:00
this.updateIsLoading(false)
2022-07-11 14:15:10 +00:00
this.$alertsGenericos.imprimirError(this.$buefy, err.response.data)
2022-06-28 06:41:38 +00:00
})
},
editarHora(diaSeleccion) {
2022-07-06 06:57:55 +00:00
if (this.diaSeleccion != diaSeleccion) this.mostrar = true
else
this.mostrar === false ? (this.mostrar = true) : (this.mostrar = false)
2022-06-28 06:41:38 +00:00
this.diaSeleccion = diaSeleccion
},
2022-07-06 06:57:55 +00:00
cambiarHora(id_institucion_dia, hora_inicio, hora_fin, activo) {
2022-06-28 06:41:38 +00:00
const data = {
2022-07-06 06:57:55 +00:00
id_institucion_dia,
hora_inicio,
hora_fin,
activo,
2022-06-28 06:41:38 +00:00
}
this.updateIsLoading(true)
axios
2022-07-19 16:41:33 +00:00
.put(`${process.env.api}/institucion-dia`, data, this.$getToken.token())
2022-06-28 06:41:38 +00:00
.then((res) => {
this.updateIsLoading(false)
2022-07-11 14:15:10 +00:00
this.$alertsGenericos.imprimirMensaje(this.$buefy, res.data.message)
2022-06-28 17:20:39 +00:00
this.updateActualizarTabla(true)
2022-06-28 06:41:38 +00:00
})
.catch((err) => {
this.error = 'is-danger'
this.updateIsLoading(false)
2022-07-11 14:15:10 +00:00
this.$alertsGenericos.imprimirError(this.$buefy, err.response.data)
2022-06-28 06:41:38 +00:00
})
},
},
2022-06-28 17:20:39 +00:00
watch: {
actualizarTabla() {
if (this.actualizarTabla) {
this.obtenerDias()
this.updateActualizarTabla(false)
}
},
},
2022-06-28 06:41:38 +00:00
created() {
this.obtenerDias()
},
}
</script>