diff --git a/app/components/app/division/entry-form.vue b/app/components/app/division/entry-form.vue index 5f4b3299..d6f7556f 100644 --- a/app/components/app/division/entry-form.vue +++ b/app/components/app/division/entry-form.vue @@ -4,6 +4,7 @@ import Block from '~/components/pub/custom-ui/doc-entry/block.vue' import Cell from '~/components/pub/custom-ui/doc-entry/cell.vue' import Field from '~/components/pub/custom-ui/doc-entry/field.vue' import Label from '~/components/pub/custom-ui/doc-entry/label.vue' +import Combobox from '~/components/pub/custom-ui/form/combobox.vue' // Types import type { DivisionFormData } from '~/schemas/division.schema.ts' @@ -15,6 +16,7 @@ import { useForm } from 'vee-validate' interface Props { schema: z.ZodSchema + divisions: any[] values: any isLoading?: boolean isReadonly?: boolean @@ -85,6 +87,21 @@ function onCancelForm() { + + + + + +
diff --git a/app/components/app/division/list-cfg.ts b/app/components/app/division/list-cfg.ts index 3674b5c2..0fe14dd1 100644 --- a/app/components/app/division/list-cfg.ts +++ b/app/components/app/division/list-cfg.ts @@ -12,11 +12,11 @@ type SmallDetailDto = any const action = defineAsyncComponent(() => import('~/components/pub/custom-ui/data/dropdown-action-ud.vue')) -export const cols: Col[] = [{ width: 100 }, {}, {}, { width: 50 }] +export const cols: Col[] = [{}, {}, {}, { width: 50 }] export const header: Th[][] = [[{ label: 'Kode' }, { label: 'Nama' }, { label: 'Divisi Induk' }, { label: '' }]] -export const keys = ['code', 'name', 'ancestor', 'action'] +export const keys = ['code', 'name', 'parent', 'action'] export const delKeyNames: KeyLabel[] = [ { key: 'code', label: 'Kode' }, @@ -24,13 +24,9 @@ export const delKeyNames: KeyLabel[] = [ ] export const funcParsed: RecStrFuncUnknown = { - ancestor: (rec: unknown): unknown => { + parent: (rec: unknown): unknown => { const recX = rec as SmallDetailDto - if (recX.meta === null) { - return '-' - } - - return recX.meta.name + return recX.parent?.name || '-' }, } diff --git a/app/components/content/division/list.vue b/app/components/content/division/list.vue index 8d55db24..9da83819 100644 --- a/app/components/content/division/list.vue +++ b/app/components/content/division/list.vue @@ -28,6 +28,7 @@ import { handleActionRemove, handleCancelForm, } from '~/handlers/division.handler' +import { divisions, getDivisionParentList } from '~/handlers/_shared.handler' // Services import { getDivisions, getDivisionDetail } from '~/services/division.service' @@ -111,6 +112,7 @@ watch([recId, recAction], () => { onMounted(async () => { await getDivisionList() + await getDivisionParentList(false, data.value || []) }) @@ -127,6 +129,7 @@ onMounted(async () => { { }) onMounted(async () => { - await getUomList() await getEquipmentList() + await getUomList() }) diff --git a/app/components/content/installation/list.vue b/app/components/content/installation/list.vue index 5be09e61..f8494ba8 100644 --- a/app/components/content/installation/list.vue +++ b/app/components/content/installation/list.vue @@ -111,8 +111,8 @@ watch([recId, recAction], () => { }) onMounted(async () => { - await getEncounterClassConstants() await getInstallationList() + await getEncounterClassConstants() }) diff --git a/app/components/content/medicine/list.vue b/app/components/content/medicine/list.vue index e77ce620..2f2accb9 100644 --- a/app/components/content/medicine/list.vue +++ b/app/components/content/medicine/list.vue @@ -55,7 +55,11 @@ const { fetchData: getMedicineList, } = usePaginatedList({ fetchFn: async (params: any) => { - const result = await getMedicines({ search: params.search, page: params['page-number'] || 0, includes: 'medicineGroup,medicineMethod,uom' }) + const result = await getMedicines({ + search: params.search, + page: params['page-number'] || 0, + includes: 'medicineGroup,medicineMethod,uom', + }) return { success: result.success || false, body: result.body || {} } }, entityName: 'medicine', @@ -120,10 +124,10 @@ watch([recId, recAction], () => { }) onMounted(async () => { + await getMedicineList() await getMedicineGroupList() await getMedicineMethodList() await getUomList() - await getMedicineList() }) diff --git a/app/components/content/specialist/list.vue b/app/components/content/specialist/list.vue index 628f83ac..c157642b 100644 --- a/app/components/content/specialist/list.vue +++ b/app/components/content/specialist/list.vue @@ -112,8 +112,8 @@ watch([recId, recAction], () => { }) onMounted(async () => { - await getUnitList() await getSpecialistList() + await getUnitList() }) diff --git a/app/components/content/subspecialist/list.vue b/app/components/content/subspecialist/list.vue index 78466bef..5571f632 100644 --- a/app/components/content/subspecialist/list.vue +++ b/app/components/content/subspecialist/list.vue @@ -111,8 +111,8 @@ watch([recId, recAction], () => { }) onMounted(async () => { - await getSpecialistsList() await getSubSpecialistList() + await getSpecialistsList() }) diff --git a/app/components/content/tools/list.vue b/app/components/content/tools/list.vue index 5de63c0a..28cccb8f 100644 --- a/app/components/content/tools/list.vue +++ b/app/components/content/tools/list.vue @@ -116,8 +116,8 @@ watch([recId, recAction], () => { }) onMounted(async () => { - await getUomList() await getToolsList() + await getUomList() }) diff --git a/app/components/content/unit/list.vue b/app/components/content/unit/list.vue index 69acc005..1e8edd99 100644 --- a/app/components/content/unit/list.vue +++ b/app/components/content/unit/list.vue @@ -111,8 +111,8 @@ watch([recId, recAction], () => { }) onMounted(async () => { - await getInstallationList() await getUnitList() + await getInstallationList() }) diff --git a/app/handlers/_handler.ts b/app/handlers/_handler.ts index 4148c726..c81e87ed 100644 --- a/app/handlers/_handler.ts +++ b/app/handlers/_handler.ts @@ -33,7 +33,7 @@ export function createCrudHandler(crud: { if (refresh) refresh() }, onFinally: (isSuccess: boolean) => { - if (isSuccess) setTimeout(reset, 500) + setTimeout(reset, 300) isProcessing.value = false }, }) @@ -58,7 +58,7 @@ export function createCrudHandler(crud: { if (refresh) refresh() }, onFinally: (isSuccess: boolean) => { - if (isSuccess) setTimeout(reset, 500) + setTimeout(reset, 300) isProcessing.value = false }, }) @@ -77,6 +77,7 @@ export function createCrudHandler(crud: { if (refresh) refresh() }, onFinally: () => { + setTimeout(refresh, 300) isProcessing.value = false }, }) diff --git a/app/handlers/_shared.handler.ts b/app/handlers/_shared.handler.ts index af88190a..53417888 100644 --- a/app/handlers/_shared.handler.ts +++ b/app/handlers/_shared.handler.ts @@ -1,6 +1,7 @@ // types import type { MedicineGroup } from '~/models/medicine-group' import type { MedicineMethod } from '~/models/medicine-method' +import type { Division } from '~/models/division' import type { Installation } from '~/models/installation' import type { Specialist } from '~/models/specialist' import type { Uom } from '~/models/uom' @@ -13,6 +14,7 @@ import { encounterClassCodes } from '~/lib/constants' import { getMedicineGroups } from '~/services/medicine-group.service' import { getMedicineMethods } from '~/services/medicine-method.service' import { getEncounters } from '~/services/encounter.service' +import { getDivisions } from '~/services/division.service' import { getInstallations } from '~/services/installation.service' import { getSpecialists } from '~/services/specialist.service' import { getUoms } from '~/services/uom.service' @@ -22,6 +24,7 @@ import { getUnits } from '~/services/unit.service' export const medicineGroups = ref<{ value: string; label: string }[]>([]) export const medicineMethods = ref<{ value: string; label: string }[]>([]) export const encounterClasses = ref<{ value: string; label: string }[]>([]) +export const divisions = ref<{ value: string; label: string }[]>([]) export const installations = ref<{ value: string; label: string }[]>([]) export const specialists = ref<{ value: string; label: string }[]>([]) export const uoms = ref<{ value: string; label: string }[]>([]) @@ -49,6 +52,23 @@ export const getMedicineMethodList = async () => { } } +export const getDivisionParentList = async (isFetch = true, externalDivisions: any[] = []) => { + if (isFetch) { + const result = await getDivisions() + if (result.success) { + const currentDivisions = result.body?.data || [] + divisions.value = currentDivisions.map((division: Division) => ({ + value: division.code, + label: division.name, + })) + } + } + divisions.value = externalDivisions.map((division: Division) => ({ + value: division.code, + label: division.name, + })) +} + export const getEncounterClassList = async () => { const result = await getEncounters() if (result.success) { diff --git a/app/handlers/division.handler.ts b/app/handlers/division.handler.ts index e830260f..8b14ca86 100644 --- a/app/handlers/division.handler.ts +++ b/app/handlers/division.handler.ts @@ -1,5 +1,33 @@ import { createCrudHandler } from '~/handlers/_handler' import { postDivision, patchDivision, removeDivision } from '~/services/division.service' +import { + postDivisionPosition, + patchDivisionPosition, + removeDivisionPosition, +} from '~/services/division-position.service' + +function selectPost(payload: any) { + if (payload.division_id && Number(payload.division_id) > 0) { + return postDivisionPosition + } + delete payload.division_id; + return postDivision +} + +function selectPatch(id: number | string, payload: any) { + if (payload.division_id && Number(payload.division_id) > 0) { + return patchDivisionPosition + } + delete payload.division_id; + return patchDivision +} + +function selectRemove(payload: any) { + if (payload.division_id && Number(payload.division_id) > 0) { + return removeDivisionPosition + } + return removeDivision +} export const { recId, @@ -15,7 +43,7 @@ export const { handleActionRemove, handleCancelForm, } = createCrudHandler({ - post: postDivision, - patch: patchDivision, - remove: removeDivision, + post: (payload: any) => selectPost(payload)(payload), + patch: (id: number | string, payload: any) => selectPatch(id, payload)(id, payload), + remove: (payload: any) => selectRemove(payload)(payload), })