1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
| <script lang="ts" setup>
| import type { VbenFormSchema } from "#/adapter/form";
|
| import { useVbenModal } from "@vben/common-ui";
| import { MesProPalletStatusEnum } from "@vben/constants";
|
| import { message } from "ant-design-vue";
|
| import { useVbenForm } from "#/adapter/form";
| import { bindBagCodePallet } from "#/api/mes/pro/bagCode";
| import { getPalletSimpleList } from "#/api/mes/pro/pallet";
| import { $t } from "#/locales";
|
| defineOptions({ name: "MesProBagCodeBindPallet" });
|
| /** 弹窗传入数据 */
| interface ModalData {
| batchId: number;
| batchCode?: string;
| ids: number[];
| }
|
| const emit = defineEmits(["success"]);
|
| /** 构建表单(托盘下拉选项由外部加载注入) */
| function buildSchema(palletOptions: { label: string; value: number }[]): VbenFormSchema[] {
| return [
| {
| fieldName: "batchCode",
| label: "生产批次",
| component: "Input",
| componentProps: {
| disabled: true,
| },
| },
| {
| fieldName: "bagCount",
| label: "绑定袋数",
| component: "InputNumber",
| componentProps: {
| class: "!w-full",
| disabled: true,
| },
| },
| {
| fieldName: "palletId",
| label: "目标托盘",
| component: "Select",
| componentProps: {
| optionFilterProp: "label",
| options: palletOptions,
| placeholder: "请选择目标托盘",
| showSearch: true,
| },
| rules: "selectRequired",
| },
| ];
| }
|
| 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 bindBagCodePallet({ palletId: values.palletId, ids: data.ids });
| message.success($t("ui.actionMessage.operationSuccess"));
| emit("success");
| await modalApi.close();
| } finally {
| modalApi.unlock();
| }
| },
| async onOpenChange(isOpen: boolean) {
| if (!isOpen) return;
| const data = modalApi.getData<ModalData>();
| modalApi.lock();
| try {
| // 加载该批次下的托盘(排除已作废)
| const pallets = await getPalletSimpleList(data.batchId);
| const options = pallets
| .filter(
| (pallet) => pallet.status !== MesProPalletStatusEnum.CANCELED
| )
| .map((pallet) => ({
| label: `${pallet.code}(已装 ${pallet.bagCount ?? 0} 袋 / 可装 ${
| pallet.capacity ?? "不限"
| } 袋)`,
| value: pallet.id!,
| }));
| await formApi.setState({ schema: buildSchema(options) });
| await formApi.setValues({
| bagCount: data.ids.length,
| batchCode: data.batchCode,
| });
| } finally {
| modalApi.unlock();
| }
| },
| });
| </script>
|
| <template>
| <Modal title="袋码绑定托盘" class="w-2/5">
| <Form class="mx-4" />
| </Modal>
| </template>
|
|