217 lines
7.8 KiB
Vue
217 lines
7.8 KiB
Vue
<template>
|
|
<v-container>
|
|
<div class="text-end">
|
|
<v-btn class="" color="red-darken-1" density="compact" icon="mdi-close-thick" size="small"
|
|
@click="$emit('closer')">
|
|
</v-btn>
|
|
</div>
|
|
<v-card-title class="text-subtitle-1">Результат голосования: {{ title }}</v-card-title>
|
|
<v-card-subtitle class="text-subtitle-2">{{ description }}</v-card-subtitle>
|
|
<v-tabs v-model="activeTab" class="mb-4">
|
|
<v-tab
|
|
v-for="(question, questionIndex) in questions"
|
|
:key="questionIndex"
|
|
>
|
|
<template v-if="shouldShowTooltip(question.name || 'Без названия', 10)">
|
|
<v-tooltip bottom>
|
|
<template v-slot:activator="{ props }">
|
|
<span v-bind="props">
|
|
{{ truncateText(question.name || 'Без названия', 10) }}
|
|
</span>
|
|
</template>
|
|
<span>{{ question.name || 'Без названия' }}</span>
|
|
</v-tooltip>
|
|
</template>
|
|
<template v-else>
|
|
<span>{{ truncateText(question.name || 'Без названия', 10) }}</span>
|
|
</template>
|
|
</v-tab>
|
|
<v-tab>Не голосовали</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">
|
|
<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>
|
|
</v-card-title>
|
|
<v-card-subtitle>
|
|
Количество голосов: {{ getWinner(question)?.count || 0 }}
|
|
</v-card-subtitle>
|
|
</v-col>
|
|
<v-col cols="12">
|
|
<v-card class="mb-4">
|
|
<v-card-title class="text-teal-darken-3">Топ {{ getTopResults(question).length }}</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>
|
|
<v-avatar v-if="answer.file === null && answer.employee"
|
|
:image="checkremote(`${spravURL()}${answer.employee.login}.jpg`)"
|
|
class="cursor-pointer"
|
|
@click.stop="opendialog(checkremote(`${spravURL()}${answer.employee.login}.jpg`))"/>
|
|
<v-avatar v-if="answer.file !== null" :image="baseURL.slice(0, -1) + answer.file"
|
|
class="cursor-pointer"
|
|
@click.stop="opendialog(answer)"/>
|
|
<strong class="ml-4">{{ answer.employee ? answer.employee.fio : answer.name }}</strong>:
|
|
{{ answer.count }}
|
|
{{ voteCount(answer.count) }}
|
|
<template v-if="answer.employee">
|
|
<br/>
|
|
<small>Отдел: {{ answer.employee ? answer.employee.department : '' }}</small>
|
|
<br/>
|
|
<small>Должность: {{ answer.employee ? answer.employee.post : '' }}</small>
|
|
</template>
|
|
</p>
|
|
<v-progress-linear
|
|
:model-value="getPercentage(answer.count, question)"
|
|
color="teal-darken-4"
|
|
height="13"
|
|
rounded
|
|
striped
|
|
>
|
|
<template v-slot:default="{ value }">
|
|
<strong v-if="value < 50" class="text-grey-darken-3">{{ Math.ceil(value) }}%</strong>
|
|
<strong v-else class="text-grey-lighten-5">{{ Math.ceil(value) }}%</strong>
|
|
</template>
|
|
</v-progress-linear>
|
|
</v-list-item>
|
|
</v-list>
|
|
</v-card-text>
|
|
</v-card>
|
|
</v-col>
|
|
</v-row>
|
|
</v-tabs-window-item>
|
|
<!-- Не голосовали -->
|
|
<!-- <v-tabs-window-item v-for="(question, questionIndex) in questions" :key="questionIndex">-->
|
|
<!-- <v-card-title class="text-red-darken-3">Не голосовали:</v-card-title>-->
|
|
<!-- <v-list style="max-height: 40vh; overflow-y: auto;">-->
|
|
<!-- <v-list-item-->
|
|
<!-- v-for="(answer, answerIndex) in getTopResults(question)"-->
|
|
<!-- :key="answerIndex"-->
|
|
<!-- >-->
|
|
<!-- {{answer.employee.fio}}-->
|
|
<!-- </v-list-item>-->
|
|
<!-- </v-list>-->
|
|
<!-- </v-tabs-window-item>-->
|
|
</v-tabs-window>
|
|
</v-container>
|
|
|
|
<v-dialog v-model="dialog" max-width="100vh">
|
|
<v-card max-height="800">
|
|
<v-card-title class="v-row">
|
|
<div class="v-col-auto">
|
|
{{ activepick.answer }}
|
|
</div>
|
|
<v-spacer></v-spacer>
|
|
<div>
|
|
<v-btn color="red-darken-1" density="compact" icon="mdi-close-thick" size="small" @click="dialog=false"/>
|
|
</div>
|
|
|
|
</v-card-title>
|
|
<v-card-item>
|
|
<v-img :src="activepick.file !== undefined ? baseURL.slice(0, -1) + activepick.file : activepick"
|
|
max-height="600"></v-img>
|
|
</v-card-item>
|
|
</v-card>
|
|
</v-dialog>
|
|
</template>
|
|
|
|
<script>
|
|
import {computed, ref} from 'vue';
|
|
import {baseURL, spravURL} from "@/utils/axios-api";
|
|
import {checkremote} from "@/utils/universal_functions";
|
|
|
|
export default {
|
|
name: 'VoteResult',
|
|
methods: {
|
|
checkremote,
|
|
spravURL() {
|
|
return spravURL
|
|
}
|
|
},
|
|
computed: {
|
|
baseURL() {
|
|
return baseURL
|
|
}
|
|
},
|
|
emits: ['closer'],
|
|
props: {
|
|
data: {
|
|
type: Object,
|
|
required: true,
|
|
},
|
|
},
|
|
setup(props) {
|
|
const activeTab = ref(0);
|
|
const questions = computed(() => props.data.questions || []);
|
|
|
|
const title = props.data.name;
|
|
const description = props.data.description;
|
|
|
|
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);
|
|
};
|
|
|
|
const truncateText = (text, maxLength) => {
|
|
if (!text) return '';
|
|
return text.length > maxLength ? text.slice(0, maxLength) + '…' : text;
|
|
};
|
|
|
|
const shouldShowTooltip = (text, maxLength) => {
|
|
return text && text.length > maxLength;
|
|
};
|
|
|
|
const voteCount = (count) => {
|
|
let currentVote = '';
|
|
const lastDigit = count % 10;
|
|
if (lastDigit === 1) currentVote = 'голос'
|
|
if (lastDigit > 1) currentVote = 'голоса'
|
|
if (lastDigit > 4 || count === 0 || count === 11 || count === 12 || count === 13 || count === 14) currentVote = 'голосов'
|
|
return currentVote
|
|
}
|
|
|
|
const getPercentage = (count, question) => {
|
|
const totalVotes = question.answers.reduce((sum, answer) => sum + answer.count, 0);
|
|
return totalVotes > 0 ? (count / totalVotes) * 100 : 0;
|
|
};
|
|
|
|
const activepick = ref(null)
|
|
const dialog = ref(false)
|
|
const opendialog = (val) => {
|
|
dialog.value = true
|
|
activepick.value = val
|
|
}
|
|
|
|
return {
|
|
activepick,
|
|
opendialog,
|
|
dialog,
|
|
activeTab,
|
|
questions,
|
|
getWinner,
|
|
getTopResults,
|
|
truncateText,
|
|
shouldShowTooltip,
|
|
voteCount,
|
|
title,
|
|
description,
|
|
getPercentage
|
|
};
|
|
},
|
|
};
|
|
</script>
|