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

This commit is contained in:
Denzel committed 2025-01-17 14:11:32 +03:00
1 parent a8bba7cb8b
commit 86dcc7f375
3 files changed
+265 -235

No files matched your search

+135 -130
View File
@@ -1,138 +1,143 @@
<template>
<v-row class="px-2">
<v-card variant="text"
:disabled="disabledcard.disabled"
class="py-2 mx-auto">
<v-card-title class="text-body-1"> До {{ disabledcard.text }} голосования осталось: </v-card-title>
<v-row no-gutters class="align-baseline">
<v-col class="text-center">
<v-card class="bg-yellow-darken-4">
<div>{{ displayDays }}</div>
</v-card>
<span class="text-caption">{{ declOfNum(displayDays, [' день', ' дня', ' дней']) }}</span>
</v-col>
<v-col cols="auto" class="px-1">:</v-col>
<v-col class="text-center">
<v-card class="bg-yellow-darken-4">
<div>{{ displayHours }}</div>
</v-card>
<span class="text-caption">{{ declOfNum(displayHours, [' час', ' часа', ' часов']) }}</span>
</v-col>
<v-col cols="auto" class="px-1">:</v-col>
<v-col class="text-center">
<v-card class="bg-yellow-darken-4">
<div>{{ displayMinutes }}</div>
</v-card>
<span class="text-caption">{{ declOfNum(displayMinutes, [' минута', ' минуты', ' минут']) }}</span>
</v-col>
<v-col cols="auto" class="px-1">:</v-col>
<v-col class="text-center">
<v-card class="bg-yellow-darken-4">
<div>{{ displaySeconds }}</div>
</v-card>
<span class="text-caption">{{ declOfNum(displaySeconds, [' секунда', ' секунды', ' секунд']) }}</span>
</v-col>
</v-row>
</v-card>
</v-row>
<v-row class="px-2">
<v-card variant="text"
:disabled="disabledcard.disabled"
class="py-2 mx-auto">
<v-card-title class="text-body-1">
<template v-if="!isFinished">
До {{ disabledcard.text }} голосования осталось:
</template>
<template v-else>
Завершено: {{ finishedDate }}
</template>
</v-card-title>
<v-row v-if="!isFinished" no-gutters class="align-baseline">
<v-col class="text-center">
<v-card class="bg-yellow-darken-4">
<div>{{ displayDays }}</div>
</v-card>
<span class="text-caption">{{ declOfNum(displayDays, [' день', ' дня', ' дней']) }}</span>
</v-col>
<v-col cols="auto" class="px-1">:</v-col>
<v-col class="text-center">
<v-card class="bg-yellow-darken-4">
<div>{{ displayHours }}</div>
</v-card>
<span class="text-caption">{{ declOfNum(displayHours, [' час', ' часа', ' часов']) }}</span>
</v-col>
<v-col cols="auto" class="px-1">:</v-col>
<v-col class="text-center">
<v-card class="bg-yellow-darken-4">
<div>{{ displayMinutes }}</div>
</v-card>
<span class="text-caption">{{ declOfNum(displayMinutes, [' минута', ' минуты', ' минут']) }}</span>
</v-col>
<v-col cols="auto" class="px-1">:</v-col>
<v-col class="text-center">
<v-card class="bg-yellow-darken-4">
<div>{{ displaySeconds }}</div>
</v-card>
<span class="text-caption">{{ declOfNum(displaySeconds, [' секунда', ' секунды', ' секунд']) }}</span>
</v-col>
</v-row>
</v-card>
</v-row>
</template>
<script>
import { computed, ref } from 'vue'
export default {
props: {
voteTime: {
type: Object,
default: () => { return {
dateend:new Date().setFullYear(),
datestart:new Date().setFullYear()
}}
}
},
setup(props, {emit}) {
const seconds = 1000
const displayMinutes = ref(0);
const displayHours = ref(0);
const displayDays = ref(0);
const displaySeconds = ref(0)
const minutes = computed(() => {
return seconds * 60
})
const hours = computed(() => {
return minutes.value * 60
})
const days = computed(() => {
return hours.value * 24
})
function declOfNum(value, titles) {
const cases = [2, 0, 1, 1, 1, 2]
return titles[(value % 100 > 4 && value % 100 < 20) ? 2 : cases[(value % 10 < 5) ? value % 10 : 5]]
}
const disabledcard = ref({
text: 'окончания',
disabled: false
})
const dateendorStart = ()=>{
let param = 'dateend'
if (new Date().getTime() < new Date(props.voteTime.datestart).getTime()) {
param='datestart'
disabledcard.value= {
text: 'начала',
disabled: true,
}
emit('changeBtn', true)
} else {
disabledcard.value= {
text: 'окончания',
disabled: false,
}
emit('changeBtn', false)
}
return param
}
function countDown() {
const timer = setInterval(() => {
const date = new Date()
const distance = new Date(props.voteTime[dateendorStart()]).getTime() - date.getTime()
if (distance <= 1) {
clearInterval(timer)
setTimeout(()=>countDown(),1000)
return
}
const daysOf = Math.floor(distance / days.value)
const hoursOf = Math.floor((distance % days.value) / hours.value)
const minutesOf = Math.floor((distance % hours.value) / minutes.value)
const secondsOf = Math.floor((distance % minutes.value) / seconds)
displayDays.value = daysOf < 10 ? "0" + daysOf : daysOf
displayHours.value = hoursOf < 10 ? "0" + hoursOf : hoursOf
displayMinutes.value = minutesOf < 10 ? "0" + minutesOf : minutesOf
displaySeconds.value = secondsOf < 10 ? "0" + secondsOf : secondsOf
}, 1000)
}
countDown()
return {
displayMinutes,
displayHours,
displayDays,
displaySeconds,
declOfNum,
dateendorStart,
disabledcard
}
props: {
voteTime: {
type: Object,
default: () => { return {
dateend: new Date().setFullYear(),
datestart: new Date().setFullYear()
}}
}
},
setup(props, {emit}) {
const seconds = 1000
const displayMinutes = ref(0);
const displayHours = ref(0);
const displayDays = ref(0);
const displaySeconds = ref(0);
const isFinished = ref(false);
const finishedDate = ref('');
const minutes = computed(() => seconds * 60);
const hours = computed(() => minutes.value * 60);
const days = computed(() => hours.value * 24);
function declOfNum(value, titles) {
const cases = [2, 0, 1, 1, 1, 2];
return titles[(value % 100 > 4 && value % 100 < 20) ? 2 : cases[(value % 10 < 5) ? value % 10 : 5]];
}
const disabledcard = ref({
text: 'окончания',
disabled: false
});
const dateendorStart = () => {
let param = 'dateend';
if (new Date().getTime() < new Date(props.voteTime.datestart).getTime()) {
param = 'datestart';
disabledcard.value = {
text: 'начала',
disabled: true,
};
emit('changeBtn', true);
} else {
disabledcard.value = {
text: 'окончания',
disabled: false,
};
emit('changeBtn', false);
}
return param;
};
function countDown() {
const timer = setInterval(() => {
const date = new Date();
const endDate = new Date(props.voteTime.dateend);
const distance = endDate.getTime() - date.getTime();
if (distance <= 0) {
clearInterval(timer);
isFinished.value = true;
finishedDate.value = endDate.toLocaleDateString();
return;
}
const daysOf = Math.floor(distance / days.value);
const hoursOf = Math.floor((distance % days.value) / hours.value);
const minutesOf = Math.floor((distance % hours.value) / minutes.value);
const secondsOf = Math.floor((distance % minutes.value) / seconds);
displayDays.value = daysOf < 10 ? "0" + daysOf : daysOf;
displayHours.value = hoursOf < 10 ? "0" + hoursOf : hoursOf;
displayMinutes.value = minutesOf < 10 ? "0" + minutesOf : minutesOf;
displaySeconds.value = secondsOf < 10 ? "0" + secondsOf : secondsOf;
}, 1000);
}
countDown();
return {
displayMinutes,
displayHours,
displayDays,
displaySeconds,
declOfNum,
dateendorStart,
disabledcard,
isFinished,
finishedDate
};
}
}
</script>
</script>
+108 -89
View File
@@ -1,100 +1,119 @@
<template>
<v-card>
<v-card-text class=" d-flex justify-space-between ga-3 text-h6"> {{ voteCard.name }}
<v-btn flat size="medium" @click="$emit('openEditVoteModal', voteCard)">
<v-icon color="orange-lighten-1">mdi-pencil</v-icon>
</v-btn>
</v-card-text>
<v-row>
<v-col>
<v-card>
<v-card-text class=" d-flex justify-space-between ga-3 text-h6"> {{ voteCard.name }}
<v-btn flat size="medium" @click="$emit('openEditVoteModal', voteCard)">
<v-icon color="orange-lighten-1">mdi-pencil</v-icon>
</v-btn>
</v-card-text>
<v-row>
<v-col>
<v-carousel
cycle
height="200" hide-delimiters
show-arrows="hover">
<v-carousel-item
v-for="(picture, index) in images"
:key="index"
:src="`${baseURL.slice(0, -1)}${picture}`">
</v-carousel-item>
</v-carousel>
</v-col>
</v-row>
<v-card-text class="">{{ voteCard.description }}</v-card-text>
<Timer :voteTime="{ dateend: voteCard.dateend, datestart: voteCard.datestart }"
@changeBtn="(time) => timeChange = time"/>
<v-card-actions class="justify-space-between mt-4 pb-2">
<template v-if="!isFinished">
<v-btn :disabled="voteCard.is_passed || timeChange" color="teal-darken-4" prepend-icon="mdi-vote-outline"
rounded="xl" size="small" variant="outlined" @click="$emit('openVoteModal', voteCard)">
{{ !voteCard.is_passed ? "Проголосовать" : "Уже проголосовали" }}
</v-btn>
</template>
<template v-else>
<v-btn color="teal-darken-4" prepend-icon="mdi-trophy-outline"
rounded="xl" size="small" variant="outlined" @click="$emit('openResultModal', voteCard)">
Результаты
</v-btn>
</template>
<v-btn color="error" size="medium" @click="youSure=true">
<v-icon>mdi-delete</v-icon>
<v-dialog v-model="youSure" width="500">
<v-carousel
show-arrows="hover"
hide-delimiters cycle
height="200">
<v-carousel-item
v-for="(picture, index) in images"
:key="index"
:src="`${baseURL.slice(0, -1)}${picture}`">
</v-carousel-item>
</v-carousel>
</v-col>
</v-row>
<v-card-text class="">{{ voteCard.description }}</v-card-text>
<Timer :voteTime="{ dateend: voteCard.dateend, datestart: voteCard.datestart }" @changeBtn="(time) => timeChange = time" />
<v-card-actions class="justify-space-between mt-4 pb-2">
<v-btn :disabled="voteCard.is_passed || timeChange" color="teal-darken-4" prepend-icon="mdi-vote-outline"
variant="outlined" rounded="xl" size="small" @click="$emit('openVoteModal', voteCard)">
{{ !voteCard.is_passed ? "Проголосовать" : "Уже проголосовали" }}
</v-btn>
<v-btn color="error" @click="youSure=true" size="medium">
<v-icon>mdi-delete</v-icon>
<v-dialog v-model="youSure" width="500">
<v-card max-width="450" class="flex">
<v-btn
class="align-self-end ma-2 text-red"
icon="mdi-close"
variant="text"
size="medium"
@click="youSure = false"
/>
<div class="ml-5 text-h6">
Вы действительно хотите удалить голосование?
</div>
<template v-slot:actions>
<v-btn-group>
<v-btn
class="text-red"
@click="$emit('deleteVoting', voteCard.id), youSure = false">
Да
</v-btn>
<v-btn
class="text-green"
@click="youSure = false">
Нет
</v-btn>
</v-btn-group>
</template>
</v-card>
</v-dialog>
</v-btn>
</v-card-actions>
</v-card>
<v-card class="flex" max-width="450">
<v-btn
class="align-self-end ma-2 text-red"
icon="mdi-close"
size="medium"
variant="text"
@click="youSure = false"
/>
<div class="ml-5 text-h6">
Вы действительно хотите удалить голосование?
</div>
<template v-slot:actions>
<v-btn-group>
<v-btn
class="text-red"
@click="$emit('deleteVoting', voteCard.id), youSure = false">
Да
</v-btn>
<v-btn
class="text-green"
@click="youSure = false">
Нет
</v-btn>
</v-btn-group>
</template>
</v-card>
</v-dialog>
</v-btn>
</v-card-actions>
</v-card>
</template>
<script>
import Timer from "@/components/UI/Timer.vue"
import { baseURL } from "@/utils/axios-api";
import { ref, computed } from 'vue'
export default {
components: { Timer },
emits: ['openVoteModal', 'openEditVoteModal', 'deleteVoting'],
props: {
voteCard: {
type: Object,
default: () => {
return {
id: 0,
name: "",
description: "",
files: [],
dateend: new Date(new Date().getTime() + 600000),
is_passed: true,
}
}
}
},
setup(props) {
const timeChange = ref(false)
const youSure = ref(false)
import {baseURL} from "@/utils/axios-api";
import {computed, ref} from 'vue'
const images = computed(() => {
return props.voteCard.files.length > 0 ? props.voteCard.files : ['/media/defaultimg/vote.png']
})
return { timeChange, baseURL, images, youSure }
export default {
components: {Timer},
emits: ['openVoteModal', 'openEditVoteModal', 'deleteVoting', 'openResultModal'],
props: {
voteCard: {
type: Object,
default: () => {
return {
id: 0,
name: "",
description: "",
files: [],
dateend: new Date(new Date().getTime() + 600000),
is_passed: true,
}
}
}
},
setup(props) {
const timeChange = ref(false)
const youSure = ref(false)
const isFinished = ref(false);
const images = computed(() => {
return props.voteCard.files.length > 0 ? props.voteCard.files : ['/media/defaultimg/vote.png']
})
const date = new Date();
const endDate = new Date(props.voteCard.dateend);
const distance = endDate.getTime() - date.getTime();
if (distance <= 0) {
isFinished.value = true;
}
return {timeChange, baseURL, images, youSure, isFinished}
}
}
</script>
</script>
+22 -16
View File
@@ -46,20 +46,27 @@
lg="3"
md="4"
>
<v-card>
<v-card-title>{{ voting.name }}</v-card-title>
<v-card-subtitle>
Завершено: {{ voting.dateend }}
</v-card-subtitle>
<v-card-actions class="justify-space-between">
<v-btn color="teal-darken-4" size="medium" @click="() => openModal('results', voting)">
Результаты
</v-btn>
<v-btn color="error" size="medium" @click="deleteVoting(voting.id)">
<v-icon>mdi-delete</v-icon>
</v-btn>
</v-card-actions>
</v-card>
<VoteCardVue
:voteCard="voting"
@deleteVoting="deleteVoting"
@openEditVoteModal="(voting) => openModal('edit', voting)"
@openVoteModal="(voting) => openModal('vote', voting)"
@openResultModal="(voting) => openModal('results', voting)"
/>
<!-- <v-card>-->
<!-- <v-card-title>{{ voting.name }}</v-card-title>-->
<!-- <v-card-subtitle>-->
<!-- Завершено: {{ voting.dateend }}-->
<!-- </v-card-subtitle>-->
<!-- <v-card-actions class="justify-space-between">-->
<!-- <v-btn color="teal-darken-4" size="medium" @click="() => openModal('results', voting)">-->
<!-- Результаты-->
<!-- </v-btn>-->
<!-- <v-btn color="error" size="medium" @click="deleteVoting(voting.id)">-->
<!-- <v-icon>mdi-delete</v-icon>-->
<!-- </v-btn>-->
<!-- </v-card-actions>-->
<!-- </v-card>-->
</v-col>
</v-row>
</v-container>
@@ -156,8 +163,6 @@ export default {
.sort((a, b) => new Date(b.dateend) - new Date(a.dateend))
);
console.log(completedVotes.value);
const loadVoteDetails = async (id) => {
try {
const data = await getVoteDetail(id);
@@ -221,6 +226,7 @@ export default {
updating("active");
updating("completed");
console.log(completedVotes);
return {
currentTab,