P-98 Результаты голосования

This commit is contained in:
Denzel committed 2025-01-21 10:41:48 +03:00
1 parent f75ec3cd73
commit 3ed8723673
4 files changed
+38 -38

No files matched your search

@@ -49,7 +49,7 @@
<v-list v-model:selected="result[question.id]" density="compact" select-strategy="leaf" slim style="max-height: 100%; overflow-y: auto;"> <v-list v-model:selected="result[question.id]" density="compact" select-strategy="leaf" slim style="max-height: 100%; overflow-y: auto;">
<v-list-item v-for="answer in question.answers" :key="answer.id" :value="answer.id" <v-list-item v-for="answer in question.answers" :key="answer.id" :value="answer.id"
density="compact"> density="compact">
{{ answer.name }} {{ answer.employee?.fio || answer.name }}
<template v-slot:prepend="{ isSelected }"> <template v-slot:prepend="{ isSelected }">
<v-list-item-action start> <v-list-item-action start>
<v-checkbox-btn :model-value="isSelected"></v-checkbox-btn> <v-checkbox-btn :model-value="isSelected"></v-checkbox-btn>
+13 -9
View File
@@ -4,14 +4,15 @@
<v-tooltip bottom> <v-tooltip bottom>
<template v-slot:activator="{ props }"> <template v-slot:activator="{ props }">
<span <span
v-bind="props" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;"
style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;"> v-bind="props">
{{ voteCard.name }} {{ voteCard.name }}
</span> </span>
</template> </template>
<span>{{ voteCard.name }}</span> <span>{{ voteCard.name }}</span>
</v-tooltip> </v-tooltip>
<v-btn v-if="user.id === voteCard.author || user.is_superuser" flat size="medium" @click="$emit('openEditVoteModal', voteCard)"> <v-btn v-if="user.id === voteCard.author || user.is_superuser" flat size="medium"
@click="$emit('openEditVoteModal', voteCard)">
<v-icon color="orange-lighten-1">mdi-pencil</v-icon> <v-icon color="orange-lighten-1">mdi-pencil</v-icon>
</v-btn> </v-btn>
</v-card-text> </v-card-text>
@@ -33,17 +34,20 @@
<v-tooltip bottom> <v-tooltip bottom>
<template v-slot:activator="{ props }"> <template v-slot:activator="{ props }">
<span <span
v-bind="props" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;"
style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;"> v-bind="props">
{{ voteCard.description }} {{ voteCard.description }}
</span> </span>
</template> </template>
<span>{{ voteCard.description }}</span> <span>{{ voteCard.description }}</span>
</v-tooltip> </v-tooltip>
</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 v-else class="font-weight-bold text-center"> Завершено: {{
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"
@@ -102,8 +106,8 @@ export default {
components: {Timer}, components: {Timer},
emits: ['openVoteModal', 'openEditVoteModal', 'deleteVoting', 'openResultModal'], emits: ['openVoteModal', 'openEditVoteModal', 'deleteVoting', 'openResultModal'],
props: { props: {
isFinished:{ isFinished: {
type:Boolean, type: Boolean,
default: false default: false
}, },
voteCard: { voteCard: {
+21 -23
View File
@@ -1,35 +1,40 @@
<template> <template>
<v-container> <v-container>
<v-row v-for="(question, questionIndex) in questions" :key="questionIndex"> <v-tabs v-model="activeTab" class="mb-4">
<v-card flat> <v-tab v-for="(question, questionIndex) in questions" :key="questionIndex">
<v-card-title>
Опрос {{ question.numb }}: {{ question.name || 'Без названия' }} Опрос {{ question.numb }}: {{ question.name || 'Без названия' }}
</v-card-title> </v-tab>
</v-card> </v-tabs>
<v-tabs-window v-model="activeTab">
<v-tabs-window-item v-for="(question, questionIndex) in questions" :key="questionIndex">
<v-row>
<!-- Победитель -->
<v-col cols="12"> <v-col cols="12">
<v-card-title class="d-flex ga-2 align-center"> <v-card-title class="d-flex ga-2 align-center">
<h4 class="text-teal-darken-4">Победитель:</h4> <h3>{{ getWinner(question).employee?.fio || getWinner(question).name }} 🏆</h3> <h4 class="text-teal-darken-4">Победитель:</h4>
<h3>{{ getWinner(question).employee?.fio || getWinner(question).name }} 🏆</h3>
</v-card-title> </v-card-title>
<v-card-subtitle> <v-card-subtitle>
Количество голосов: {{ getWinner(question)?.count || 0 }} Количество голосов: {{ getWinner(question)?.count || 0 }}
</v-card-subtitle> </v-card-subtitle>
</v-col> </v-col>
<!-- Топ 10 -->
<v-col cols="12"> <v-col cols="12">
<v-card class="mb-4" outlined> <v-card class="mb-4">
<v-card-title class="text-teal-darken-3">Топ 10</v-card-title> <v-card-title class="text-teal-darken-3">Топ 10</v-card-title>
<v-card-text> <v-card-text>
<v-list> <v-list style="max-height: 40vh; overflow-y: auto;">
<v-list-item <v-list-item
v-for="(answer, answerIndex) in getTopResults(question)" v-for="(answer, answerIndex) in getTopResults(question)"
:key="answerIndex" :key="answerIndex"
> >
<p> <p>
<strong>{{ answer.employee ? answer.employee.fio : answer.name }}</strong>: {{ answer.count }} голосов <strong>{{ answer.employee ? answer.employee.fio : answer.name }}</strong>: {{ answer.count }} голосов
<br/> <br />
<small>Отдел: {{ answer.employee ? answer.employee.department : '' }}</small> <small>Отдел: {{ answer.employee ? answer.employee.department : '' }}</small>
<br/> <br />
<small>Должность: {{ answer.employee ? answer.employee.post : '' }}</small> <small>Должность: {{ answer.employee ? answer.employee.post : '' }}</small>
</p> </p>
</v-list-item> </v-list-item>
@@ -38,11 +43,13 @@
</v-card> </v-card>
</v-col> </v-col>
</v-row> </v-row>
</v-tabs-window-item>
</v-tabs-window>
</v-container> </v-container>
</template> </template>
<script> <script>
import {computed} from 'vue'; import { computed, ref } from 'vue';
export default { export default {
name: 'VoteResult', name: 'VoteResult',
@@ -53,10 +60,9 @@ export default {
}, },
}, },
setup(props) { setup(props) {
// Извлекаем вопросы const activeTab = ref(0);
const questions = computed(() => props.data.questions || []); const questions = computed(() => props.data.questions || []);
// Функция для поиска победителя по вопросу
const getWinner = (question) => { const getWinner = (question) => {
return question.answers.reduce( return question.answers.reduce(
(max, answer) => (answer.count > max.count ? answer : max), (max, answer) => (answer.count > max.count ? answer : max),
@@ -64,14 +70,12 @@ export default {
); );
}; };
// Функция для получения топ-10 результатов по вопросу
const getTopResults = (question) => { const getTopResults = (question) => {
return [...question.answers] return [...question.answers].sort((a, b) => b.count - a.count).slice(0, 10);
.sort((a, b) => b.count - a.count)
.slice(0, 10);
}; };
return { return {
activeTab,
questions, questions,
getWinner, getWinner,
getTopResults, getTopResults,
@@ -79,9 +83,3 @@ export default {
}, },
}; };
</script> </script>
<style scoped>
h1 {
margin-bottom: 20px;
}
</style>
+3 -5
View File
@@ -39,8 +39,8 @@
<!-- Конструктор --> <!-- Конструктор -->
<v-tabs-window-item value="constructor" class="h-100 overflow-auto"> <v-tabs-window-item class="h-100 overflow-auto" value="constructor">
<VoteConstructor @updating="updating" /> <VoteConstructor @updating="updating"/>
</v-tabs-window-item> </v-tabs-window-item>
<!-- </v-tabs-window> --> <!-- </v-tabs-window> -->
@@ -69,9 +69,7 @@
<v-dialog v-model="resultsModal" max-width="1200px" @click:outside="closeModal"> <v-dialog v-model="resultsModal" 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>
<VoteResult :data="result"/> <VoteResult :data="result"/>
</v-card-text>
<v-card-actions> <v-card-actions>
<v-btn @click="closeModal">Закрыть</v-btn> <v-btn @click="closeModal">Закрыть</v-btn>
</v-card-actions> </v-card-actions>
@@ -179,7 +177,7 @@ export default {
} }
}; };
watch(currentTab,async () => await updating(currentTab.value)) watch(currentTab, async () => await updating(currentTab.value))
watch( watch(
() => route, () => route,