AddOrUpdate.tsx
2.29 KB
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
import { postProductCollectBillAddOrModify } from '@/services';
import { useModel } from '@@/exports';
import {
ModalForm,
ProFormDigit,
ProFormSelect,
ProFormText,
ProFormTextArea,
} from '@ant-design/pro-components';
import { Button, Form, message } from 'antd';
export default ({ record, onFinish }) => {
const [form] = Form.useForm();
const { getWarehouse } = useModel('enum');
return (
<ModalForm
title="新建表单"
trigger={
record?.id ? (
<Button type="link">修改</Button>
) : (
<Button type="primary">新建</Button>
)
}
form={form}
autoFocusFirstInput
modalProps={{
destroyOnClose: true,
onCancel: () => console.log('run'),
}}
submitTimeout={2000}
onFinish={async (values) => {
let res = await postProductCollectBillAddOrModify({
data: values,
});
if (res) {
message.success(res.message);
onFinish();
}
return true;
}}
>
<ProFormDigit
label="id"
name="id"
initialValue={record?.id}
width="sm"
hidden={true}
/>
<ProFormText
width="md"
initialValue={record?.productName}
name="productName"
label="申领物品"
rules={[{ required: true, message: '申领物品必填' }]}
/>
<ProFormDigit
label="申领数量"
name="productNumber"
initialValue={record?.productNumber}
width="sm"
min={1}
rules={[{ required: true, message: '申领数量必填' }]}
/>
<ProFormSelect
width="md"
request={async () => {
const res = await getWarehouse();
console.log('options:' + res);
let options = Object.entries(res).map(([value, label]) => ({
label,
value,
}));
console.log('options:' + options);
return options;
}}
// initialValue={record?.warehouseCode}
name="warehouseCode"
label="申领仓库"
rules={[{ required: true, message: '申领仓库为必填项' }]}
/>
<ProFormTextArea
initialValue={record?.applyRemarks}
name="applyRemarks"
label="申领备注"
/>
</ModalForm>
);
};