feat(material): retest material
This commit is contained in:
@@ -5,12 +5,12 @@ import type { MaterialFormData } from '~/schemas/material'
|
||||
// helpers
|
||||
import { toTypedSchema } from '@vee-validate/zod'
|
||||
import { useForm } from 'vee-validate'
|
||||
import Alert from '~/components/pub/ui/alert/Alert.vue'
|
||||
// components
|
||||
|
||||
interface Props {
|
||||
schema: z.ZodSchema<any>
|
||||
uoms: any[]
|
||||
items: any[]
|
||||
}
|
||||
|
||||
const isLoading = ref(false)
|
||||
@@ -26,7 +26,6 @@ const { handleSubmit, defineField, errors } = useForm({
|
||||
code: '',
|
||||
name: '',
|
||||
uom_code: '',
|
||||
item_id: '',
|
||||
stock: 0,
|
||||
} as Partial<MaterialFormData>,
|
||||
})
|
||||
@@ -34,14 +33,12 @@ 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 [stock, stockAttrs] = defineField('stock')
|
||||
|
||||
const resetForm = () => {
|
||||
code.value = ''
|
||||
name.value = ''
|
||||
uom.value = ''
|
||||
item.value = ''
|
||||
stock.value = 0
|
||||
}
|
||||
|
||||
@@ -61,7 +58,7 @@ function onCancelForm() {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<form class="grid gap-2" @submit="handleSubmit(onSubmitForm)">
|
||||
<form id="form-equipment" class="grid gap-2">
|
||||
<div class="grid gap-2">
|
||||
<label for="code">Kode</label>
|
||||
<Input
|
||||
@@ -120,8 +117,16 @@ function onCancelForm() {
|
||||
</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]"
|
||||
@click="
|
||||
() => {
|
||||
handleSubmit(onSubmitForm)()
|
||||
}
|
||||
"
|
||||
>
|
||||
<!-- <Loader2 v-if="isLoading" class="mr-2 h-4 w-4 animate-spin" /> -->
|
||||
Simpan
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -7,6 +7,9 @@ import Header from '~/components/pub/custom-ui/nav-header/prep.vue'
|
||||
import AppEquipmentEntryForm from '~/components/app/equipment/entry-form.vue'
|
||||
import RecordConfirmation from '~/components/pub/custom-ui/confirmation/record-confirmation.vue'
|
||||
|
||||
// Types
|
||||
import type { Uom } from '~/models/uom'
|
||||
|
||||
// Handlers
|
||||
import {
|
||||
recId,
|
||||
@@ -23,16 +26,7 @@ import {
|
||||
import { getSourceMaterials, getSourceMaterialDetail } from '~/services/material.service'
|
||||
import { getSourceUoms } from '~/services/uom.service'
|
||||
|
||||
const uoms = [
|
||||
{ value: 'uom-1', label: 'Satuan 1' },
|
||||
{ value: 'uom-2', label: 'Satuan 2' },
|
||||
{ value: 'uom-3', label: 'Satuan 3' },
|
||||
]
|
||||
const items = [
|
||||
{ value: 'item-1', label: 'Item 1' },
|
||||
{ value: 'item-2', label: 'Item 2' },
|
||||
{ value: 'item-3', label: 'Item 3' },
|
||||
]
|
||||
const uoms = ref<{ value: string; label: string }[]>([])
|
||||
|
||||
const getEquipmentDetail = async (id: number | string) => {
|
||||
const result = await getSourceMaterialDetail(id)
|
||||
@@ -42,6 +36,13 @@ const getEquipmentDetail = async (id: number | string) => {
|
||||
}
|
||||
}
|
||||
|
||||
const getUomList = async () => {
|
||||
const result = await getSourceUoms()
|
||||
if (result.success) {
|
||||
uoms.value = result.data.map((uom: Uom) => ({ value: uom.code || uom.erp_id, label: uom.name }))
|
||||
}
|
||||
}
|
||||
|
||||
const {
|
||||
data,
|
||||
isLoading,
|
||||
@@ -51,7 +52,10 @@ const {
|
||||
handleSearch,
|
||||
fetchData: getEquipmentList,
|
||||
} = usePaginatedList({
|
||||
fetchFn: getSourceMaterials as any,
|
||||
fetchFn: async ({ page }) => {
|
||||
const result = await getSourceMaterials({ page })
|
||||
return result.data || []
|
||||
},
|
||||
entityName: 'equipment',
|
||||
})
|
||||
|
||||
@@ -100,7 +104,7 @@ watch(recId, () => {
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
await getSourceUoms()
|
||||
await getUomList();
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -115,7 +119,6 @@ onMounted(async () => {
|
||||
<AppEquipmentEntryForm
|
||||
:schema="MaterialSchema"
|
||||
:uoms="uoms"
|
||||
:items="items"
|
||||
@submit="(values: MaterialFormData, resetForm: any) => handleActionSave(values, getEquipmentList, resetForm)"
|
||||
@cancel="handleCancelForm"
|
||||
/>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export interface Uom {
|
||||
code: string
|
||||
name: string
|
||||
erp_id: string
|
||||
}
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
import process from 'node:process'
|
||||
import { defineEventHandler, getCookie, getRequestHeaders, getRequestURL, readBody } from 'h3'
|
||||
|
||||
const API_ORIGIN = process.env.API_ORIGIN as string
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const { method } = event.node.req
|
||||
const headers = getRequestHeaders(event)
|
||||
const url = getRequestURL(event)
|
||||
const config = useRuntimeConfig()
|
||||
|
||||
const apiOrigin = config.API_ORIGIN || API_ORIGIN
|
||||
const apiOrigin = config.API_ORIGIN
|
||||
const pathname = url.pathname.replace(/^\/api/, '')
|
||||
|
||||
const targetUrl = apiOrigin + pathname + (url.search || '')
|
||||
|
||||
Reference in New Issue
Block a user