Merge branch 'dev-denzel' into Alex

This commit is contained in:
Alex committed 2025-01-14 10:25:31 +03:00
commit 446a6590b0
2 files changed
+133 -124

No files matched your search

+109 -112
View File
@@ -1,78 +1,80 @@
<template>
<template v-if="!isVoteSubmitted">
<!-- Заголовок голосовалки -->
<v-row class="pt-0">
<v-col cols="12">
<v-card flat>
<v-card-title>{{ title }}</v-card-title>
<v-card-subtitle>{{ description }}</v-card-subtitle>
</v-card>
</v-col>
</v-row>
<!-- Ожидаемая дата окончания голосования -->
<v-row>
<v-col cols="12">
<v-chip :color="isVotingActive ? 'green' : 'red'">
<v-icon>{{ isVotingActive ? 'mdi-check-circle' : 'mdi-clock' }}</v-icon>&nbsp;
{{ isVotingActive ? 'Голосование активно' : `Голосование закончится: ${endDateFormatted}` }}
</v-chip>
</v-col>
</v-row>
<!-- Вопросы голосования -->
<v-row v-for="(question, index) in questions" :key="index">
<v-col cols="12">
<v-card flat>
<v-card-title>{{ question.text }}</v-card-title>
<!-- Вопросы с типом "Ввести вручную" -->
<v-card-text v-if="question.type === 'Ввести вручную'">
<v-row v-for="(answer, id) in question.answers" :key="id">
<v-checkbox
v-model="answers[index]"
:value="answer.text"
color="teal-darken-4 opacity-100"
hide-details
>
<template #label>
<span class="text-black text-subtitle-1 opacity-100">{{ answer.text }}</span>
</template>
</v-checkbox>
</v-row>
</v-card-text>
<!-- Вопросы с типом "Выбрать сотрудника" -->
<v-card-text v-if="question.type === 'Выбрать сотрудника'">
<v-row v-for="employee in question.selectedEmployees" :key="employee.id">
<v-checkbox
v-model="selectedEmployees[index]"
:value="employee.id"
color="teal-darken-4 opacity-100"
hide-details
>
<template #label>
<span class="text-black text-subtitle-1 opacity-100">{{ employee.name }}</span>
</template>
</v-checkbox>
</v-row>
</v-card-text>
</v-card>
</v-col>
</v-row>
<!-- Кнопка для отправки голосования -->
<v-row>
<v-col cols="12">
<v-btn
:disabled="!isVotingActive || !isAllQuestionsAnswered"
color="teal-darken-4"
@click="submitVote"
<v-stepper v-model="activeStep" editable>
<v-card-title>{{ title }}</v-card-title>
<v-card-subtitle>{{ description }}</v-card-subtitle>
<!-- Заголовок -->
<v-stepper-header>
<v-stepper-item
v-for="(question, index) in questions"
:key="index"
:complete="index < activeStep"
:step="index + 1"
>
Отправить голос
</v-btn>
</v-col>
</v-row>
Вопрос {{ index + 1 }}
</v-stepper-item>
</v-stepper-header>
<v-stepper-window>
<v-stepper-window-item v-for="(question, index) in questions" :key="index" :step="index + 1">
<v-card flat>
<v-card-title>{{ question.text }}</v-card-title>
<!-- Вопросы с типом "Ввести вручную" -->
<v-card-text v-if="question.type === 'Ввести вручную'">
<v-row v-for="(answer, id) in question.answers" :key="id">
<v-checkbox
v-model="answers[index]"
:value="answer.text"
color="teal-darken-4"
hide-details
>
<template #label>
<span class="text-black">{{ answer.text }}</span>
</template>
</v-checkbox>
</v-row>
</v-card-text>
<!-- Вопросы с типом "Выбрать сотрудника" -->
<v-card-text v-if="question.type === 'Выбрать сотрудника'">
<v-row v-for="employee in question.selectedEmployees" :key="employee.id">
<v-checkbox
v-model="selectedEmployees[index]"
:value="employee.id"
color="teal-darken-4"
hide-details
>
<template #label>
<span class="text-black">{{ employee.name }}</span>
</template>
</v-checkbox>
</v-row>
</v-card-text>
<v-card-actions>
<v-btn v-if="index > 0" @click="prevStep" outlined>Назад</v-btn>
<v-btn
v-if="index < questions.length - 1"
:disabled="!isCurrentQuestionAnswered"
@click="nextStep"
color="teal-darken-4"
>
Далее
</v-btn>
<v-btn
v-else
:disabled="!isCurrentQuestionAnswered"
color="teal-darken-4"
@click="submitVote"
>
Отправить
</v-btn>
</v-card-actions>
</v-card>
</v-stepper-window-item>
</v-stepper-window>
</v-stepper>
</template>
<!-- Спасибо за голос -->
@@ -85,9 +87,8 @@
</v-row>
</template>
</template>
<script>
import {computed, ref} from "vue";
import { computed, ref } from "vue";
export default {
props: {
@@ -97,67 +98,63 @@ export default {
startDate: String,
title: String,
},
setup(props, {emit}) {
// Ответы на вопросы
setup(props, { emit }) {
const activeStep = ref(0);
const answers = ref([]);
const selectedEmployees = ref(props.questions.map(() => []));
// Форматированная дата окончания голосования
const endDateFormatted = computed(() =>
new Date(props.endDate).toLocaleString()
);
// Проверка активности голосования
const isVotingActive = computed(() => {
const currentDate = new Date();
const endDate = new Date(props.endDate);
return currentDate < endDate;
});
// Проверка, все ли вопросы были отвечены
const isAllQuestionsAnswered = computed(() => {
return props.questions.every((question, index) => {
if (question.type === "Ввести вручную") {
return !!answers.value[index];
}
if (question.type === "Выбрать сотрудника") {
return selectedEmployees.value[index].length > 0;
}
return false;
});
});
// Состояние для определения отправки голоса
const isVoteSubmitted = ref(false);
// Отправка голосования
const isCurrentQuestionAnswered = computed(() => {
const currentQuestion = props.questions[activeStep.value];
if (currentQuestion.type === "Ввести вручную") {
return !!answers.value[activeStep.value];
}
if (currentQuestion.type === "Выбрать сотрудника") {
return selectedEmployees.value[activeStep.value].length > 0;
}
return false;
});
const nextStep = () => {
if (activeStep.value < props.questions.length - 1) {
activeStep.value++;
}
};
const prevStep = () => {
if (activeStep.value > 0) {
activeStep.value--;
}
};
const submitVote = () => {
const voteData = props.questions.map((question, index) => ({
question: question.text,
type: question.type,
answer:
question.type === "Ввести вручную"
? answers.value[index]
: selectedEmployees.value[index],
question.type === "Ввести вручную"
? answers.value[index]
: selectedEmployees.value[index],
}));
console.log("Отправляем данные голосования:", voteData);
// После успешной отправки
isVoteSubmitted.value = true;
emit("submit", voteData);
};
return {
activeStep,
answers,
selectedEmployees,
endDateFormatted,
isVotingActive,
isVoteSubmitted,
isAllQuestionsAnswered,
isCurrentQuestionAnswered,
nextStep,
prevStep,
submitVote,
isVoteSubmitted
};
},
};
</script>
<style>
+24 -12
View File
@@ -5,11 +5,11 @@ export const votingData = {
{
answers: [
{
text: "аыфавы",
text: "Да",
image: null
},
{
text: "оаок5е",
text: "Нет",
image: null
}
],
@@ -19,7 +19,7 @@ export const votingData = {
},
selectedEmployeeImages: {},
selectedEmployees: [],
text: "Опрос1",
text: "Ваши родители знают что Вы гей?",
type: "Ввести вручную"
},
{
@@ -30,16 +30,28 @@ export const votingData = {
},
selectedEmployeeImages: {},
selectedEmployees: [
{
id: 1,
name: "Сотрудник 1"
},
{
id: 2,
name: "Сотрудник 2"
}
{ id: 1, name: "Иванов Иван" },
{ id: 2, name: "Петров Пётр" },
{ id: 3, name: "Сидоров Сергей" },
{ id: 4, name: "Алексеева Алена" },
{ id: 5, name: "Михайлов Михаил" },
{ id: 6, name: "Кузнецов Константин" },
{ id: 7, name: "Смирнова Светлана" },
{ id: 8, name: "Попов Павел" },
{ id: 9, name: "Егорова Екатерина" },
{ id: 10, name: "Фёдоров Фёдор" },
{ id: 11, name: "Васильев Василий" },
{ id: 12, name: "Ковалёва Ксения" },
{ id: 13, name: "Григорьев Григорий" },
{ id: 14, name: "Леонова Лилия" },
{ id: 15, name: "Орлов Олег" },
{ id: 16, name: "Белова Белла" },
{ id: 17, name: "Захаров Захар" },
{ id: 18, name: "Чернова Надежда" },
{ id: 19, name: "Максимов Максим" },
{ id: 20, name: "Тимофеева Тамара" }
],
text: "Опрос2",
text: "Самый подозрительный сотрудник",
type: "Выбрать сотрудника"
}
],