Merge remote-tracking branch 'origin/develop' into dev-denzel
This commit is contained in:
commit
9df060e0c3
10 files changed
+357
-143
No files matched your search
@@ -1,87 +1,154 @@
|
||||
<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-card style="height: 85vh;">
|
||||
<div class="d-flex flex-column flex-fill px-2 " >
|
||||
<v-col cols="auto">
|
||||
<v-row class="d-flex flex-column">
|
||||
<v-col cols="12" class="d-flex flex-row pa-0">
|
||||
<v-col>
|
||||
<v-card-title>{{ data.name }}</v-card-title>
|
||||
<v-card-subtitle>{{ data.description }}</v-card-subtitle>
|
||||
</v-col>
|
||||
<v-col cols="auto">
|
||||
<v-btn color="red-darken-1" density="compact" size="small" icon="mdi-close-thick" @click="$emit('closer')">
|
||||
|
||||
</v-btn>
|
||||
</v-col>
|
||||
</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>
|
||||
<!-- Ответы на вопрос -->
|
||||
|
||||
{{ 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-row>
|
||||
</v-col>
|
||||
<div class="d-flex flex-column flex-fill ">
|
||||
<v-stepper class="d-flex flex-column flex-fill" v-model="activeStep">
|
||||
<!-- Шаги голосования -->
|
||||
<v-stepper-header class="py-0">
|
||||
<template v-for="question in data.questions" :key="question.numb">
|
||||
<v-stepper-item
|
||||
:color="question.numb < activeStep+1?'success':'warning'"
|
||||
edit-icon="mdi-help"
|
||||
:complete="question.numb < activeStep+1" :step="question.numb">
|
||||
Вопрос {{ question.numb }}
|
||||
</v-stepper-item>
|
||||
</template>
|
||||
</v-stepper-header>
|
||||
|
||||
<!-- Действия -->
|
||||
<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>
|
||||
<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=""
|
||||
:step="question.numb">
|
||||
|
||||
<!-- <v-card class="d-flex flex-fill" > -->
|
||||
<div class="">
|
||||
<div class="" >{{ question.question }}</div>
|
||||
|
||||
<v-row>
|
||||
<div class="v-col align-self-center ">
|
||||
<v-img class=""
|
||||
style="max-height:400px"
|
||||
@click.stop="opendialog({answer:question.question, file:question.file})"
|
||||
:src="question.file"/>
|
||||
</div>
|
||||
<div class="v-col-6">
|
||||
|
||||
<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>
|
||||
<template v-slot:append>
|
||||
|
||||
<v-avatar @click.stop="opendialog(answer)" :image="answer.file"></v-avatar>
|
||||
|
||||
</template>
|
||||
|
||||
|
||||
|
||||
|
||||
</v-list-item>
|
||||
|
||||
</v-list>
|
||||
</div>
|
||||
</v-row>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Действия -->
|
||||
<v-card-actions class="">
|
||||
|
||||
</v-card-actions>
|
||||
<!-- </v-card> -->
|
||||
<!-- </v-card> -->
|
||||
</v-stepper-window-item>
|
||||
|
||||
</v-stepper-window>
|
||||
<v-stepper-actions >
|
||||
<template v-slot:prev>
|
||||
|
||||
<v-btn @click="prevStep" outlined>Назад</v-btn></template>
|
||||
<template v-slot:next>
|
||||
|
||||
<v-btn v-if="activeStep < 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>
|
||||
</template></v-stepper-actions>
|
||||
</v-stepper>
|
||||
</div>
|
||||
</div>
|
||||
</v-card>
|
||||
<v-dialog v-model="dialog">
|
||||
<v-card max-height="800">
|
||||
<v-card-title class="v-row">
|
||||
<div clas="v-col-auto">
|
||||
|
||||
{{ activepick.answer }} </div>
|
||||
<v-spacer></v-spacer>
|
||||
<div clas="bg-yellow">
|
||||
<v-btn color="red-darken-1" density="compact" size="small" icon="mdi-close-thick" @click="dialog=false">
|
||||
|
||||
</v-btn>
|
||||
</div>
|
||||
|
||||
</v-card-title>
|
||||
<v-card-item>
|
||||
|
||||
<v-img :src="activepick.file" max-height="600" ></v-img>
|
||||
</v-card-item>
|
||||
</v-card>
|
||||
</v-dialog>
|
||||
</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-card width="400" class="mx-auto">
|
||||
<v-row align="center" justify="center" class="pa-3">
|
||||
<v-col class="text-center">
|
||||
<v-icon :color="messeger[messeger.key].color" :icon="messeger[messeger.key].icon" size="64" />
|
||||
<h2>{{ messeger[messeger.key].text }}</h2>
|
||||
<v-btn @click="$emit('closer')" class="ma-3 ">Закрыть</v-btn>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-card>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { axiosApiInstance } from "@/utils/axios-api";
|
||||
import { computed, ref } from "vue";
|
||||
import { useAccountStore } from "@/store/AccountStore";
|
||||
|
||||
export default {
|
||||
name: 'CurrentVote',
|
||||
emits: ['closer'],
|
||||
props: {
|
||||
data: {
|
||||
type: Object,
|
||||
@@ -90,20 +157,27 @@ export default {
|
||||
},
|
||||
},
|
||||
setup(props, { emit }) {
|
||||
const accountStore = useAccountStore();
|
||||
const messeger = ref({
|
||||
good: { icon: 'mdi-check-circle', text: 'Спасибо за Ваш голос!', color: "green" },
|
||||
bad: { icon: 'mdi-alert', text: 'Произошла ошибка!', color: "red" },
|
||||
key: 'good'
|
||||
})
|
||||
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;
|
||||
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 getres = () => {
|
||||
return props.data.questions.reduce((acc, item) => {
|
||||
acc[item.id] = []
|
||||
return acc
|
||||
}, {})
|
||||
}
|
||||
const result=ref(getres())
|
||||
const result = ref(getres())
|
||||
const nextStep = () => {
|
||||
if (activeStep.value < props.data.questions.length - 1) {
|
||||
activeStep.value++;
|
||||
@@ -117,18 +191,36 @@ export default {
|
||||
};
|
||||
|
||||
const submitVote = () => {
|
||||
// const voteData = props.data.questions.map((question, index) => ({
|
||||
// question: question.id,
|
||||
// answer: answers.value[index],
|
||||
// }));
|
||||
result.value
|
||||
console.log(props.data);
|
||||
console.log("Отправляем данные голосования:", result.value);
|
||||
let voteData = []
|
||||
for (let val of Object.values(result.value)) {
|
||||
val.forEach(e => voteData.push({ answer: e, comment: null, user: accountStore.user.id }))
|
||||
}
|
||||
|
||||
axiosApiInstance.post('api/vote/voteresultcreate/', voteData).then(res => {
|
||||
messeger.value.key = 'good'
|
||||
|
||||
}).catch(e => {
|
||||
console.log(e);
|
||||
messeger.value.key = 'bad'
|
||||
}
|
||||
|
||||
).finally(() => isVoteSubmitted.value = true)
|
||||
|
||||
// isVoteSubmitted.value = true;
|
||||
// emit("submit", voteData);
|
||||
};
|
||||
const activepick = ref(null)
|
||||
const dialog=ref(false)
|
||||
const opendialog=(val)=>{
|
||||
dialog.value=true
|
||||
activepick.value=val
|
||||
}
|
||||
|
||||
return {
|
||||
activepick,
|
||||
opendialog,
|
||||
dialog,
|
||||
messeger,
|
||||
activeStep,
|
||||
answers,
|
||||
isCurrentQuestionAnswered,
|
||||
|
||||
@@ -6,32 +6,58 @@
|
||||
</v-btn>
|
||||
</v-card-text>
|
||||
<v-row>
|
||||
<v-col>
|
||||
|
||||
<v-carousel show-arrows="hover" hide-delimiters cycle height="200">
|
||||
<v-carousel-item v-for="(picture, index) in images"
|
||||
:key="index"
|
||||
:src="`${baseURL.slice(0, -1)}${picture}`">
|
||||
</v-carousel-item>
|
||||
</v-carousel>
|
||||
</v-col>
|
||||
<v-col>
|
||||
|
||||
<v-carousel
|
||||
show-arrows="hover"
|
||||
hide-delimiters cycle
|
||||
height="200">
|
||||
<v-carousel-item
|
||||
v-for="(picture, index) in images"
|
||||
:key="index"
|
||||
:src="`${baseURL.slice(0, -1)}${picture}`">
|
||||
</v-carousel-item>
|
||||
</v-carousel>
|
||||
</v-col>
|
||||
</v-row>
|
||||
<v-card-text class="">{{ voteCard.description }}</v-card-text>
|
||||
<Timer :voteTime="{dateend:voteCard.dateend,datestart:voteCard.datestart}" @changeBtn="(time) => timeChange = time"/>
|
||||
<Timer :voteTime="{ dateend: voteCard.dateend, datestart: voteCard.datestart }" @changeBtn="(time) => timeChange = time" />
|
||||
<v-card-actions class="justify-space-between mt-4 pb-2">
|
||||
<v-btn
|
||||
:disabled="voteCard.is_passed || timeChange"
|
||||
color="teal-darken-4"
|
||||
prepend-icon="mdi-vote-outline"
|
||||
variant="outlined"
|
||||
rounded="xl"
|
||||
size="medium"
|
||||
class="pa-2"
|
||||
@click="$emit('openVoteModal', voteCard)">
|
||||
{{!voteCard.is_passed?"Проголосовать":"Уже проголосовали"}}
|
||||
<v-btn :disabled="voteCard.is_passed || timeChange" color="teal-darken-4" prepend-icon="mdi-vote-outline"
|
||||
variant="outlined" rounded="xl" size="small" @click="$emit('openVoteModal', voteCard)">
|
||||
{{ !voteCard.is_passed ? "Проголосовать" : "Уже проголосовали" }}
|
||||
</v-btn>
|
||||
<v-btn color="error" @click="$emit('deleteVoting', voteCard.id)" size="medium">
|
||||
<v-btn color="error" @click="youSure=true" size="medium">
|
||||
<v-icon>mdi-delete</v-icon>
|
||||
<v-dialog v-model="youSure" width="500">
|
||||
|
||||
<v-card max-width="450" class="flex">
|
||||
<v-btn
|
||||
class="align-self-end ma-2 text-red"
|
||||
icon="mdi-close"
|
||||
variant="text"
|
||||
size="medium"
|
||||
@click="youSure = false"
|
||||
/>
|
||||
<div class="ml-5 text-h6">
|
||||
Вы действительно хотите удалить голосование?
|
||||
</div>
|
||||
<template v-slot:actions>
|
||||
<v-btn-group>
|
||||
<v-btn
|
||||
class="text-red"
|
||||
@click="$emit('deleteVoting', voteCard.id), youSure = false">
|
||||
Да
|
||||
</v-btn>
|
||||
<v-btn
|
||||
class="text-green"
|
||||
@click="youSure = false">
|
||||
Нет
|
||||
</v-btn>
|
||||
</v-btn-group>
|
||||
</template>
|
||||
</v-card>
|
||||
</v-dialog>
|
||||
</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
@@ -61,10 +87,12 @@ export default {
|
||||
},
|
||||
setup(props) {
|
||||
const timeChange = ref(false)
|
||||
const images = computed(()=>{
|
||||
return props.voteCard.files.length>0? props.voteCard.files:['/media/defaultimg/vote.png']
|
||||
const youSure = ref(false)
|
||||
|
||||
const images = computed(() => {
|
||||
return props.voteCard.files.length > 0 ? props.voteCard.files : ['/media/defaultimg/vote.png']
|
||||
})
|
||||
return { timeChange, baseURL ,images}
|
||||
return { timeChange, baseURL, images, youSure }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -150,13 +150,21 @@ const routes = [
|
||||
path: "/vote",
|
||||
name: "VoteHomePage",
|
||||
component: () =>
|
||||
import("@/views/VoteHomePage.vue")
|
||||
import("@/views/VoteHomePage.vue"),
|
||||
meta: {
|
||||
title: "Голосование",
|
||||
ico: "mdi-account",
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "/vote/voting/:id",
|
||||
name: "Voting",
|
||||
component: () =>
|
||||
import("@/views/VoteHomePage.vue")
|
||||
import("@/views/VoteHomePage.vue"),
|
||||
meta: {
|
||||
title: "Голосование",
|
||||
ico: "mdi-account",
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "/vote/edit-vote/:id",
|
||||
|
||||
@@ -93,22 +93,45 @@ async function getVotes(status) {
|
||||
}
|
||||
}
|
||||
|
||||
async function createVote(voteData, files) {
|
||||
|
||||
async function createVote(voteData) {
|
||||
|
||||
try {
|
||||
|
||||
const formData = new FormData();
|
||||
voteData.questions.forEach(question => {
|
||||
formData.append('questionsfiles', question.image)
|
||||
console.log(question.image);
|
||||
if(!!question.image){
|
||||
const {name,size,lastModified}=question.image
|
||||
question.image={name,size,lastModified}
|
||||
}
|
||||
|
||||
question.answers.forEach(answer=>{
|
||||
|
||||
formData.append('answersfiles', answer.image)
|
||||
if(!!answer.image){
|
||||
const {name,size,lastModified}=answer.image
|
||||
answer.image={name,size,lastModified}
|
||||
}
|
||||
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
|
||||
formData.append('title', voteData.title);
|
||||
formData.append('description', voteData.description);
|
||||
formData.append('startDate', new Date(voteData.startDate).toISOString());
|
||||
formData.append('endDate', new Date(voteData.endDate).toISOString());
|
||||
formData.append('questions', JSON.stringify(voteData.questions));
|
||||
formData.append('settings', {...voteData.type});
|
||||
|
||||
formData.append('questions', JSON.stringify(...voteData.questions));
|
||||
|
||||
|
||||
const response = await axiosApiInstance.post('/api/vote/votecreate/', formData, {
|
||||
headers: {'Content-Type': 'multipart/form-data'},
|
||||
});
|
||||
|
||||
return response.data;
|
||||
// return response.data;
|
||||
} catch (error) {
|
||||
console.error('Ошибка создания голосования:', error);
|
||||
throw error;
|
||||
|
||||
@@ -72,17 +72,12 @@
|
||||
</v-tabs-window>
|
||||
|
||||
<!-- Модальные окна -->
|
||||
<v-dialog v-model="voteModal" max-width="1200px" @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" />
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
<v-dialog v-model="voteModal" @click:outside="closeModal">
|
||||
|
||||
|
||||
<CurrentVote :data="res" @closer="closeModal"/>
|
||||
|
||||
|
||||
</v-dialog>
|
||||
|
||||
<v-dialog v-model="editVoteModal" max-width="1200px" @click:outside="closeModal">
|
||||
@@ -123,6 +118,7 @@ import { formatDate } from "@vueuse/shared";
|
||||
|
||||
export default {
|
||||
methods: { formatDate },
|
||||
|
||||
components: { CurrentVote, VoteConstructor, VoteCardVue },
|
||||
setup() {
|
||||
const currentTab = ref("current");
|
||||
@@ -171,6 +167,7 @@ export default {
|
||||
resultsModal.value = false;
|
||||
selectedVoting.value = null;
|
||||
router.push({ name: "VoteHomePage" });
|
||||
updating("active");
|
||||
};
|
||||
|
||||
const openModal = async (type, voting) => {
|
||||
|
||||
Reference in new issue
Block a user