forked from verdnatura/salix-front
WIP
This commit is contained in:
parent
6baaebf6bd
commit
c7b60346e9
|
@ -9,19 +9,26 @@ import axios from 'axios';
|
||||||
import { useRole } from 'src/composables/useRole';
|
import { useRole } from 'src/composables/useRole';
|
||||||
import { useWeekdayStore } from 'src/stores/useWeekdayStore';
|
import { useWeekdayStore } from 'src/stores/useWeekdayStore';
|
||||||
import { useStateStore } from 'stores/useStateStore';
|
import { useStateStore } from 'stores/useStateStore';
|
||||||
|
import { useState } from 'src/composables/useState';
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const { notify } = useNotify();
|
// const { notify } = useNotify();
|
||||||
const { hasAny } = useRole();
|
const { hasAny } = useRole();
|
||||||
|
const state = useState();
|
||||||
|
const user = state.getUser();
|
||||||
const stateStore = useStateStore();
|
const stateStore = useStateStore();
|
||||||
const weekdayStore = useWeekdayStore();
|
const weekdayStore = useWeekdayStore();
|
||||||
|
|
||||||
const entryDirections = [
|
// const entryDirections = [
|
||||||
{ code: 'in', description: t('Entrada') },
|
// { code: 'in', description: t('Entrada') },
|
||||||
{ code: 'middle', description: t('Intermedio') },
|
// { code: 'middle', description: t('Intermedio') },
|
||||||
{ code: 'out', description: t('Salida') },
|
// { code: 'out', description: t('Salida') },
|
||||||
];
|
// ];
|
||||||
|
|
||||||
|
const isHr = computed(() => hasAny(['hr']));
|
||||||
|
|
||||||
|
const isHimSelf = computed(() => user.value.id === route.params.id);
|
||||||
|
|
||||||
const columns = computed(() => {
|
const columns = computed(() => {
|
||||||
return weekdayStore.localeWeekdays?.map((day) => {
|
return weekdayStore.localeWeekdays?.map((day) => {
|
||||||
|
@ -34,55 +41,75 @@ const columns = computed(() => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const fetchWorkerTimeControlRef = ref(null);
|
||||||
const calendarRef = ref(null);
|
const calendarRef = ref(null);
|
||||||
const selectedDate = ref(null);
|
// const selectedDate = ref(null);
|
||||||
const selectedDateRange = ref(null);
|
const selectedDates = ref([]);
|
||||||
|
const endOfWeek = ref(null);
|
||||||
|
const startOfWeek = ref(null);
|
||||||
|
|
||||||
const handleDateSelection = (date) => {
|
const defaultDate = computed(() => {
|
||||||
if (!date) return;
|
const date = Date.vnNew();
|
||||||
console.log('date', date);
|
const year = date.getFullYear();
|
||||||
|
const month = date.getMonth() + 1; // Nota: getMonth devuelve el mes indexado desde 0
|
||||||
|
return `${year}/${month.toString().padStart(2, '0')}`;
|
||||||
|
});
|
||||||
|
|
||||||
const _date = new Date(date.year, date.month - 1, date.day);
|
const handleDateSelection = async (dates, _, selectedDateDetails) => {
|
||||||
console.log('_date', _date);
|
if (!dates.length || !selectedDateDetails) return;
|
||||||
|
|
||||||
const dateRange = { from: '', to: '' };
|
const selectedDate = new Date(
|
||||||
|
selectedDateDetails.year,
|
||||||
|
selectedDateDetails.month - 1,
|
||||||
|
selectedDateDetails.day
|
||||||
|
);
|
||||||
|
|
||||||
// Obtener la fecha de 3 días atrás
|
// Obtener el día de la semana de la fecha seleccionada (0 = Domingo, 1 = Lunes, ..., 6 = Sábado)
|
||||||
const threeDaysAgo = new Date(_date);
|
const dayOfWeek = selectedDate.getDay();
|
||||||
threeDaysAgo.setDate(_date.getDate() - 3);
|
|
||||||
dateRange.from = {
|
// Obtener el primer día de la semana (Lunes)
|
||||||
year: threeDaysAgo.getFullYear(),
|
const newStartOfWeek = new Date(selectedDate);
|
||||||
month: threeDaysAgo.getMonth() + 1, // Los meses van de 0 a 11, por eso sumamos 1
|
newStartOfWeek.setDate(
|
||||||
day: threeDaysAgo.getDate(),
|
selectedDate.getDate() - dayOfWeek + (dayOfWeek === 0 ? -6 : 1)
|
||||||
|
);
|
||||||
|
startOfWeek.value = newStartOfWeek;
|
||||||
|
|
||||||
|
// Obtener el último día de la semana (Domingo)
|
||||||
|
const newEndOfWeek = new Date(newStartOfWeek);
|
||||||
|
newEndOfWeek.setDate(newStartOfWeek.getDate() + 6);
|
||||||
|
endOfWeek.value = newEndOfWeek;
|
||||||
|
|
||||||
|
// Crear un array con las fechas de la semana seleccionada
|
||||||
|
const selectedDatesArray = [];
|
||||||
|
for (
|
||||||
|
let date = new Date(newStartOfWeek);
|
||||||
|
date <= newEndOfWeek;
|
||||||
|
date.setDate(date.getDate() + 1)
|
||||||
|
) {
|
||||||
|
selectedDatesArray.push(new Date(date).toISOString().slice(0, 10));
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('start of week:: ', startOfWeek.value);
|
||||||
|
console.log('new end of week:: ', endOfWeek.value);
|
||||||
|
|
||||||
|
// Asignar el array de fechas de la semana seleccionada al valor reactivo
|
||||||
|
selectedDates.value = selectedDatesArray;
|
||||||
|
|
||||||
|
setTimeout(async () => {
|
||||||
|
await fetchWorkerTimeControlRef.value.fetch();
|
||||||
|
}, 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Obtener la fecha de 3 días adelante
|
const workerTimeControlsFilter = computed(() => ({
|
||||||
const threeDaysAhead = new Date(_date);
|
where: {
|
||||||
threeDaysAhead.setDate(_date.getDate() + 3);
|
and: [{ timed: { gte: startOfWeek.value } }, { timed: { lte: endOfWeek.value } }],
|
||||||
dateRange.to = {
|
},
|
||||||
year: threeDaysAhead.getFullYear(),
|
}));
|
||||||
month: threeDaysAhead.getMonth() + 1, // Los meses van de 0 a 11, por eso sumamos 1
|
|
||||||
day: threeDaysAhead.getDate(),
|
|
||||||
};
|
|
||||||
|
|
||||||
calendarRef.value.setEditingRange(dateRange.from, dateRange.to);
|
const setWorkerTimeControls = (data) => {
|
||||||
console.log('date range:', dateRange);
|
console.log('worker time controls:: ', data);
|
||||||
};
|
};
|
||||||
|
|
||||||
// const isAllowedToEdit = computed(() => hasAny(['hr', 'productionAssi']));
|
|
||||||
// const columns = computed(() => [
|
|
||||||
// {
|
|
||||||
// label: 'asd',
|
|
||||||
// name: 'picture',
|
|
||||||
// align: 'left',
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// label: t('entry.latestBuys.tags'),
|
|
||||||
// name: 'tags',
|
|
||||||
// align: 'left',
|
|
||||||
// },
|
|
||||||
// ]);
|
|
||||||
|
|
||||||
console.log('columns:: ', columns.value);
|
console.log('columns:: ', columns.value);
|
||||||
|
|
||||||
onBeforeMount(() => {
|
onBeforeMount(() => {
|
||||||
|
@ -96,34 +123,28 @@ onMounted(async () => {
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<!-- <FetchData
|
<FetchData
|
||||||
ref="fetchCurrentDeviceRef"
|
ref="fetchWorkerTimeControlRef"
|
||||||
url="DeviceProductionUsers"
|
url="WorkerTimeControls/filter"
|
||||||
:filter="{
|
:filter="workerTimeControlsFilter"
|
||||||
where: { userFk: route.params.id },
|
:params="{
|
||||||
include: { relation: 'deviceProduction' },
|
workerFk: route.params.id,
|
||||||
}"
|
}"
|
||||||
auto-load
|
@on-fetch="(data) => setWorkerTimeControls(data)"
|
||||||
@on-fetch="(data) => setCurrentPDA(data[0])"
|
/>
|
||||||
/> -->
|
|
||||||
<QDrawer v-model="stateStore.rightDrawer" side="right" :width="300" show-if-above>
|
<QDrawer v-model="stateStore.rightDrawer" side="right" :width="300" show-if-above>
|
||||||
<!-- <QScrollArea class="fit text-grey-8"> -->
|
|
||||||
<div class="fit">
|
|
||||||
<QDate
|
<QDate
|
||||||
ref="calendarRef"
|
ref="calendarRef"
|
||||||
v-model="selectedDate"
|
:model-value="selectedDates"
|
||||||
@range-start="handleDateSelection"
|
@update:model-value="handleDateSelection"
|
||||||
mask="YYYY-MM-DD"
|
mask="YYYY-MM-DD"
|
||||||
color="primary"
|
color="primary"
|
||||||
minimal
|
minimal
|
||||||
:years-in-month-view="false"
|
multiple
|
||||||
first-day-of-week="1"
|
bordered
|
||||||
range
|
:default-year-month="defaultDate"
|
||||||
class
|
|
||||||
/>
|
/>
|
||||||
</div>
|
<pre>date range: {{ selectedDates }}</pre>
|
||||||
|
|
||||||
<!-- </QScrollArea> -->
|
|
||||||
</QDrawer>
|
</QDrawer>
|
||||||
<QPage class="column items-center q-pa-md">
|
<QPage class="column items-center q-pa-md">
|
||||||
<QCard class="full-width">
|
<QCard class="full-width">
|
||||||
|
@ -132,11 +153,7 @@ onMounted(async () => {
|
||||||
</QPage>
|
</QPage>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss"></style>
|
||||||
.test {
|
|
||||||
max-width: 100px !important;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<i18n>
|
<i18n>
|
||||||
es:
|
es:
|
||||||
|
|
Loading…
Reference in New Issue