86 lines
2.7 KiB
Vue
86 lines
2.7 KiB
Vue
<template>
|
|
<v-container>
|
|
<v-tabs v-model="activeTab" class="mb-4">
|
|
<v-tab v-for="(question, questionIndex) in questions" :key="questionIndex">
|
|
Опрос {{ question.numb }}: {{ question.name || 'Без названия' }}
|
|
</v-tab>
|
|
</v-tabs>
|
|
|
|
<v-tabs-window v-model="activeTab">
|
|
<v-tabs-window-item v-for="(question, questionIndex) in questions" :key="questionIndex">
|
|
<v-row>
|
|
<!-- Победитель -->
|
|
<v-col cols="12">
|
|
<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>
|
|
|
|
<!-- Топ 10 -->
|
|
<v-col cols="12">
|
|
<v-card class="mb-4">
|
|
<v-card-title class="text-teal-darken-3">Топ 10</v-card-title>
|
|
<v-card-text>
|
|
<v-list style="max-height: 40vh; overflow-y: auto;">
|
|
<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>
|
|
</p>
|
|
</v-list-item>
|
|
</v-list>
|
|
</v-card-text>
|
|
</v-card>
|
|
</v-col>
|
|
</v-row>
|
|
</v-tabs-window-item>
|
|
</v-tabs-window>
|
|
</v-container>
|
|
</template>
|
|
|
|
<script>
|
|
import { computed, ref } from 'vue';
|
|
|
|
export default {
|
|
name: 'VoteResult',
|
|
props: {
|
|
data: {
|
|
type: Object,
|
|
required: true,
|
|
},
|
|
},
|
|
setup(props) {
|
|
const activeTab = ref(0);
|
|
const questions = computed(() => props.data.questions || []);
|
|
|
|
const getWinner = (question) => {
|
|
return question.answers.reduce(
|
|
(max, answer) => (answer.count > max.count ? answer : max),
|
|
{count: 0, employee: {fio: '', department: '', post: ''}, name: ''}
|
|
);
|
|
};
|
|
|
|
const getTopResults = (question) => {
|
|
return [...question.answers].sort((a, b) => b.count - a.count).slice(0, 10);
|
|
};
|
|
|
|
return {
|
|
activeTab,
|
|
questions,
|
|
getWinner,
|
|
getTopResults,
|
|
};
|
|
},
|
|
};
|
|
</script>
|