Files
E-Vote/resources/assets/js/components/demo/admin/home/final.vue
T
nurafrinaalimi16 2a7f91199e add jumlah undian
2024-04-28 16:22:05 +08:00

130 lines
3.2 KiB
Vue

<template>
<div class="container">
<div class="row">
<div class="col-md-12">
<div v-for="position in positions">
<h5>{{ position.name }}</h5>
<div class="table-responsive">
<table class="table table-striped table-condensed">
<thead>
<tr>
<th width="20%">No. Anggota</th>
<th width="30%">Nama</th>
<th width="20%">Unit</th>
<th width="10%">Undian</th>
<th width="20%">Peratus (%)</th>
</tr>
</thead>
<tbody>
<tr v-for="result in results" v-if="result.position_id == position.id">
<td>{{ getNominee(result.nominee_id)['no_anggota'] }}</td>
<td>{{ getNominee(result.nominee_id)['name'] }}</td>
<td>{{ getNominee(result.nominee_id)['unit'] }}</td>
<td>{{ result.votes }}</td>
<td>{{ calculatePercentage(result.votes, position.id) }}</td>
</tr>
<tr v-for="no_vote in no_votes" v-if="no_vote.position_id == position.id">
<td>{{ no_vote.no_anggota }}</td>
<td>{{ no_vote.name }}</td>
<td>{{ no_vote.unit }}</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td colspan="3"><b>Jumlah Undian</b></td>
<td><b>{{ calculateTotalVotes(position.id) }}</b></td>
</tr>
</tbody>
</table>
</div>
<hr />
</div>
</div>
</div>
</div>
</template>
<script>
export default {
data: function () {
return {
nominees: [],
results: [],
partylists: [],
positions: []
}
},
methods: {
getNominee: function (id) {
let nominees = this.nominees;
for (var i in nominees)
if (id == nominees[i]['id'])
return nominees[i];
return {};
},
getPartylist: function (id) {
let partylists = this.partylists;
for (var i in partylists)
if (id == partylists[i]['id'])
return partylists[i]['name'];
return 'No Partylist';
},
calculatePercentage(votes, positionId) {
const totalVotes = this.results
.filter(result => result.position_id === positionId)
.reduce((total, result) => total + result.votes, 0);
return ((votes / totalVotes) * 100).toFixed(2);
},
calculateTotalVotes(positionId) {
return this.results
.filter(result => result.position_id === positionId)
.reduce((total, result) => total + result.votes, 0);
}
},
created: function () {
this.util.notify('Loading please wait...', 'loading');
var vm = this;
axios.get(config.API + 'election/result/' + this.election_id)
.then(response => {
$.notifyClose();
vm.nominees = response.data.nominee;
vm.results = response.data.result;
vm.partylists = response.data.partylist;
vm.positions = response.data.position;
})
.catch(error => {
$.notifyClose();
vm.util.showResult(error, 'error');
})
},
computed: {
election_id: function () {
return this.$route.params.election_id;
},
no_votes: function () {
let nominees = this.nominees;
let results = this.results;
let no_votes = [];
for (var i in nominees) {
var hasvote = false;
for (var y in results) {
if (results[y]['nominee_id'] == nominees[i]['id'])
hasvote = true;
}
if (!hasvote)
no_votes.push(nominees[i]);
}
return no_votes;
}
}
}
</script>