Files
PORTAL_COD2/src/front/src/components/vote/CurrentVote.vue
T
2025-01-15 15:19:44 +03:00

151 lines
4.0 KiB
Vue

<template>
<template v-if="!isVoteSubmitted">
<v-stepper v-model="activeStep">
<v-card-title>{{ data.name }}</v-card-title>
<v-card-subtitle>{{ data.description }}</v-card-subtitle>
{{ data }}
<!-- Шаги голосования -->
<v-stepper-header>
<v-stepper-item
v-for="question in data.questions"
:key="question.numb"
:complete="question.numb < activeStep"
:step="question.numb"
>
Вопрос {{ question.numb }}
</v-stepper-item>
</v-stepper-header>
<v-stepper-window>
<v-stepper-window-item
v-for="(question, index) in data.questions"
:key="question.numb"
:step="question.numb"
>
<v-card flat>
<v-card-title>{{ question.question }}</v-card-title>
<v-card-text>
<!-- Ответы на вопрос -->
{{ result }}--
<v-row v-for="(answer, id) in question.answers" :key="id">
<v-checkbox
v-model="result[question.id]"
:label="answer.answer"
:value="answer.id"
color="teal-darken-4"
hide-details
>
</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 < data.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 v-else>
<v-row align="center" justify="center" style="height: 50vh;">
<v-col class="text-center" cols="12">
<v-icon color="green" size="64">mdi-check-circle</v-icon>
<h2>Спасибо за Ваш голос!</h2>
</v-col>
</v-row>
</template>
</template>
<script>
import { computed, ref } from "vue";
export default {
props: {
data: {
type: Object,
required: true,
default: () => ({}),
},
},
setup(props, { emit }) {
const activeStep = ref(0);
const answers = ref(props.data.questions.map(() => null));
const isVoteSubmitted = ref(false);
const isCurrentQuestionAnswered = computed(() => {
let q = props.data.questions.find(e=>e.numb==activeStep.value+1)
return result.value[q.id].length>0;
});
const getres=()=>{
return props.data.questions.reduce((acc,item)=> {acc[item.id]=[]
return acc
},{})
}
const result=ref(getres())
const nextStep = () => {
if (activeStep.value < props.data.questions.length - 1) {
activeStep.value++;
}
};
const prevStep = () => {
if (activeStep.value > 0) {
activeStep.value--;
}
};
const submitVote = () => {
// const voteData = props.data.questions.map((question, index) => ({
// question: question.id,
// answer: answers.value[index],
// }));
result.value
console.log("Отправляем данные голосования:", result.value);
// isVoteSubmitted.value = true;
// emit("submit", voteData);
};
return {
activeStep,
answers,
isCurrentQuestionAnswered,
nextStep,
prevStep,
submitVote,
isVoteSubmitted,
result
};
},
};
</script>
<style>
.v-label {
color: #000 !important;
opacity: 1 !important;
}
</style>