P-97 возможность создания нескольких вопросов в одной голосовалке и привязка ответов к каждому вопросу
This commit is contained in:
1 parent
4887ae9cb5
commit
4b340fe02b
2 files changed
+189
-102
No files matched your search
@@ -1,7 +1,6 @@
|
||||
<template>
|
||||
<v-container>
|
||||
<v-stepper v-model="step" editable>
|
||||
<!-- Заголовки шагов -->
|
||||
<v-stepper-header>
|
||||
<v-stepper-item :complete="step > 0" step="1">Основная информация</v-stepper-item>
|
||||
<v-divider></v-divider>
|
||||
@@ -12,15 +11,14 @@
|
||||
<v-stepper-item step="4">Подтверждение</v-stepper-item>
|
||||
</v-stepper-header>
|
||||
|
||||
<!-- Контент шагов -->
|
||||
<v-stepper-window>
|
||||
<!-- Основная информация -->
|
||||
<v-stepper-window-item step="1">
|
||||
<v-card flat>
|
||||
<v-card-title>Основная информация</v-card-title>
|
||||
<v-card-text>
|
||||
<v-text-field v-model="form.title" label="Название голосования" outlined></v-text-field>
|
||||
<v-textarea v-model="form.description" label="Описание" outlined></v-textarea>
|
||||
|
||||
<v-text-field
|
||||
:placeholder="form.startDate.toLocaleDateString()"
|
||||
:value="form.startDate.toLocaleDateString()"
|
||||
@@ -71,81 +69,119 @@
|
||||
</v-card>
|
||||
</v-stepper-window-item>
|
||||
|
||||
<!-- Создание опроса -->
|
||||
<v-stepper-window-item step="2">
|
||||
<v-card flat>
|
||||
<v-card-title>Создание опроса</v-card-title>
|
||||
<v-card-text>
|
||||
<v-text-field v-model="form.question" label="Текст опроса" outlined></v-text-field>
|
||||
<v-select v-model="form.type" :items="questionTypes" label="Тип ответа" outlined></v-select>
|
||||
<v-file-input v-model="form.image" label="Картинка для вопроса" outlined></v-file-input>
|
||||
<div v-for="(question, index) in form.questions" :key="index" class="mb-4">
|
||||
<v-text-field
|
||||
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-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-card-actions>
|
||||
</v-card>
|
||||
</v-stepper-window-item>
|
||||
|
||||
<!-- Настройка ответов -->
|
||||
<v-stepper-window-item step="3">
|
||||
<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>
|
||||
<div v-if="form.type === 'Ввести вручную'">
|
||||
<div v-for="(answer, index) in form.answers" :key="index" class="d-flex align-start">
|
||||
<v-text-field
|
||||
v-model="answer.text"
|
||||
:label="'Ответ ' + (index + 1)"
|
||||
outlined
|
||||
></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)"
|
||||
<div v-if="currentQuestion">
|
||||
<div v-if="currentQuestion.type === 'Ввести вручную'">
|
||||
<div
|
||||
v-for="(answer, index) in currentQuestion.answers"
|
||||
:key="index"
|
||||
class="d-flex align-start mb-4"
|
||||
>
|
||||
<v-icon>mdi-delete</v-icon>
|
||||
</v-btn>
|
||||
<v-text-field
|
||||
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>
|
||||
<v-btn color="primary" @click="addManualAnswer">Добавить ответ</v-btn>
|
||||
</div>
|
||||
|
||||
<div v-else>
|
||||
<v-autocomplete
|
||||
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>
|
||||
<p>Выберите вопрос, чтобы добавить ответы.</p>
|
||||
</div>
|
||||
</v-card-text>
|
||||
<v-card-actions>
|
||||
@@ -155,33 +191,55 @@
|
||||
</v-card>
|
||||
</v-stepper-window-item>
|
||||
|
||||
<!-- Подтверждение -->
|
||||
<v-stepper-window-item step="4">
|
||||
<v-card flat>
|
||||
<v-card-title>Подтверждение</v-card-title>
|
||||
<v-card-text>
|
||||
<p><strong>Название:</strong> {{ form.title }}</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.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-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-card-actions>
|
||||
</v-card>
|
||||
</v-stepper-window-item>
|
||||
|
||||
</v-stepper-window>
|
||||
</v-stepper>
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {ref} from "vue";
|
||||
import {computed, ref} from "vue";
|
||||
|
||||
export default {
|
||||
setup() {
|
||||
@@ -190,38 +248,57 @@ export default {
|
||||
title: "",
|
||||
description: "",
|
||||
startDate: new Date(),
|
||||
endDate: new Date(new Date().setDate(new Date().getDate() + 14)), // добавляем 14 дней,
|
||||
question: '',
|
||||
answers: [],
|
||||
type: '',
|
||||
image: null,
|
||||
selectedEmployees: [],
|
||||
endDate: new Date(new Date().setDate(new Date().getDate() + 14)),
|
||||
questions: [],
|
||||
});
|
||||
|
||||
const employeeImages = ref({});
|
||||
|
||||
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 currentQuestionIndex = ref(0);
|
||||
const questionTypes = ["Ввести вручную", "Выбрать сотрудника"];
|
||||
|
||||
const groupedEmployees = [
|
||||
{id: 11, fio: "Иван Иванов", department: "Отдел A"},
|
||||
{id: 22, fio: "Петр Петров", department: "Отдел B"},
|
||||
{id: 1, fio: "Иван Иванов", department: "Отдел A"},
|
||||
{id: 2, fio: "Петр Петров", department: "Отдел B"},
|
||||
];
|
||||
|
||||
const removeManualAnswer = (index) => {
|
||||
form.value.answers.splice(index, 1);
|
||||
const currentQuestion = computed(() =>
|
||||
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 = () => {
|
||||
form.value.answers.push({text: "", image: null});
|
||||
const addQuestion = () => {
|
||||
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 = () => {
|
||||
@@ -233,16 +310,16 @@ export default {
|
||||
form,
|
||||
questionTypes,
|
||||
groupedEmployees,
|
||||
addManualAnswer,
|
||||
saveVoting,
|
||||
removeManualAnswer,
|
||||
removeEmployee,
|
||||
currentQuestionIndex,
|
||||
currentQuestion,
|
||||
addQuestion,
|
||||
removeQuestion,
|
||||
addAnswer,
|
||||
removeAnswer,
|
||||
findEmployeeById,
|
||||
employeeImages
|
||||
removeEmployee,
|
||||
saveVoting,
|
||||
};
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
</style>
|
||||
@@ -38,7 +38,10 @@
|
||||
>
|
||||
Проголосовать
|
||||
</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>
|
||||
</v-col>
|
||||
@@ -62,7 +65,10 @@
|
||||
</v-card-subtitle>
|
||||
<v-card-actions>
|
||||
<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-card-actions>
|
||||
</v-card>
|
||||
@@ -184,6 +190,10 @@ export default {
|
||||
selectedVoting.value = null;
|
||||
};
|
||||
|
||||
const deleteVoting = (id) => {
|
||||
votes.value = votes.value.filter((v) => v.id !== id);
|
||||
};
|
||||
|
||||
return {
|
||||
currentTab,
|
||||
votes,
|
||||
@@ -199,6 +209,7 @@ export default {
|
||||
submitVote,
|
||||
openResultsModal,
|
||||
closeResultsModal,
|
||||
deleteVoting,
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -207,6 +218,5 @@ export default {
|
||||
<style>
|
||||
.voted-card {
|
||||
opacity: 0.6;
|
||||
pointer-events: none;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user