WIP
This commit is contained in:
parent
0f6c6cde91
commit
503efb79c9
|
@ -268,8 +268,8 @@ defineExpose({
|
||||||
<QItem v-for="type in absenceTypeList" :key="type.id">
|
<QItem v-for="type in absenceTypeList" :key="type.id">
|
||||||
<WorkerDateLabel
|
<WorkerDateLabel
|
||||||
:color="type.rgb"
|
:color="type.rgb"
|
||||||
:selected="selectedAbsenceType === type.id"
|
:selected="selectedAbsenceType?.id === type.id"
|
||||||
@click="selectedAbsenceType = type.id"
|
@click="selectedAbsenceType = type"
|
||||||
>
|
>
|
||||||
{{ type.name }}
|
{{ type.name }}
|
||||||
</WorkerDateLabel>
|
</WorkerDateLabel>
|
||||||
|
|
|
@ -23,7 +23,7 @@ const props = defineProps({
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
absenceType: {
|
absenceType: {
|
||||||
type: Number,
|
type: Object,
|
||||||
default: null,
|
default: null,
|
||||||
},
|
},
|
||||||
businessFk: {
|
businessFk: {
|
||||||
|
@ -58,7 +58,7 @@ const createEvent = async (date) => {
|
||||||
try {
|
try {
|
||||||
const params = {
|
const params = {
|
||||||
dated: date,
|
dated: date,
|
||||||
absenceTypeId: props.absenceType,
|
absenceTypeId: props.absenceType.id,
|
||||||
businessFk: props.businessFk,
|
businessFk: props.businessFk,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -66,20 +66,41 @@ const createEvent = async (date) => {
|
||||||
`Workers/${route.params.id}/createAbsence`,
|
`Workers/${route.params.id}/createAbsence`,
|
||||||
params
|
params
|
||||||
);
|
);
|
||||||
console.log('data:: ', data);
|
if (data) emit('refresh');
|
||||||
// TODO: Agregar notify success
|
|
||||||
emit('refresh');
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('error creating event:: ', error);
|
console.log('error creating event:: ', error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const editEvent = async (event) => {
|
const editEvent = async (event) => {
|
||||||
console.log('editEvent');
|
try {
|
||||||
|
console.log('editEvent');
|
||||||
|
const absenceType = props.absenceType;
|
||||||
|
const params = {
|
||||||
|
absenceId: event.absenceId,
|
||||||
|
absenceTypeId: absenceType.id,
|
||||||
|
};
|
||||||
|
|
||||||
|
const { data } = await axios.patch(
|
||||||
|
`Workers/${route.params.id}/updateAbsence`,
|
||||||
|
params
|
||||||
|
);
|
||||||
|
|
||||||
|
if (data) emit('refresh');
|
||||||
|
} catch (error) {
|
||||||
|
console.log('error editing event:: ', error);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteEvent = async (date, event) => {
|
const deleteEvent = async (date, event) => {
|
||||||
console.log('deleteEvent');
|
console.log('deleteEvent');
|
||||||
|
const params = { absenceId: event.absenceId };
|
||||||
|
|
||||||
|
const { data } = await axios.delete(`Workers/${route.params.id}/deleteAbsence`, {
|
||||||
|
params,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (data) emit('refresh');
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDateSelected = (date) => {
|
const handleDateSelected = (date) => {
|
||||||
|
@ -93,10 +114,15 @@ const handleDateSelected = (date) => {
|
||||||
const stamp = _date.getTime();
|
const stamp = _date.getTime();
|
||||||
const event = props.events[stamp];
|
const event = props.events[stamp];
|
||||||
|
|
||||||
if (event && event.absenceId) {
|
if (!event) createEvent(_date);
|
||||||
if (event.type == props.absenceType.code) deleteEvent(_date, event);
|
};
|
||||||
else editEvent(event);
|
|
||||||
} else createEvent(_date);
|
const handleEventSelected = (event, { year, month, day }) => {
|
||||||
|
console.log('event:: ', event);
|
||||||
|
const date = new Date(year, month - 1, day);
|
||||||
|
console.log('date:: ', date);
|
||||||
|
if (event.type == props.absenceType.code) deleteEvent(date, event);
|
||||||
|
else editEvent(event);
|
||||||
};
|
};
|
||||||
|
|
||||||
const getEventByTimestamp = ({ year, month, day }) => {
|
const getEventByTimestamp = ({ year, month, day }) => {
|
||||||
|
@ -109,6 +135,8 @@ const getEventAttrs = (timestamp) => {
|
||||||
if (!event) return {};
|
if (!event) return {};
|
||||||
|
|
||||||
const { name, color } = event;
|
const { name, color } = event;
|
||||||
|
|
||||||
|
// Atributos a asignar a cada slot que representa un evento en el calendario
|
||||||
return {
|
return {
|
||||||
title: name,
|
title: name,
|
||||||
style: `background-color: ${color};`,
|
style: `background-color: ${color};`,
|
||||||
|
@ -147,9 +175,13 @@ watch(props.year, (newValue) => {
|
||||||
mini-mode
|
mini-mode
|
||||||
>
|
>
|
||||||
<template #day="{ scope: { timestamp } }">
|
<template #day="{ scope: { timestamp } }">
|
||||||
|
<!-- Este slot representa cada día del calendario y muestra un botón representando el correspondiente evento -->
|
||||||
<QButton
|
<QButton
|
||||||
v-if="getEventByTimestamp(timestamp)"
|
v-if="getEventByTimestamp(timestamp)"
|
||||||
v-bind="{ ...getEventAttrs(timestamp) }"
|
v-bind="{ ...getEventAttrs(timestamp) }"
|
||||||
|
@click="
|
||||||
|
handleEventSelected(getEventByTimestamp(timestamp), timestamp)
|
||||||
|
"
|
||||||
class="calendar-event"
|
class="calendar-event"
|
||||||
>
|
>
|
||||||
{{ timestamp.day }}
|
{{ timestamp.day }}
|
||||||
|
|
Loading…
Reference in New Issue