f94b6d273a
* fix: adjustment some schemas * fix(room): fixing integrate unit of room * feat(warehouse): modify form and integration * feat(counter): modify form and integration * feat(screen): add list, form and integration * feat(screen): add page for public screen * fix: add on reset state at list * fix: solve list of relation * feat(chamber): integrate form to api chamber * feat(bed): integrate form to api bed * fix: add searching function on list service * fix: rewrite style for dropdown and tree select * fix: add sort params * fix: add sort params on division + medicine * feat(division-position): layouting form + list * fix: add sort params for getValueList * chore: modify side menu style * chore: fix ui dashboard * feat(division-position): add content list * feat(division-position): add temporary page * feat(division-position): modify content and entry form
109 lines
3.2 KiB
Vue
109 lines
3.2 KiB
Vue
<script setup lang="ts">
|
|
// Components
|
|
import Block from '~/components/pub/my-ui/doc-entry/block.vue'
|
|
import Cell from '~/components/pub/my-ui/doc-entry/cell.vue'
|
|
import Field from '~/components/pub/my-ui/doc-entry/field.vue'
|
|
import Label from '~/components/pub/my-ui/doc-entry/label.vue'
|
|
import Button from '~/components/pub/ui/button/Button.vue'
|
|
|
|
// Constants
|
|
import { infraGroupCodesKeys } from "~/lib/constants"
|
|
|
|
// Types
|
|
import type { InfraFormData } from '~/schemas/infra.schema'
|
|
|
|
// Helpers
|
|
import type z from 'zod'
|
|
import { useForm } from 'vee-validate'
|
|
import { toTypedSchema } from '@vee-validate/zod'
|
|
|
|
interface Props {
|
|
schema: z.ZodSchema<any>
|
|
values: any
|
|
isLoading?: boolean
|
|
isReadonly?: boolean
|
|
}
|
|
|
|
const props = defineProps<Props>()
|
|
const isLoading = props.isLoading !== undefined ? props.isLoading : false
|
|
const isReadonly = props.isReadonly !== undefined ? props.isReadonly : false
|
|
const emit = defineEmits<{
|
|
submit: [values: InfraFormData, resetForm: () => void]
|
|
cancel: [resetForm: () => void]
|
|
}>()
|
|
|
|
const { defineField, errors, meta } = useForm({
|
|
validationSchema: toTypedSchema(props.schema),
|
|
initialValues: {
|
|
code: '',
|
|
name: '',
|
|
infraGroup_code: infraGroupCodesKeys.counter,
|
|
parent_id: null,
|
|
} as Partial<InfraFormData>,
|
|
})
|
|
|
|
const [code, codeAttrs] = defineField('code')
|
|
const [name, nameAttrs] = defineField('name')
|
|
const [infraGroup_code] = defineField('infraGroup_code')
|
|
const [parent_id] = defineField('parent_id')
|
|
|
|
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.infraGroup_code !== undefined) infraGroup_code.value = props.values.infraGroup_code
|
|
if (props.values.parent_id !== undefined) parent_id.value = props.values.parent_id
|
|
}
|
|
|
|
const resetForm = () => {
|
|
code.value = ''
|
|
name.value = ''
|
|
infraGroup_code.value = infraGroupCodesKeys.counter
|
|
parent_id.value = null
|
|
}
|
|
|
|
function onSubmitForm() {
|
|
const formData: InfraFormData = {
|
|
code: code.value || '',
|
|
name: name.value || '',
|
|
infraGroup_code: infraGroup_code.value || infraGroupCodesKeys.counter,
|
|
parent_id: parent_id.value || null,
|
|
}
|
|
emit('submit', formData, resetForm)
|
|
}
|
|
|
|
function onCancelForm() {
|
|
emit('cancel', resetForm)
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<form id="form-building" @submit.prevent>
|
|
<Block labelSize="thin" class="!mb-2.5 !pt-0 xl:!mb-3" :colCount="1">
|
|
<Cell>
|
|
<Label height="compact">Kode</Label>
|
|
<Field :errMessage="errors.code">
|
|
<Input id="code" v-model="code" v-bind="codeAttrs" :disabled="isLoading || isReadonly" />
|
|
</Field>
|
|
</Cell>
|
|
<Cell>
|
|
<Label height="compact">Nama</Label>
|
|
<Field :errMessage="errors.name">
|
|
<Input id="name" v-model="name" v-bind="nameAttrs" :disabled="isLoading || isReadonly" />
|
|
</Field>
|
|
</Cell>
|
|
</Block>
|
|
<div class="my-2 flex justify-end gap-2 py-2">
|
|
<Button type="button" variant="secondary" class="w-[120px]" @click="onCancelForm"> Kembali </Button>
|
|
<Button
|
|
v-if="!isReadonly"
|
|
type="button"
|
|
class="w-[120px]"
|
|
:disabled="isLoading || !meta.valid"
|
|
@click="onSubmitForm"
|
|
>
|
|
Simpan
|
|
</Button>
|
|
</div>
|
|
</form>
|
|
</template>
|