P-98 Результаты голосования
This commit is contained in:
1 parent
0d75cadf13
commit
46f0ab9570
4 files changed
+60
-29
No files matched your search
@@ -43,7 +43,7 @@
|
|||||||
</v-card-text>
|
</v-card-text>
|
||||||
<Timer v-if ="!isFinished" :voteTime="{ dateend: voteCard.dateend, datestart: voteCard.datestart }"
|
<Timer v-if ="!isFinished" :voteTime="{ dateend: voteCard.dateend, datestart: voteCard.datestart }"
|
||||||
@changeBtn="(time) => timeChange = time"/>
|
@changeBtn="(time) => timeChange = time"/>
|
||||||
<div class="font-weight-bold text-center" v-else> Завершено: {{ new Date(voteCard.dateend).toLocaleDateString() }}</div>
|
<div class="font-weight-bold text-center" v-else> Завершено: {{ new Date(voteCard.dateend).toLocaleDateString() }}</div>
|
||||||
<v-card-actions class="justify-space-between mt-4 pb-2">
|
<v-card-actions class="justify-space-between mt-4 pb-2">
|
||||||
<template v-if="!isFinished">
|
<template v-if="!isFinished">
|
||||||
<v-btn :disabled="voteCard.is_passed || timeChange" color="teal-darken-4" prepend-icon="mdi-vote-outline"
|
<v-btn :disabled="voteCard.is_passed || timeChange" color="teal-darken-4" prepend-icon="mdi-vote-outline"
|
||||||
@@ -60,7 +60,6 @@
|
|||||||
<v-btn v-if="user.id === voteCard.author || user.is_superuser" color="error" size="medium" @click="youSure=true">
|
<v-btn v-if="user.id === voteCard.author || user.is_superuser" color="error" size="medium" @click="youSure=true">
|
||||||
<v-icon>mdi-delete</v-icon>
|
<v-icon>mdi-delete</v-icon>
|
||||||
<v-dialog v-model="youSure" width="500">
|
<v-dialog v-model="youSure" width="500">
|
||||||
|
|
||||||
<v-card class="flex" max-width="450">
|
<v-card class="flex" max-width="450">
|
||||||
<v-btn
|
<v-btn
|
||||||
class="align-self-end ma-2 text-red"
|
class="align-self-end ma-2 text-red"
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
<template>
|
<template>
|
||||||
<v-container>
|
<v-container>
|
||||||
|
|
||||||
<v-row>
|
<v-row>
|
||||||
<v-col cols="12">
|
<v-col cols="12">
|
||||||
<v-card class="mb-4" outlined>
|
<v-card class="mb-4" outlined>
|
||||||
<v-card-title>Победитель: {{ winner.name }}</v-card-title>
|
<v-card-title>Победитель: {{ winner?.employee.fio || 'Нет данных' }}</v-card-title>
|
||||||
<v-card-subtitle>
|
<v-card-subtitle>
|
||||||
Количество голосов: {{ winner.votes }}
|
Количество голосов: {{ winner?.count || 0 }}
|
||||||
</v-card-subtitle>
|
</v-card-subtitle>
|
||||||
</v-card>
|
</v-card>
|
||||||
</v-col>
|
</v-col>
|
||||||
@@ -15,12 +14,16 @@
|
|||||||
<v-row>
|
<v-row>
|
||||||
<v-col cols="12">
|
<v-col cols="12">
|
||||||
<v-card class="mb-4" outlined>
|
<v-card class="mb-4" outlined>
|
||||||
<v-card-title>Все результаты</v-card-title>
|
<v-card-title>Топ 5</v-card-title>
|
||||||
<v-card-text>
|
<v-card-text>
|
||||||
<v-list>
|
<v-list>
|
||||||
<v-list-item v-for="(option, index) in sortedResults" :key="index">
|
<v-list-item v-for="(answer, index) in topResults" :key="index">
|
||||||
<p>
|
<p>
|
||||||
<strong>{{ option.name }}</strong>: {{ option.votes }} голосов
|
<strong>{{ answer.employee.fio }}</strong>: {{ answer.count }} голосов
|
||||||
|
<br />
|
||||||
|
<small>Отдел: {{ answer.employee.department }}</small>
|
||||||
|
<br />
|
||||||
|
<small>Должность: {{ answer.employee.post }}</small>
|
||||||
</p>
|
</p>
|
||||||
</v-list-item>
|
</v-list-item>
|
||||||
</v-list>
|
</v-list>
|
||||||
@@ -37,26 +40,35 @@ import { computed } from 'vue';
|
|||||||
export default {
|
export default {
|
||||||
name: 'VoteResult',
|
name: 'VoteResult',
|
||||||
props: {
|
props: {
|
||||||
results: {
|
data: {
|
||||||
type: Array,
|
type: Object,
|
||||||
required: true,
|
required: true,
|
||||||
default: () => []
|
},
|
||||||
}
|
|
||||||
},
|
},
|
||||||
setup(props) {
|
setup(props) {
|
||||||
|
// Получаем список ответов
|
||||||
|
const answers = computed(() => props.data.questions[0]?.answers || []);
|
||||||
|
|
||||||
|
// Находим победителя
|
||||||
const winner = computed(() => {
|
const winner = computed(() => {
|
||||||
return props.results.reduce((max, option) => (option.votes > max.votes ? option : max), { name: '', votes: 0 });
|
return answers.value.reduce(
|
||||||
|
(max, answer) => (answer.count > max.count ? answer : max),
|
||||||
|
{count: 0, employee: {fio: '', department: '', post: ''}}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
const sortedResults = computed(() => {
|
// Сортируем результаты и выбираем топ-5
|
||||||
return [...props.results].sort((a, b) => b.votes - a.votes);
|
const topResults = computed(() => {
|
||||||
|
return [...answers.value]
|
||||||
|
.sort((a, b) => b.count - a.count)
|
||||||
|
.slice(0, 5); // Берем первые 5 элементов
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
winner,
|
winner,
|
||||||
sortedResults
|
topResults,
|
||||||
};
|
};
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -186,6 +186,16 @@ async function getEmployees() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getVoteResult(id) {
|
||||||
|
try {
|
||||||
|
const response = await axiosApiInstance.get(`/api/vote/getresults/?id=${id}`);
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Ошибка получения результата голосования:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
axiosApiInstance,
|
axiosApiInstance,
|
||||||
@@ -200,5 +210,6 @@ export {
|
|||||||
updateVote,
|
updateVote,
|
||||||
patchVote,
|
patchVote,
|
||||||
deleteVote,
|
deleteVote,
|
||||||
getEmployees
|
getEmployees,
|
||||||
|
getVoteResult
|
||||||
}
|
}
|
||||||
@@ -60,7 +60,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>
|
||||||
<VoteResult :results="testResults"/>
|
<VoteResult :data="result"/>
|
||||||
</v-card-text>
|
</v-card-text>
|
||||||
<v-card-actions>
|
<v-card-actions>
|
||||||
<v-btn @click="closeModal">Закрыть</v-btn>
|
<v-btn @click="closeModal">Закрыть</v-btn>
|
||||||
@@ -79,7 +79,7 @@ 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 VoteResult from "@/components/vote/VoteResult.vue";
|
import VoteResult from "@/components/vote/VoteResult.vue";
|
||||||
import {deleteVote, getVoteDetail, getVotes} from "@/utils/axios-api";
|
import {deleteVote, getVoteDetail, getVoteResult, getVotes} from "@/utils/axios-api";
|
||||||
import {formatDate} from "@vueuse/shared";
|
import {formatDate} from "@vueuse/shared";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -93,17 +93,12 @@ export default {
|
|||||||
{value: "constructor", text: 'Создать новое голосование'},
|
{value: "constructor", text: 'Создать новое голосование'},
|
||||||
]
|
]
|
||||||
|
|
||||||
const testResults = [
|
|
||||||
{name: 'Дональд Трамп', votes: 99},
|
|
||||||
{name: 'Иван Иванов', votes: 30},
|
|
||||||
{name: 'Аркадий Упукник', votes: 95},
|
|
||||||
];
|
|
||||||
|
|
||||||
const currentTab = ref("active");
|
const currentTab = ref("active");
|
||||||
const votes = ref([]);
|
const votes = ref([]);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const res = ref(null);
|
const res = ref(null);
|
||||||
|
const result = ref(null);
|
||||||
|
|
||||||
const updating = async (param) => {
|
const updating = async (param) => {
|
||||||
const data = await getVotes(param);
|
const data = await getVotes(param);
|
||||||
@@ -131,6 +126,16 @@ export default {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const loadVoteResult = async (id) => {
|
||||||
|
try {
|
||||||
|
const data = await getVoteResult(id);
|
||||||
|
result.value = data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Ошибка при загрузке данных голосования:", error);
|
||||||
|
res.value = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const closeModal = () => {
|
const closeModal = () => {
|
||||||
voteModal.value = false;
|
voteModal.value = false;
|
||||||
editVoteModal.value = false;
|
editVoteModal.value = false;
|
||||||
@@ -149,6 +154,7 @@ export default {
|
|||||||
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") {
|
||||||
|
await loadVoteResult(voting.id);
|
||||||
resultsModal.value = true;
|
resultsModal.value = true;
|
||||||
router.push({name: "VoteResults", params: {id: voting.id}});
|
router.push({name: "VoteResults", params: {id: voting.id}});
|
||||||
}
|
}
|
||||||
@@ -175,7 +181,10 @@ export default {
|
|||||||
voteModal.value = true;
|
voteModal.value = true;
|
||||||
}
|
}
|
||||||
if (route.name === "EditVote") editVoteModal.value = true;
|
if (route.name === "EditVote") editVoteModal.value = true;
|
||||||
if (route.name === "VoteResults") resultsModal.value = true;
|
if (route.name === "VoteResults") {
|
||||||
|
await loadVoteResult(route.params.id)
|
||||||
|
resultsModal.value = true;
|
||||||
|
}
|
||||||
selectedVoting.value = voting || null;
|
selectedVoting.value = voting || null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -188,7 +197,6 @@ export default {
|
|||||||
currentTab,
|
currentTab,
|
||||||
votes,
|
votes,
|
||||||
sortedVotes,
|
sortedVotes,
|
||||||
testResults,
|
|
||||||
voteModal,
|
voteModal,
|
||||||
editVoteModal,
|
editVoteModal,
|
||||||
resultsModal,
|
resultsModal,
|
||||||
@@ -198,7 +206,8 @@ export default {
|
|||||||
deleteVoting,
|
deleteVoting,
|
||||||
updating,
|
updating,
|
||||||
res,
|
res,
|
||||||
tabs
|
tabs,
|
||||||
|
result
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user