P-98 Результаты голосования
This commit is contained in:
1 parent
64c948d077
commit
a8bba7cb8b
4 files changed
+131
-58
No files matched your search
@@ -11,7 +11,7 @@
|
||||
</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>
|
||||
@@ -24,7 +24,7 @@
|
||||
<!-- Шаги голосования -->
|
||||
<v-stepper-header class="py-0">
|
||||
<template v-for="question in data.questions" :key="question.numb">
|
||||
<v-stepper-item
|
||||
<v-stepper-item
|
||||
:color="question.numb < activeStep+1?'success':'warning'"
|
||||
edit-icon="mdi-help"
|
||||
:complete="question.numb < activeStep+1" :step="question.numb">
|
||||
@@ -35,22 +35,22 @@
|
||||
|
||||
<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=""
|
||||
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=""
|
||||
<v-img class=""
|
||||
style="max-height:400px"
|
||||
@click.stop="opendialog({answer:question.question, file:question.file})"
|
||||
@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"
|
||||
@@ -62,9 +62,9 @@
|
||||
</v-list-item-action>
|
||||
</template>
|
||||
<template v-slot:append>
|
||||
|
||||
|
||||
<v-avatar @click.stop="opendialog(answer)" :image="answer.file"></v-avatar>
|
||||
|
||||
|
||||
</template>
|
||||
|
||||
|
||||
@@ -76,23 +76,23 @@
|
||||
</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">
|
||||
Далее
|
||||
@@ -114,10 +114,10 @@
|
||||
<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>
|
||||
|
||||
@@ -168,9 +168,10 @@ export default {
|
||||
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 q !== undefined ? result.value[q.id].length > 0 : false;
|
||||
});
|
||||
|
||||
const getres = () => {
|
||||
return props.data.questions.reduce((acc, item) => {
|
||||
acc[item.id] = []
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
<template>
|
||||
<v-container>
|
||||
|
||||
<v-row>
|
||||
<v-col cols="12">
|
||||
<v-card class="mb-4" outlined>
|
||||
<v-card-title>Победитель: {{ winner.name }}</v-card-title>
|
||||
<v-card-subtitle>
|
||||
Количество голосов: {{ winner.votes }}
|
||||
</v-card-subtitle>
|
||||
</v-card>
|
||||
</v-col>
|
||||
</v-row>
|
||||
|
||||
<v-row>
|
||||
<v-col cols="12">
|
||||
<v-card class="mb-4" outlined>
|
||||
<v-card-title>Все результаты</v-card-title>
|
||||
<v-card-text>
|
||||
<v-list>
|
||||
<v-list-item v-for="(option, index) in sortedResults" :key="index">
|
||||
<p>
|
||||
<strong>{{ option.name }}</strong>: {{ option.votes }} голосов
|
||||
</p>
|
||||
</v-list-item>
|
||||
</v-list>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { computed } from 'vue';
|
||||
|
||||
export default {
|
||||
name: 'VoteResult',
|
||||
props: {
|
||||
results: {
|
||||
type: Array,
|
||||
required: true,
|
||||
default: () => []
|
||||
}
|
||||
},
|
||||
setup(props) {
|
||||
const winner = computed(() => {
|
||||
return props.results.reduce((max, option) => (option.votes > max.votes ? option : max), { name: '', votes: 0 });
|
||||
});
|
||||
|
||||
const sortedResults = computed(() => {
|
||||
return [...props.results].sort((a, b) => b.votes - a.votes);
|
||||
});
|
||||
|
||||
return {
|
||||
winner,
|
||||
sortedResults
|
||||
};
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
h1 {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
</style>
|
||||
@@ -93,11 +93,10 @@ async function getVotes(status) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function createVote(voteData) {
|
||||
|
||||
try {
|
||||
|
||||
|
||||
const formData = new FormData();
|
||||
voteData.questions.forEach(question => {
|
||||
formData.append('questionsfiles', question.image)
|
||||
@@ -106,9 +105,9 @@ async function createVote(voteData) {
|
||||
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
|
||||
@@ -125,8 +124,8 @@ async function createVote(voteData) {
|
||||
formData.append('startDate', new Date(voteData.startDate).toISOString());
|
||||
formData.append('endDate', new Date(voteData.endDate).toISOString());
|
||||
formData.append('questions', JSON.stringify(voteData.questions));
|
||||
|
||||
|
||||
|
||||
|
||||
const response = await axiosApiInstance.post('/api/vote/votecreate/', formData, {
|
||||
headers: {'Content-Type': 'multipart/form-data'},
|
||||
});
|
||||
@@ -188,9 +187,6 @@ async function getEmployees() {
|
||||
}
|
||||
}
|
||||
|
||||
getEmployees()
|
||||
.then(r => console.log(r))
|
||||
|
||||
|
||||
export {
|
||||
axiosApiInstance,
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
>
|
||||
<VoteCardVue
|
||||
:voteCard="voting"
|
||||
@openVoteModal="(voting) => openModal('vote', voting)"
|
||||
@openEditVoteModal="(voting) => openModal('edit', voting)"
|
||||
@deleteVoting="deleteVoting"
|
||||
@openEditVoteModal="(voting) => openModal('edit', voting)"
|
||||
@openVoteModal="(voting) => openModal('vote', voting)"
|
||||
/>
|
||||
</v-col>
|
||||
</v-row>
|
||||
@@ -41,18 +41,18 @@
|
||||
<v-col
|
||||
v-for="voting in sortedCompletedVotes"
|
||||
:key="voting.id"
|
||||
:class="{ 'voted-card': voting.voted }"
|
||||
cols="12"
|
||||
lg="3"
|
||||
md="4"
|
||||
:class="{ 'voted-card': voting.voted }"
|
||||
>
|
||||
<v-card>
|
||||
<v-card-title>{{ voting.title }}</v-card-title>
|
||||
<v-card-title>{{ voting.name }}</v-card-title>
|
||||
<v-card-subtitle>
|
||||
Завершено: {{ formatDate(voting.endDate) }}
|
||||
Завершено: {{ voting.dateend }}
|
||||
</v-card-subtitle>
|
||||
<v-card-actions class="justify-space-between">
|
||||
<v-btn color="teal-darken-4" size="medium" @click="(voting) => openModal('results', voting)">
|
||||
<v-btn color="teal-darken-4" size="medium" @click="() => openModal('results', voting)">
|
||||
Результаты
|
||||
</v-btn>
|
||||
<v-btn color="error" size="medium" @click="deleteVoting(voting.id)">
|
||||
@@ -67,24 +67,20 @@
|
||||
|
||||
<!-- Конструктор -->
|
||||
<v-tabs-window-item value="constructor">
|
||||
<VoteConstructor @updating="updating" />
|
||||
<VoteConstructor @updating="updating"/>
|
||||
</v-tabs-window-item>
|
||||
</v-tabs-window>
|
||||
|
||||
<!-- Модальные окна -->
|
||||
<v-dialog v-model="voteModal" @click:outside="closeModal">
|
||||
|
||||
|
||||
<CurrentVote :data="res" @closer="closeModal"/>
|
||||
|
||||
|
||||
<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">
|
||||
<v-card>
|
||||
<v-card-title>Редактировать голосование: {{ selectedVoting?.title }}</v-card-title>
|
||||
<v-card-text>
|
||||
<VoteConstructor />
|
||||
<VoteConstructor/>
|
||||
</v-card-text>
|
||||
<v-card-actions>
|
||||
<v-btn color="teal-darken-4">Сохранить</v-btn>
|
||||
@@ -97,7 +93,7 @@
|
||||
<v-card>
|
||||
<v-card-title>Результаты голосования: {{ selectedVoting?.title }}</v-card-title>
|
||||
<v-card-text>
|
||||
<p>Здесь отображаются результаты голосования...</p>
|
||||
<VoteResult :results="testResults"/>
|
||||
</v-card-text>
|
||||
<v-card-actions>
|
||||
<v-btn @click="closeModal">Закрыть</v-btn>
|
||||
@@ -108,31 +104,40 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { ref, computed, watch } from "vue";
|
||||
import {computed, ref, watch} from "vue";
|
||||
import VoteConstructor from "@/components/vote/VoteConstructor.vue";
|
||||
import CurrentVote from "@/components/vote/CurrentVote.vue";
|
||||
import VoteCardVue from "@/components/vote/VoteCard.vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { deleteVote, getVoteDetail, getVotes } from "@/utils/axios-api";
|
||||
import { formatDate } from "@vueuse/shared";
|
||||
import {useRoute, useRouter} from "vue-router";
|
||||
import {deleteVote, getVoteDetail, getVotes} from "@/utils/axios-api";
|
||||
import {formatDate} from "@vueuse/shared";
|
||||
import VoteResult from "@/components/vote/VoteResult.vue";
|
||||
|
||||
export default {
|
||||
methods: { formatDate },
|
||||
|
||||
components: { CurrentVote, VoteConstructor, VoteCardVue },
|
||||
methods: {formatDate},
|
||||
|
||||
components: {VoteResult, CurrentVote, VoteConstructor, VoteCardVue},
|
||||
setup() {
|
||||
const testResults = [
|
||||
{name: 'Дональд Трамп', votes: 99},
|
||||
{name: 'Иван Иванов', votes: 30},
|
||||
{name: 'Аркадий Упукник', votes: 95},
|
||||
];
|
||||
const currentTab = ref("current");
|
||||
const votes = ref([]);
|
||||
const completedVotes = ref([]);
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
const res = ref(null);
|
||||
|
||||
const updating = async (param) => {
|
||||
const data = await getVotes(param);
|
||||
votes.value = data;
|
||||
if (param === 'active') votes.value = data;
|
||||
else completedVotes.value = data;
|
||||
};
|
||||
|
||||
updating("active");
|
||||
updating('completed')
|
||||
|
||||
const voteModal = ref(false);
|
||||
const editVoteModal = ref(false);
|
||||
@@ -146,11 +151,13 @@ export default {
|
||||
);
|
||||
|
||||
const sortedCompletedVotes = computed(() =>
|
||||
votes.value
|
||||
completedVotes.value
|
||||
.filter((v) => new Date(v.dateend) <= new Date())
|
||||
.sort((a, b) => new Date(b.dateend) - new Date(a.dateend))
|
||||
);
|
||||
|
||||
console.log(completedVotes.value);
|
||||
|
||||
const loadVoteDetails = async (id) => {
|
||||
try {
|
||||
const data = await getVoteDetail(id);
|
||||
@@ -166,7 +173,7 @@ export default {
|
||||
editVoteModal.value = false;
|
||||
resultsModal.value = false;
|
||||
selectedVoting.value = null;
|
||||
router.push({ name: "VoteHomePage" });
|
||||
router.push({name: "VoteHomePage"});
|
||||
updating("active");
|
||||
};
|
||||
|
||||
@@ -176,13 +183,13 @@ export default {
|
||||
if (type === "vote") {
|
||||
await loadVoteDetails(voting.id);
|
||||
voteModal.value = true;
|
||||
router.push({ name: "Voting", params: { id: voting.id } });
|
||||
router.push({name: "Voting", params: {id: voting.id}});
|
||||
} else if (type === "edit") {
|
||||
editVoteModal.value = true;
|
||||
router.push({ name: "EditVote", params: { id: voting.id } });
|
||||
router.push({name: "EditVote", params: {id: voting.id}});
|
||||
} else if (type === "results") {
|
||||
resultsModal.value = true;
|
||||
router.push({ name: "VoteResults", params: { id: voting.id } });
|
||||
router.push({name: "VoteResults", params: {id: voting.id}});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -209,10 +216,11 @@ export default {
|
||||
selectedVoting.value = voting || null;
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
{immediate: true}
|
||||
);
|
||||
|
||||
updating("active");
|
||||
updating("completed");
|
||||
|
||||
return {
|
||||
currentTab,
|
||||
@@ -228,6 +236,7 @@ export default {
|
||||
deleteVoting,
|
||||
updating,
|
||||
res,
|
||||
testResults
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user