Files
PORTAL_COD2/src/front/src/components/vote/VoteResult.vue
T
2025-01-21 09:44:56 +03:00

84 lines
2.3 KiB
Vue

<template>
<v-container>
<v-row>
<v-col cols="12">
<v-card class="mb-4" outlined>
<v-card-title>Победитель: {{ winner.employee?.fio || winner.name }}</v-card-title>
<v-card-subtitle>
Количество голосов: {{ winner?.count || 0 }}
</v-card-subtitle>
</v-card>
</v-col>
</v-row>
<v-row>
<v-col cols="12">
<v-card class="mb-4" outlined>
<v-card-title>Топ 10</v-card-title>
<v-card-text>
<v-list>
<v-list-item v-for="(answer, index) in topResults" :key="index">
<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-container>
</template>
<script>
import { computed } from 'vue';
export default {
name: 'VoteResult',
props: {
data: {
type: Object,
required: true,
},
},
setup(props) {
// Получаем список ответов
const answers = computed(() => props.data.questions[0]?.answers || []);
// Находим победителя
const winner = computed(() => {
if(props.data.questions[0].settings.choice=='employee'){
return answers.value.reduce(
(max, answer) => (answer.count > max.count ? answer : max),
{count: 0, employee: {fio: '', department: '', post: ''}}
);
}
return answers.value.reduce( (max, answer) => (answer.count > max.count ? answer : max),{count:0,name:""})
});
// Сортируем результаты и выбираем топ-5
const topResults = computed(() => {
return [...answers.value]
.sort((a, b) => b.count - a.count)
.slice(0, 10); // Берем первые 5 элементов
});
return {
winner,
topResults,
};
},
};
</script>
<style scoped>
h1 {
margin-bottom: 20px;
}
</style>