DeliverModal.tsx
4.97 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
import { RESPONSE_CODE } from '@/constants/enum';
import { postServiceOrderSendProduct } from '@/services';
import { enumToSelect } from '@/utils';
import {
ProColumns,
ProForm,
ProFormSelect,
ProFormText,
ProTable,
} from '@ant-design/pro-components';
import { Button, Input, InputNumber, Modal, Select, message } from 'antd';
import { cloneDeep } from 'lodash';
import { useEffect, useRef, useState } from 'react';
import { LOGISTICS_STATUS_OPTIONS } from '../constant';
const DeliverModal = ({ data: propsData, isSendProduct, onClose }) => {
const [data, setData] = useState(propsData || {});
const form = useRef();
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',
width: 80,
dataIndex: 'id',
render: (_, record) => <Input value={record.id} disabled />,
},
{
title: '商品编号',
width: 80,
dataIndex: 'productCode',
render: (_, record) => <Input value={record.productCode} disabled />,
},
{
title: '商品名称',
dataIndex: 'productName',
align: 'right',
width: 80,
render: (_, record) => <Input value={record.productName} disabled />,
},
{
title: '商品参数',
dataIndex: 'parameters',
align: 'right',
width: 80,
render: (_, record) => <Input value={record.parameters} disabled />,
},
{
title: '商品数量',
width: 80,
dataIndex: 'status',
render: (_, record) => <InputNumber value={record.quantity} disabled />,
},
{
title: '包裹数量',
width: 80,
dataIndex: 'packageNumber',
render: (_, record, index) => (
<InputNumber
value={record.packageNumber}
onChange={(value) => handleChange('packageNumber', index, value)}
/>
),
},
{
title: '物流方式',
width: 150,
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数据
/>
),
},
{
title: '物流单号',
width: 150,
key: 'serialNumber',
render: (_, record, index) => (
<Input
placeholder="请输入物流单号"
value={record.serialNumber}
onChange={(value) => {
handleChange('serialNumber', index, value);
}}
/>
),
},
];
return (
<Modal
open
width={900}
title={isSendProduct ? '发货' : '修改发货信息'}
onOk={async () => {
//请求体封装
let list = data.map((item) => {
return {
id: item.id,
logisticsMethod: item.logisticsMethod,
serialNumber: item.serialNumber,
packageNumber: item.packageNumber,
};
});
let body = { id: data[0].mainOrderId, list: list, flag: false };
if (isSendProduct) {
body.flag = true;
}
//发货请求
const res = await postServiceOrderSendProduct({ data: body });
if (res.result === RESPONSE_CODE.SUCCESS) {
message.success(res.message);
onClose();
}
}}
onCancel={() => {
onClose();
}}
>
<strong>将物流方式和物流单号更新到下方所有订单</strong>
<ProForm
layout="inline"
submitter={false}
className="mb-8"
formRef={form}
>
<ProFormSelect
placeholder="请输入物流方式"
name="logisticsMethod"
width="sm"
label="物流方式"
options={enumToSelect(LOGISTICS_STATUS_OPTIONS)}
/>
<ProFormText name="serialNumber" label="物流单号"></ProFormText>
<Button
type="primary"
onClick={() => {
const values = form.current.getFieldsValue();
let newData = cloneDeep(data);
newData = newData.map((item) => ({
...item,
logisticsMethod: values.logisticsMethod,
serialNumber: values.serialNumber, // 物流单号?
}));
setData(newData);
}}
>
批量更新
</Button>
</ProForm>
<ProTable<any>
className="px-0"
dataSource={data}
rowKey="id"
pagination={false}
columns={columns}
search={false}
dateFormatter="string"
options={false}
/>
</Modal>
);
};
export default DeliverModal;