<script lang="ts" setup>
|
import type { VbenFormSchema } from "#/adapter/form";
|
|
import { useVbenModal } from "@vben/common-ui";
|
import { MesProBatchStatusEnum } from "@vben/constants";
|
import { message } from "ant-design-vue";
|
|
import { useVbenForm } from "#/adapter/form";
|
import { bindBagCodeBatch } from "#/api/mes/pro/bagCode";
|
import { getBatchSimpleList } from "#/api/mes/pro/batch";
|
import { $t } from "#/locales";
|
|
defineOptions({ name: "MesProBagCodeBindBatch" });
|
|
interface ModalData { ids: number[] }
|
const emit = defineEmits(["success"]);
|
|
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;
|
const data = modalApi.getData<ModalData>();
|
const values = await formApi.getValues();
|
modalApi.lock();
|
try {
|
await bindBagCodeBatch({ batchId: values.batchId, ids: data.ids });
|
message.success($t("ui.actionMessage.operationSuccess"));
|
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 && batch.code,
|
)
|
.map((batch) => ({ label: batch.code!, value: batch.id! }));
|
const schema: VbenFormSchema[] = [{
|
fieldName: "batchId", label: "生产批次", component: "Select",
|
componentProps: { options, optionFilterProp: "label", placeholder: "请选择生产中的批次", showSearch: true },
|
rules: "selectRequired",
|
}];
|
await formApi.setState({ schema });
|
} finally { modalApi.unlock(); }
|
},
|
});
|
</script>
|
|
<template>
|
<Modal title="录入生产批次" class="w-2/5"><Form class="mx-4" /></Modal>
|
</template>
|