index.tsx
6.57 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
import React, { useCallback, useEffect, useState } from "react";
import { Modal, Skeleton, Select, Form, message, InputNumber } from "antd";
import * as API from '../../api';
import _ from "lodash";
interface Props {
visible:boolean;
row?:API.Item;
compList:any[];
cityList:any[];
onCancel:()=>void;
onRefresh:() => void;
}
function AddModel({visible, row, compList, cityList, onCancel, onRefresh}:Props) {
const [form] = Form.useForm();
const [loading, setLoading] = useState<boolean>(false);
const { id } = row || {};
useEffect(() => {
if (id) {
const { tradeCompName, sendAreaName, firstWeight, continuedWeight, arriveAreaName } = row || {};
form.setFieldsValue({
tradeComp: compList.filter(it => tradeCompName === it.name).map(item => ({value: item.id, label: item.name}))[0],
sendArea: cityList.filter(it => sendAreaName === it.fullName).map(item => ({value: item.bh, label: item.fullName}))[0],
firstWeight,
continuedWeight,
arriveAreas: cityList.filter(it => arriveAreaName === it.fullName).map(item => ({value: item.bh, label: item.fullName}))[0]
});
}
}, [row]);
/**
* @description: 确定
* @param {*}
* @return {*}
*/
const handleSave = (feildValue:any) => {
setLoading(true);
const {tradeComp, sendArea, arriveAreas, firstWeight, continuedWeight} = feildValue;
const _arriveAreas = id ? [{ ...arriveAreas }].map(item => ({arriveAreaNo: item.value, arriveAreaName: item.label}))
: arriveAreas.length && arriveAreas.map((item:any) => ({arriveAreaNo: item.value, arriveAreaName: item.label}));
const params = {
expressChargeStandardId: id,
tradeCompId: tradeComp.value,
tradeCompName: tradeComp.label,
tradeCompShortName: compList && compList.filter(item => item.id == tradeComp.value)[0].shortName,
sendAreaNo: sendArea.value,
sendAreaName: sendArea.label,
firstWeight,
continuedWeight,
arriveAreas: _arriveAreas
};
API.addStandardSave({ ...params })
.then(res => {
message.success("操作成功");
_onCancel();
setLoading(false);
onRefresh();
}).catch(err => {
message.error(err?.message);
setLoading(false);
});
};
/**
* @description: 关闭弹框
* @param {*}
* @return {*}
*/
const _onCancel = () => {
onCancel && onCancel();
form.resetFields();
};
return (
<Modal
title={`${id ? '编辑':'新增'}快递收费标准`}
visible={visible}
confirmLoading={loading}
onCancel={_onCancel}
onOk={form.submit}
cancelButtonProps={{ hidden: true }}
width="50%"
bodyStyle={{minHeight: 300}}
>
<Skeleton loading={false}>
<Form form={form} onFinish={handleSave} wrapperCol={{ span: 18 }} labelCol={{ span: 4 }}>
<Form.Item
label="快递公司"
name="tradeComp"
rules={[{required: true, message: '请选择快递公司'}]}
>
<Select
placeholder="请选择快递公司"
showSearch
allowClear
optionFilterProp="children"
labelInValue
onSelect={(it:any) => {
const item = compList.filter((i:any) => it.value === i.id);
}}
filterOption={(input, option: any) => option?.children.indexOf(input) >= 0}
>
{
compList.map(item => (
<Select.Option value={item.id} key={item.id}>
{item.name}
</Select.Option>
))
}
</Select>
</Form.Item>
<Form.Item
label="寄件地区"
name="sendArea"
rules={[{required: true, message: '请选择寄件地区'}]}
>
<Select
placeholder="请选择寄件地区"
showSearch
allowClear
optionFilterProp="children"
labelInValue
onSelect={(it:any) => {
const item = cityList.filter((i:any) => it.value === i.id);
}}
filterOption={(input, option: any) => option?.children.indexOf(input) >= 0}
>
{
cityList.map(item => (
<Select.Option value={item.bh} key={item.bh}>
{item.fullName}
</Select.Option>
))
}
</Select>
</Form.Item>
<Form.Item
label="到达地区"
name="arriveAreas"
rules={[{required: true, message: '请选择到达地区'}]}
>
<Select
placeholder={`请选择到达地区${id ? '' : '(支持多选)'}`}
mode={id ? undefined : 'multiple'}
showSearch
allowClear
showArrow
optionFilterProp="children"
labelInValue
onSelect={(it:any) => {
const item = cityList.filter((i:any) => it.value === i.id);
}}
filterOption={(input, option: any) => option?.children.indexOf(input) >= 0}
>
{
cityList.map(item => (
<Select.Option value={item.bh} key={item.bh}>
{item.fullName}
</Select.Option>
))
}
</Select>
</Form.Item>
<Form.Item
label="首重"
name="firstWeight"
rules={[{required: true, message: '请填写首重'}]}
>
<InputNumber placeholder="请填写" addonAfter="元" max={100000000} min={0} precision={2} />
</Form.Item>
<Form.Item
label="续重"
name="continuedWeight"
rules={[{required: true, message: '请填写续重'}]}
>
<InputNumber placeholder="请填写" addonAfter="元/kg" max={100000000} min={0} precision={2} />
</Form.Item>
</Form>
</Skeleton>
</Modal>
);
}
export default AddModel;