refactor [OVT-62]: фикс победителей

This commit is contained in:
denzel committed 2026-10-21 08:49:33 -04:00
1 parent 53736a1d5d
commit ae8ca296fe
9 files changed
+18556 -17

No files matched your search

+18432
View File
File diff suppressed because it is too large. Load diff
+21 -17
View File
@@ -43,10 +43,10 @@
<strong class="text-teal-darken-4" style="max-width: 800px; white-space: normal; word-wrap: break-word;">{{ department }}</strong>
</v-card-title>
<v-card-subtitle>
Победитель: {{ winner.employee.fio || winner.name }} 🏆
Победитель: {{ getWinnerNames(winner) }} 🏆
</v-card-subtitle>
<v-card-text>
Количество голосов: {{ winner.count }}
Количество голосов: {{ winner[0]?.count || 0 }}
</v-card-text>
</v-card>
</v-col>
@@ -57,10 +57,10 @@
<h3 class="text-center">{{ question.name }}</h3>
<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>
<h3>{{ getWinnerNames(getWinners(question)) }} 🏆</h3>
</v-card-title>
<v-card-subtitle>
Количество голосов: {{ getWinner(question)?.count || 0 }}
Количество голосов: {{ getWinners(question)[0]?.count || 0 }}
</v-card-subtitle>
</v-col>
<v-col cols="12">
@@ -263,11 +263,19 @@ export default {
dialogWinner.value = true;
};
const getWinner = (question) => {
return question.answers.reduce(
(max, answer) => (answer.count > max.count ? answer : max),
{ count: 0, employee: { fio: '', department: '', post: '' }, name: '' },
);
const getWinners = (question) => {
const answers = question.answers || [];
const maxCount = answers.reduce((max, answer) => Math.max(max, answer.count), 0);
if (maxCount === 0) {
return [{ count: 0, employee: { fio: '', department: '', post: '' }, name: '' }];
}
return answers.filter(answer => answer.count === maxCount);
};
const getWinnerNames = (winners) => {
return winners.map(answer => answer.employee?.fio || answer.name).join(' / ');
};
const getTopResults = (question) => {
@@ -366,15 +374,10 @@ export default {
return groups;
}, {});
// Для каждого департамента находим победителя
// Для каждого департамента находим всех лидеров
const winnersByDepartment = {};
for (const department in groupedByDepartment) {
const answers = groupedByDepartment[department];
const winner = answers.reduce(
(max, answer) => (answer.count > max.count ? answer : max),
{ count: 0, employee: { fio: '', department: '', post: '' }, name: '' },
);
winnersByDepartment[department] = winner;
winnersByDepartment[department] = getWinners({ answers: groupedByDepartment[department] });
}
return { groupedByDepartment, winnersByDepartment };
@@ -393,7 +396,8 @@ export default {
dialog,
activeTab,
questions,
getWinner,
getWinners,
getWinnerNames,
getTopResults,
truncateText,
shouldShowTooltip,