This commit is contained in:
Nukeap committed 2025-01-16 11:12:29 +03:00
1 parent 5f70a73221
commit c43f303e3e
2 files changed
+115 -87

No files matched your search

+109 -77
View File
@@ -1,33 +1,66 @@
<template> <template>
<template v-if="!isVoteSubmitted"> <template v-if="!isVoteSubmitted">
<v-stepper v-model="activeStep"> <v-card>
<v-card-title>{{ data.name }}</v-card-title> <div class="d-flex flex-column px-2 flex-fill">
<v-card-subtitle>{{ data.description }}</v-card-subtitle> <v-col cols="auto">
<v-row class="d-flex flex-column">
<!-- Шаги голосования --> <v-col cols="12" class="d-flex flex-row pa-0">
<v-stepper-header> <v-col>
<v-stepper-item <v-card-title>{{ data.name }}</v-card-title>
v-for="question in data.questions" <v-card-subtitle>{{ data.description }}</v-card-subtitle>
:key="question.numb" </v-col>
:complete="question.numb < activeStep" <v-col cols="auto">
:step="question.numb" <v-btn color="red-darken-1" size="medium" class="mt-4" @click="$emit('closer')">
> <v-icon>mdi-close-thick</v-icon>
Вопрос {{ question.numb }} </v-btn>
</v-stepper-item> </v-col>
</v-stepper-header> </v-col>
<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>
<!-- Ответы на вопрос -->
</v-row>
</v-col>
<!-- <v-col class=" "> -->
<v-stepper v-model="activeStep" class="d-flex flex-column flex-fill col">
<!-- Шаги голосования -->
<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 class="d-flex flex-column flex-fill">
<v-stepper-window-item v-for="(question, index) in data.questions" :key="question.numb"
class="bg-red "
:step="question.numb">
<!-- <v-card> -->
<div>{{ question.question }}</div>
<!-- -->
<div class="d-flex flex-column flex-fill">
<v-col cols="2" class="align-self-center">
<v-img cover class=" " :src="question.file" />
</v-col>
<v-col class="bg-pink">
<v-list v-model:selected="result[question.id]" slim density="compact" select-strategy="leaf">
<v-list-item density="compact" v-for="answer in question.answers" :key="answer.id"
:value="answer.id">
{{ answer.answer }}
<template v-slot:prepend="{ isSelected }">
<v-list-item-action start>
<v-checkbox-btn :model-value="isSelected"></v-checkbox-btn>
</v-list-item-action>
</template>
</v-list-item>
</v-list>
</v-col>
</div>
<!-- Ответы на вопрос -->
<!-- {{ data.questions }} -->
<!--
<v-row v-for="(answer, id) in question.answers" :key="id"> <v-row v-for="(answer, id) in question.answers" :key="id">
<v-checkbox <v-checkbox
v-model="result[question.id]" v-model="result[question.id]"
@@ -38,42 +71,38 @@
> >
</v-checkbox> </v-checkbox>
</v-row> </v-row> -->
</v-card-text>
<!-- Действия -->
<v-card-actions> <!-- Действия -->
<v-btn v-if="index > 0" @click="prevStep" outlined>Назад</v-btn> <v-card-actions>
<v-btn <v-btn v-if="index > 0" @click="prevStep" outlined>Назад</v-btn>
v-if="index < data.questions.length - 1" <v-btn v-if="index < data.questions.length - 1" :disabled="!isCurrentQuestionAnswered" @click="nextStep"
:disabled="!isCurrentQuestionAnswered" color="teal-darken-4">
@click="nextStep" Далее
color="teal-darken-4" </v-btn>
> <v-btn v-else :disabled="!isCurrentQuestionAnswered" color="teal-darken-4" @click="submitVote">
Далее Отправить
</v-btn> </v-btn>
<v-btn </v-card-actions>
v-else <!-- </v-card> -->
:disabled="!isCurrentQuestionAnswered" </v-stepper-window-item>
color="teal-darken-4"
@click="submitVote" </v-stepper-window>
> <v-stepper-actions>sd</v-stepper-actions>
Отправить </v-stepper>
</v-btn> <!-- </v-col> -->
</v-card-actions> </div>
</v-card> </v-card>
</v-stepper-window-item>
</v-stepper-window>
</v-stepper>
</template> </template>
<!-- Спасибо за голос --> <!-- Спасибо за голос -->
<template v-else> <template v-else>
<v-row align="center" justify="center" style="height: 50vh;"> <v-row align="center" justify="center" style="height: 50vh;">
<v-col class="text-center" cols="12"> <v-col class="text-center" cols="12">
<v-icon :color="messeger[messeger.key].color" :icon="messeger[messeger.key].icon" size="64"/> <v-icon :color="messeger[messeger.key].color" :icon="messeger[messeger.key].icon" size="64" />
<h2>{{ messeger[messeger.key].text }}</h2> <h2>{{ messeger[messeger.key].text }}</h2>
<v-btn @click="$emit('closer')" class="ma-3 ">Закрыть</v-btn> <v-btn @click="$emit('closer')" class="ma-3 ">Закрыть</v-btn>
</v-col> </v-col>
</v-row> </v-row>
</template> </template>
@@ -86,7 +115,7 @@ import { useAccountStore } from "@/store/AccountStore";
export default { export default {
name: 'CurrentVote', name: 'CurrentVote',
emits:['closer'], emits: ['closer'],
props: { props: {
data: { data: {
type: Object, type: Object,
@@ -96,24 +125,26 @@ export default {
}, },
setup(props, { emit }) { setup(props, { emit }) {
const accountStore = useAccountStore(); const accountStore = useAccountStore();
const messeger = ref({good:{icon:'mdi-check-circle',text:'Спасибо за Ваш голос!',color:"green"}, const messeger = ref({
bad:{icon:'mdi-alert',text:'Произошла ошибка!',color:"red"}, good: { icon: 'mdi-check-circle', text: 'Спасибо за Ваш голос!', color: "green" },
key:'good' bad: { icon: 'mdi-alert', text: 'Произошла ошибка!', color: "red" },
}) key: 'good'
})
const activeStep = ref(0); const activeStep = ref(0);
const answers = ref(props.data.questions.map(() => null)); const answers = ref(props.data.questions.map(() => null));
const isVoteSubmitted = ref(false); const isVoteSubmitted = ref(false);
const isCurrentQuestionAnswered = computed(() => { const isCurrentQuestionAnswered = computed(() => {
let q = props.data.questions.find(e=>e.numb==activeStep.value+1) let q = props.data.questions.find(e => e.numb == activeStep.value + 1)
return result.value[q.id].length>0; return result.value[q.id].length > 0;
}); });
const getres=()=>{ const getres = () => {
return props.data.questions.reduce((acc,item)=> {acc[item.id]=[] return props.data.questions.reduce((acc, item) => {
return acc acc[item.id] = []
},{}) return acc
}, {})
} }
const result=ref(getres()) const result = ref(getres())
const nextStep = () => { const nextStep = () => {
if (activeStep.value < props.data.questions.length - 1) { if (activeStep.value < props.data.questions.length - 1) {
activeStep.value++; activeStep.value++;
@@ -127,21 +158,22 @@ export default {
}; };
const submitVote = () => { const submitVote = () => {
console.log(accountStore); console.log(props.data);
console.log("Отправляем данные голосования:", result.value); console.log("Отправляем данные голосования:", result.value);
let voteData= [] let voteData = []
for (let val of Object.values(result.value)){ for (let val of Object.values(result.value)) {
val.forEach(e=> voteData.push({answer:e,comment:null, user:accountStore.user.id })) val.forEach(e => voteData.push({ answer: e, comment: null, user: accountStore.user.id }))
} }
axiosApiInstance.post('api/vote/voteresultcreate/',voteData).then(res=>{ axiosApiInstance.post('api/vote/voteresultcreate/', voteData).then(res => {
messeger.value.key='good' messeger.value.key = 'good'
console.log(res);
}).catch(e=> {
console.log(e);
messeger.value.key='bad'}
).finally(()=>isVoteSubmitted.value = true) }).catch(e => {
console.log(e);
messeger.value.key = 'bad'
}
).finally(() => isVoteSubmitted.value = true)
}; };
+6 -10
View File
@@ -72,17 +72,12 @@
</v-tabs-window> </v-tabs-window>
<!-- Модальные окна --> <!-- Модальные окна -->
<v-dialog v-model="voteModal" max-width="1200px" @click:outside="closeModal"> <v-dialog fullscreen v-model="voteModal" @click:outside="closeModal">
<v-card>
<v-card-actions>
<v-btn color="red-darken-1" size="medium" @click="closeModal">
<v-icon>mdi-close-thick</v-icon>
</v-btn>
</v-card-actions>
<v-card-text class="pt-0">
<CurrentVote :data="res" @closer="closeModal"/> <CurrentVote :data="res" @closer="closeModal"/>
</v-card-text>
</v-card>
</v-dialog> </v-dialog>
<v-dialog v-model="editVoteModal" max-width="1200px" @click:outside="closeModal"> <v-dialog v-model="editVoteModal" max-width="1200px" @click:outside="closeModal">
@@ -172,6 +167,7 @@ export default {
resultsModal.value = false; resultsModal.value = false;
selectedVoting.value = null; selectedVoting.value = null;
router.push({ name: "VoteHomePage" }); router.push({ name: "VoteHomePage" });
updating("active");
}; };
const openModal = async (type, voting) => { const openModal = async (type, voting) => {