DeliverModal.tsx
7.49 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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
import { RESPONSE_CODE } from '@/constants/enum';
import {
postServiceOrderProcureSend,
postServiceOrderSendProduct,
postServiceOrderSupplierSendOrder,
} from '@/services';
import { enumToSelect } from '@/utils';
import {
ProColumns,
ProForm,
ProFormSelect,
ProFormText,
ProTable,
} from '@ant-design/pro-components';
import {
Button,
Col,
Flex,
Input,
InputNumber,
Modal,
Row,
Select,
message,
} from 'antd';
import { cloneDeep } from 'lodash';
import { useEffect, useRef, useState } from 'react';
import { CHECK_TYPE, LOGISTICS_STATUS_OPTIONS } from '../constant';
const DeliverModal = ({
data: propsData,
isSendProduct,
setVisible,
sendType,
onClose,
}) => {
const [data, setData] = useState(propsData || {});
const form = useRef();
/**
* 是供应商发货还是普通发货
* @param typeString
* @returns
*/
function optType(typeString: string) {
if (sendType === typeString) {
return true;
}
return false;
}
useEffect(() => {
setData(propsData);
}, [propsData]);
const handleChange = (key: string, index: number, obj: any) => {
const newData = cloneDeep(data);
if (typeof obj !== 'object') {
newData[index][key] = obj;
} else {
newData[index][key] = obj.target?.value;
}
setData(newData);
};
const columns: ProColumns<any>[] = [
{
title: 'ID',
dataIndex: 'id',
width: 120,
render: (_, record) => <Input value={record.id} disabled />,
},
{
title: '商品编号',
dataIndex: 'productCode',
width: 120,
render: (_, record) => <Input value={record.productCode} disabled />,
},
{
title: '商品名称',
dataIndex: 'productName',
width: 120,
render: (_, record) => <Input value={record.productName} disabled />,
},
{
title: '商品参数',
dataIndex: 'parameters',
width: 80,
render: (_, record) => <Input value={record.parameters} disabled />,
},
{
title: '商品数量',
dataIndex: 'status',
render: (_, record) => <InputNumber value={record.quantity} disabled />,
},
{
title: '包裹数量',
dataIndex: 'packageNumber',
render: (_, record, index) => (
<InputNumber
min={1}
value={record.packageNumber}
defaultValue={1}
onChange={(value) => handleChange('packageNumber', index, value)}
/>
),
},
{
title: '物流方式',
key: 'logisticsMethod',
render: (_, record, index) => (
<Select
style={{ minWidth: 150 }}
placeholder="请输入物流方式"
value={record.logisticsMethod}
options={enumToSelect(LOGISTICS_STATUS_OPTIONS)}
onChange={(value) => {
handleChange('logisticsMethod', index, value); //修改时更改record数据
if (value === 'OTHER_LOGISTICS') {
message.info(
'您选择的是[其他物流方式],请将该物流方式写在备注中',
);
}
}}
/>
),
},
{
title: '物流单号',
key: 'serialNumber',
render: (_, record, index) => (
<Input
placeholder="请输入物流单号"
value={record.serialNumber}
onChange={(value) => {
handleChange('serialNumber', index, value);
}}
/>
),
},
{
title: '物流备注',
dataIndex: 'packageNumber',
render: (_, record, index) => (
<Input.TextArea
value={record.logisticsNotes}
onChange={(value) => handleChange('logisticsNotes', index, value)}
/>
),
},
];
return (
<Modal
open
width={1000}
title={isSendProduct ? '发货' : '修改发货信息'}
onOk={async () => {
//请求体封装
let list = data.map((item) => {
return {
id: item.id,
logisticsMethod: item.logisticsMethod,
serialNumber: item.serialNumber,
packageNumber:
item.packageNumber === null || item.packageNumber === undefined
? 1
: item.packageNumber,
logisticsNotes: item.logisticsNotes,
};
});
for (let item of list) {
let method = item.logisticsMethod;
let notes = item.logisticsNotes;
if (
method === 'OTHER_LOGISTICS' &&
(notes === '' || notes === undefined)
) {
message.error(
'请检查:物流方式为[其他物流方式]的记录中,物流备注不能为空!请将实际的物流方式填写在备注中!',
);
return;
}
}
let body = { id: data[0].mainOrderId, list: list, flag: false };
if (isSendProduct) {
body.flag = true;
}
//发货请求
let res;
if (optType(CHECK_TYPE.SUPPLIER)) {
res = await postServiceOrderSupplierSendOrder({ data: body });
} else if (optType(CHECK_TYPE.PROCURE)) {
res = await postServiceOrderProcureSend({ data: body });
} else {
res = await postServiceOrderSendProduct({ data: body });
}
if (res.result === RESPONSE_CODE.SUCCESS) {
message.success(res.message);
onClose();
}
}}
onCancel={() => {
setVisible(false);
}}
>
<Flex vertical>
<strong>将物流方式和物流单号更新到下方所有订单</strong>
<span className="text-[red] py-1">
选择【其他物流方式】时,需要将对应的物流方式填写在备注中。例如:如果发圆通快递,系统上没有这个选项,就需要选【其他物流方式】,然后把“圆通快递”填在备注上。
</span>
</Flex>
<ProForm
layout="inline"
submitter={false}
className="mb-8"
formRef={form}
>
<Row gutter={[0, 6]}>
<Col>
<ProFormSelect
placeholder="请输入物流方式"
name="logisticsMethod"
width="sm"
label="物流方式"
options={enumToSelect(LOGISTICS_STATUS_OPTIONS)}
/>
<ProFormText name="logisticsNotes" label="物流备注"></ProFormText>
</Col>
<Col>
<ProFormText name="serialNumber" label="物流单号"></ProFormText>
</Col>
</Row>
<Button
type="primary"
onClick={() => {
const values = form.current.getFieldsValue();
if (values.logisticsMethod === 'OTHER_LOGISTICS') {
message.info(
'自动填充成功!您选择的是其他物流方式,请将物流方式写在物流备注中!',
);
}
let newData = cloneDeep(data);
newData = newData.map((item) => ({
...item,
logisticsMethod: values.logisticsMethod,
serialNumber: values.serialNumber,
logisticsNotes: values.logisticsNotes,
}));
setData(newData);
}}
>
批量更新
</Button>
</ProForm>
<ProTable<any>
className="px-0"
dataSource={data}
rowKey="id"
pagination={false}
columns={columns}
search={false}
dateFormatter="string"
options={false}
scroll={{ x: 1400 }}
/>
</Modal>
);
};
export default DeliverModal;