Files
PORTAL_COD2/src/front/src/views/VoteHomePage.vue
T
2025-01-15 12:38:17 +03:00

215 lines
6.5 KiB
Vue

<template>
<v-container>
<v-toolbar color="transparent">
<v-toolbar-title>Голосования</v-toolbar-title>
<template v-slot:extension>
<v-tabs v-model="currentTab">
<v-tab :key="0" value="active">Текущие голосования</v-tab>
<v-tab :key="1" value="completed">Завершенные голосования</v-tab>
<v-tab :key="2" value="constructor">Создать новое голосование</v-tab>
</v-tabs>
</template>
</v-toolbar>
<v-tabs-window v-model="currentTab">
<!-- Текущие голосования -->
<v-tabs-window-item value="active">
<v-container>
<v-row>
<v-col v-for="voting in votes" :key="voting.id" cols="12" xl="3" lg="4" md="6">
<VoteCardVue
:voteCard="voting"
@openVoteModal="openVoteModal"
@openEditVoteModal="openEditVoteModal"
@deleteVoting="deleteVoting" />
</v-col>
</v-row>
</v-container>
</v-tabs-window-item>
<!-- Завершенные голосования -->
<v-tabs-window-item value="completed">
<v-container>
<v-row>
<v-col v-for="voting in votes" :key="voting.id" cols="12" lg="3" md="4">
<v-card>
<v-card-title>{{ voting.title }}</v-card-title>
<v-card-subtitle>
Завершено: {{ formatDate(voting.endDate) }}
</v-card-subtitle>
<v-card-actions class="justify-space-between">
<v-btn color="teal-darken-4" size="medium" @click="openResultsModal(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>
</v-tabs-window-item>
<!-- Конструктор -->
<v-tabs-window-item value="constructor">
<VoteConstructor @updating="updating" />
</v-tabs-window-item>
</v-tabs-window>
<!-- Модальное окно для голосования -->
<v-dialog v-model="voteModal" max-width="1200px">
<v-card>
<v-card-actions>
<!--<v-btn color="teal-darken-4" @click="submitVote">Проголосовать</v-btn>-->
<v-btn color="red-darken-1" size="medium" @click="closeVoteModal">
<v-icon>mdi-close-thick</v-icon>
</v-btn>
</v-card-actions>
<v-card-text class="pt-0">
<CurrentVote :description="votingData.description" :endDate="votingData.endDate"
:questions="votingData.questions" :startDate="votingData.startDate" :title="votingData.title" />
</v-card-text>
</v-card>
</v-dialog>
<!-- Модальное окно для редактирования -->
<v-dialog v-model="editVoteModal" max-width="1200px">
<v-card>
<v-card-title>Голосование: {{ selectedVoting?.title }}</v-card-title>
<v-card-text>
<!-- <p>Редактирование голосования...</p> -->
<VoteConstructor />
</v-card-text>
<v-card-actions>
<v-btn color="teal-darken-4">Сохранить</v-btn>
<v-btn @click="closeEditVoteModal">Закрыть</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<!-- Модальное окно для результатов -->
<v-dialog v-model="resultsModal" max-width="1200px">
<v-card>
<v-card-title>Результаты голосования: {{ selectedVoting?.title }}</v-card-title>
<v-card-text>
<p>Здесь отображаются результаты голосования...</p>
</v-card-text>
<v-card-actions>
<v-btn @click="closeResultsModal">Закрыть</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</v-container>
</template>
<script>
import { ref, watch } from "vue";
import VoteConstructor from "@/components/vote/VoteConstructor.vue";
import CurrentVote from "@/components/vote/CurrentVote.vue";
import VoteCardVue from "@/components/vote/VoteCard.vue";
import { getVotes } from "@/utils/axios-api"
// import { votingData } from "@/test/testDataForVote"
export default {
components: { CurrentVote, VoteConstructor, VoteCardVue },
setup() {
const currentTab = ref("active");
const votes = ref([])
function updating(param) {
getVotes(param)
.then(data => {
console.log(data);
votes.value = data;
})
}
updating('active')
watch(
() => currentTab.value,
(newValue) => {
if (newValue !== 'constructor') {
console.log(newValue);
updating(newValue)
}
}
);
const voteModal = ref(false);
const editVoteModal = ref(false);
const resultsModal = ref(false);
const selectedVoting = ref(null);
const formatDate = (date) => new Date(date).toLocaleString();
const openVoteModal = (voting) => {
selectedVoting.value = voting;
voteModal.value = true;
};
const closeVoteModal = () => {
voteModal.value = false;
selectedVoting.value = null;
};
const openEditVoteModal = (voting) => {
selectedVoting.value = voting;
editVoteModal.value = true;
};
const closeEditVoteModal = () => {
editVoteModal.value = false;
selectedVoting.value = null;
};
const submitVote = () => {
selectedVoting.value.voted = true;
closeVoteModal();
};
const openResultsModal = (voting) => {
selectedVoting.value = voting;
resultsModal.value = true;
};
const closeResultsModal = () => {
resultsModal.value = false;
selectedVoting.value = null;
};
const deleteVoting = (id) => {
votes.value = votes.value.filter((v) => v.id !== id);
};
return {
currentTab,
votes,
voteModal,
resultsModal,
selectedVoting,
formatDate,
openVoteModal,
closeVoteModal,
submitVote,
openResultsModal,
closeResultsModal,
deleteVoting,
editVoteModal,
openEditVoteModal,
closeEditVoteModal,
updating,
};
},
};
</script>
<style>
.voted-card {
opacity: 0.6;
}
</style>