EditModal.tsx
10.9 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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
import React, { useState, useEffect } from 'react';
import { Modal, Button, message, Form, InputNumber, DatePicker, Radio, Row, Col } from 'antd';
import {useStore} from '../index';
import {ListResult, saveConfigApi} from '../api';
import { debounce, isNil } from 'lodash';
import ShopSelectNew from '@/components/ShopSelectNew';
import moment from 'moment';
import '../index.less';
const { RangePicker } = DatePicker;
export default function DetailModal() {
const {currentData, setCurrentData, setLoading} = useStore();
const [confirm, setConfirm] = useState<boolean>(false);
const [type, setType] = useState<number>(2);
const [form] = Form.useForm();
useEffect(() => {
if (currentData.visible && currentData.data.id) {
handleSetValue();
} else {
form.setFieldsValue({addedValueType: 2});
}
}, [currentData.visible]);
const handleChangeType = (value: number) => {
setType(value);
if (value === 1) {
form.setFieldsValue({
tciOutputValueRatio: 100,
vciOutputValueRatio: 100,
jcxOutputValueRatio: 100,
decoOutputValueRatio: 100,
});
} else if (value === 2) {
form.setFieldsValue({
tciOutputValueRatio: 0,
vciOutputValueRatio: 0,
jcxOutputValueRatio: 0,
decoOutputValueRatio: 0,
});
}
};
const handleCancel = () => {
form.resetFields();
setCurrentData({visible: false, data: {}, title: ""});
setType(2);
};
const handleSetValue = () => {
form.setFieldsValue({
addedValueTask: currentData.data?.addedValueTask,
tciOutputValueRatio: currentData.data?.tciOutputValueRatio,
vciOutputValueRatio: currentData.data?.vciOutputValueRatio,
jcxOutputValueRatio: currentData.data?.jcxOutputValueRatio,
decoOutputValueRatio: currentData.data?.decoOutputValueRatio,
shopList: currentData.data?.shopList?.map((v: any) => ({value: v.shopId, label: v.shopName})) || [],
rangeDate: [moment(currentData.data.beginTime), moment(currentData.data.endTime)],
addedValueType: currentData?.data?.addedValueType,
vciOutputValueTask: currentData?.data?.vciOutputValueTask,
decoOutputValueTask: currentData?.data?.decoOutputValueTask
});
setType(currentData.data?.addedValueType || 2);
};
const onFinish = async () => {
const params = await form.validateFields();
setConfirm(true);
const _params: ListResult = {
id: currentData.data?.id,
addedValueTask: params.addedValueTask,
tciOutputValueRatio: params.tciOutputValueRatio,
vciOutputValueRatio: params.vciOutputValueRatio,
jcxOutputValueRatio: params.jcxOutputValueRatio,
decoOutputValueRatio: params.decoOutputValueRatio,
shopList: params.shopList.map((v: any) => ({shopId: v.value, shopName: v.label})),
beginTime: moment(params.rangeDate[0]).valueOf(),
endTime: moment(params.rangeDate[1]).valueOf(),
addedValueType: params.addedValueType,
vciOutputValueTask: params.vciOutputValueTask,
decoOutputValueTask: params.decoOutputValueTask
};
saveConfigApi(_params)
.then(res => {
message.success(res.result);
setConfirm(false);
setLoading(true);
handleCancel();
})
.catch(e => {
setConfirm(false);
message.error(e.message);
});
};
return (
<Modal
destroyOnClose
forceRender
title={currentData.title}
open={currentData.visible}
maskClosable={false}
onCancel={handleCancel}
width="50%"
footer={[
<Button key="cancel" onClick={handleCancel} style={{marginLeft: 10}}>取消</Button>,
<Button key="submit" onClick={debounce(onFinish, 380)} type="primary" htmlType="submit" loading={confirm}>确认</Button>
]}
>
<Form
form={form}
labelAlign="left"
style={{marginLeft: 30, marginRight: 30}}
>
<Form.Item name="addedValueType">
<Radio.Group onChange={(e) => handleChangeType(e.target.value)} defaultValue={2} buttonStyle="solid">
<Radio.Button value={2}>按毛利计算</Radio.Button>
<Radio.Button value={1}>按产值计算</Radio.Button>
</Radio.Group>
</Form.Item>
<Form.Item
label={type === 2 ? "单车附加值毛利目标" : "单车附加值产值目标"}
name="addedValueTask"
rules={[{ required: true, message: "请输入" }]}
>
<InputNumber
style={{width: '100%'}}
controls={false}
min={0}
formatter={(value: any) => `${value}元/台`}
precision={2}
parser={(value: string) => value?.replace('元/台', '')}
/>
</Form.Item>
<Row style={{marginLeft: 30}}>
<Form.Item
label={<span>其中:<span>商业险产值目标</span></span>}
name="vciOutputValueTask"
style={{width: '100%'}}
rules={[({ getFieldValue }) => ({
validator(_, value) {
if (isNil(value)) {
return Promise.reject(new Error('请输入'));
}
return Promise.resolve();
},
})]}
>
<InputNumber
style={{width: '100%'}}
controls={false}
min={0}
formatter={(value: any) => `${value}元/台`}
precision={2}
parser={(value: string) => value?.replace('元/台', '')}
/>
</Form.Item>
<Form.Item
label={<span style={{textIndent: '42px'}}>装潢产值目标</span>}
name="decoOutputValueTask"
style={{width: '100%'}}
rules={[({ getFieldValue }) => ({
validator(_, value) {
if (isNil(value)) {
return Promise.reject(new Error('请输入'));
}
return Promise.resolve();
},
})]}
>
<InputNumber
style={{width: '100%'}}
controls={false}
min={0}
formatter={(value: any) => `${value}元/台`}
precision={2}
parser={(value: string) => value?.replace('元/台', '')}
/>
</Form.Item>
</Row>
<div className="addValue_wrapper"><span className="addvalue_text">*</span><span>产值构成:</span></div>
<Form.Item
label={type === 2 ? "1.计算保险毛利" : "1.计算保险产值:"}
>
<Form.Item
label={<span className="addValue_label">商业险金额 x</span>}
name="vciOutputValueRatio"
colon={false}
rules={[({ getFieldValue }) => ({
validator(_, value) {
if (isNil(value)) {
return Promise.reject(new Error('请输入'));
}
return Promise.resolve();
},
})]}
>
<InputNumber
style={{width: '100%'}}
controls={false}
disabled={type === 1}
min={0}
max={100}
formatter={(value: any) => `${value}%`}
precision={2}
parser={(value?: string) => value?.replace('%', '')}
/>
</Form.Item>
<Form.Item
label={<span className="addValue_label">交强险金额 x</span>}
colon={false}
name="tciOutputValueRatio"
rules={[({ getFieldValue }) => ({
validator(_, value) {
if (isNil(value)) {
return Promise.reject(new Error('请输入'));
}
return Promise.resolve();
},
})]}
>
<InputNumber
style={{width: '100%'}}
controls={false}
disabled={type === 1}
min={0}
max={100}
formatter={(value: any) => `${value}%`}
precision={2}
parser={(value?: string) => value?.replace('%', '')}
/>
</Form.Item>
<Form.Item
label={<span className="addValue_label">驾意险金额 x</span>}
colon={false}
name="jcxOutputValueRatio"
rules={[({ getFieldValue }) => ({
validator(_, value) {
if (isNil(value)) {
return Promise.reject(new Error('请输入'));
}
return Promise.resolve();
},
})]}
>
<InputNumber
style={{width: '100%'}}
controls={false}
disabled={type === 1}
min={0}
max={100}
formatter={(value: any) => `${value}%`}
precision={2}
parser={(value?: string) => value?.replace('%', '')}
/>
</Form.Item>
</Form.Item>
<Form.Item
label={<span style={{fontSize: '14px'}}><span style={{color: "#333"}}>2.{type === 2 ? "计算装潢毛利" : "计算装潢产值"}:</span><span className="addValue_label">装潢金额 x</span></span>}
colon={false}
name="decoOutputValueRatio"
rules={[({ getFieldValue }) => ({
validator(_, value) {
if (isNil(value)) {
return Promise.reject(new Error('请输入'));
}
return Promise.resolve();
},
})]}
>
<InputNumber
style={{width: '100%'}}
controls={false}
disabled={type === 1}
min={0}
max={100}
formatter={(value: any) => `${value}%`}
precision={2}
parser={(value?: string) => value?.replace('%', '')}
/>
</Form.Item>
<div style={{marginBottom: '25px'}}>
<span style={{color: "#333", fontSize: '14px'}}>3.其他附加值:</span>
<span style={{color: "#F4333C", fontSize: '14px'}}>分期附加费</span>
<span style={{color: "#999", fontSize: '12px'}}>(包含服务费、GPS费、抵押上户费、解除抵押费)</span>
<span style={{color: "#F4333C", fontSize: '14px'}}>和全款上户费要按实收计算</span>
</div>
<Form.Item
label="适用门店"
name="shopList"
rules={[{ required: true, message: "请输入" }]}
>
<ShopSelectNew defaultOptions={{bizTypes: "1"}} placeholder="请选择门店" multiple />
</Form.Item>
<Form.Item
label="生效时间"
name="rangeDate"
rules={[{ required: true, message: "请输入" }]}
>
<RangePicker disabled={!!currentData.data.id} disabledDate={(current) => current && current < moment().startOf('day')} picker="month" format="YYYY-MM" />
</Form.Item>
</Form>
</Modal>
);
}