177 lines
5.3 KiB
Vue
177 lines
5.3 KiB
Vue
<template>
|
|
<v-card class="fill-height d-flex flex-column" flat>
|
|
<v-card-title>{{ isTest ? 'Основная информация о тесте' : 'Основная информация' }}</v-card-title>
|
|
<v-card-text class="d-flex flex-column overflow-auto">
|
|
<v-text-field
|
|
v-model="localForm.title"
|
|
:rules="[rules.required]"
|
|
class="flex-grow-0 flex-shrink-1"
|
|
label="Название"
|
|
variant="underlined"
|
|
></v-text-field>
|
|
<div class="flex-grow-1 flex-shrink-0">
|
|
<v-textarea
|
|
v-model="localForm.description"
|
|
:rules="[rules.required]"
|
|
label="Описание"
|
|
variant="outlined"
|
|
></v-textarea>
|
|
</div>
|
|
<div class="text-overline text-grey">Дата и время:</div>
|
|
<div class="d-flex justify-space-around">
|
|
<div class="d-flex ga-3 align-center">
|
|
<h6 class="text-subtitle-1 pt-2">начало:</h6>
|
|
<date-select :datedefault="form.startDate" @returndate="returnstart" />
|
|
<v-select
|
|
v-model="selectedTimeStart"
|
|
:items="timeOptions"
|
|
density="compact"
|
|
hide-details
|
|
variant="plain"
|
|
>
|
|
<template v-slot:prepend-inner>
|
|
<v-icon color="red" icon="mdi-timer" size="xsmall"></v-icon>
|
|
</template>
|
|
</v-select>
|
|
</div>
|
|
<div class="d-flex ga-3 align-center">
|
|
<h6 class="text-subtitle-1 pt-2">окончание:</h6>
|
|
<date-select :datedefault="form.endDate" @returndate="returnend" />
|
|
<v-select
|
|
v-model="selectedTimeEnd"
|
|
:items="timeOptions"
|
|
density="compact"
|
|
hide-details
|
|
outlined
|
|
variant="plain"
|
|
>
|
|
<template v-slot:prepend-inner>
|
|
<v-icon color="red" icon="mdi-timer" size="xsmall"></v-icon>
|
|
</template>
|
|
</v-select>
|
|
</div>
|
|
</div>
|
|
</v-card-text>
|
|
<slot></slot>
|
|
</v-card>
|
|
</template>
|
|
|
|
<script>
|
|
import DateSelect from '@/components/UI/date-select.vue';
|
|
import { ref, watch, computed } from 'vue';
|
|
import { checkremote } from '@/utils/universal_functions.js';
|
|
import { spravURL } from '@/utils/axios-api.js';
|
|
import { useRoute } from 'vue-router';
|
|
import SearcEmployess from '@/components/UI/SearcEmployess.vue';
|
|
|
|
export default {
|
|
methods: {
|
|
spravURL() {
|
|
return spravURL
|
|
}, checkremote },
|
|
components: { SearcEmployess, DateSelect },
|
|
props: {
|
|
form: Object,
|
|
rules: {
|
|
type: Object,
|
|
default: () => ({
|
|
required: (value) => !!value || 'Это поле обязательно для заполнения',
|
|
}),
|
|
},
|
|
isTest: {
|
|
type: Boolean,
|
|
default: false
|
|
}
|
|
},
|
|
emits: ['update:form'],
|
|
setup(props, { emit }) {
|
|
const route = useRoute();
|
|
const isTestRoute = computed(() => {
|
|
return route.path && String(route.path).includes('test');
|
|
});
|
|
// Если form не передан, создаём объект с дефолтными значениями
|
|
const localForm = ref(
|
|
props.form
|
|
? { ...props.form }
|
|
: {
|
|
title: '',
|
|
description: '',
|
|
createnews: false,
|
|
appoint: false,
|
|
startDate: new Date(),
|
|
endDate: new Date(),
|
|
}
|
|
);
|
|
|
|
// Отправляем изменения в родителя
|
|
watch(
|
|
localForm,
|
|
(newForm) => {
|
|
emit('update:form', newForm);
|
|
},
|
|
{ deep: true }
|
|
);
|
|
|
|
const returnstart = (date) => {
|
|
localForm.value.startDate =
|
|
date instanceof Date ? date : new Date(date);
|
|
};
|
|
|
|
const returnend = (date) => {
|
|
localForm.value.endDate =
|
|
date instanceof Date ? date : new Date(date);
|
|
};
|
|
|
|
const formatTime = (date) =>
|
|
date instanceof Date ? date.toTimeString().slice(0, 5) : '00:00';
|
|
|
|
const selectedTimeStart = computed({
|
|
get: () => formatTime(localForm.value.startDate),
|
|
set: (newTime) => {
|
|
const [hours, minutes] = newTime.split(':').map(Number);
|
|
const oldDate =
|
|
localForm.value.startDate instanceof Date
|
|
? localForm.value.startDate
|
|
: new Date();
|
|
const newDate = new Date(oldDate); // создаём новый объект с копией даты
|
|
newDate.setHours(hours, minutes, 0, 0);
|
|
localForm.value.startDate = newDate;
|
|
},
|
|
});
|
|
|
|
const selectedTimeEnd = computed({
|
|
get: () => formatTime(localForm.value.endDate),
|
|
set: (newTime) => {
|
|
const [hours, minutes] = newTime.split(':').map(Number);
|
|
const oldDate =
|
|
localForm.value.endDate instanceof Date ? localForm.value.endDate : new Date();
|
|
const newDate = new Date(oldDate);
|
|
newDate.setHours(hours, minutes, 0, 0);
|
|
localForm.value.endDate = newDate;
|
|
},
|
|
});
|
|
|
|
const timeOptions = Array.from({ length: 48 }, (_, i) => {
|
|
const hours = String(Math.floor(i / 2)).padStart(2, '0');
|
|
const minutes = i % 2 === 0 ? '00' : '30';
|
|
return `${hours}:${minutes}`;
|
|
});
|
|
|
|
return {
|
|
localForm,
|
|
returnstart,
|
|
returnend,
|
|
selectedTimeStart,
|
|
selectedTimeEnd,
|
|
timeOptions,
|
|
isTestRoute,
|
|
isTest: props.isTest
|
|
};
|
|
},
|
|
};
|
|
</script>
|
|
|
|
<style scoped>
|
|
|
|
</style>
|