3a63ee47
谢忠泽
add:费用承担配置
|
1
|
import React, { useEffect, useState } from "react";
|
691e978a
谢忠泽
update:费用承担配置模块
|
2
|
import { Modal, Skeleton, Table, Select, Form, Input, Divider, Popconfirm, InputNumber, Button, message } from "antd";
|
3a63ee47
谢忠泽
add:费用承担配置
|
3
4
5
6
|
import useInitial from "@/hooks/useInitail";
import { PlusOutlined } from "@ant-design/icons";
import { fetchComps, getshoplist } from "../../api";
import st from "../../style.less";
|
691e978a
谢忠泽
update:费用承担配置模块
|
7
|
import { edit } from "@/pages/ware/Spu/SkuManage/api";
|
3a63ee47
谢忠泽
add:费用承担配置
|
8
9
10
11
12
13
14
15
16
17
18
19
|
interface Props{
onChange?:(data:BearCostSetting.TableList[])=>void;
value?: BearCostSetting.TableList[];
}
const { Column } = Table;
const ShareRateItemlist = ({onChange, value=[]}:Props) => {
const typeList = [{id: 1, name: '门店'}, {id: 2, name: '往来单位'}];
const [form] = Form.useForm();
const [data, setData] = useState<BearCostSetting.Data>({});
|
691e978a
谢忠泽
update:费用承担配置模块
|
20
|
const [item, setItem] = useState<BearCostSetting.Item>({});
|
3a63ee47
谢忠泽
add:费用承担配置
|
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
|
const [tableList, setTableList] = useState<BearCostSetting.TableList[]>([]);
const [compsList, setCompsList] = useState<BearCostSetting.Comp[]>([] as BearCostSetting.Comp[]);
const [shoplist, setShoplist] = useState<BearCostSetting.Shop[]>([]);
const [visible, setVisible] = useState(false);
useEffect(() => {
if (!data.type) return;
fetchComps()
.then(res => {
res.data && setCompsList([...res.data]);
})
.catch(err => {
message.error("操作失败");
});
getshoplist()
.then(res => {
res.data && setShoplist([...res.data]);
})
.catch(err => {
message.error("操作失败");
});
}, [data.type]);
/**
* @description: 关闭Modal
* @param {*}
* @return {*}
*/
const closeModal = () => {
setVisible(false);
form.resetFields();
};
|
691e978a
谢忠泽
update:费用承担配置模块
|
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
|
/**
* @description: 编辑
* @param {BearCostSetting} item
* @return {*}
*/
const edit = (item:BearCostSetting.TableList) => {
const {type, shareRate, id, name, key} = item;
console.log('type-->', type);
const shopname = typeList.filter(i => i.id === type)[0].name;
// if (type === 1) {
// const _shoplist = shoplist.filter(i => i.id !== id);
// setShoplist([..._shoplist]);
// } else if (type === 2) {
// const _compsList = compsList.filter(i => i.id !== id);
// setCompsList([..._compsList]);
// }
setData({...data, type});
form.setFieldsValue({
type: {value: type, label: shopname},
id: {value: id, label: name},
shareRate,
key
});
};
const _delete = (row:BearCostSetting.TableList) => {
const { key} =row;
const _tableList = tableList.filter(i => i.key !== key);
onChange && onChange?.([..._tableList]);
// value = [];
setTableList([..._tableList]);
|
3a63ee47
谢忠泽
add:费用承担配置
|
85
86
87
88
89
90
91
92
|
};
/**
* @description: 分摊form
* @param {any} feildValue
* @return {*}
*/
function handleItemSave(feildValue: any) {
|
691e978a
谢忠泽
update:费用承担配置模块
|
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
console.log('feildValue-->', feildValue);
const {id, type, shareRate, key} = feildValue;
const _tableList = tableList.filter(i => {
return i?.key !== key;
});
// const _total = tableList.reduce((total, item) => {
// if (item.shareRate)total += item.shareRate;
// return total;
// }, 0);
// if (_total + shareRate >100) {
// message.error("分摊比例大于100%");
// return;
// }
const tableItem = {id: id.value, type: type.value, name: id.label, shareRate, key: _tableList.length +1};
onChange && onChange?.([..._tableList, tableItem]);
setTableList([..._tableList, tableItem]);
|
3a63ee47
谢忠泽
add:费用承担配置
|
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
closeModal();
}
return (
<>
<div className={st.header} style={{ display: "flex", justifyContent: "flex-end", marginBottom: 15}}>
<Button
type="primary"
icon={<PlusOutlined />}
onClick={() => {
setVisible(true);
}}
>
新增
</Button>
</div>
<Table
dataSource={tableList}
|
691e978a
谢忠泽
update:费用承担配置模块
|
127
128
|
rowKey={(item, index) => `${index}`}
size="small"
|
3a63ee47
谢忠泽
add:费用承担配置
|
129
130
|
>
<Column
|
4392a939
谢忠泽
fix:缴费标识文案
|
131
|
title="门店/往来单位"
|
3a63ee47
谢忠泽
add:费用承担配置
|
132
133
|
dataIndex="name"
width={200}
|
691e978a
谢忠泽
update:费用承担配置模块
|
134
|
render={(t) => t || "-"}
|
3a63ee47
谢忠泽
add:费用承担配置
|
135
136
|
/>
<Column
|
691e978a
谢忠泽
update:费用承担配置模块
|
137
|
title="分摊比例"
|
3a63ee47
谢忠泽
add:费用承担配置
|
138
139
|
dataIndex="shareRate"
width={200}
|
691e978a
谢忠泽
update:费用承担配置模块
|
140
|
render={(t) => (t && `${t}%`) || "-"}
|
3a63ee47
谢忠泽
add:费用承担配置
|
141
142
143
144
145
|
/>
<Column
title="操作"
width={100}
dataIndex="unit"
|
691e978a
谢忠泽
update:费用承担配置模块
|
146
|
render={(text, row:BearCostSetting.Item, index) => (
|
3a63ee47
谢忠泽
add:费用承担配置
|
147
|
<span>
|
691e978a
谢忠泽
update:费用承担配置模块
|
148
149
150
151
152
153
154
155
156
157
|
<a
onClick={() => {
console.log('index', index);
edit(row);
setVisible(true);
}}
>
编辑
</a>
<Divider type="vertical" />
|
3a63ee47
谢忠泽
add:费用承担配置
|
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
<Popconfirm title="是否删除?" onConfirm={() => _delete(row)} okText="确定" cancelText="取消">
<a
onClick={(e) => {
e.preventDefault();
}}
style={{ color: "red" }}
>
删除
</a>
</Popconfirm>
</span>
)}
/>
</Table>
<Modal
|
691e978a
谢忠泽
update:费用承担配置模块
|
174
|
title="新增分摊比例"
|
3a63ee47
谢忠泽
add:费用承担配置
|
175
176
177
178
|
visible={visible}
onCancel={closeModal}
onOk={form.submit}
>
|
4392a939
谢忠泽
fix:缴费标识文案
|
179
|
<Form form={form} labelCol={{span: '4'}} onFinish={handleItemSave}>
|
3a63ee47
谢忠泽
add:费用承担配置
|
180
|
<Form.Item
|
691e978a
谢忠泽
update:费用承担配置模块
|
181
|
label="对象类型:"
|
3a63ee47
谢忠泽
add:费用承担配置
|
182
183
184
185
186
187
188
189
190
|
name="type"
rules={[{ required: true, message: '请选择缴费方式' }]}
>
<Select
placeholder="请选择"
showSearch
optionFilterProp="children"
labelInValue
onSelect={(item:any) => {
|
691e978a
谢忠泽
update:费用承担配置模块
|
191
|
form.resetFields(['id']);
|
3a63ee47
谢忠泽
add:费用承担配置
|
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
setData({...data, type: item.value});
}}
filterOption={(input, option: any) => option?.children.indexOf(input) >= 0}
>
{
typeList && typeList.map((item:any) => (
<Select.Option value={item.id} key={item.id}>
{item.name}
</Select.Option>
))
}
</Select>
</Form.Item>
<Form.Item
|
4392a939
谢忠泽
fix:缴费标识文案
|
206
|
label={data?.type === 1 ? '门店': "往来单位"}
|
691e978a
谢忠泽
update:费用承担配置模块
|
207
|
name="id"
|
3a63ee47
谢忠泽
add:费用承担配置
|
208
209
210
211
212
213
214
|
rules={[{ required: true, message: '请选择缴费方式' }]}
>
<Select
placeholder="请选择"
showSearch
optionFilterProp="children"
labelInValue
|
3a63ee47
谢忠泽
add:费用承担配置
|
215
|
allowClear
|
691e978a
谢忠泽
update:费用承担配置模块
|
216
|
filterOption={(input, option: any) => option?.children.indexOf(input) >= 0}
|
3a63ee47
谢忠泽
add:费用承担配置
|
217
218
219
220
221
222
223
224
225
226
227
228
229
|
>
{
data?.type === 2 && (
compsList && compsList.map((item:any) => (
<Select.Option value={item.id} key={item.id}>
{item.name}
</Select.Option>
))
)
}
{
data?.type === 1 && (
|
3a63ee47
谢忠泽
add:费用承担配置
|
230
231
232
233
234
235
236
237
238
239
|
shoplist && shoplist.map((item:any) => (
<Select.Option value={item.id} key={item.id}>
{item.name}
</Select.Option>
))
)
}
</Select>
</Form.Item>
<Form.Item
|
12931648
谢忠泽
fix&update:新增缴费标识
|
240
|
label="分摊比例"
|
3a63ee47
谢忠泽
add:费用承担配置
|
241
242
243
|
name="shareRate"
rules={[{ required: true, message: '请输入缴费标识' }]}
>
|
1f0ed47f
谢忠泽
fix:分摊比例提示
|
244
|
<InputNumber placeholder="请填写" addonAfter="%" max={100} min={0} precision={2} />
|
3a63ee47
谢忠泽
add:费用承担配置
|
245
|
</Form.Item>
|
691e978a
谢忠泽
update:费用承担配置模块
|
246
247
248
|
<Form.Item
name="key"
/>
|
3a63ee47
谢忠泽
add:费用承担配置
|
249
250
251
252
253
254
255
|
</Form>
</Modal>
</>
);
};
export default ShareRateItemlist;
|