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
+75 -75

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-item v-for="answer in question.answers" :key="answer.id" :value="answer.id"
density="compact">
{{ answer.name }}
{{ answer.employee?.fio || answer.name }}
<template v-slot:prepend="{ isSelected }">
<v-list-item-action start>
<v-checkbox-btn :model-value="isSelected"></v-checkbox-btn>
+13 -9
View File
@@ -4,14 +4,15 @@
<v-tooltip bottom>
<template v-slot:activator="{ props }">
<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 }}
</span>
</template>
<span>{{ voteCard.name }}</span>
</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-btn>
</v-card-text>
@@ -33,17 +34,20 @@
<v-tooltip bottom>
<template v-slot:activator="{ props }">
<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 }}
</span>
</template>
<span>{{ voteCard.description }}</span>
</v-tooltip>
</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"/>
<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">
<template v-if="!isFinished">
<v-btn :disabled="voteCard.is_passed || timeChange" color="teal-darken-4" prepend-icon="mdi-vote-outline"
@@ -102,8 +106,8 @@ export default {
components: {Timer},
emits: ['openVoteModal', 'openEditVoteModal', 'deleteVoting', 'openResultModal'],
props: {
isFinished:{
type:Boolean,
isFinished: {
type: Boolean,
default: false
},
voteCard: {
+47 -49
View File
@@ -1,48 +1,55 @@
<template>
<v-container>
<v-row v-for="(question, questionIndex) in questions" :key="questionIndex">
<v-card flat>
<v-card-title>
Опрос {{ question.numb }}: {{ question.name || 'Без названия' }}
</v-card-title>
</v-card>
<v-tabs v-model="activeTab" class="mb-4">
<v-tab v-for="(question, questionIndex) in questions" :key="questionIndex">
Опрос {{ question.numb }}: {{ question.name || 'Без названия' }}
</v-tab>
</v-tabs>
<v-col cols="12">
<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>
</v-card-title>
<v-card-subtitle>
Количество голосов: {{ getWinner(question)?.count || 0 }}
</v-card-subtitle>
</v-col>
<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-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>
</v-card-title>
<v-card-subtitle>
Количество голосов: {{ getWinner(question)?.count || 0 }}
</v-card-subtitle>
</v-col>
<v-col cols="12">
<v-card class="mb-4" outlined>
<v-card-title class="text-teal-darken-3">Топ 10</v-card-title>
<v-card-text>
<v-list>
<v-list-item
v-for="(answer, answerIndex) in getTopResults(question)"
:key="answerIndex"
>
<p>
<strong>{{ answer.employee ? answer.employee.fio : answer.name }}</strong>: {{ answer.count }} голосов
<br/>
<small>Отдел: {{ answer.employee ? answer.employee.department : '' }}</small>
<br/>
<small>Должность: {{ answer.employee ? answer.employee.post : '' }}</small>
</p>
</v-list-item>
</v-list>
</v-card-text>
</v-card>
</v-col>
</v-row>
<!-- Топ 10 -->
<v-col cols="12">
<v-card class="mb-4">
<v-card-title class="text-teal-darken-3">Топ 10</v-card-title>
<v-card-text>
<v-list style="max-height: 40vh; overflow-y: auto;">
<v-list-item
v-for="(answer, answerIndex) in getTopResults(question)"
:key="answerIndex"
>
<p>
<strong>{{ answer.employee ? answer.employee.fio : answer.name }}</strong>: {{ answer.count }} голосов
<br />
<small>Отдел: {{ answer.employee ? answer.employee.department : '' }}</small>
<br />
<small>Должность: {{ answer.employee ? answer.employee.post : '' }}</small>
</p>
</v-list-item>
</v-list>
</v-card-text>
</v-card>
</v-col>
</v-row>
</v-tabs-window-item>
</v-tabs-window>
</v-container>
</template>
<script>
import {computed} from 'vue';
import { computed, ref } from 'vue';
export default {
name: 'VoteResult',
@@ -53,10 +60,9 @@ export default {
},
},
setup(props) {
// Извлекаем вопросы
const activeTab = ref(0);
const questions = computed(() => props.data.questions || []);
// Функция для поиска победителя по вопросу
const getWinner = (question) => {
return question.answers.reduce(
(max, answer) => (answer.count > max.count ? answer : max),
@@ -64,14 +70,12 @@ export default {
);
};
// Функция для получения топ-10 результатов по вопросу
const getTopResults = (question) => {
return [...question.answers]
.sort((a, b) => b.count - a.count)
.slice(0, 10);
return [...question.answers].sort((a, b) => b.count - a.count).slice(0, 10);
};
return {
activeTab,
questions,
getWinner,
getTopResults,
@@ -79,9 +83,3 @@ export default {
},
};
</script>
<style scoped>
h1 {
margin-bottom: 20px;
}
</style>
+14 -16
View File
@@ -36,20 +36,20 @@
<v-tabs-window-item class="h-100 overflow-auto bg-yellow" value="constructor">
<VoteConstructor @updating="updating"/>
</v-tabs-window-item>
<!-- Конструктор -->
<v-tabs-window-item value="constructor" class="h-100 overflow-auto">
<VoteConstructor @updating="updating" />
</v-tabs-window-item>
<!-- </v-tabs-window> -->
</v-window>
<!-- Модальные окна -->
<v-dialog v-model="voteModal" @click:outside="closeModal">
<!-- Конструктор -->
<v-tabs-window-item class="h-100 overflow-auto" value="constructor">
<VoteConstructor @updating="updating"/>
</v-tabs-window-item>
<!-- </v-tabs-window> -->
</v-window>
<!-- Модальные окна -->
<v-dialog v-model="voteModal" @click:outside="closeModal">
<CurrentVote :data="res" @closer="closeModal"/>
</v-dialog>
@@ -69,9 +69,7 @@
<v-dialog v-model="resultsModal" max-width="1200px" @click:outside="closeModal">
<v-card>
<v-card-title>Результаты голосования: {{ selectedVoting?.title }}</v-card-title>
<v-card-text>
<VoteResult :data="result"/>
</v-card-text>
<VoteResult :data="result"/>
<v-card-actions>
<v-btn @click="closeModal">Закрыть</v-btn>
</v-card-actions>
@@ -179,7 +177,7 @@ export default {
}
};
watch(currentTab,async () => await updating(currentTab.value))
watch(currentTab, async () => await updating(currentTab.value))
watch(
() => route,