index.tsx
8.25 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
import React, { useEffect, useState } from "react";
import { Modal, Skeleton, Table, Select, Form, Input, Button, message } from "antd";
import useInitial from "@/hooks/useInitail";
import { PlusOutlined } from "@ant-design/icons";
import ShareRateItemlist from '../ShareRateItemlist';
import { getFeetypeList, fetchComps, getshoplist, addPaymentMark } from "../../api";
import st from "../../style.less";
interface Props{
visible:boolean;
onRefresh: () => void;
onCancel?: () => void;
}
const { Column } = Table;
const SaveModal = ({visible, onCancel, onRefresh}:Props) => {
const paymentModeList = [{id: 1, name: '充值'}, {id: 2, name: '账单'}];
const [form] = Form.useForm();
const [loading, setLoading] = useState<boolean>(true);
const [paymentMode, setPaymentMode] = useState<number>(0);
const [data, setData] = useState<BearCostSetting.Data>({});
const [disabled, setDisabled] = useState<boolean>(true);
const [compsList, setCompsList] = useState<BearCostSetting.Comp[]>([] as BearCostSetting.Comp[]);
const [shoplist, setShoplist] = useState<BearCostSetting.Shop[]>([]);
const {data: feetypeList} = useInitial<BearCostSetting.FeeTypeList[], BearCostSetting.QueryParams>(getFeetypeList, [], {configType: 'COST_APPLY'});
useEffect(() => {
setTimeout(() => {
setLoading(false);
}, 500);
}, []);
useEffect(() => {
if (!data.compTypes) return;
fetchComps({types: data.compTypes.join(',')})
.then(res => {
res.data && setCompsList([...compsList, ...res.data]);
})
.catch(err => {
message.error("操作失败");
});
}, [data.compTypes]);
useEffect(() => {
if (!data.roleCodes) return;
getshoplist()
.then(res => {
res.data && setShoplist([...shoplist, ...res.data]);
})
.catch(err => {
});
}, [data.roleCodes]);
/**
* @description: 费用承担form
* @param {any} feildValue
* @return {*}
*/
function handleSave(feildValue: any) {
const {name, feeTypeValue, paymentMode, shareRateItemList, stmtShopId, tradeCompId, unit} = feildValue;
const _shareRateItemList = shareRateItemList?.length && shareRateItemList.map((item:any) => {
const _shareRate = parseFloat((item.shareRate/100).toFixed(4));
return { id: item.id, type: item.type, shareRate: _shareRate };
});
const params = {
name,
unit,
feeTypeValue: feeTypeValue.value,
paymentMode: paymentMode.value,
tradeCompId: tradeCompId.value,
stmtShopId: stmtShopId.value,
shareRateItemList: _shareRateItemList,
};
addPaymentMark(params)
.then(res => {
message.success("操作成功");
_onCancel();
onRefresh();
})
.catch(err => {
message.error(err?.message);
});
}
/**
* @description: 关闭弹框
* @param {*}
* @return {*}
*/
const _onCancel = () => {
onCancel && onCancel();
form.resetFields();
};
return (
<Modal
title="新增缴费标识"
visible={visible}
onCancel={_onCancel}
onOk={form.submit}
cancelButtonProps={{ hidden: true }}
width="55%"
>
<Skeleton active loading={loading}>
<Form form={form} onFinish={handleSave} wrapperCol={{ span: 18 }} labelCol={{ span: 4 }}>
<Form.Item
label="缴费标识:"
name="name"
rules={[{ required: true, message: '请输入缴费标识' }]}
>
<Input
placeholder="请填写"
/>
</Form.Item>
<Form.Item
label="费用类型"
name="feeTypeValue"
rules={[{ required: true, message: '请选择费用类型' }]}
>
<Select
placeholder="请选择"
showSearch
optionFilterProp="children"
labelInValue
onSelect={(it:any) => {
const item = feetypeList.filter(i => it.value === i.typeValue);
const {compTypes, roleCodes} = item[0];
setData({...data, compTypes, roleCodes, typeValue: it.value});
setDisabled(false);
}}
filterOption={(input, option: any) => option?.children.indexOf(input) >= 0}
>
{
feetypeList && feetypeList.map((item:any) => (
<Select.Option value={item.typeValue} key={item.typeValue}>
{item.typeName}
</Select.Option>
))
}
</Select>
</Form.Item>
<Form.Item
label="往来单位:"
name="tradeCompId"
rules={[{ required: true, message: '请选择往来单位' }]}
>
<Select
placeholder="请选择"
showSearch
disabled={disabled}
optionFilterProp="children"
labelInValue
filterOption={(input, option: any) => option?.children.indexOf(input) >= 0}
>
{
data?.compTypes && (
compsList && compsList.map((item:any) => (
<Select.Option value={item.id} key={item.id}>
{item.name}
</Select.Option>
))
)
}
</Select>
</Form.Item>
<Form.Item
label="结算门店:"
name="stmtShopId"
rules={[{ required: true, message: '请选择结算门店' }]}
>
<Select
placeholder="请选择"
showSearch
disabled={disabled}
optionFilterProp="children"
labelInValue
filterOption={(input, option: any) => option?.children.indexOf(input) >= 0}
>
{
data?.compTypes && (
shoplist && shoplist.map((item:any) => (
<Select.Option value={item.id} key={item.id}>
{item.name}
</Select.Option>
))
)
}
</Select>
</Form.Item>
<Form.Item
label="缴费方式:"
name="paymentMode"
rules={[{ required: true, message: '请选择缴费方式' }]}
>
<Select
placeholder="请选择"
showSearch
optionFilterProp="children"
labelInValue
filterOption={(input, option: any) => option?.children.indexOf(input) >= 0}
onSelect={(it:any) => {
setPaymentMode(it.value);
}}
>
{
paymentModeList && paymentModeList.map((item:any) => (
<Select.Option value={item.id} key={item.id}>
{item.name}
</Select.Option>
))
}
</Select>
</Form.Item>
{
paymentMode == 2 && ['RP00000053', 'RP00000066', 'RP00000067'].includes(data.typeValue || '') && (
<Form.Item
label="计量单位:"
name="unit"
rules={[{ required: false, message: '请输入计量单位' }]}
>
<Input placeholder="请填写" maxLength={4} />
</Form.Item>
)
}
<Form.Item
name="shareRateItemList"
label="分摊比例"
rules={[{ required: false, message: "分摊比例配置不能为空" }]}
>
<ShareRateItemlist />
</Form.Item>
</Form>
</Skeleton>
</Modal>
);
};
export default SaveModal;