fix: update list division + equipment
This commit is contained in:
@@ -29,10 +29,9 @@ import {
|
||||
handleActionRemove,
|
||||
handleCancelForm,
|
||||
} from '~/handlers/division.handler'
|
||||
import { convertDivisionToTreeItems } from '~/handlers/_shared.handler'
|
||||
|
||||
// Services
|
||||
import { getDivisions, getDivisionDetail } from '~/services/division.service'
|
||||
import { getList, getDetail, getValueTreeItems } from '~/services/division.service'
|
||||
|
||||
const divisionsTrees = ref<TreeItem[]>([])
|
||||
const title = ref('')
|
||||
@@ -47,11 +46,10 @@ const {
|
||||
fetchData: getDivisionList,
|
||||
} = usePaginatedList({
|
||||
fetchFn: async (params: any) => {
|
||||
// TODO: use pagination params
|
||||
const result = await getDivisions({
|
||||
const result = await getList({
|
||||
search: params.search,
|
||||
'page-number': params['page-number'] || 0,
|
||||
'page-size': params['page-size'] || 100,
|
||||
'page-size': params['page-size'] || 10,
|
||||
includes: 'parent,childrens',
|
||||
})
|
||||
return { success: result.success || false, body: result.body || {} }
|
||||
@@ -91,7 +89,7 @@ provide('rec_item', recItem)
|
||||
provide('table_data_loader', isLoading)
|
||||
|
||||
const getCurrentDivisionDetail = async (id: number | string) => {
|
||||
const result = await getDivisionDetail(id)
|
||||
const result = await getDetail(id)
|
||||
if (result.success) {
|
||||
const currentValue = result.body?.data || {}
|
||||
recItem.value = currentValue
|
||||
@@ -122,14 +120,14 @@ watch(
|
||||
() => data.value,
|
||||
async () => {
|
||||
if (!data.value) return
|
||||
const result = await getDivisions({
|
||||
const result = await getList({
|
||||
'page-size': 100,
|
||||
'only-have-children': false,
|
||||
includes: 'parent,childrens',
|
||||
})
|
||||
if (result.success) {
|
||||
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
|
||||
import { ActionEvents, type HeaderPrep } from '~/components/pub/my-ui/data/types'
|
||||
import { MaterialSchema, type MaterialFormData } from '~/schemas/material.schema'
|
||||
import type { Uom } from '~/models/uom'
|
||||
|
||||
// Handlers
|
||||
import {
|
||||
@@ -29,11 +28,12 @@ import {
|
||||
handleActionRemove,
|
||||
handleCancelForm,
|
||||
} from '~/handlers/material.handler'
|
||||
import { uoms, getUomList } from '~/handlers/_shared.handler'
|
||||
|
||||
// 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 {
|
||||
@@ -46,8 +46,11 @@ const {
|
||||
fetchData: getEquipmentList,
|
||||
} = usePaginatedList({
|
||||
fetchFn: async (params: any) => {
|
||||
// TODO: use pagination params
|
||||
const result = await getMaterials({ search: params.search, page: params['page-number'] || 0 })
|
||||
const result = await getList({
|
||||
search: params.search,
|
||||
'page-number': params['page-number'] || 0,
|
||||
'page-size': params['page-size'] || 10,
|
||||
})
|
||||
return { success: result.success || false, body: result.body || {} }
|
||||
},
|
||||
entityName: 'equipment',
|
||||
@@ -85,7 +88,7 @@ provide('rec_item', recItem)
|
||||
provide('table_data_loader', isLoading)
|
||||
|
||||
const getCurrentMaterialDetail = async (id: number | string) => {
|
||||
const result = await getMaterialDetail(id)
|
||||
const result = await getDetail(id)
|
||||
if (result.success) {
|
||||
const currentValue = result.body?.data || {}
|
||||
recItem.value = currentValue
|
||||
@@ -113,8 +116,8 @@ watch([recId, recAction], () => {
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
uoms.value = await getUomList()
|
||||
await getEquipmentList()
|
||||
await getUomList()
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
// types
|
||||
import type { Division } from '~/models/division'
|
||||
import type { TreeItem } from '~/models/_model'
|
||||
|
||||
|
||||
// variables
|
||||
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 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
|
||||
import type { Division } from '~/models/division'
|
||||
import type { TreeItem } from '~/models/_model'
|
||||
|
||||
const path = '/api/v1/division'
|
||||
const name = 'division'
|
||||
@@ -39,3 +40,22 @@ export async function getValueLabelList(params: any = null): Promise<{ value: st
|
||||
}
|
||||
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