This commit is contained in:
Denzel committed 2025-01-14 10:21:39 +03:00
1 parent d9ff1107e4
commit bf4bd71816
2 files changed
+133 -124

No files matched your search

+109 -112
View File
@@ -1,78 +1,80 @@
<template> <template>
<template v-if="!isVoteSubmitted"> <template v-if="!isVoteSubmitted">
<!-- Заголовок голосовалки --> <v-stepper v-model="activeStep" editable>
<v-row class="pt-0"> <v-card-title>{{ title }}</v-card-title>
<v-col cols="12"> <v-card-subtitle>{{ description }}</v-card-subtitle>
<v-card flat> <!-- Заголовок -->
<v-card-title>{{ title }}</v-card-title> <v-stepper-header>
<v-card-subtitle>{{ description }}</v-card-subtitle> <v-stepper-item
</v-card> v-for="(question, index) in questions"
</v-col> :key="index"
</v-row> :complete="index < activeStep"
:step="index + 1"
<!-- Ожидаемая дата окончания голосования -->
<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"
> >
Отправить голос Вопрос {{ index + 1 }}
</v-btn> </v-stepper-item>
</v-col> </v-stepper-header>
</v-row>
<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> </template>
<!-- Спасибо за голос --> <!-- Спасибо за голос -->
@@ -85,9 +87,8 @@
</v-row> </v-row>
</template> </template>
</template> </template>
<script> <script>
import {computed, ref} from "vue"; import { computed, ref } from "vue";
export default { export default {
props: { props: {
@@ -97,67 +98,63 @@ export default {
startDate: String, startDate: String,
title: String, title: String,
}, },
setup(props, {emit}) { setup(props, { emit }) {
// Ответы на вопросы const activeStep = ref(0);
const answers = ref([]); const answers = ref([]);
const selectedEmployees = ref(props.questions.map(() => [])); 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 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 submitVote = () => {
const voteData = props.questions.map((question, index) => ({ const voteData = props.questions.map((question, index) => ({
question: question.text, question: question.text,
type: question.type, type: question.type,
answer: answer:
question.type === "Ввести вручную" question.type === "Ввести вручную"
? answers.value[index] ? answers.value[index]
: selectedEmployees.value[index], : selectedEmployees.value[index],
})); }));
console.log("Отправляем данные голосования:", voteData); console.log("Отправляем данные голосования:", voteData);
// После успешной отправки
isVoteSubmitted.value = true; isVoteSubmitted.value = true;
emit("submit", voteData); emit("submit", voteData);
}; };
return { return {
activeStep,
answers, answers,
selectedEmployees, selectedEmployees,
endDateFormatted, isCurrentQuestionAnswered,
isVotingActive, nextStep,
isVoteSubmitted, prevStep,
isAllQuestionsAnswered,
submitVote, submitVote,
isVoteSubmitted
}; };
}, },
}; };
</script> </script>
<style> <style>
+24 -12
View File
@@ -5,11 +5,11 @@ export const votingData = {
{ {
answers: [ answers: [
{ {
text: "аыфавы", text: "Да",
image: null image: null
}, },
{ {
text: "оаок5е", text: "Нет",
image: null image: null
} }
], ],
@@ -19,7 +19,7 @@ export const votingData = {
}, },
selectedEmployeeImages: {}, selectedEmployeeImages: {},
selectedEmployees: [], selectedEmployees: [],
text: "Опрос1", text: "Ваши родители знают что Вы гей?",
type: "Ввести вручную" type: "Ввести вручную"
}, },
{ {
@@ -30,16 +30,28 @@ export const votingData = {
}, },
selectedEmployeeImages: {}, selectedEmployeeImages: {},
selectedEmployees: [ selectedEmployees: [
{ { id: 1, name: "Иванов Иван" },
id: 1, { id: 2, name: "Петров Пётр" },
name: "Сотрудник 1" { id: 3, name: "Сидоров Сергей" },
}, { id: 4, name: "Алексеева Алена" },
{ { id: 5, name: "Михайлов Михаил" },
id: 2, { id: 6, name: "Кузнецов Константин" },
name: "Сотрудник 2" { 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: "Выбрать сотрудника" type: "Выбрать сотрудника"
} }
], ],