P-97 возможность создания нескольких вопросов в одной голосовалке и привязка ответов к каждому вопросу

This commit is contained in:
Denzel committed 2025-01-10 13:10:13 +03:00
1 parent 4887ae9cb5
commit 4b340fe02b
2 files changed
+189 -102

No files matched your search

+176 -99
View File
@@ -1,7 +1,6 @@
<template> <template>
<v-container> <v-container>
<v-stepper v-model="step" editable> <v-stepper v-model="step" editable>
<!-- Заголовки шагов -->
<v-stepper-header> <v-stepper-header>
<v-stepper-item :complete="step > 0" step="1">Основная информация</v-stepper-item> <v-stepper-item :complete="step > 0" step="1">Основная информация</v-stepper-item>
<v-divider></v-divider> <v-divider></v-divider>
@@ -12,15 +11,14 @@
<v-stepper-item step="4">Подтверждение</v-stepper-item> <v-stepper-item step="4">Подтверждение</v-stepper-item>
</v-stepper-header> </v-stepper-header>
<!-- Контент шагов -->
<v-stepper-window> <v-stepper-window>
<!-- Основная информация -->
<v-stepper-window-item step="1"> <v-stepper-window-item step="1">
<v-card flat> <v-card flat>
<v-card-title>Основная информация</v-card-title> <v-card-title>Основная информация</v-card-title>
<v-card-text> <v-card-text>
<v-text-field v-model="form.title" label="Название голосования" outlined></v-text-field> <v-text-field v-model="form.title" label="Название голосования" outlined></v-text-field>
<v-textarea v-model="form.description" label="Описание" outlined></v-textarea> <v-textarea v-model="form.description" label="Описание" outlined></v-textarea>
<v-text-field <v-text-field
:placeholder="form.startDate.toLocaleDateString()" :placeholder="form.startDate.toLocaleDateString()"
:value="form.startDate.toLocaleDateString()" :value="form.startDate.toLocaleDateString()"
@@ -71,81 +69,119 @@
</v-card> </v-card>
</v-stepper-window-item> </v-stepper-window-item>
<!-- Создание опроса -->
<v-stepper-window-item step="2"> <v-stepper-window-item step="2">
<v-card flat> <v-card flat>
<v-card-title>Создание опроса</v-card-title> <v-card-title>Создание опроса</v-card-title>
<v-card-text> <v-card-text>
<v-text-field v-model="form.question" label="Текст опроса" outlined></v-text-field> <div v-for="(question, index) in form.questions" :key="index" class="mb-4">
<v-select v-model="form.type" :items="questionTypes" label="Тип ответа" outlined></v-select> <v-text-field
<v-file-input v-model="form.image" label="Картинка для вопроса" outlined></v-file-input> v-model="question.text"
:label="'Вопрос ' + (index + 1)"
outlined
></v-text-field>
<v-file-input
v-model="question.image"
accept="image/*"
label="Картинка для вопроса"
outlined
></v-file-input>
<v-select
v-model="question.type"
:items="questionTypes"
label="Тип ответа"
outlined
></v-select>
<v-btn color="error" icon @click="removeQuestion(index)">
<v-icon>mdi-delete</v-icon>
</v-btn>
</div>
<v-btn color="primary" @click="addQuestion">Добавить вопрос</v-btn>
</v-card-text> </v-card-text>
<v-card-actions> <v-card-actions>
<v-btn color="primary" @click="step-=1">Назад</v-btn> <v-btn color="primary" @click="step -= 1">Назад</v-btn>
<v-btn color="primary" @click="step = 2">Далее</v-btn> <v-btn color="primary" @click="step = 2">Далее</v-btn>
</v-card-actions> </v-card-actions>
</v-card> </v-card>
</v-stepper-window-item> </v-stepper-window-item>
<!-- Настройка ответов -->
<v-stepper-window-item step="3"> <v-stepper-window-item step="3">
<v-card flat> <v-card flat>
<v-card-title>Настройка ответов</v-card-title> <v-card-title>
Настройка ответов
<v-select
v-model="currentQuestionIndex"
:items="form.questions.map((q, i) => ({ text: `Вопрос ${i + 1}: ${q.text || 'Без названия'}`, value: i }))"
class="ml-4"
dense
item-title="text"
item-value="value"
label="Выберите вопрос"
outlined
></v-select>
</v-card-title>
<v-card-text> <v-card-text>
<div v-if="form.type === 'Ввести вручную'"> <div v-if="currentQuestion">
<div v-for="(answer, index) in form.answers" :key="index" class="d-flex align-start"> <div v-if="currentQuestion.type === 'Ввести вручную'">
<v-text-field <div
v-model="answer.text" v-for="(answer, index) in currentQuestion.answers"
:label="'Ответ ' + (index + 1)" :key="index"
outlined class="d-flex align-start mb-4"
></v-text-field>
<v-file-input
v-model="answer.image"
accept="image/*"
dense
hide-details
label="Картинка"
outlined
></v-file-input>
<v-btn
color="red-lighten-2"
icon
@click="removeManualAnswer(index)"
> >
<v-icon>mdi-delete</v-icon> <v-text-field
</v-btn> v-model="answer.text"
:label="'Ответ ' + (index + 1)"
class="mr-4"
outlined
></v-text-field>
<v-file-input
v-model="answer.image"
accept="image/*"
dense
hide-details
label="Картинка"
outlined
></v-file-input>
<v-btn color="error" icon @click="removeAnswer(index)">
<v-icon>mdi-delete</v-icon>
</v-btn>
</div>
<v-btn color="primary" @click="addAnswer">Добавить ответ</v-btn>
</div>
<div v-else>
<v-autocomplete
v-model="currentQuestion.selectedEmployees"
:items="groupedEmployees"
item-title="fio"
item-value="id"
label="Выберите сотрудников"
multiple
outlined
></v-autocomplete>
<div
v-for="(person, index) in currentQuestion.selectedEmployees"
:key="person.id"
class="d-flex align-center mb-4"
>
<v-chip>{{ findEmployeeById(person).fio }}</v-chip>
<v-file-input
v-model="currentQuestion.selectedEmployeeImages[person]"
accept="image/*"
class="ml-4"
dense
hide-details
label="Картинка"
outlined
></v-file-input>
<v-btn color="error" icon @click="removeEmployee(index)">
<v-icon>mdi-delete</v-icon>
</v-btn>
</div>
</div> </div>
<v-btn color="primary" @click="addManualAnswer">Добавить ответ</v-btn>
</div> </div>
<div v-else> <div v-else>
<v-autocomplete <p>Выберите вопрос, чтобы добавить ответы.</p>
v-model="form.selectedEmployees"
:items="groupedEmployees"
item-title="fio"
item-value="id"
label="Выберите сотрудников"
multiple
outlined
></v-autocomplete>
<div v-for="(person, index) in form.selectedEmployees" :key="person.id"
class="d-flex align-center"
style="gap: 16px; margin-bottom: 8px;">
<v-chip>{{ findEmployeeById(person).fio }}</v-chip>
<v-file-input
v-model="employeeImages[person]"
accept="image/*"
dense
hide-details
label="Картинка"
outlined
></v-file-input>
<v-btn
color="red-lighten-2"
icon
@click="removeEmployee(index)"
>
<v-icon>mdi-delete</v-icon>
</v-btn>
</div>
</div> </div>
</v-card-text> </v-card-text>
<v-card-actions> <v-card-actions>
@@ -155,33 +191,55 @@
</v-card> </v-card>
</v-stepper-window-item> </v-stepper-window-item>
<!-- Подтверждение -->
<v-stepper-window-item step="4"> <v-stepper-window-item step="4">
<v-card flat> <v-card flat>
<v-card-title>Подтверждение</v-card-title> <v-card-title>Подтверждение</v-card-title>
<v-card-text> <v-card-text>
<p><strong>Название:</strong> {{ form.title }}</p> <p><strong>Название:</strong> {{ form.title }}</p>
<p><strong>Описание:</strong> {{ form.description }}</p> <p><strong>Описание:</strong> {{ form.description }}</p>
<p><strong>Вопрос:</strong> {{ form.question }}</p>
<p><strong>Тип вопроса:</strong> {{ form.type }}</p>
<p><strong>Варианты ответа:</strong>
{{ form.type === 'Ввести вручную' ? form.answers : form.selectedEmployees }}</p>
<p><strong>Картинка:</strong> {{ form.image ?? 'отсутсвует' }}</p>
<p><strong>Дата начала:</strong> {{ form.startDate.toLocaleDateString() }}</p> <p><strong>Дата начала:</strong> {{ form.startDate.toLocaleDateString() }}</p>
<p><strong>Дата окончания:</strong> {{ form.endDate.toLocaleDateString() }}</p> <p><strong>Дата окончания:</strong> {{ form.endDate.toLocaleDateString() }}</p>
<p><strong>Вопросы:</strong></p>
<ul>
<li v-for="(question, index) in form.questions" :key="index" class="mb-4">
<p><strong>Вопрос {{ index + 1 }}:</strong> {{ question.text }} ({{ question.type }})</p>
<div v-if="question.type === 'Ввести вручную' && question.answers.length">
<p><strong>Варианты ответов:</strong></p>
<ul>
<li v-for="(answer, answerIndex) in question.answers" :key="answerIndex">
{{ answer.text }}
</li>
</ul>
</div>
<div v-if="question.type === 'Выбрать сотрудника' && question.selectedEmployees.length">
<p><strong>Выбранные сотрудники:</strong></p>
<ul>
<li
v-for="employeeId in question.selectedEmployees"
:key="employeeId"
>
{{ findEmployeeById(employeeId).fio }}
</li>
</ul>
</div>
</li>
</ul>
</v-card-text> </v-card-text>
<v-card-actions> <v-card-actions>
<v-btn color="primary" @click="step -=1 ">Назад</v-btn> <v-btn color="primary" @click="step -= 1">Назад</v-btn>
<v-btn color="primary" @click="saveVoting">Сохранить</v-btn> <v-btn color="primary" @click="saveVoting">Сохранить</v-btn>
</v-card-actions> </v-card-actions>
</v-card> </v-card>
</v-stepper-window-item> </v-stepper-window-item>
</v-stepper-window> </v-stepper-window>
</v-stepper> </v-stepper>
</v-container> </v-container>
</template> </template>
<script> <script>
import {ref} from "vue"; import {computed, ref} from "vue";
export default { export default {
setup() { setup() {
@@ -190,38 +248,57 @@ export default {
title: "", title: "",
description: "", description: "",
startDate: new Date(), startDate: new Date(),
endDate: new Date(new Date().setDate(new Date().getDate() + 14)), // добавляем 14 дней, endDate: new Date(new Date().setDate(new Date().getDate() + 14)),
question: '', questions: [],
answers: [],
type: '',
image: null,
selectedEmployees: [],
}); });
const employeeImages = ref({}); const currentQuestionIndex = ref(0);
const findEmployeeById = (id) => {
return groupedEmployees.find((employee) => employee.id === id) || {};
};
const removeEmployee = (index) => {
const employeeId = form.value.selectedEmployees[index];
delete employeeImages.value[employeeId];
form.value.selectedEmployees.splice(index, 1);
};
const questionTypes = ["Ввести вручную", "Выбрать сотрудника"]; const questionTypes = ["Ввести вручную", "Выбрать сотрудника"];
const groupedEmployees = [ const groupedEmployees = [
{id: 11, fio: "Иван Иванов", department: "Отдел A"}, {id: 1, fio: "Иван Иванов", department: "Отдел A"},
{id: 22, fio: "Петр Петров", department: "Отдел B"}, {id: 2, fio: "Петр Петров", department: "Отдел B"},
]; ];
const removeManualAnswer = (index) => { const currentQuestion = computed(() =>
form.value.answers.splice(index, 1); form.value.questions[currentQuestionIndex.value] || null
);
const findEmployeeById = (id) =>
groupedEmployees.find((employee) => employee.id === id) || {};
const removeEmployee = (index) => {
currentQuestion.value.selectedEmployees.splice(index, 1);
}; };
const addManualAnswer = () => { const addQuestion = () => {
form.value.answers.push({text: "", image: null}); form.value.questions.push({
text: "",
type: "Ввести вручную",
image: null,
answers: [],
selectedEmployees: [],
selectedEmployeeImages: {},
});
};
const removeQuestion = (index) => {
form.value.questions.splice(index, 1);
if (currentQuestionIndex.value >= form.value.questions.length) {
currentQuestionIndex.value = form.value.questions.length - 1;
}
};
const addAnswer = () => {
if (currentQuestion.value) {
currentQuestion.value.answers.push({text: "", image: null});
}
};
const removeAnswer = (index) => {
if (currentQuestion.value) {
currentQuestion.value.answers.splice(index, 1);
}
}; };
const saveVoting = () => { const saveVoting = () => {
@@ -233,16 +310,16 @@ export default {
form, form,
questionTypes, questionTypes,
groupedEmployees, groupedEmployees,
addManualAnswer, currentQuestionIndex,
saveVoting, currentQuestion,
removeManualAnswer, addQuestion,
removeEmployee, removeQuestion,
addAnswer,
removeAnswer,
findEmployeeById, findEmployeeById,
employeeImages removeEmployee,
saveVoting,
}; };
}, },
}; };
</script> </script>
<style scoped>
</style>
+13 -3
View File
@@ -38,7 +38,10 @@
> >
Проголосовать Проголосовать
</v-btn> </v-btn>
<v-btn v-else disabled>Вы уже проголосовали</v-btn> <v-btn v-else disabled>Уже проголосовали</v-btn>
<v-btn color="error" @click="deleteVoting(voting.id)">
<v-icon>mdi-delete</v-icon>
</v-btn>
</v-card-actions> </v-card-actions>
</v-card> </v-card>
</v-col> </v-col>
@@ -62,7 +65,10 @@
</v-card-subtitle> </v-card-subtitle>
<v-card-actions> <v-card-actions>
<v-btn color="primary" @click="openResultsModal(voting)"> <v-btn color="primary" @click="openResultsModal(voting)">
Смотреть результаты Результаты
</v-btn>
<v-btn color="error" @click="deleteVoting(voting.id)">
<v-icon>mdi-delete</v-icon>
</v-btn> </v-btn>
</v-card-actions> </v-card-actions>
</v-card> </v-card>
@@ -184,6 +190,10 @@ export default {
selectedVoting.value = null; selectedVoting.value = null;
}; };
const deleteVoting = (id) => {
votes.value = votes.value.filter((v) => v.id !== id);
};
return { return {
currentTab, currentTab,
votes, votes,
@@ -199,6 +209,7 @@ export default {
submitVote, submitVote,
openResultsModal, openResultsModal,
closeResultsModal, closeResultsModal,
deleteVoting,
}; };
}, },
}; };
@@ -207,6 +218,5 @@ export default {
<style> <style>
.voted-card { .voted-card {
opacity: 0.6; opacity: 0.6;
pointer-events: none;
} }
</style> </style>