<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 { getBatchSimpleList } from "#/api/mes/pro/batch";
|
import { bindPalletBatch } from "#/api/mes/pro/pallet";
|
import { $t } from "#/locales";
|
|
defineOptions({ name: "MesProPalletBindBatch" });
|
|
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 bindPalletBatch({ 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>
|