fix [P-47]: исправления выбора дат в форме

This commit is contained in:
Inna committed 2025-09-23 09:45:33 +03:00
1 parent 6013c4ed0f
commit 678a683e4d
3 files changed
+86 -76

No files matched your search

@@ -29,7 +29,7 @@
</template>
<script>
import { ref, onMounted } from 'vue';
import { ref, onMounted, watch } from 'vue';
import { useWeekendsStore } from '@/store/WeekendsStore';
import EventCreate from '@/components/calendar_of_events/event-create.vue';
import CustomCalendar from '@/components/calendar_of_events/UI_calendar/CustomCalendar.vue';
@@ -85,7 +85,7 @@ export default {
});
};
onMounted(() => {
onMounted(() => {
getEvents();
week.getWeekend(MyYear.value);
});
@@ -102,7 +102,7 @@ export default {
}
};
return {
return {
selectedDate,
getMonth,
getYear,
@@ -2,10 +2,10 @@
<v-col lg="3" :class="`order-${order[0]}`">
<v-menu
v-model="menudate"
:close-on-content-click="false"
:nudge-right="40"
transition="scale-transition"
offset-y
:close-on-content-click="false"
>
<template v-slot:activator="{ props }">
<v-textarea
@@ -21,12 +21,7 @@
hide-details
>
<template v-slot:prepend-inner>
<v-icon
v-bind="props"
icon="mdi-calendar-today"
color="cyan-darken-3"
size="x-small"
/>
<v-icon v-bind="props" icon="mdi-calendar-today" color="cyan-darken-3" size="x-small" />
</template>
</v-textarea>
</template>
@@ -38,7 +33,7 @@
hide-header
border
no-time
:max="order[0] == 2 ? new Date(limitation) : endMax()"
:max="endMax()"
:min="order[0] == 2 ? startMin() : minData()"
/>
</v-locale-provider>
@@ -66,29 +61,24 @@
activator="parent"
transition="scale-transition"
>
<v-time-picker
v-if="menutime"
v-model="timeEvent"
full-width
format="24hr"
></v-time-picker>
<v-time-picker v-if="menutime" v-model="timeEvent" full-width format="24hr"></v-time-picker>
</v-menu>
</v-col>
</template>
<script>
import { ref, computed } from "vue";
import { formatComa, formatDash } from "@/utils/universal_functions";
import { ref, computed } from 'vue';
import { formatComa, formatDash } from '@/utils/universal_functions';
export default {
props: {
dateEvent: {
type: String,
default: "",
default: '',
},
limitation: {
type: String,
default: "",
default: '',
},
order: {
@@ -111,7 +101,7 @@ export default {
const propsDateEvent = computed({
get: () => new Date(props.dateEvent),
set: (value) => emit("update:dateEvent", value),
set: (value) => emit('update:dateEvent', value),
});
const modelDate = computed({
@@ -119,77 +109,100 @@ export default {
return propsDateEvent.value;
},
set(newValue) {
creatwdDate(newValue, timeEvent.value);
createdDate(newValue, timeEvent.value);
},
});
const timeEvent = computed({
get() {
return `${new Date(propsDateEvent.value).getHours()}:${String(
new Date(propsDateEvent.value).getMinutes()
).padStart(2, "0")}`;
new Date(propsDateEvent.value).getMinutes(),
).padStart(2, '0')}`;
},
set(newValue) {
creatwdDate(modelDate.value, newValue);
createdDate(modelDate.value, newValue);
},
});
const creatwdDate = (date, time) => {
let tzero = time.split(":");
time = tzero[0].padStart(2, "0") + ":" + tzero[1];
// const creatwdDate = (date, time) => {
// let tzero = time.split(':');
// time = tzero[0].padStart(2, '0') + ':' + tzero[1];
// if (props.order[0] == 4) {
// if (time == '0:00') {
// propsDateEvent.value = date;
// } else if (new Date(formatDash(date) + 'T' + time) >= new Date(props.limitation)) {
// propsDateEvent.value = new Date(formatDash(date) + 'T' + time);
// } else {
// propsDateEvent.value = new Date(props.limitation);
// }
// } else {
// propsDateEvent.value = time == '0:00' ? date : new Date(formatDash(date) + 'T' + time);
// }
// };
const createdDate = (date, time) => {
const [hours, minutes] = time.split(':').map(Number);
const newDate = new Date(date);
newDate.setHours(hours, minutes, 0, 0);
if (props.order[0] == 4) {
if (time == "0:00") {
propsDateEvent.value = date;
} else if (
new Date(formatDash(date) + "T" + time) >= new Date(props.limitation)
) {
propsDateEvent.value = new Date(formatDash(date) + "T" + time);
} else {
propsDateEvent.value = new Date(props.limitation);
}
// Для окончания: проверяем чтобы не было раньше начала
const startDate = new Date(props.limitation);
propsDateEvent.value = newDate >= startDate ? newDate : startDate;
} else {
propsDateEvent.value =
time == "0:00" ? date : new Date(formatDash(date) + "T" + time);
// Для начала: просто устанавливаем дату
propsDateEvent.value = newDate;
}
menudate.value = false;
menutime.value = false;
};
const minData = () => {
let h = `${new Date(props.limitation).getHours()}:${String(
new Date(props.limitation).getMinutes()
).padStart(2, "0")}`;
let min =
h == "0:00"
? new Date(props.limitation)
: new Date(
new Date(props.limitation).setDate(
new Date(props.limitation).getDate() - 1
)
);
return new Date(min);
// let h = `${new Date(props.limitation).getHours()}:${String(
// new Date(props.limitation).getMinutes()
// ).padStart(2, "0")}`;
// let min =
// h == "0:00"
// ? new Date(props.limitation)
// : new Date(
// new Date(props.limitation).setDate(
// new Date(props.limitation).getDate() - 1
// )
// );
// return new Date(min);
return new Date(props.limitation);
};
const startMin = () => {
if (props.rule == 2) {
return new Date(
new Date(props.limitation).setDate(
new Date(props.limitation).getDate() - 7
)
);
}
return false;
// if (props.rule == 2) {
// return new Date(
// new Date(props.limitation).setDate(
// new Date(props.limitation).getDate() - 7
// )
// );
// }
// return false;
return new Date(); // ← По умолчанию: нельзя выбрать прошедшие даты
};
const endMax = () => {
if (props.rule == 2) {
// if (props.rule == 2) {
// return new Date(
// new Date(props.limitation).setDate(new Date(props.limitation).getDate() + 6),
// );
// }
// return false;
if (props.order[0] == 2 && props.rule == 2) {
// Для недельного повторения: ограничение сверху +6 дней от начала
return new Date(
new Date(props.limitation).setDate(
new Date(props.limitation).getDate() + 6
)
new Date(props.limitation).setDate(new Date(props.limitation).getDate() + 6),
);
}
return false;
return false; // ← Без ограничения сверху
};
return {
@@ -52,6 +52,8 @@
return-object
:rules="rules.calendar"
:disabled="'id' in propsEvent.event"
clearable
auto-select-first
>
<template v-slot:selection="{ item }">
<v-avatar class="cursor-pointer" size="8" :color="item.raw.cl_color" />
@@ -59,17 +61,13 @@
{{ item.title }}
</span>
</template>
<template v-slot:item="{ item }">
<v-list-item
:key="item.title"
:value="item"
color="primary"
@click.stop="myCalendar = item.raw"
>
<template v-slot:item="{ item, props }">
<v-list-item :key="item.raw.id" :value="item" color="primary" v-bind="props"
@click.stop="myCalendar = item.raw" >
<template v-slot:prepend>
<v-avatar class="cursor-pointer" size="8" :color="item.raw.cl_color" />
</template>
{{ item.title }}
<!-- {{ item.title }} -->
</v-list-item>
</template>
</v-autocomplete>
@@ -213,6 +211,7 @@ export default {
setup(props, { emit }) {
const accountStore = useAccountStore();
const createDialog = ref(null);
const calendarAutocompleteRef = ref(null);
const propsEvent = computed({
get: () => {
@@ -223,9 +222,6 @@ export default {
});
// ВАЛИДАЦИЯ
const isFormValid = ref(false);
const rules = {
name: [
(val) => !!val || 'Поле обязательно для заполнения',
@@ -441,6 +437,7 @@ export default {
// Computed property с защитой от undefined
const safeCalendars = computed(() => props.myCalendars || []);
const isCalendarsReady = computed(() => safeCalendars.value.length > 0);
// Автовыбор при появлении данных