提交
This commit is contained in:
1 parent
1938a9b76a
commit
9da462fcba
36 files changed
+609614
-6945
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import type { Personnel, PersonnelDetail, VehiclePersonnelRow } from '@/api/pl'
|
||||
|
||||
/** 车辆关联人员:人员表单保存后同步下拉选项并选中当前行 */
|
||||
export function usePlVehiclePersonnelQuickCreate(options: {
|
||||
personnelOptions: Ref<Personnel[]>
|
||||
onSelect: (row: VehiclePersonnelRow, personnelId: string | undefined) => void
|
||||
}) {
|
||||
function upsertPersonnelOption(personnel: PersonnelDetail) {
|
||||
const next = personnel as Personnel
|
||||
const index = options.personnelOptions.value.findIndex((item) => item.id === next.id)
|
||||
if (index >= 0) {
|
||||
const list = [...options.personnelOptions.value]
|
||||
list[index] = next
|
||||
options.personnelOptions.value = list
|
||||
return
|
||||
}
|
||||
options.personnelOptions.value = [next, ...options.personnelOptions.value]
|
||||
}
|
||||
|
||||
function handlePersonnelFormSaved(
|
||||
row: VehiclePersonnelRow,
|
||||
payload: { mode: 'create' | 'edit'; personnel: PersonnelDetail }
|
||||
) {
|
||||
upsertPersonnelOption(payload.personnel)
|
||||
options.onSelect(row, payload.personnel.id)
|
||||
}
|
||||
|
||||
return {
|
||||
handlePersonnelFormSaved
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user