326 lines
12 KiB
Vue
326 lines
12 KiB
Vue
<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>
|
|
<v-stepper-item :complete="step > 1" step="2">Создание опроса</v-stepper-item>
|
|
<v-divider></v-divider>
|
|
<v-stepper-item :complete="step > 2" step="3">Настройка ответов</v-stepper-item>
|
|
<v-divider></v-divider>
|
|
<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()"
|
|
color="teal-darken-4"
|
|
label="Дата начала"
|
|
persistentPlaceholder
|
|
readonly
|
|
>
|
|
<v-menu activator="parent">
|
|
<v-date-picker
|
|
v-model="form.startDate"
|
|
color="teal-darken-4"
|
|
hideHeader
|
|
hideWeekdays
|
|
>
|
|
</v-date-picker>
|
|
</v-menu>
|
|
<v-btn flat icon style="background-color: transparent">
|
|
<v-icon>mdi-calendar</v-icon>
|
|
</v-btn>
|
|
</v-text-field>
|
|
|
|
<v-text-field
|
|
:placeholder="form.endDate.toLocaleDateString()"
|
|
:value="form.endDate.toLocaleDateString()"
|
|
color="teal-darken-4"
|
|
label="Дата окончания"
|
|
persistentPlaceholder
|
|
readonly
|
|
>
|
|
<v-menu activator="parent">
|
|
<v-date-picker
|
|
v-model="form.endDate"
|
|
color="teal-darken-4"
|
|
hideHeader
|
|
hideWeekdays
|
|
>
|
|
</v-date-picker>
|
|
</v-menu>
|
|
<v-btn flat icon style="background-color: transparent">
|
|
<v-icon>mdi-calendar</v-icon>
|
|
</v-btn>
|
|
</v-text-field>
|
|
</v-card-text>
|
|
<v-card-actions>
|
|
<v-btn color="teal-darken-4" @click="step = 1" size="medium">Далее</v-btn>
|
|
</v-card-actions>
|
|
</v-card>
|
|
</v-stepper-window-item>
|
|
|
|
<!-- Создание опроса -->
|
|
<v-stepper-window-item step="2">
|
|
<v-card flat>
|
|
<v-card-title>Создание опроса</v-card-title>
|
|
<v-card-text>
|
|
<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="teal-darken-4" @click="addQuestion">Добавить вопрос</v-btn>
|
|
</v-card-text>
|
|
<v-card-actions>
|
|
<v-btn color="teal-darken-4" size="medium" @click="step -= 1">Назад</v-btn>
|
|
<v-btn color="teal-darken-4" size="medium" @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-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="currentQuestion">
|
|
<div v-if="currentQuestion.type === 'Ввести вручную'">
|
|
<div
|
|
v-for="(answer, index) in currentQuestion.answers"
|
|
:key="index"
|
|
class="d-flex align-start mb-4"
|
|
>
|
|
<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>
|
|
</div>
|
|
<div v-else>
|
|
<p>Выберите вопрос, чтобы добавить ответы.</p>
|
|
</div>
|
|
</v-card-text>
|
|
<v-card-actions>
|
|
<v-btn color="teal-darken-4" size="medium" @click="step -= 1">Назад</v-btn>
|
|
<v-btn color="teal-darken-4" size="medium" @click="step = 3">Далее</v-btn>
|
|
</v-card-actions>
|
|
</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.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="teal-darken-4" size="medium" @click="step -= 1">Назад</v-btn>
|
|
<v-btn color="teal-darken-4" size="medium" @click="saveVoting">Сохранить</v-btn>
|
|
</v-card-actions>
|
|
</v-card>
|
|
</v-stepper-window-item>
|
|
|
|
</v-stepper-window>
|
|
</v-stepper>
|
|
</v-container>
|
|
</template>
|
|
|
|
<script>
|
|
import {computed, ref} from "vue";
|
|
|
|
export default {
|
|
setup() {
|
|
const step = ref(0);
|
|
const form = ref({
|
|
title: "",
|
|
description: "",
|
|
startDate: new Date(),
|
|
endDate: new Date(new Date().setDate(new Date().getDate() + 14)),
|
|
questions: [],
|
|
});
|
|
|
|
const currentQuestionIndex = ref(0);
|
|
const questionTypes = ["Ввести вручную", "Выбрать сотрудника"];
|
|
|
|
const groupedEmployees = [
|
|
{id: 1, fio: "Иван Иванов", department: "Отдел A"},
|
|
{id: 2, fio: "Петр Петров", department: "Отдел B"},
|
|
];
|
|
|
|
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 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 = () => {
|
|
console.log("Голосование сохранено:", form.value);
|
|
};
|
|
|
|
return {
|
|
step,
|
|
form,
|
|
questionTypes,
|
|
groupedEmployees,
|
|
currentQuestionIndex,
|
|
currentQuestion,
|
|
addQuestion,
|
|
removeQuestion,
|
|
addAnswer,
|
|
removeAnswer,
|
|
findEmployeeById,
|
|
removeEmployee,
|
|
saveVoting,
|
|
};
|
|
},
|
|
};
|
|
</script>
|