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
122
123
124
| <script lang="ts" setup>
| import type { MesMdItemApi } from '#/api/mes/md/item';
| import type { MesPdBomApi } from '#/api/mes/pd/bom';
|
| import { ref } from 'vue';
|
| import { useVbenModal } from '#/packages/effects/common-ui/src';
|
| import { message } from 'ant-design-vue';
|
| import { useVbenForm } from '#/adapter/form';
| import { createPdBomLine, updatePdBomLine } from '#/api/mes/pd/bom';
| import { $t } from '#/locales';
| import { MdItemSelect } from '#/views/mes/md/item/components';
|
| const emit = defineEmits(['success']);
|
| const isUpdate = ref(false);
|
| const [Form, formApi] = useVbenForm({
| commonConfig: {
| componentProps: { class: 'w-full' },
| labelWidth: 100,
| },
| layout: 'horizontal',
| schema: [
| {
| fieldName: 'id',
| component: 'Input',
| dependencies: { triggerFields: [''], show: () => false },
| },
| {
| fieldName: 'projectId',
| component: 'Input',
| dependencies: { triggerFields: [''], show: () => false },
| },
| {
| fieldName: 'itemId',
| label: '物料',
| component: MdItemSelect,
| componentProps: {
| placeholder: '请选择物料',
| onChange: async (item: MesMdItemApi.Item | undefined) => {
| await formApi.setValues({
| itemCode: item?.code,
| itemName: item?.name,
| specification: item?.specification,
| unitMeasureName: item?.unitMeasureName,
| });
| },
| },
| rules: 'selectRequired',
| },
| {
| fieldName: 'itemCode',
| label: '物料编码',
| component: 'Input',
| componentProps: { disabled: true },
| },
| {
| fieldName: 'itemName',
| label: '物料名称',
| component: 'Input',
| componentProps: { disabled: true },
| },
| {
| fieldName: 'quantity',
| label: '用量',
| component: 'InputNumber',
| componentProps: { min: 0, precision: 4, class: 'w-full' },
| rules: 'required',
| },
| {
| fieldName: 'remark',
| label: '备注',
| component: 'Textarea',
| componentProps: { placeholder: '请输入备注', rows: 2 },
| },
| ],
| showDefaultActions: false,
| });
|
| const [Modal, modalApi] = useVbenModal({
| async onConfirm() {
| const { valid } = await formApi.validate();
| if (!valid) {
| return;
| }
| modalApi.lock();
| const data = (await formApi.getValues()) as MesPdBomApi.BomLine;
| try {
| if (isUpdate.value) {
| await updatePdBomLine(data);
| } else {
| await createPdBomLine(data);
| }
| emit('success');
| message.success($t('ui.actionMessage.operationSuccess'));
| await modalApi.close();
| } finally {
| modalApi.unlock();
| }
| },
| async onOpenChange(isOpen: boolean) {
| if (!isOpen) {
| return;
| }
| const data = modalApi.getData<{ projectId: number; row?: MesPdBomApi.BomLine }>();
| isUpdate.value = !!data.row?.id;
| modalApi.setState({ title: isUpdate.value ? '编辑 BOM 行' : '添加 BOM 行' });
| if (data.row) {
| await formApi.setValues(data.row);
| return;
| }
| await formApi.setValues({ projectId: data.projectId, quantity: 1 });
| },
| });
| </script>
|
| <template>
| <Modal class="w-[560px]">
| <Form class="mx-4" />
| </Modal>
| </template>
|
|