fix: update list division + equipment
This commit is contained in:
@@ -29,10 +29,9 @@ import {
|
|||||||
handleActionRemove,
|
handleActionRemove,
|
||||||
handleCancelForm,
|
handleCancelForm,
|
||||||
} from '~/handlers/division.handler'
|
} from '~/handlers/division.handler'
|
||||||
import { convertDivisionToTreeItems } from '~/handlers/_shared.handler'
|
|
||||||
|
|
||||||
// Services
|
// Services
|
||||||
import { getDivisions, getDivisionDetail } from '~/services/division.service'
|
import { getList, getDetail, getValueTreeItems } from '~/services/division.service'
|
||||||
|
|
||||||
const divisionsTrees = ref<TreeItem[]>([])
|
const divisionsTrees = ref<TreeItem[]>([])
|
||||||
const title = ref('')
|
const title = ref('')
|
||||||
@@ -47,11 +46,10 @@ const {
|
|||||||
fetchData: getDivisionList,
|
fetchData: getDivisionList,
|
||||||
} = usePaginatedList({
|
} = usePaginatedList({
|
||||||
fetchFn: async (params: any) => {
|
fetchFn: async (params: any) => {
|
||||||
// TODO: use pagination params
|
const result = await getList({
|
||||||
const result = await getDivisions({
|
|
||||||
search: params.search,
|
search: params.search,
|
||||||
'page-number': params['page-number'] || 0,
|
'page-number': params['page-number'] || 0,
|
||||||
'page-size': params['page-size'] || 100,
|
'page-size': params['page-size'] || 10,
|
||||||
includes: 'parent,childrens',
|
includes: 'parent,childrens',
|
||||||
})
|
})
|
||||||
return { success: result.success || false, body: result.body || {} }
|
return { success: result.success || false, body: result.body || {} }
|
||||||
@@ -91,7 +89,7 @@ provide('rec_item', recItem)
|
|||||||
provide('table_data_loader', isLoading)
|
provide('table_data_loader', isLoading)
|
||||||
|
|
||||||
const getCurrentDivisionDetail = async (id: number | string) => {
|
const getCurrentDivisionDetail = async (id: number | string) => {
|
||||||
const result = await getDivisionDetail(id)
|
const result = await getDetail(id)
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
const currentValue = result.body?.data || {}
|
const currentValue = result.body?.data || {}
|
||||||
recItem.value = currentValue
|
recItem.value = currentValue
|
||||||
@@ -122,14 +120,14 @@ watch(
|
|||||||
() => data.value,
|
() => data.value,
|
||||||
async () => {
|
async () => {
|
||||||
if (!data.value) return
|
if (!data.value) return
|
||||||
const result = await getDivisions({
|
const result = await getList({
|
||||||
'page-size': 100,
|
'page-size': 100,
|
||||||
'only-have-children': false,
|
'only-have-children': false,
|
||||||
includes: 'parent,childrens',
|
includes: 'parent,childrens',
|
||||||
})
|
})
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
const currentData = result.body.data || []
|
const currentData = result.body.data || []
|
||||||
divisionsTrees.value = convertDivisionToTreeItems(currentData || [])
|
divisionsTrees.value = getValueTreeItems(currentData || [])
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import { toast } from '~/components/pub/ui/toast'
|
|||||||
// Types
|
// Types
|
||||||
import { ActionEvents, type HeaderPrep } from '~/components/pub/my-ui/data/types'
|
import { ActionEvents, type HeaderPrep } from '~/components/pub/my-ui/data/types'
|
||||||
import { MaterialSchema, type MaterialFormData } from '~/schemas/material.schema'
|
import { MaterialSchema, type MaterialFormData } from '~/schemas/material.schema'
|
||||||
import type { Uom } from '~/models/uom'
|
|
||||||
|
|
||||||
// Handlers
|
// Handlers
|
||||||
import {
|
import {
|
||||||
@@ -29,11 +28,12 @@ import {
|
|||||||
handleActionRemove,
|
handleActionRemove,
|
||||||
handleCancelForm,
|
handleCancelForm,
|
||||||
} from '~/handlers/material.handler'
|
} from '~/handlers/material.handler'
|
||||||
import { uoms, getUomList } from '~/handlers/_shared.handler'
|
|
||||||
|
|
||||||
// Services
|
// Services
|
||||||
import { getMaterials, getMaterialDetail } from '~/services/material.service'
|
import { getList, getDetail } from '~/services/material.service'
|
||||||
|
import { getValueLabelList as getUomList } from '~/services/uom.service'
|
||||||
|
|
||||||
|
const uoms = ref<{ value: string; label: string }[]>([])
|
||||||
const title = ref('')
|
const title = ref('')
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -46,8 +46,11 @@ const {
|
|||||||
fetchData: getEquipmentList,
|
fetchData: getEquipmentList,
|
||||||
} = usePaginatedList({
|
} = usePaginatedList({
|
||||||
fetchFn: async (params: any) => {
|
fetchFn: async (params: any) => {
|
||||||
// TODO: use pagination params
|
const result = await getList({
|
||||||
const result = await getMaterials({ search: params.search, page: params['page-number'] || 0 })
|
search: params.search,
|
||||||
|
'page-number': params['page-number'] || 0,
|
||||||
|
'page-size': params['page-size'] || 10,
|
||||||
|
})
|
||||||
return { success: result.success || false, body: result.body || {} }
|
return { success: result.success || false, body: result.body || {} }
|
||||||
},
|
},
|
||||||
entityName: 'equipment',
|
entityName: 'equipment',
|
||||||
@@ -85,7 +88,7 @@ provide('rec_item', recItem)
|
|||||||
provide('table_data_loader', isLoading)
|
provide('table_data_loader', isLoading)
|
||||||
|
|
||||||
const getCurrentMaterialDetail = async (id: number | string) => {
|
const getCurrentMaterialDetail = async (id: number | string) => {
|
||||||
const result = await getMaterialDetail(id)
|
const result = await getDetail(id)
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
const currentValue = result.body?.data || {}
|
const currentValue = result.body?.data || {}
|
||||||
recItem.value = currentValue
|
recItem.value = currentValue
|
||||||
@@ -113,8 +116,8 @@ watch([recId, recAction], () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
uoms.value = await getUomList()
|
||||||
await getEquipmentList()
|
await getEquipmentList()
|
||||||
await getUomList()
|
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
// types
|
|
||||||
import type { Division } from '~/models/division'
|
|
||||||
import type { TreeItem } from '~/models/_model'
|
|
||||||
|
|
||||||
// variables
|
// variables
|
||||||
export const medicineGroups = ref<{ value: string; label: string }[]>([])
|
export const medicineGroups = ref<{ value: string; label: string }[]>([])
|
||||||
@@ -12,19 +10,3 @@ export const specialists = ref<{ value: string | number; label: string }[]>([])
|
|||||||
export const uoms = ref<{ value: string; label: string }[]>([])
|
export const uoms = ref<{ value: string; label: string }[]>([])
|
||||||
export const units = ref<{ value: string | number; label: string }[]>([])
|
export const units = ref<{ value: string | number; label: string }[]>([])
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert division response (with childrens) to TreeItem[]
|
|
||||||
* @param divisions Array of division objects from API
|
|
||||||
* @returns TreeItem[]
|
|
||||||
*/
|
|
||||||
export function convertDivisionToTreeItems(divisions: any[]): TreeItem[] {
|
|
||||||
return divisions.filter((division: Division) => !division.parent_id).map((division: Division) => ({
|
|
||||||
value: division.id ? String(division.id) : division.code,
|
|
||||||
label: division.name,
|
|
||||||
hasChildren: Array.isArray(division.childrens) && division.childrens.length > 0,
|
|
||||||
children:
|
|
||||||
Array.isArray(division.childrens) && division.childrens.length > 0
|
|
||||||
? convertDivisionToTreeItems(division.childrens)
|
|
||||||
: undefined,
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import * as base from './_crud-base'
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import type { Division } from '~/models/division'
|
import type { Division } from '~/models/division'
|
||||||
|
import type { TreeItem } from '~/models/_model'
|
||||||
|
|
||||||
const path = '/api/v1/division'
|
const path = '/api/v1/division'
|
||||||
const name = 'division'
|
const name = 'division'
|
||||||
@@ -39,3 +40,22 @@ export async function getValueLabelList(params: any = null): Promise<{ value: st
|
|||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert division response (with childrens) to TreeItem[]
|
||||||
|
* @param divisions Array of division objects from API
|
||||||
|
* @returns TreeItem[]
|
||||||
|
*/
|
||||||
|
export function getValueTreeItems(divisions: any[]): TreeItem[] {
|
||||||
|
return divisions
|
||||||
|
.filter((division: Division) => !division.parent_id)
|
||||||
|
.map((division: Division) => ({
|
||||||
|
value: division.id ? String(division.id) : division.code,
|
||||||
|
label: division.name,
|
||||||
|
hasChildren: Array.isArray(division.childrens) && division.childrens.length > 0,
|
||||||
|
children:
|
||||||
|
Array.isArray(division.childrens) && division.childrens.length > 0
|
||||||
|
? getValueTreeItems(division.childrens)
|
||||||
|
: undefined,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user