263 lines
6.4 KiB
Vue
Executable File
263 lines
6.4 KiB
Vue
Executable File
<script setup lang="ts">
|
|
interface SlaOption {
|
|
id: number
|
|
name: string
|
|
min: string
|
|
max: string
|
|
}
|
|
|
|
import InputReadonly from '@/components/Form/InputReadonly.vue'
|
|
import Select from '@/components/Select.vue'
|
|
import DatePicker from '@/components/DatePicker.vue'
|
|
import InputWithSuffix from '../InputWithSuffix.vue'
|
|
import {
|
|
selectedUid,
|
|
selectedUp3Posko,
|
|
selectedPosko,
|
|
fetchUid,
|
|
itemsUid,
|
|
itemsUp3,
|
|
itemsPosko
|
|
} from './reference'
|
|
import { onMounted, ref, watch } from 'vue'
|
|
import { readDataJson } from '@/utils/storage'
|
|
|
|
const props = defineProps({
|
|
slaOptions: {
|
|
type: Array as () => SlaOption[],
|
|
default: [
|
|
{
|
|
id: 1,
|
|
name: 'Dibawah / Sesuai SLA (<= 45 menit)',
|
|
min: '0',
|
|
max: '45'
|
|
},
|
|
{
|
|
id: 2,
|
|
name: 'Melebihi SLA (> 45 menit)',
|
|
min: '46',
|
|
max: `${99999 * 60 * 24}`
|
|
}
|
|
]
|
|
}
|
|
})
|
|
|
|
const sla = props.slaOptions.map((item: any) => {
|
|
return {
|
|
id: item.id,
|
|
name: item.name
|
|
}
|
|
})
|
|
const emit = defineEmits(['update:filters'])
|
|
const uidPlaceholder = 'Semua Unit Induk Distribusi/Wilayah'
|
|
const up3Placeholder = 'Semua Unit Pelaksanaan Pelayanan Pelanggan'
|
|
const poskoPlaceholder = 'Semua Posko'
|
|
const isHidden = ref(false)
|
|
const totalMin = ref('1 Menit')
|
|
const totalMax = ref('5 Menit')
|
|
|
|
const setDataMin = (value: any) => (totalMin.value = value)
|
|
const getDataMin = () => totalMin.value
|
|
const setDataMax = (value: any) => (totalMax.value = value)
|
|
const getDataMax = () => totalMax.value
|
|
const renderUp3 = ref(false)
|
|
const renderPosko = ref(false)
|
|
const data = ref({
|
|
uid: { id: 0, name: uidPlaceholder },
|
|
up3: { id: 0, name: up3Placeholder },
|
|
posko: { id: 0, name: poskoPlaceholder },
|
|
periode: '',
|
|
minTime: getDataMin().split(' ')[0],
|
|
maxTime: getDataMax().split(' ')[0]
|
|
})
|
|
watch(data, (value) => {
|
|
emit('update:filters', value)
|
|
})
|
|
|
|
const setUid = (value: any) => {
|
|
selectedUid(value)
|
|
data.value = {
|
|
...data.value,
|
|
uid: value,
|
|
up3: { id: 0, name: up3Placeholder },
|
|
posko: { id: 0, name: poskoPlaceholder }
|
|
}
|
|
|
|
renderUp3.value = true
|
|
renderPosko.value = true
|
|
setTimeout(() => {
|
|
renderUp3.value = false
|
|
renderPosko.value = false
|
|
}, 200)
|
|
}
|
|
|
|
const setUp3 = (value: any) => {
|
|
selectedUp3Posko(value)
|
|
data.value = {
|
|
...data.value,
|
|
up3: value,
|
|
posko: { id: 0, name: poskoPlaceholder }
|
|
}
|
|
|
|
renderPosko.value = true
|
|
setTimeout(() => {
|
|
renderPosko.value = false
|
|
}, 200)
|
|
}
|
|
|
|
const setPosko = (value: any) => {
|
|
selectedPosko(value)
|
|
data.value = {
|
|
...data.value,
|
|
posko: value
|
|
}
|
|
}
|
|
|
|
const setMin = (value: any) => {
|
|
console.log(value)
|
|
data.value.minTime = value
|
|
setDataMin(value)
|
|
}
|
|
const setMax = (value: any) => {
|
|
data.value.maxTime = value
|
|
setDataMax(value)
|
|
}
|
|
const triggerInput = ref(false)
|
|
const changeDuration = (value: any) => {
|
|
if (value.id === 0) {
|
|
setMin('1')
|
|
setMax('5')
|
|
|
|
triggerInput.value = false
|
|
isHidden.value = false
|
|
} else if (value.id === 1) {
|
|
setMin(props.slaOptions[0].min)
|
|
setMax(props.slaOptions[0].max)
|
|
|
|
triggerInput.value = true
|
|
isHidden.value = true
|
|
} else {
|
|
setMin(props.slaOptions[1].min)
|
|
setMax(props.slaOptions[1].max)
|
|
|
|
triggerInput.value = true
|
|
isHidden.value = true
|
|
}
|
|
}
|
|
|
|
const presetUID: any = ref(null)
|
|
const presetUP3: any = ref(null)
|
|
const presetPosko: any = ref(null)
|
|
const filterPresets: any = ref()
|
|
|
|
const keys: any = ['uid', 'up3', 'posko']
|
|
const presetValues: any = [presetUID, presetUP3, presetPosko]
|
|
const setFunctions: any = [setUid, setUp3, setPosko]
|
|
|
|
onMounted(() => {
|
|
filterPresets.value = readDataJson('filterPresets') || null
|
|
|
|
if (filterPresets.value) {
|
|
keys.forEach((key: any, index: any) => {
|
|
if (filterPresets.value[key]) {
|
|
presetValues[index].value = filterPresets.value[key]
|
|
setFunctions[index](filterPresets.value[key])
|
|
}
|
|
})
|
|
} else {
|
|
fetchUid()
|
|
}
|
|
|
|
emit('update:filters', data.value)
|
|
})
|
|
</script>
|
|
|
|
<template>
|
|
<div class="grid grid-cols-1 gap-4 md:grid-cols-2">
|
|
<div class="flex flex-col flex-1 space-y-2">
|
|
<label class="filter-input-label">Unit Induk Distribusi/Wilayah:</label>
|
|
|
|
<Select
|
|
v-if="!presetUID"
|
|
@update:selected="setUid($event)"
|
|
:data="itemsUid"
|
|
:placeholder="uidPlaceholder"
|
|
/>
|
|
|
|
<InputReadonly v-if="presetUID" :value="presetUID.name" />
|
|
</div>
|
|
|
|
<div class="flex flex-col flex-1 space-y-2">
|
|
<label class="filter-input-label">Unit Pelaksanaan Pelayanan Pelanggan:</label>
|
|
|
|
<div v-if="!presetUP3">
|
|
<Select
|
|
v-if="renderUp3"
|
|
@update:selected="setUp3($event)"
|
|
:data="itemsUp3"
|
|
:placeholder="up3Placeholder"
|
|
/>
|
|
|
|
<Select
|
|
v-else
|
|
@update:selected="setUp3($event)"
|
|
:data="itemsUp3"
|
|
:placeholder="up3Placeholder"
|
|
/>
|
|
</div>
|
|
|
|
<InputReadonly v-if="presetUP3" :value="presetUP3.name" />
|
|
</div>
|
|
|
|
<div class="flex flex-col flex-1 space-y-2">
|
|
<label class="filter-input-label">Posko:</label>
|
|
|
|
<div v-if="!presetPosko">
|
|
<Select
|
|
v-if="renderPosko"
|
|
@update:selected="setPosko($event)"
|
|
:data="itemsPosko"
|
|
:placeholder="poskoPlaceholder"
|
|
/>
|
|
|
|
<Select
|
|
v-else
|
|
@update:selected="setPosko($event)"
|
|
:data="itemsPosko"
|
|
:placeholder="poskoPlaceholder"
|
|
/>
|
|
</div>
|
|
|
|
<InputReadonly v-if="presetPosko" :value="presetPosko.name" />
|
|
</div>
|
|
|
|
<div class="flex flex-col flex-1 space-y-2">
|
|
<label class="filter-input-label">Periode Tanggal:</label>
|
|
|
|
<DatePicker @update:date-value="(value) => (data.periode = value)" />
|
|
</div>
|
|
|
|
<div class="flex flex-col flex-1 space-y-2">
|
|
<label class="filter-input-label">Durasi:</label>
|
|
|
|
<div class="flex flex-col gap-y-1">
|
|
<Select @update:selected="changeDuration($event)" :data="sla" placeholder="Durasi Menit" />
|
|
|
|
<div class="flex flex-1 justify-between gap-x-1.5" :class="[isHidden ? 'hidden' : '']">
|
|
<InputWithSuffix
|
|
:value="`${data.minTime} Menit`"
|
|
@update:text="setMin($event)"
|
|
class="flex flex-1"
|
|
/>
|
|
<small class="flex items-center">s/d</small>
|
|
<InputWithSuffix
|
|
:value="`${data.maxTime} Menit`"
|
|
@update:text="setMax($event)"
|
|
class="flex flex-1"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|