P-98 Результаты голосования
This commit is contained in:
1 parent
e063d5c755
commit
f75ec3cd73
1 file changed
+41
-37
@@ -1,30 +1,36 @@
|
|||||||
<template>
|
<template>
|
||||||
<v-container>
|
<v-container>
|
||||||
<v-row>
|
<v-row v-for="(question, questionIndex) in questions" :key="questionIndex">
|
||||||
<v-col cols="12">
|
<v-card flat>
|
||||||
<v-card class="mb-4" outlined>
|
<v-card-title>
|
||||||
<v-card-title>Победитель: {{ winner.employee?.fio || winner.name }}</v-card-title>
|
Опрос {{ question.numb }}: {{ question.name || 'Без названия' }}
|
||||||
|
</v-card-title>
|
||||||
|
</v-card>
|
||||||
|
|
||||||
<v-card-subtitle>
|
<v-col cols="12">
|
||||||
Количество голосов: {{ winner?.count || 0 }}
|
<v-card-title class="d-flex ga-2 align-center">
|
||||||
</v-card-subtitle>
|
<h4 class="text-teal-darken-4">Победитель:</h4> <h3>{{ getWinner(question).employee?.fio || getWinner(question).name }} 🏆</h3>
|
||||||
</v-card>
|
</v-card-title>
|
||||||
|
<v-card-subtitle>
|
||||||
|
Количество голосов: {{ getWinner(question)?.count || 0 }}
|
||||||
|
</v-card-subtitle>
|
||||||
</v-col>
|
</v-col>
|
||||||
</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>Топ 10</v-card-title>
|
<v-card-title class="text-teal-darken-3">Топ 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, answerIndex) in getTopResults(question)"
|
||||||
|
:key="answerIndex"
|
||||||
|
>
|
||||||
<p>
|
<p>
|
||||||
<strong>{{ answer.employee?answer.employee.fio:answer.name }}</strong>: {{ answer.count }} голосов
|
<strong>{{ answer.employee ? answer.employee.fio : answer.name }}</strong>: {{ answer.count }} голосов
|
||||||
<br />
|
<br/>
|
||||||
<small>Отдел: {{ answer.employee?answer.employee.department:'' }}</small>
|
<small>Отдел: {{ answer.employee ? answer.employee.department : '' }}</small>
|
||||||
<br />
|
<br/>
|
||||||
<small>Должность: {{ answer.employee?answer.employee.post:'' }}</small>
|
<small>Должность: {{ answer.employee ? answer.employee.post : '' }}</small>
|
||||||
</p>
|
</p>
|
||||||
</v-list-item>
|
</v-list-item>
|
||||||
</v-list>
|
</v-list>
|
||||||
@@ -36,7 +42,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { computed } from 'vue';
|
import {computed} from 'vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'VoteResult',
|
name: 'VoteResult',
|
||||||
@@ -47,30 +53,28 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
setup(props) {
|
setup(props) {
|
||||||
// Получаем список ответов
|
// Извлекаем вопросы
|
||||||
const answers = computed(() => props.data.questions[0]?.answers || []);
|
const questions = computed(() => props.data.questions || []);
|
||||||
|
|
||||||
// Находим победителя
|
// Функция для поиска победителя по вопросу
|
||||||
const winner = computed(() => {
|
const getWinner = (question) => {
|
||||||
if(props.data.questions[0].settings.choice=='employee'){
|
return question.answers.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: ''}, name: ''}
|
||||||
{count: 0, employee: {fio: '', department: '', post: ''}}
|
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
return answers.value.reduce( (max, answer) => (answer.count > max.count ? answer : max),{count:0,name:""})
|
|
||||||
});
|
|
||||||
|
|
||||||
// Сортируем результаты и выбираем топ-5
|
// Функция для получения топ-10 результатов по вопросу
|
||||||
const topResults = computed(() => {
|
const getTopResults = (question) => {
|
||||||
return [...answers.value]
|
return [...question.answers]
|
||||||
.sort((a, b) => b.count - a.count)
|
.sort((a, b) => b.count - a.count)
|
||||||
.slice(0, 10); // Берем первые 5 элементов
|
.slice(0, 10);
|
||||||
});
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
winner,
|
questions,
|
||||||
topResults,
|
getWinner,
|
||||||
|
getTopResults,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user