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
+263 -233

No files matched your search

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