Files
2025-09-25 11:59:19 +08:00

142 lines
4.8 KiB
Vue

<template>
<div id="cawangan_selector" class="mx-auto">
<a v-if="route === 'ada'" class="text-yellow-200 rounded bg-gray-400 px-6 py-3 font-bold mr-4 uppercase sm:invisible lg:visible xl:visible">
CAWANGAN :
<select v-model="caw" @change="tukarcawangan" class="rounded-md border bg-gray-400 font-bold border-gray-400 focus:outline-none rounded-md focus:ring-1 ring-cyan-500 uppercase">
<option v-for="(caw,i) in cawangan" :key="i" :value="caw.kodcaw">{{ caw.details_caw }}</option>
</select>
</a>
<a v-if="route === 'tiada'" class="text-yellow-200 rounded bg-gray-400 px-6 py-3 font-bold mr-4 uppercase sm:invisible lg:visible xl:visible">
CAWANGAN : {{ this.namacawangan(this.caw) }}
</a>
<a class="text-yellow-200 rounded bg-gray-400 px-4 py-3 font-bold mr-4 uppercase md:invisible xl:visible">
<i v-if="this.roles == 'admin'" class="fas fa-1x fa-user-lock"></i>
<i v-if="this.roles == 'akaun'" class="fas fa-1x fa-calculator"></i>
<i v-if="this.roles == 'operasi'" class="fas fa-1x fa-user-cog"></i>
<i v-if="this.roles == 'kpo'" class="fas fa-1x fa-user"></i>
</a>
</div>
</template>
<script>
export default {
props: {
roles: String,
route:String,
akaun:String
},
data: function(){
return{
cawangan:{},
caw:this.$kodcaw
}
},
created() {
this.caw = this.$kodcaw
this.axios.get('/api/check/cawangan').then(response => {
this.cawangan = response.data;
});
this.$on('updateCawangan', (newCaw) => {
this.caw = newCaw; // Update the header branch
});
fetch('/api/check/cawangan')
.then(response => response.json()).then(response => this.cawangan = response);
},
methods:{
getText: function(){
alert('emit triggered');
},
tukarcawangan: function(){
this.setkodcaw(this.caw)
// this.sethostname(this.caw)
this.pembahagiancawangan(this.caw)
this.$forceUpdate();
if(this.akaun =='no')
location.reload();
},
namacawangan: function(cawangannama){
let namcaw = '';
if(this.cawangan.length >0)
{
this.cawangan.some(function(value, key) {
if(cawangannama === value.kodcaw)
{
namcaw = value.details_caw
}
});
}
return namcaw;
},
pembahagiancawangan: function(cawangannama){
switch (cawangannama) {
case 'KB2':
case '1STOP':
case 'WB':{
this.sethostname(process.env.MIX_API_URL);
break;
}
case 'WCY':
case '020301':
case 'ALS':
case '020306':
case 'ARM':
case 'APM':
case '010311':
case 'GC':
case 'JLI':
case 'ARP':
case '020303':{
this.sethostname(process.env.MIX_API_URL_ZONE1);
break;
}
case '010621':
case '010136':
case '011235':
case '010620':
case '010617':
case '010915':
case '010219':
case '010618':
case '011013':
case '011412':{
// this.$hostname = 'http://api_arrahn'
this.sethostname(process.env.MIX_API_URL_ZONE2);
break;
}
case '011229':
case '011230':
case '011227':
case '011231':
case '011232':
case '011228':
case '011234':
case '011237':
case '011233':{
// this.$hostname = 'http://api3.arrahn'
this.sethostname(process.env.MIX_API_URL_ZONE3);
break;
}
default: this.sethostname(process.env.MIX_API_URL)
break;
}
}
}
}
</script>