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>
|
||||||
<v-col cols="auto">
|
<v-col cols="auto">
|
||||||
<v-btn color="red-darken-1" density="compact" size="small" icon="mdi-close-thick" @click="$emit('closer')">
|
<v-btn color="red-darken-1" density="compact" size="small" icon="mdi-close-thick" @click="$emit('closer')">
|
||||||
|
|
||||||
</v-btn>
|
</v-btn>
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-col>
|
</v-col>
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
<!-- Шаги голосования -->
|
<!-- Шаги голосования -->
|
||||||
<v-stepper-header class="py-0">
|
<v-stepper-header class="py-0">
|
||||||
<template v-for="question in data.questions" :key="question.numb">
|
<template v-for="question in data.questions" :key="question.numb">
|
||||||
<v-stepper-item
|
<v-stepper-item
|
||||||
:color="question.numb < activeStep+1?'success':'warning'"
|
:color="question.numb < activeStep+1?'success':'warning'"
|
||||||
edit-icon="mdi-help"
|
edit-icon="mdi-help"
|
||||||
:complete="question.numb < activeStep+1" :step="question.numb">
|
: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 class="d-flex flex-column flex-fill " >
|
||||||
<v-stepper-window-item v-for="(question, index) in data.questions" :key="question.numb"
|
<v-stepper-window-item v-for="(question, index) in data.questions" :key="question.numb"
|
||||||
class=""
|
class=""
|
||||||
:step="question.numb">
|
:step="question.numb">
|
||||||
|
|
||||||
<!-- <v-card class="d-flex flex-fill" > -->
|
<!-- <v-card class="d-flex flex-fill" > -->
|
||||||
<div class="">
|
<div class="">
|
||||||
<div class="" >{{ question.question }}</div>
|
<div class="" >{{ question.question }}</div>
|
||||||
|
|
||||||
<v-row>
|
<v-row>
|
||||||
<div class="v-col align-self-center ">
|
<div class="v-col align-self-center ">
|
||||||
<v-img class=""
|
<v-img class=""
|
||||||
style="max-height:400px"
|
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"/>
|
:src="question.file"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="v-col-6">
|
<div class="v-col-6">
|
||||||
|
|
||||||
<v-list v-model:selected="result[question.id]" slim density="compact" select-strategy="leaf">
|
<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"
|
<v-list-item density="compact" v-for="answer in question.answers" :key="answer.id"
|
||||||
@@ -62,9 +62,9 @@
|
|||||||
</v-list-item-action>
|
</v-list-item-action>
|
||||||
</template>
|
</template>
|
||||||
<template v-slot:append>
|
<template v-slot:append>
|
||||||
|
|
||||||
<v-avatar @click.stop="opendialog(answer)" :image="answer.file"></v-avatar>
|
<v-avatar @click.stop="opendialog(answer)" :image="answer.file"></v-avatar>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
||||||
@@ -76,23 +76,23 @@
|
|||||||
</div>
|
</div>
|
||||||
</v-row>
|
</v-row>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<!-- Действия -->
|
<!-- Действия -->
|
||||||
<v-card-actions class="">
|
<v-card-actions class="">
|
||||||
|
|
||||||
</v-card-actions>
|
</v-card-actions>
|
||||||
<!-- </v-card> -->
|
<!-- </v-card> -->
|
||||||
<!-- </v-card> -->
|
<!-- </v-card> -->
|
||||||
</v-stepper-window-item>
|
</v-stepper-window-item>
|
||||||
|
|
||||||
</v-stepper-window>
|
</v-stepper-window>
|
||||||
<v-stepper-actions >
|
<v-stepper-actions >
|
||||||
<template v-slot:prev>
|
<template v-slot:prev>
|
||||||
|
|
||||||
<v-btn @click="prevStep" outlined>Назад</v-btn></template>
|
<v-btn @click="prevStep" outlined>Назад</v-btn></template>
|
||||||
<template v-slot:next>
|
<template v-slot:next>
|
||||||
|
|
||||||
<v-btn v-if="activeStep < data.questions.length - 1" :disabled="!isCurrentQuestionAnswered" @click="nextStep"
|
<v-btn v-if="activeStep < data.questions.length - 1" :disabled="!isCurrentQuestionAnswered" @click="nextStep"
|
||||||
color="teal-darken-4">
|
color="teal-darken-4">
|
||||||
Далее
|
Далее
|
||||||
@@ -114,10 +114,10 @@
|
|||||||
<v-spacer></v-spacer>
|
<v-spacer></v-spacer>
|
||||||
<div clas="bg-yellow">
|
<div clas="bg-yellow">
|
||||||
<v-btn color="red-darken-1" density="compact" size="small" icon="mdi-close-thick" @click="dialog=false">
|
<v-btn color="red-darken-1" density="compact" size="small" icon="mdi-close-thick" @click="dialog=false">
|
||||||
|
|
||||||
</v-btn>
|
</v-btn>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</v-card-title>
|
</v-card-title>
|
||||||
<v-card-item>
|
<v-card-item>
|
||||||
|
|
||||||
@@ -168,9 +168,10 @@ export default {
|
|||||||
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 q !== undefined ? result.value[q.id].length > 0 : false;
|
||||||
});
|
});
|
||||||
|
|
||||||
const getres = () => {
|
const getres = () => {
|
||||||
return props.data.questions.reduce((acc, item) => {
|
return props.data.questions.reduce((acc, item) => {
|
||||||
acc[item.id] = []
|
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) {
|
async function createVote(voteData) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
voteData.questions.forEach(question => {
|
voteData.questions.forEach(question => {
|
||||||
formData.append('questionsfiles', question.image)
|
formData.append('questionsfiles', question.image)
|
||||||
@@ -106,9 +105,9 @@ async function createVote(voteData) {
|
|||||||
const {name,size,lastModified}=question.image
|
const {name,size,lastModified}=question.image
|
||||||
question.image={name,size,lastModified}
|
question.image={name,size,lastModified}
|
||||||
}
|
}
|
||||||
|
|
||||||
question.answers.forEach(answer=>{
|
question.answers.forEach(answer=>{
|
||||||
|
|
||||||
formData.append('answersfiles', answer.image)
|
formData.append('answersfiles', answer.image)
|
||||||
if(!!answer.image){
|
if(!!answer.image){
|
||||||
const {name,size,lastModified}=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('startDate', new Date(voteData.startDate).toISOString());
|
||||||
formData.append('endDate', new Date(voteData.endDate).toISOString());
|
formData.append('endDate', new Date(voteData.endDate).toISOString());
|
||||||
formData.append('questions', JSON.stringify(voteData.questions));
|
formData.append('questions', JSON.stringify(voteData.questions));
|
||||||
|
|
||||||
|
|
||||||
const response = await axiosApiInstance.post('/api/vote/votecreate/', formData, {
|
const response = await axiosApiInstance.post('/api/vote/votecreate/', formData, {
|
||||||
headers: {'Content-Type': 'multipart/form-data'},
|
headers: {'Content-Type': 'multipart/form-data'},
|
||||||
});
|
});
|
||||||
@@ -188,9 +187,6 @@ async function getEmployees() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getEmployees()
|
|
||||||
.then(r => console.log(r))
|
|
||||||
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
axiosApiInstance,
|
axiosApiInstance,
|
||||||
|
|||||||
@@ -25,9 +25,9 @@
|
|||||||
>
|
>
|
||||||
<VoteCardVue
|
<VoteCardVue
|
||||||
:voteCard="voting"
|
:voteCard="voting"
|
||||||
@openVoteModal="(voting) => openModal('vote', voting)"
|
|
||||||
@openEditVoteModal="(voting) => openModal('edit', voting)"
|
|
||||||
@deleteVoting="deleteVoting"
|
@deleteVoting="deleteVoting"
|
||||||
|
@openEditVoteModal="(voting) => openModal('edit', voting)"
|
||||||
|
@openVoteModal="(voting) => openModal('vote', voting)"
|
||||||
/>
|
/>
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
@@ -41,18 +41,18 @@
|
|||||||
<v-col
|
<v-col
|
||||||
v-for="voting in sortedCompletedVotes"
|
v-for="voting in sortedCompletedVotes"
|
||||||
:key="voting.id"
|
:key="voting.id"
|
||||||
|
:class="{ 'voted-card': voting.voted }"
|
||||||
cols="12"
|
cols="12"
|
||||||
lg="3"
|
lg="3"
|
||||||
md="4"
|
md="4"
|
||||||
:class="{ 'voted-card': voting.voted }"
|
|
||||||
>
|
>
|
||||||
<v-card>
|
<v-card>
|
||||||
<v-card-title>{{ voting.title }}</v-card-title>
|
<v-card-title>{{ voting.name }}</v-card-title>
|
||||||
<v-card-subtitle>
|
<v-card-subtitle>
|
||||||
Завершено: {{ formatDate(voting.endDate) }}
|
Завершено: {{ voting.dateend }}
|
||||||
</v-card-subtitle>
|
</v-card-subtitle>
|
||||||
<v-card-actions class="justify-space-between">
|
<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>
|
||||||
<v-btn color="error" size="medium" @click="deleteVoting(voting.id)">
|
<v-btn color="error" size="medium" @click="deleteVoting(voting.id)">
|
||||||
@@ -67,24 +67,20 @@
|
|||||||
|
|
||||||
<!-- Конструктор -->
|
<!-- Конструктор -->
|
||||||
<v-tabs-window-item value="constructor">
|
<v-tabs-window-item value="constructor">
|
||||||
<VoteConstructor @updating="updating" />
|
<VoteConstructor @updating="updating"/>
|
||||||
</v-tabs-window-item>
|
</v-tabs-window-item>
|
||||||
</v-tabs-window>
|
</v-tabs-window>
|
||||||
|
|
||||||
<!-- Модальные окна -->
|
<!-- Модальные окна -->
|
||||||
<v-dialog v-model="voteModal" @click:outside="closeModal">
|
<v-dialog v-model="voteModal" @click:outside="closeModal">
|
||||||
|
<CurrentVote :data="res" @closer="closeModal"/>
|
||||||
|
|
||||||
<CurrentVote :data="res" @closer="closeModal"/>
|
|
||||||
|
|
||||||
|
|
||||||
</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">
|
||||||
<v-card>
|
<v-card>
|
||||||
<v-card-title>Редактировать голосование: {{ selectedVoting?.title }}</v-card-title>
|
<v-card-title>Редактировать голосование: {{ selectedVoting?.title }}</v-card-title>
|
||||||
<v-card-text>
|
<v-card-text>
|
||||||
<VoteConstructor />
|
<VoteConstructor/>
|
||||||
</v-card-text>
|
</v-card-text>
|
||||||
<v-card-actions>
|
<v-card-actions>
|
||||||
<v-btn color="teal-darken-4">Сохранить</v-btn>
|
<v-btn color="teal-darken-4">Сохранить</v-btn>
|
||||||
@@ -97,7 +93,7 @@
|
|||||||
<v-card>
|
<v-card>
|
||||||
<v-card-title>Результаты голосования: {{ selectedVoting?.title }}</v-card-title>
|
<v-card-title>Результаты голосования: {{ selectedVoting?.title }}</v-card-title>
|
||||||
<v-card-text>
|
<v-card-text>
|
||||||
<p>Здесь отображаются результаты голосования...</p>
|
<VoteResult :results="testResults"/>
|
||||||
</v-card-text>
|
</v-card-text>
|
||||||
<v-card-actions>
|
<v-card-actions>
|
||||||
<v-btn @click="closeModal">Закрыть</v-btn>
|
<v-btn @click="closeModal">Закрыть</v-btn>
|
||||||
@@ -108,31 +104,40 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { ref, computed, watch } from "vue";
|
import {computed, ref, watch} from "vue";
|
||||||
import VoteConstructor from "@/components/vote/VoteConstructor.vue";
|
import VoteConstructor from "@/components/vote/VoteConstructor.vue";
|
||||||
import CurrentVote from "@/components/vote/CurrentVote.vue";
|
import CurrentVote from "@/components/vote/CurrentVote.vue";
|
||||||
import VoteCardVue from "@/components/vote/VoteCard.vue";
|
import VoteCardVue from "@/components/vote/VoteCard.vue";
|
||||||
import { useRoute, useRouter } from "vue-router";
|
import {useRoute, useRouter} from "vue-router";
|
||||||
import { deleteVote, getVoteDetail, getVotes } from "@/utils/axios-api";
|
import {deleteVote, getVoteDetail, getVotes} from "@/utils/axios-api";
|
||||||
import { formatDate } from "@vueuse/shared";
|
import {formatDate} from "@vueuse/shared";
|
||||||
|
import VoteResult from "@/components/vote/VoteResult.vue";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
methods: { formatDate },
|
methods: {formatDate},
|
||||||
|
|
||||||
components: { CurrentVote, VoteConstructor, VoteCardVue },
|
components: {VoteResult, CurrentVote, VoteConstructor, VoteCardVue},
|
||||||
setup() {
|
setup() {
|
||||||
|
const testResults = [
|
||||||
|
{name: 'Дональд Трамп', votes: 99},
|
||||||
|
{name: 'Иван Иванов', votes: 30},
|
||||||
|
{name: 'Аркадий Упукник', votes: 95},
|
||||||
|
];
|
||||||
const currentTab = ref("current");
|
const currentTab = ref("current");
|
||||||
const votes = ref([]);
|
const votes = ref([]);
|
||||||
|
const completedVotes = ref([]);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const res = ref(null);
|
const res = ref(null);
|
||||||
|
|
||||||
const updating = async (param) => {
|
const updating = async (param) => {
|
||||||
const data = await getVotes(param);
|
const data = await getVotes(param);
|
||||||
votes.value = data;
|
if (param === 'active') votes.value = data;
|
||||||
|
else completedVotes.value = data;
|
||||||
};
|
};
|
||||||
|
|
||||||
updating("active");
|
updating("active");
|
||||||
|
updating('completed')
|
||||||
|
|
||||||
const voteModal = ref(false);
|
const voteModal = ref(false);
|
||||||
const editVoteModal = ref(false);
|
const editVoteModal = ref(false);
|
||||||
@@ -146,11 +151,13 @@ export default {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const sortedCompletedVotes = computed(() =>
|
const sortedCompletedVotes = computed(() =>
|
||||||
votes.value
|
completedVotes.value
|
||||||
.filter((v) => new Date(v.dateend) <= new Date())
|
.filter((v) => new Date(v.dateend) <= new Date())
|
||||||
.sort((a, b) => new Date(b.dateend) - new Date(a.dateend))
|
.sort((a, b) => new Date(b.dateend) - new Date(a.dateend))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
console.log(completedVotes.value);
|
||||||
|
|
||||||
const loadVoteDetails = async (id) => {
|
const loadVoteDetails = async (id) => {
|
||||||
try {
|
try {
|
||||||
const data = await getVoteDetail(id);
|
const data = await getVoteDetail(id);
|
||||||
@@ -166,7 +173,7 @@ export default {
|
|||||||
editVoteModal.value = false;
|
editVoteModal.value = false;
|
||||||
resultsModal.value = false;
|
resultsModal.value = false;
|
||||||
selectedVoting.value = null;
|
selectedVoting.value = null;
|
||||||
router.push({ name: "VoteHomePage" });
|
router.push({name: "VoteHomePage"});
|
||||||
updating("active");
|
updating("active");
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -176,13 +183,13 @@ export default {
|
|||||||
if (type === "vote") {
|
if (type === "vote") {
|
||||||
await loadVoteDetails(voting.id);
|
await loadVoteDetails(voting.id);
|
||||||
voteModal.value = true;
|
voteModal.value = true;
|
||||||
router.push({ name: "Voting", params: { id: voting.id } });
|
router.push({name: "Voting", params: {id: voting.id}});
|
||||||
} else if (type === "edit") {
|
} else if (type === "edit") {
|
||||||
editVoteModal.value = true;
|
editVoteModal.value = true;
|
||||||
router.push({ name: "EditVote", params: { id: voting.id } });
|
router.push({name: "EditVote", params: {id: voting.id}});
|
||||||
} else if (type === "results") {
|
} else if (type === "results") {
|
||||||
resultsModal.value = true;
|
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;
|
selectedVoting.value = voting || null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ immediate: true }
|
{immediate: true}
|
||||||
);
|
);
|
||||||
|
|
||||||
updating("active");
|
updating("active");
|
||||||
|
updating("completed");
|
||||||
|
|
||||||
return {
|
return {
|
||||||
currentTab,
|
currentTab,
|
||||||
@@ -228,6 +236,7 @@ export default {
|
|||||||
deleteVoting,
|
deleteVoting,
|
||||||
updating,
|
updating,
|
||||||
res,
|
res,
|
||||||
|
testResults
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user