diff --git a/nuxt4/app/components/operaciones/Form.vue b/nuxt4/app/components/operaciones/Form.vue
index 12bf4bd..89c7778 100644
--- a/nuxt4/app/components/operaciones/Form.vue
+++ b/nuxt4/app/components/operaciones/Form.vue
@@ -63,6 +63,7 @@
+
+
+
+
+
Nuevo lote de entrada
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
()
-const { fetchLotes, createOperacion, TIPOS_OPERACION, TIPOS_LOTE } = useLotes()
+const { fetchLotes, createLote, createOperacion, TIPOS_OPERACION, TIPOS_LOTE } = useLotes()
const step = ref(1)
const loading = ref(false)
const loadingLotes = ref(false)
const lotesDisponibles = ref([])
+const showCreateInputForm = ref(false)
+const creatingInput = ref(false)
+const newInputLote = ref({
+ codigo: '',
+ tipo: '',
+ cantidad_kg: undefined as number | undefined,
+})
const formState = ref({
tipo: '',
@@ -247,6 +315,43 @@ const removeOutput = (index: number) => {
formState.value.outputs.splice(index, 1)
}
+const cancelCreateInput = () => {
+ showCreateInputForm.value = false
+ newInputLote.value = {
+ codigo: '',
+ tipo: '',
+ cantidad_kg: undefined,
+ }
+}
+
+const handleCreateInput = async () => {
+ creatingInput.value = true
+ try {
+ const createdLote = await createLote({
+ codigo: newInputLote.value.codigo || undefined,
+ tipo: newInputLote.value.tipo,
+ cantidad_kg: newInputLote.value.cantidad_kg,
+ })
+
+ if (createdLote) {
+ // Agregar a la lista de lotes disponibles
+ lotesDisponibles.value.unshift(createdLote)
+
+ // Seleccionarlo automáticamente como input
+ formState.value.inputs.push({
+ lote_id: createdLote.id,
+ cantidad_kg: createdLote.cantidad_kg || undefined,
+ _lote: createdLote,
+ })
+
+ // Cerrar el formulario
+ cancelCreateInput()
+ }
+ } finally {
+ creatingInput.value = false
+ }
+}
+
const getTipoLabel = (tipo: string) => {
const foundOp = TIPOS_OPERACION.find((t) => t.value === tipo)
if (foundOp) return foundOp.label