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

This commit is contained in:
Denzel committed 2025-01-17 13:40:50 +03:00
1 parent 64c948d077
commit a8bba7cb8b
4 files changed
+107 -34

No files matched your search

@@ -168,9 +168,10 @@ export default {
const isVoteSubmitted = ref(false); const isVoteSubmitted = ref(false);
const isCurrentQuestionAnswered = computed(() => { const isCurrentQuestionAnswered = computed(() => {
let q = props.data.questions.find(e => e.numb == activeStep.value + 1) let q = props.data.questions.find(e => e.numb === activeStep.value + 1)
return result.value[q.id].length > 0; return q !== undefined ? result.value[q.id].length > 0 : false;
}); });
const getres = () => { const getres = () => {
return props.data.questions.reduce((acc, item) => { return props.data.questions.reduce((acc, item) => {
acc[item.id] = [] acc[item.id] = []
@@ -0,0 +1,67 @@
<template>
<v-container>
<v-row>
<v-col cols="12">
<v-card class="mb-4" outlined>
<v-card-title>Победитель: {{ winner.name }}</v-card-title>
<v-card-subtitle>
Количество голосов: {{ winner.votes }}
</v-card-subtitle>
</v-card>
</v-col>
</v-row>
<v-row>
<v-col cols="12">
<v-card class="mb-4" outlined>
<v-card-title>Все результаты</v-card-title>
<v-card-text>
<v-list>
<v-list-item v-for="(option, index) in sortedResults" :key="index">
<p>
<strong>{{ option.name }}</strong>: {{ option.votes }} голосов
</p>
</v-list-item>
</v-list>
</v-card-text>
</v-card>
</v-col>
</v-row>
</v-container>
</template>
<script>
import { computed } from 'vue';
export default {
name: 'VoteResult',
props: {
results: {
type: Array,
required: true,
default: () => []
}
},
setup(props) {
const winner = computed(() => {
return props.results.reduce((max, option) => (option.votes > max.votes ? option : max), { name: '', votes: 0 });
});
const sortedResults = computed(() => {
return [...props.results].sort((a, b) => b.votes - a.votes);
});
return {
winner,
sortedResults
};
}
};
</script>
<style scoped>
h1 {
margin-bottom: 20px;
}
</style>
-4
View File
@@ -93,7 +93,6 @@ async function getVotes(status) {
} }
} }
async function createVote(voteData) { async function createVote(voteData) {
try { try {
@@ -188,9 +187,6 @@ async function getEmployees() {
} }
} }
getEmployees()
.then(r => console.log(r))
export { export {
axiosApiInstance, axiosApiInstance,
+37 -28
View File
@@ -25,9 +25,9 @@
> >
<VoteCardVue <VoteCardVue
:voteCard="voting" :voteCard="voting"
@openVoteModal="(voting) => openModal('vote', voting)"
@openEditVoteModal="(voting) => openModal('edit', voting)"
@deleteVoting="deleteVoting" @deleteVoting="deleteVoting"
@openEditVoteModal="(voting) => openModal('edit', voting)"
@openVoteModal="(voting) => openModal('vote', voting)"
/> />
</v-col> </v-col>
</v-row> </v-row>
@@ -41,18 +41,18 @@
<v-col <v-col
v-for="voting in sortedCompletedVotes" v-for="voting in sortedCompletedVotes"
:key="voting.id" :key="voting.id"
:class="{ 'voted-card': voting.voted }"
cols="12" cols="12"
lg="3" lg="3"
md="4" md="4"
:class="{ 'voted-card': voting.voted }"
> >
<v-card> <v-card>
<v-card-title>{{ voting.title }}</v-card-title> <v-card-title>{{ voting.name }}</v-card-title>
<v-card-subtitle> <v-card-subtitle>
Завершено: {{ formatDate(voting.endDate) }} Завершено: {{ voting.dateend }}
</v-card-subtitle> </v-card-subtitle>
<v-card-actions class="justify-space-between"> <v-card-actions class="justify-space-between">
<v-btn color="teal-darken-4" size="medium" @click="(voting) => openModal('results', voting)"> <v-btn color="teal-darken-4" size="medium" @click="() => openModal('results', voting)">
Результаты Результаты
</v-btn> </v-btn>
<v-btn color="error" size="medium" @click="deleteVoting(voting.id)"> <v-btn color="error" size="medium" @click="deleteVoting(voting.id)">
@@ -67,24 +67,20 @@
<!-- Конструктор --> <!-- Конструктор -->
<v-tabs-window-item value="constructor"> <v-tabs-window-item value="constructor">
<VoteConstructor @updating="updating" /> <VoteConstructor @updating="updating"/>
</v-tabs-window-item> </v-tabs-window-item>
</v-tabs-window> </v-tabs-window>
<!-- Модальные окна --> <!-- Модальные окна -->
<v-dialog v-model="voteModal" @click:outside="closeModal"> <v-dialog v-model="voteModal" @click:outside="closeModal">
<CurrentVote :data="res" @closer="closeModal"/>
<CurrentVote :data="res" @closer="closeModal"/>
</v-dialog> </v-dialog>
<v-dialog v-model="editVoteModal" max-width="1200px" @click:outside="closeModal"> <v-dialog v-model="editVoteModal" max-width="1200px" @click:outside="closeModal">
<v-card> <v-card>
<v-card-title>Редактировать голосование: {{ selectedVoting?.title }}</v-card-title> <v-card-title>Редактировать голосование: {{ selectedVoting?.title }}</v-card-title>
<v-card-text> <v-card-text>
<VoteConstructor /> <VoteConstructor/>
</v-card-text> </v-card-text>
<v-card-actions> <v-card-actions>
<v-btn color="teal-darken-4">Сохранить</v-btn> <v-btn color="teal-darken-4">Сохранить</v-btn>
@@ -97,7 +93,7 @@
<v-card> <v-card>
<v-card-title>Результаты голосования: {{ selectedVoting?.title }}</v-card-title> <v-card-title>Результаты голосования: {{ selectedVoting?.title }}</v-card-title>
<v-card-text> <v-card-text>
<p>Здесь отображаются результаты голосования...</p> <VoteResult :results="testResults"/>
</v-card-text> </v-card-text>
<v-card-actions> <v-card-actions>
<v-btn @click="closeModal">Закрыть</v-btn> <v-btn @click="closeModal">Закрыть</v-btn>
@@ -108,31 +104,40 @@
</template> </template>
<script> <script>
import { ref, computed, watch } from "vue"; import {computed, ref, watch} from "vue";
import VoteConstructor from "@/components/vote/VoteConstructor.vue"; import VoteConstructor from "@/components/vote/VoteConstructor.vue";
import CurrentVote from "@/components/vote/CurrentVote.vue"; import CurrentVote from "@/components/vote/CurrentVote.vue";
import VoteCardVue from "@/components/vote/VoteCard.vue"; import VoteCardVue from "@/components/vote/VoteCard.vue";
import { useRoute, useRouter } from "vue-router"; import {useRoute, useRouter} from "vue-router";
import { deleteVote, getVoteDetail, getVotes } from "@/utils/axios-api"; import {deleteVote, getVoteDetail, getVotes} from "@/utils/axios-api";
import { formatDate } from "@vueuse/shared"; import {formatDate} from "@vueuse/shared";
import VoteResult from "@/components/vote/VoteResult.vue";
export default { export default {
methods: { formatDate }, methods: {formatDate},
components: { CurrentVote, VoteConstructor, VoteCardVue }, components: {VoteResult, CurrentVote, VoteConstructor, VoteCardVue},
setup() { setup() {
const testResults = [
{name: 'Дональд Трамп', votes: 99},
{name: 'Иван Иванов', votes: 30},
{name: 'Аркадий Упукник', votes: 95},
];
const currentTab = ref("current"); const currentTab = ref("current");
const votes = ref([]); const votes = ref([]);
const completedVotes = ref([]);
const router = useRouter(); const router = useRouter();
const route = useRoute(); const route = useRoute();
const res = ref(null); const res = ref(null);
const updating = async (param) => { const updating = async (param) => {
const data = await getVotes(param); const data = await getVotes(param);
votes.value = data; if (param === 'active') votes.value = data;
else completedVotes.value = data;
}; };
updating("active"); updating("active");
updating('completed')
const voteModal = ref(false); const voteModal = ref(false);
const editVoteModal = ref(false); const editVoteModal = ref(false);
@@ -146,11 +151,13 @@ export default {
); );
const sortedCompletedVotes = computed(() => const sortedCompletedVotes = computed(() =>
votes.value completedVotes.value
.filter((v) => new Date(v.dateend) <= new Date()) .filter((v) => new Date(v.dateend) <= new Date())
.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);
@@ -166,7 +173,7 @@ export default {
editVoteModal.value = false; editVoteModal.value = false;
resultsModal.value = false; resultsModal.value = false;
selectedVoting.value = null; selectedVoting.value = null;
router.push({ name: "VoteHomePage" }); router.push({name: "VoteHomePage"});
updating("active"); updating("active");
}; };
@@ -176,13 +183,13 @@ export default {
if (type === "vote") { if (type === "vote") {
await loadVoteDetails(voting.id); await loadVoteDetails(voting.id);
voteModal.value = true; voteModal.value = true;
router.push({ name: "Voting", params: { id: voting.id } }); router.push({name: "Voting", params: {id: voting.id}});
} else if (type === "edit") { } else if (type === "edit") {
editVoteModal.value = true; editVoteModal.value = true;
router.push({ name: "EditVote", params: { id: voting.id } }); router.push({name: "EditVote", params: {id: voting.id}});
} else if (type === "results") { } else if (type === "results") {
resultsModal.value = true; resultsModal.value = true;
router.push({ name: "VoteResults", params: { id: voting.id } }); router.push({name: "VoteResults", params: {id: voting.id}});
} }
}; };
@@ -209,10 +216,11 @@ export default {
selectedVoting.value = voting || null; selectedVoting.value = voting || null;
} }
}, },
{ immediate: true } {immediate: true}
); );
updating("active"); updating("active");
updating("completed");
return { return {
currentTab, currentTab,
@@ -228,6 +236,7 @@ export default {
deleteVoting, deleteVoting,
updating, updating,
res, res,
testResults
}; };
}, },
}; };