fix [P-255]: ограничил ввод дат в самом датепикере

This commit is contained in:
Denis Voinovich committed 2025-06-03 10:46:23 +03:00
1 parent 99661b2271
commit a39b962d0a
2 files changed
+56 -68

No files matched your search

+7 -9
View File
@@ -35,6 +35,7 @@
v-model="selectedDate" v-model="selectedDate"
show-adjacent-months show-adjacent-months
hide-header hide-header
:min="new Date().toISOString().slice(0, 10)"
@update:modelValue="dateStart" @update:modelValue="dateStart"
border border
/> />
@@ -53,25 +54,22 @@ export default {
props: { props: {
datedefault: { datedefault: {
type: Date, type: Date,
default: '' default: () => new Date()
} }
}, },
setup(props, {emit}) { setup(props, {emit}) {
const appStore = useAppStore() const appStore = useAppStore()
const maxdate = formatDash(new Date())
const menudate = ref(false) const menudate = ref(false)
const selectedDate = ref(null) const selectedDate = ref(props.datedefault ? formatDash(new Date(props.datedefault)) : formatDash(new Date()))
const dateStart = () => { const dateStart = () => {
emit('returndate', selectedDate.value) if (selectedDate.value) {
menudate.value=false emit('returndate', selectedDate.value)
menudate.value = false
}
} }
return { return {
menudate, menudate,
selectedDate, selectedDate,
@@ -178,70 +178,60 @@ export default {
}, },
emits: ['update:modelValue', 'assign', 'unassign'], emits: ['update:modelValue', 'assign', 'unassign'],
setup(props, { emit }) { setup(props, { emit }) {
const selectedEmployees = ref([]); const selectedEmployees = ref([]);
const publishNews = ref(false); const publishNews = ref(false);
const defaultEndDate = new Date();
defaultEndDate.setHours(18, 0, 0, 0);
const defaultStartDate = new Date();
defaultStartDate.setHours(9, 0, 0, 0);
const completionDate = ref(defaultEndDate);
const startDate = ref(defaultStartDate);
const snackbar = ref({
show: false,
text: '',
color: 'error'
});
const showSnackbar = (text, color = 'error') => { // Устанавливаем начальные даты
snackbar.value = { const currentDate = new Date();
show: true, const defaultStartDate = new Date(currentDate);
text, defaultStartDate.setHours(9, 0, 0, 0);
color
};
};
const handleEmployeeSelection = (value) => { const defaultEndDate = new Date(currentDate);
selectedEmployees.value = value; defaultEndDate.setHours(18, 0, 0, 0);
};
const handleDateChange = (date, type = 'end') => { const startDate = ref(defaultStartDate);
if (date) { const completionDate = ref(defaultEndDate);
const newDate = new Date(date);
if (type === 'end') {
newDate.setHours(18, 0, 0, 0);
} else {
newDate.setHours(9, 0, 0, 0);
}
const today = new Date(); const snackbar = ref({
today.setHours(0, 0, 0, 0); show: false,
if (newDate < today) { text: '',
showSnackbar('Нельзя назначить прошедшую дату'); color: 'error'
if (type === 'end') { });
completionDate.value = null;
} else {
startDate.value = null;
}
return;
}
if (type === 'end') { const showSnackbar = (text, color = 'error') => {
if (startDate.value && newDate < startDate.value) { snackbar.value = {
showSnackbar('Дата окончания не может быть раньше даты начала'); show: true,
completionDate.value = null; text,
return; color
} };
completionDate.value = newDate; };
} else {
if (completionDate.value && newDate > completionDate.value) { const handleEmployeeSelection = (value) => {
showSnackbar('Дата начала не может быть позже даты окончания'); selectedEmployees.value = value;
startDate.value = null; };
return;
} const handleDateChange = (date, type = 'end') => {
startDate.value = newDate; if (!date) return;
}
} const newDate = new Date(date);
}; if (type === 'end') {
newDate.setHours(18, 0, 0, 0);
completionDate.value = newDate;
if (startDate.value && newDate < startDate.value) {
startDate.value = newDate;
startDate.value.setHours(9, 0, 0, 0);
}
} else {
newDate.setHours(9, 0, 0, 0);
startDate.value = newDate;
if (completionDate.value && newDate > completionDate.value) {
completionDate.value = newDate;
completionDate.value.setHours(18, 0, 0, 0);
}
}
};
const handleAssign = () => { const handleAssign = () => {
if (!selectedEmployees.value.length) { if (!selectedEmployees.value.length) {