43 lines
1.3 KiB
Vue
43 lines
1.3 KiB
Vue
<template>
|
|
<div class="card mb-6 border border-2 border-primary rounded primary-shadow">
|
|
<div class="card-body">
|
|
<!-- 1위가 여러개일때 -->
|
|
<vote-result-random v-if="topVoters.length > 1" :data="topVoters" :randomResultNum="randomResultNum"
|
|
@randomList="randomList"/>
|
|
<!-- 1위가 하나일때-->
|
|
<vote-result-card v-if="topVoters.length == 1" :data="topVoters"/>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup>
|
|
import voteResultRandom from '@c/voteboard/voteResultRandom.vue';
|
|
import voteResultCard from '@c/voteboard/voteResultCard.vue';
|
|
import { computed } from 'vue';
|
|
const emit = defineEmits(['randomList']);
|
|
const props = defineProps({
|
|
data: {
|
|
type: Array,
|
|
required: true,
|
|
},
|
|
randomResultNum: {
|
|
type: String,
|
|
required: false,
|
|
},
|
|
});
|
|
// 가장 많은 투표를 받은 항목들 (1위)
|
|
const topVoters = computed(() => {
|
|
// 가장 높은 VOTE_COUNT 찾기
|
|
const maxVoteCount = Math.max(...props.data.map(item => item.VOTE_COUNT));
|
|
// VOTE_COUNT가 가장 높은 항목들 필터링
|
|
return props.data.filter(item => item.VOTE_COUNT === maxVoteCount);
|
|
});
|
|
const randomList = (random) =>{
|
|
emit('randomList',random);
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
|
|
</style>
|