pcpuma_unam_operador/components/tablas/TablaDias.vue

158 lines
4.4 KiB
Vue
Raw Normal View History

2022-07-25 12:49:16 +00:00
<template>
<b-table
2022-07-29 01:04:17 +00:00
class="pb-6"
2022-07-26 16:49:26 +00:00
:data="dias"
2022-07-25 12:49:16 +00:00
:loading="isLoadingTable"
2022-07-27 05:45:53 +00:00
:opened-detailed="open"
detail-key="id_institucion_dia"
2022-07-26 16:49:26 +00:00
detailed
2022-07-25 12:49:16 +00:00
hoverable
2022-07-27 05:45:53 +00:00
:show-detail-icon="!mostrar"
2022-07-25 12:49:16 +00:00
striped
>
2022-07-27 05:45:53 +00:00
<b-table-column
field="props.row.dia.dia"
label="Día"
v-slot="props"
centered
>
2022-07-25 22:59:36 +00:00
<p>{{ props.row.dia.dia }}</p>
</b-table-column>
<b-table-column
field="hora_inicio"
label="Hora inicio del servicio"
v-slot="props"
2022-07-26 16:49:26 +00:00
centered
2022-07-25 22:59:36 +00:00
>
<p>{{ props.row.hora_inicio }}</p>
</b-table-column>
<b-table-column
field="hora_fin"
label="Hora fin del servicio"
v-slot="props"
2022-07-26 16:49:26 +00:00
centered
2022-07-25 22:59:36 +00:00
>
<p>{{ props.row.hora_fin }}</p>
</b-table-column>
2022-07-26 16:49:26 +00:00
<b-table-column field="editar" label="Editar horas" v-slot="props" centered>
2022-07-27 05:45:53 +00:00
<BotonEditar :editar="editar" :row="props.row" />
2022-07-25 22:59:36 +00:00
</b-table-column>
<b-table-column field="activo" label="Status" v-slot="props" centered>
<BotonDesactivar
:activarDesactivar="activarDesactivar"
2022-07-26 16:49:26 +00:00
:row="props.row"
2022-07-25 22:59:36 +00:00
:msjWarning="`¿Estás segur@ de querer ${
2022-07-26 16:49:26 +00:00
props.row.activo || props.row.mostrar ? 'desactivar' : 'activar'
2022-07-25 22:59:36 +00:00
} este tipo de carrito?`"
/>
</b-table-column>
2022-07-26 16:49:26 +00:00
<template #detail="props">
<HorasExcepcionDia
:institucionDia="props.row"
:horasExcepcion="props.row.horasExcepcion"
:isLoadingTable="isLoadingTable"
:obtenerDias="obtenerDias"
:updateIsLoading="updateIsLoading"
2022-07-27 05:45:53 +00:00
v-if="!mostrar"
/>
<Reloj
:diaSeleccion="props.row"
:cambiarHora="cambiarHora"
tipo="cambiarHora"
v-if="mostrar"
2022-07-26 16:49:26 +00:00
/>
</template>
2022-07-25 12:49:16 +00:00
</b-table>
</template>
<script>
2022-07-26 16:49:26 +00:00
import axios from 'axios'
2022-07-25 22:59:36 +00:00
import BotonDesactivar from '@/components/botones/BotonDesactivar'
2022-07-27 05:45:53 +00:00
import BotonEditar from '@/components/botones/BotonEditar'
2022-07-26 16:49:26 +00:00
import HorasExcepcionDia from '@/components/tablas/HorasExcepcionDia'
2022-07-27 05:45:53 +00:00
import Reloj from '@/components/admin/Reloj'
2022-07-25 22:59:36 +00:00
2022-07-25 12:49:16 +00:00
export default {
2022-07-27 05:45:53 +00:00
components: { BotonEditar, BotonDesactivar, HorasExcepcionDia, Reloj },
2022-07-25 12:49:16 +00:00
props: {
2022-07-26 16:49:26 +00:00
dias: { type: Array, required: true, default: () => [] },
2022-07-25 12:49:16 +00:00
isLoadingTable: { type: Boolean, required: true, default: false },
2022-07-26 16:49:26 +00:00
obtenerDias: { type: Function, required: true },
updateIsLoading: { type: Function, required: true },
2022-07-25 12:49:16 +00:00
},
data() {
2022-07-27 05:45:53 +00:00
return { mostrar: false, open: [], openAux: [] }
2022-07-25 12:49:16 +00:00
},
2022-07-26 16:49:26 +00:00
methods: {
activarDesactivar(institucionDia) {
const data = {
id_institucion_dia: institucionDia.id_institucion_dia,
activo: !institucionDia.activo,
}
this.updateIsLoading(true)
axios
.put(
`${process.env.api}/institucion-dia/`,
data,
this.$getToken.token()
)
.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-07-27 05:45:53 +00:00
editar(institucionDia) {
const index = this.open.findIndex(
(element) => element === institucionDia.id_institucion_dia
)
if (index < 0) {
this.open.push(institucionDia.id_institucion_dia)
this.openAux.push(institucionDia.id_institucion_dia)
} else {
this.open.splice(index, 1)
this.openAux.splice(index, 1)
}
if (this.open.length > this.openAux.length) this.open = [...this.openAux]
if (this.openAux.length > 0) this.mostrar = true
else this.mostrar = false
},
cambiarHora(institucionDia, hora_inicio, hora_fin) {
const data = {
id_institucion_dia: institucionDia.id_institucion_dia,
hora_inicio,
hora_fin,
}
this.updateIsLoading(true)
axios
.put(`${process.env.api}/institucion-dia`, data, this.$getToken.token())
.then((res) => {
this.obtenerDias()
this.editar(institucionDia)
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 16:49:26 +00:00
},
2022-07-25 12:49:16 +00:00
watch: {},
created() {},
}
</script>