| | |
| | | <script lang="ts" setup> |
| | | import type { VbenFormSchema } from "#/adapter/form"; |
| | | import type { MesProPalletApi } from "#/api/mes/pro/pallet"; |
| | | |
| | | import { useVbenModal } from "@vben/common-ui"; |
| | | import { MesProBatchStatusEnum } from "@vben/constants"; |
| | | |
| | | import { message } from "ant-design-vue"; |
| | | |
| | | import { useVbenForm } from "#/adapter/form"; |
| | | import { getBatchSimpleList } from "#/api/mes/pro/batch"; |
| | | import { batchCreatePallet } from "#/api/mes/pro/pallet"; |
| | | import { preGeneratePallet } from "#/api/mes/pro/pallet"; |
| | | |
| | | defineOptions({ name: "MesProPalletGenerateForm" }); |
| | | |
| | | const emit = defineEmits(["success"]); |
| | | |
| | | /** 构建表单(批次下拉选项由外部加载注入) */ |
| | | function buildSchema(batchOptions: { label: string; value: number }[]): VbenFormSchema[] { |
| | | return [ |
| | | { |
| | | fieldName: "batchId", |
| | | label: "生产批次", |
| | | component: "Select", |
| | | const [Form, formApi] = useVbenForm({ |
| | | commonConfig: { |
| | | componentProps: { |
| | | options: batchOptions, |
| | | optionFilterProp: "label", |
| | | placeholder: "请选择生产中的批次", |
| | | showSearch: true, |
| | | class: "w-full", |
| | | }, |
| | | rules: "selectRequired", |
| | | labelWidth: 100, |
| | | }, |
| | | layout: "horizontal", |
| | | schema: [], |
| | | showDefaultActions: false, |
| | | }); |
| | | |
| | | const [Modal, modalApi] = useVbenModal({ |
| | | async onConfirm() { |
| | | const { valid } = await formApi.validate(); |
| | | if (!valid) return; |
| | | modalApi.lock(); |
| | | try { |
| | | const values = await formApi.getValues(); |
| | | const result = await preGeneratePallet({ |
| | | count: values.count, |
| | | capacity: values.capacity, |
| | | remark: values.remark, |
| | | }); |
| | | message.success(`已生成 ${result.length} 个临时托盘码`); |
| | | emit("success", result); |
| | | await modalApi.close(); |
| | | } finally { |
| | | modalApi.unlock(); |
| | | } |
| | | }, |
| | | onOpenChange(isOpen: boolean) { |
| | | if (!isOpen) return; |
| | | const schema: VbenFormSchema[] = [ |
| | | { |
| | | fieldName: "count", |
| | | label: "生成数量", |
| | |
| | | }, |
| | | }, |
| | | ]; |
| | | } |
| | | |
| | | const [Form, formApi] = useVbenForm({ |
| | | commonConfig: { |
| | | componentProps: { |
| | | class: "w-full", |
| | | }, |
| | | labelWidth: 100, |
| | | }, |
| | | layout: "horizontal", |
| | | schema: [], |
| | | showDefaultActions: false, |
| | | }); |
| | | |
| | | const [Modal, modalApi] = useVbenModal({ |
| | | async onConfirm() { |
| | | const { valid } = await formApi.validate(); |
| | | if (!valid) return; |
| | | modalApi.lock(); |
| | | try { |
| | | const values = |
| | | (await formApi.getValues()) as MesProPalletApi.BatchCreateParams; |
| | | const ids = await batchCreatePallet(values); |
| | | message.success(`已成功生成 ${ids.length} 个托盘码`); |
| | | emit("success"); |
| | | await modalApi.close(); |
| | | } finally { |
| | | modalApi.unlock(); |
| | | } |
| | | }, |
| | | async onOpenChange(isOpen: boolean) { |
| | | if (!isOpen) return; |
| | | modalApi.lock(); |
| | | try { |
| | | // 仅生产中的批次允许生成托盘码 |
| | | const batches = await getBatchSimpleList(); |
| | | const options = batches |
| | | .filter( |
| | | (batch) => batch.status === MesProBatchStatusEnum.PRODUCING |
| | | ) |
| | | .map((batch) => ({ |
| | | label: batch.code!, |
| | | value: batch.id!, |
| | | })); |
| | | await formApi.setState({ schema: buildSchema(options) }); |
| | | } finally { |
| | | modalApi.unlock(); |
| | | } |
| | | formApi.setState({ schema }); |
| | | }, |
| | | }); |
| | | </script> |
| | | |
| | | <template> |
| | | <Modal title="批量生成托盘码" class="w-2/5"> |
| | | <Modal title="预生成托盘二维码" class="w-2/5"> |
| | | <Form class="mx-4" /> |
| | | </Modal> |
| | | </template> |