From 9cb8dd9caf2bff499d5fc544a8685da9aa4fccb7 Mon Sep 17 00:00:00 2001 From: riefive Date: Mon, 8 Sep 2025 13:09:55 +0700 Subject: [PATCH 1/4] refactor(equipment): add modal form to component list --- .../{material => equipment}/entry-form.vue | 51 +++-- .../app/{material => equipment}/list-cfg.ts | 0 app/components/app/equipment/list.vue | 38 ++++ app/components/app/material/list.vue | 19 -- app/components/content/equipment/list.vue | 211 ++++++++++++++++++ app/components/flow/material/entry.vue | 39 ---- app/components/flow/material/list.vue | 65 ------ .../tools-equipment-src/equipment/add.vue | 2 +- .../tools-equipment-src/equipment/index.vue | 4 +- 9 files changed, 285 insertions(+), 144 deletions(-) rename app/components/app/{material => equipment}/entry-form.vue (75%) rename app/components/app/{material => equipment}/list-cfg.ts (100%) create mode 100644 app/components/app/equipment/list.vue delete mode 100644 app/components/app/material/list.vue create mode 100644 app/components/content/equipment/list.vue delete mode 100644 app/components/flow/material/entry.vue delete mode 100644 app/components/flow/material/list.vue diff --git a/app/components/app/material/entry-form.vue b/app/components/app/equipment/entry-form.vue similarity index 75% rename from app/components/app/material/entry-form.vue rename to app/components/app/equipment/entry-form.vue index d670f60c..03882cea 100644 --- a/app/components/app/material/entry-form.vue +++ b/app/components/app/equipment/entry-form.vue @@ -5,20 +5,18 @@ import { useForm } from 'vee-validate' // types import type z from 'zod' import type { MaterialFormData } from '~/schemas/material' -// components -import Label from '~/components/pub/custom-ui/form/label.vue' interface Props { - isLoading: boolean schema: z.ZodSchema uoms: any[] items: any[] } +const isLoading = ref(false) const props = defineProps() const emit = defineEmits<{ - back: [] - submit: [data: any] + submit: [values: MaterialFormData, resetForm: () => void] + cancel: [resetForm: () => void] }>() const { handleSubmit, defineField, errors } = useForm({ @@ -38,19 +36,36 @@ const [uom, uomAttrs] = defineField('uom_code') const [item, itemAttrs] = defineField('item_id') const [stock, stockAttrs] = defineField('stock') -const onSubmit = handleSubmit(async (values) => { - try { - emit('submit', values) - } catch (error) { - console.error('Submission failed:', error) +const resetForm = () => { + code.value = '' + name.value = '' + uom.value = '' + item.value = '' + stock.value = 0 +} + +// Form submission handler +function onSubmitForm(values: any) { + const formData: MaterialFormData = { + name: values.name || '', + code: values.code || '', + uom_code: values.uom_code || '', + item_id: values.item_id || '', + stock: values.stock || 0, } -}) + emit('submit', formData, resetForm) +} + +// Form cancel handler +function onCancelForm() { + emit('cancel', resetForm) +}