Update VoteResult.vue
This commit is contained in:
1 parent
5ae668f1bb
commit
e063d5c755
1 file changed
+10
-6
@@ -3,7 +3,8 @@
|
||||
<v-row>
|
||||
<v-col cols="12">
|
||||
<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>
|
||||
Количество голосов: {{ winner?.count || 0 }}
|
||||
</v-card-subtitle>
|
||||
@@ -14,16 +15,16 @@
|
||||
<v-row>
|
||||
<v-col cols="12">
|
||||
<v-card class="mb-4" outlined>
|
||||
<v-card-title>Топ 5</v-card-title>
|
||||
<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.fio }}</strong>: {{ answer.count }} голосов
|
||||
<strong>{{ answer.employee?answer.employee.fio:answer.name }}</strong>: {{ answer.count }} голосов
|
||||
<br />
|
||||
<small>Отдел: {{ answer.employee.department }}</small>
|
||||
<small>Отдел: {{ answer.employee?answer.employee.department:'' }}</small>
|
||||
<br />
|
||||
<small>Должность: {{ answer.employee.post }}</small>
|
||||
<small>Должность: {{ answer.employee?answer.employee.post:'' }}</small>
|
||||
</p>
|
||||
</v-list-item>
|
||||
</v-list>
|
||||
@@ -51,17 +52,20 @@ export default {
|
||||
|
||||
// Находим победителя
|
||||
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, 5); // Берем первые 5 элементов
|
||||
.slice(0, 10); // Берем первые 5 элементов
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user