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

This commit is contained in:
Denzel committed 2025-01-21 10:17:42 +03:00
1 parent e063d5c755
commit f75ec3cd73
1 file changed
+41 -37
+41 -37
View File
@@ -1,30 +1,36 @@
<template>
<v-container>
<v-row>
<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-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-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-row>
<v-row>
<v-col cols="12">
<v-card class="mb-4" outlined>
<v-card-title>Топ 10</v-card-title>
<v-card-title class="text-teal-darken-3">Топ 10</v-card-title>
<v-card-text>
<v-list>
<v-list-item v-for="(answer, index) in topResults" :key="index">
<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>
<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>
@@ -36,7 +42,7 @@
</template>
<script>
import { computed } from 'vue';
import {computed} from 'vue';
export default {
name: 'VoteResult',
@@ -47,30 +53,28 @@ export default {
},
},
setup(props) {
// Получаем список ответов
const answers = computed(() => props.data.questions[0]?.answers || []);
// Извлекаем вопросы
const questions = computed(() => props.data.questions || []);
// Находим победителя
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: ''}}
// Функция для поиска победителя по вопросу
const getWinner = (question) => {
return question.answers.reduce(
(max, answer) => (answer.count > max.count ? answer : max),
{count: 0, employee: {fio: '', department: '', post: ''}, name: ''}
);
}
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 элементов
});
// Функция для получения топ-10 результатов по вопросу
const getTopResults = (question) => {
return [...question.answers]
.sort((a, b) => b.count - a.count)
.slice(0, 10);
};
return {
winner,
topResults,
questions,
getWinner,
getTopResults,
};
},
};