Update VoteResult.vue

This commit is contained in:
Nukeap committed 2025-01-21 09:44:56 +03:00
1 parent 5ae668f1bb
commit e063d5c755
1 file changed
+10 -6
+10 -6
View File
@@ -3,7 +3,8 @@
<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?.employee.fio || 'Нет данных' }}</v-card-title> <v-card-title>Победитель: {{ winner.employee?.fio || winner.name }}</v-card-title>
<v-card-subtitle> <v-card-subtitle>
Количество голосов: {{ winner?.count || 0 }} Количество голосов: {{ winner?.count || 0 }}
</v-card-subtitle> </v-card-subtitle>
@@ -14,16 +15,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>Топ 5</v-card-title> <v-card-title>Топ 10</v-card-title>
<v-card-text> <v-card-text>
<v-list> <v-list>
<v-list-item v-for="(answer, index) in topResults" :key="index"> <v-list-item v-for="(answer, index) in topResults" :key="index">
<p> <p>
<strong>{{ answer.employee.fio }}</strong>: {{ answer.count }} голосов <strong>{{ answer.employee?answer.employee.fio:answer.name }}</strong>: {{ answer.count }} голосов
<br /> <br />
<small>Отдел: {{ answer.employee.department }}</small> <small>Отдел: {{ answer.employee?answer.employee.department:'' }}</small>
<br /> <br />
<small>Должность: {{ answer.employee.post }}</small> <small>Должность: {{ answer.employee?answer.employee.post:'' }}</small>
</p> </p>
</v-list-item> </v-list-item>
</v-list> </v-list>
@@ -51,17 +52,20 @@ export default {
// Находим победителя // Находим победителя
const winner = computed(() => { const winner = computed(() => {
if(props.data.questions[0].settings.choice=='employee'){
return answers.value.reduce( return answers.value.reduce(
(max, answer) => (answer.count > max.count ? answer : max), (max, answer) => (answer.count > max.count ? answer : max),
{count: 0, employee: {fio: '', department: '', post: ''}} {count: 0, employee: {fio: '', department: '', post: ''}}
); );
}
return answers.value.reduce( (max, answer) => (answer.count > max.count ? answer : max),{count:0,name:""})
}); });
// Сортируем результаты и выбираем топ-5 // Сортируем результаты и выбираем топ-5
const topResults = computed(() => { const topResults = computed(() => {
return [...answers.value] return [...answers.value]
.sort((a, b) => b.count - a.count) .sort((a, b) => b.count - a.count)
.slice(0, 5); // Берем первые 5 элементов .slice(0, 10); // Берем первые 5 элементов
}); });
return { return {