185 lines
4.5 KiB
Vue
185 lines
4.5 KiB
Vue
<script setup lang="ts">
|
|
// Components
|
|
import Dialog from '~/components/pub/my-ui/modal/dialog.vue'
|
|
import Header from '~/components/pub/my-ui/nav-header/prep.vue'
|
|
import RecordConfirmation from '~/components/pub/my-ui/confirmation/record-confirmation.vue'
|
|
|
|
// Helpers
|
|
import { usePaginatedList } from '~/composables/usePaginatedList'
|
|
import { toast } from '~/components/pub/ui/toast'
|
|
import { config } from '~/components/app/procedure-src/list-cfg'
|
|
// Types
|
|
import { ActionEvents, type HeaderPrep } from '~/components/pub/my-ui/data/types'
|
|
import { ProcedureSrcSchema, type ProcedureSrcFormData } from '~/schemas/procedure-src.schema'
|
|
|
|
// Handlers
|
|
import {
|
|
recId,
|
|
recAction,
|
|
recItem,
|
|
isReadonly,
|
|
isProcessing,
|
|
isFormEntryDialogOpen,
|
|
isRecordConfirmationOpen,
|
|
onResetState,
|
|
handleActionSave,
|
|
handleActionEdit,
|
|
handleActionRemove,
|
|
handleCancelForm,
|
|
} from '~/handlers/procedure-src.handler'
|
|
|
|
// Services
|
|
import { getList, getDetail } from '~/services/procedure-src.service'
|
|
|
|
const title = ref('')
|
|
|
|
const {
|
|
data,
|
|
isLoading,
|
|
paginationMeta,
|
|
searchInput,
|
|
handlePageChange,
|
|
handleSearch,
|
|
fetchData: getItemList,
|
|
} = usePaginatedList({
|
|
fetchFn: async (params: any) => {
|
|
const result = await getList({
|
|
search: params.search,
|
|
sort: 'createdAt:desc',
|
|
'page-number': params['page-number'] || 0,
|
|
'page-size': params['page-size'] || 10,
|
|
})
|
|
return { success: result.success || false, body: result.body || {} }
|
|
},
|
|
entityName: 'procedure-src',
|
|
})
|
|
|
|
const headerPrep: HeaderPrep = {
|
|
title: 'MCU Prosedur',
|
|
icon: 'i-lucide-clipboard-list',
|
|
refSearchNav: {
|
|
placeholder: 'Cari (min. 3 karakter)...',
|
|
minLength: 3,
|
|
debounceMs: 500,
|
|
showValidationFeedback: true,
|
|
onInput: (val: string) => {
|
|
searchInput.value = val
|
|
},
|
|
onClick: () => {},
|
|
onClear: () => {},
|
|
},
|
|
addNav: {
|
|
label: 'Tambah',
|
|
icon: 'i-lucide-plus',
|
|
onClick: () => {
|
|
recItem.value = null
|
|
recId.value = 0
|
|
isFormEntryDialogOpen.value = true
|
|
isReadonly.value = false
|
|
},
|
|
},
|
|
}
|
|
|
|
provide('rec_id', recId)
|
|
provide('rec_action', recAction)
|
|
provide('rec_item', recItem)
|
|
provide('table_data_loader', isLoading)
|
|
|
|
const getCurrentDetail = async (id: number | string) => {
|
|
const result = await getDetail(id)
|
|
if (result.success) {
|
|
const currentValue = result.body?.data || {}
|
|
recItem.value = currentValue
|
|
isFormEntryDialogOpen.value = true
|
|
}
|
|
}
|
|
|
|
watch([recId, recAction], () => {
|
|
switch (recAction.value) {
|
|
case ActionEvents.showDetail:
|
|
getCurrentDetail(recId.value)
|
|
title.value = 'Detail Prosedur'
|
|
isReadonly.value = true
|
|
break
|
|
case ActionEvents.showEdit:
|
|
getCurrentDetail(recId.value)
|
|
title.value = 'Edit Prosedur'
|
|
isReadonly.value = false
|
|
break
|
|
case ActionEvents.showConfirmDelete:
|
|
isRecordConfirmationOpen.value = true
|
|
break
|
|
}
|
|
})
|
|
|
|
onMounted(async () => {
|
|
await getItemList()
|
|
})
|
|
</script>
|
|
|
|
<template>
|
|
<Header
|
|
v-model="searchInput"
|
|
:prep="headerPrep"
|
|
:ref-search-nav="headerPrep.refSearchNav"
|
|
@search="handleSearch"
|
|
class="mb-4 xl:mb-5"
|
|
/>
|
|
<AppProcedureSrcList
|
|
:data="data"
|
|
:pagination-meta="paginationMeta"
|
|
@page-change="handlePageChange"
|
|
/>
|
|
|
|
<Dialog
|
|
v-model:open="isFormEntryDialogOpen"
|
|
:title="!!recItem ? title : 'Tambah Prosedur'"
|
|
size="lg"
|
|
prevent-outside
|
|
@update:open="
|
|
(value: any) => {
|
|
onResetState()
|
|
isFormEntryDialogOpen = value
|
|
}
|
|
"
|
|
>
|
|
<AppProcedureSrcEntryForm
|
|
:schema="ProcedureSrcSchema"
|
|
:values="recItem"
|
|
:is-loading="isProcessing"
|
|
:is-readonly="isReadonly"
|
|
@submit="
|
|
(values: ProcedureSrcFormData | Record<string, any>, resetForm: () => void) => {
|
|
if (recId > 0) {
|
|
handleActionEdit(recId, values, getItemList, resetForm, toast)
|
|
return
|
|
}
|
|
handleActionSave(values, getItemList, resetForm, toast)
|
|
}
|
|
"
|
|
@cancel="handleCancelForm"
|
|
/>
|
|
</Dialog>
|
|
|
|
<RecordConfirmation
|
|
v-model:open="isRecordConfirmationOpen"
|
|
action="delete"
|
|
:record="recItem"
|
|
@confirm="() => handleActionRemove(recId, getItemList, toast)"
|
|
@cancel=""
|
|
>
|
|
<template #default="{ record }">
|
|
<div class="space-y-1 text-sm">
|
|
<p
|
|
v-for="field in config.delKeyNames"
|
|
:key="field.key"
|
|
:v-if="record?.[field.key]"
|
|
>
|
|
<span class="font-semibold">{{ field.label }}:</span>
|
|
{{ record[field.key] }}
|
|
</p>
|
|
</div>
|
|
</template>
|
|
</RecordConfirmation>
|
|
</template>
|