Refactor month selection logic and improve code readability

This commit is contained in:
Dede Fuji Abdul 2024-03-30 21:09:58 +07:00
parent 7d9f09c236
commit 76e3cd546c

View File

@ -155,7 +155,7 @@
</DxColumn> </DxColumn>
<template #formatText="{ data }"> <template #formatText="{ data }">
<p class="text-left cursor-pointer"> <p class="text-left cursor-pointer" @click="setMonth('')">
{{ data.text }} {{ data.text }}
</p> </p>
</template> </template>
@ -461,7 +461,8 @@ const dialogDetail = ref(false)
const closedialogDetail = () => (dialogDetail.value = false) const closedialogDetail = () => (dialogDetail.value = false)
const loadingData = ref(false) const loadingData = ref(false)
const loadingSubData = ref(false) const loadingSubData = ref(false)
const monthSelected = ref(1) const monthSelected = ref<any>(null)
const agreeToShowDialog = ref(false)
const reportMeta = ref({ const reportMeta = ref({
uid: { id: 0, name: 'Semua Unit Induk Distribusi/Wilayah' }, uid: { id: 0, name: 'Semua Unit Induk Distribusi/Wilayah' },
up3: { id: 0, name: 'Semua Unit Pelaksanaan Pelayanan Pelanggan' }, up3: { id: 0, name: 'Semua Unit Pelaksanaan Pelayanan Pelanggan' },
@ -470,7 +471,11 @@ const reportMeta = ref({
}) })
const setMonth = (month: any) => { const setMonth = (month: any) => {
monthSelected.value = getMonthNumber(month) if (month != '') {
monthSelected.value = getMonthNumber(month)
} else {
monthSelected.value = null
}
} }
const filterData = async (params: any) => { const filterData = async (params: any) => {
@ -545,19 +550,18 @@ const clearSelection = () => {
const showDetail = () => { const showDetail = () => {
clearSelection() clearSelection()
dataSubSelected.value = null dataSubSelected.value = null
dialogDetail.value = true if (monthSelected.value != null) {
getDetail() dialogDetail.value = true
getDetail()
}
} }
const onDataSelectionChanged = ({ selectedRowsData }: any) => { const onDataSelectionChanged = ({ selectedRowsData }: any) => {
// wait for 2 seconds if (selectedRowsData[0] != undefined) {
setTimeout(() => { console.log('monthSelected', monthSelected.value)
if (selectedRowsData[0] != undefined) { dataSelected.value = selectedRowsData[0]
console.log('monthSelected', monthSelected.value) showDetail()
dataSelected.value = selectedRowsData[0] }
showDetail()
}
}, 2000)
} }
const onDataSubSelectionChanged = ({ selectedRowsData }: any) => { const onDataSubSelectionChanged = ({ selectedRowsData }: any) => {