feat(device): integrate api device

This commit is contained in:
riefive
2025-09-22 13:39:36 +07:00
parent 1e5b872f05
commit 6b950f7682
6 changed files with 235 additions and 137 deletions
+12 -23
View File
@@ -9,7 +9,6 @@ import type { DeviceFormData } from '~/schemas/device'
interface Props {
schema: z.ZodSchema<any>
uoms: any[]
items: any[]
}
const isLoading = ref(false)
@@ -32,13 +31,11 @@ const { handleSubmit, defineField, errors } = useForm({
const [code, codeAttrs] = defineField('code')
const [name, nameAttrs] = defineField('name')
const [uom, uomAttrs] = defineField('uom_code')
const [item, itemAttrs] = defineField('item_id')
const resetForm = () => {
code.value = ''
name.value = ''
uom.value = ''
item.value = ''
}
// Form submission handler
@@ -47,7 +44,6 @@ function onSubmitForm(values: any) {
name: values.name || '',
code: values.code || '',
uom_code: values.uom_code || '',
item_id: values.item_id || '',
}
emit('submit', formData, resetForm)
}
@@ -59,7 +55,7 @@ function onCancelForm() {
</script>
<template>
<form class="grid gap-2" @submit="handleSubmit(onSubmitForm)">
<form id="form-tools" class="grid gap-2">
<div class="grid gap-2">
<label for="code">Kode</label>
<Input
@@ -102,26 +98,19 @@ function onCancelForm() {
{{ errors.uom_code }}
</span>
</div>
<div class="grid gap-2">
<label for="item">Item</label>
<Select
id="item"
icon-name="i-lucide-chevron-down"
placeholder="Pilih item"
v-model="item"
v-bind="itemAttrs"
:items="items"
:disabled="isLoading"
:class="{ 'border-red-500': errors.item_id }"
/>
<span v-if="errors.item_id" class="text-sm text-red-500">
{{ errors.item_id }}
</span>
</div>
<div class="my-2 flex justify-end gap-2 py-2">
<Button variant="secondary" class="w-[120px]" @click="onCancelForm"> Kembali </Button>
<Button type="submit" class="w-[120px]">
<Loader2 v-if="isLoading" class="mr-2 h-4 w-4 animate-spin" />
<Button
type="button"
class="w-[120px]"
:disabled="isLoading"
@click="
() => {
handleSubmit(onSubmitForm)()
}
"
>
<!-- <Loader2 v-if="isLoading" class="mr-2 h-4 w-4 animate-spin" /> -->
Simpan
</Button>
</div>