diff --git a/app/components/app/unit-position/entry-form.vue b/app/components/app/unit-position/entry-form.vue index da4782c0..b6ab8609 100644 --- a/app/components/app/unit-position/entry-form.vue +++ b/app/components/app/unit-position/entry-form.vue @@ -7,18 +7,18 @@ import Label from '~/components/pub/my-ui/doc-entry/label.vue' import Combobox from '~/components/pub/my-ui/combobox/combobox.vue' // Types -import type { DivisionPositionFormData } from '~/schemas/division-position.schema' +import type { UnitPositionFormData } from '~/schemas/unit-position.schema' // Helpers import type z from 'zod' import { toTypedSchema } from '@vee-validate/zod' import { useForm } from 'vee-validate' import { genBase } from '~/models/_base' -import { genDivisionPosition } from '~/models/division-position' +import { genUnitPosition } from '~/models/unit-position' interface Props { schema: z.ZodSchema - divisionId: number + units: any[] employees: any[] values: any isLoading?: boolean @@ -26,21 +26,21 @@ interface Props { } const props = defineProps() - const isLoading = props.isLoading !== undefined ? props.isLoading : false const isReadonly = props.isReadonly !== undefined ? props.isReadonly : false const emit = defineEmits<{ - submit: [values: DivisionPositionFormData, resetForm: () => void] + submit: [values: UnitPositionFormData, resetForm: () => void] cancel: [resetForm: () => void] }>() const { defineField, errors, meta } = useForm({ validationSchema: toTypedSchema(props.schema), - initialValues: genDivisionPosition() as Partial, + initialValues: genUnitPosition() as Partial, }) const [code, codeAttrs] = defineField('code') const [name, nameAttrs] = defineField('name') +const [unit, unitAttrs] = defineField('unit_id') const [employee, employeeAttrs] = defineField('employee_id') const [headStatus, headStatusAttrs] = defineField('headStatus') @@ -62,6 +62,7 @@ const headStatusStr = computed({ if (props.values) { if (props.values.code !== undefined) code.value = props.values.code if (props.values.name !== undefined) name.value = props.values.name + if (props.values.unit_id !== undefined) unit.value = props.values.unit_id ? Number(props.values.unit_id) : null if (props.values.employee_id !== undefined) employee.value = props.values.employee_id ? Number(props.values.employee_id) : null if (props.values.headStatus !== undefined) headStatus.value = !!props.values.headStatus @@ -70,20 +71,18 @@ if (props.values) { const resetForm = () => { code.value = '' name.value = '' + unit.value = null employee.value = null headStatus.value = false } // Form submission handler function onSubmitForm() { - const formData: DivisionPositionFormData = { + const formData: UnitPositionFormData = { ...genBase(), name: name.value || '', code: code.value || '', - - // readonly based on detail division - division_id: props.divisionId, - + unit_id: unit.value || null, employee_id: employee.value || null, headStatus: headStatus.value !== undefined ? headStatus.value : undefined, } @@ -98,7 +97,7 @@ function onCancelForm() {