4927eb1a
曾柯
考评组设置加列表及草稿
|
1
|
import React, { useState, useEffect } from "react";
|
27123514
曾柯
考评组排名倒数
|
2
|
import { Table, Input, InputNumber, Popconfirm, Form, Typography, Space, Divider, Modal, Radio } from "antd";
|
4927eb1a
曾柯
考评组设置加列表及草稿
|
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
|
import { SalaryMapHeader } from "@/pages/performance/CompensateGroupConfig/entity";
interface Item {
key: string;
lower: number;
upper: number;
standardScore: number;
}
interface Props {
value?: any[];
onChange?: Function;
readOnly?: boolean;
visible?: boolean;
type?: number; //2 查看得分阶梯
setladderVisible?: Function;
salaryCode?: string;
isPercent?: number;
laddersType?: number;
calType?: number;
rankType?: number;
}
interface EditableCellProps extends React.HTMLAttributes<HTMLElement> {
editing: boolean;
dataIndex: string;
title: any;
inputType: "number" | "text";
record: Item;
index: number;
children: React.ReactNode;
}
const TotalAmount = ({
laddersType,
value,
onChange,
readOnly,
visible,
type,
setladderVisible,
salaryCode,
isPercent,
calType,
rankType,
}: Props) => {
const EditableCell: React.FC<EditableCellProps> = ({
editing,
dataIndex,
title,
inputType,
record,
index,
children,
...restProps
}) => {
let precision = 0;
if (dataIndex == "upper" && isPercent == 2) {
precision = 2;
}
|
c0188e80
曾柯
考评bugfix0306
|
63
64
65
66
67
68
69
|
let max = 0;
if ((dataIndex == "upper" || dataIndex == "lower") && isPercent == 2) {
max = 100;
} else {
max = 999999999999;
}
const inputNode = inputType === "number" ? <InputNumber precision={precision} max={max} /> : <Input />;
|
27123514
曾柯
考评组排名倒数
|
70
71
72
73
74
75
|
const rankOrderType = (
<Radio.Group>
<Radio value={1}>正数</Radio>
<Radio value={2}>倒数</Radio>
</Radio.Group>
);
|
4927eb1a
曾柯
考评组设置加列表及草稿
|
76
77
78
79
80
|
return (
<td {...restProps}>
{editing ? (
<Form.Item name={dataIndex} style={{ margin: 0 }}>
|
27123514
曾柯
考评组排名倒数
|
81
|
{dataIndex == "rankOrderType" ? rankOrderType : inputNode}
|
4927eb1a
曾柯
考评组设置加列表及草稿
|
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
</Form.Item>
) : (
children
)}
</td>
);
};
const [form] = Form.useForm();
// 添加阶梯
const [disable, setDisable] = useState(false);
const [editingKey, setEditingKey] = useState("");
const isEditing = (record: Item) => record.key === editingKey;
const edit = (record: Partial<Item> & { key: React.Key }) => {
|
f2dd0995
曾柯
考评编辑bugfix
|
97
|
console.log(record);
|
4927eb1a
曾柯
考评组设置加列表及草稿
|
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
|
form.setFieldsValue({
upper: "",
money: "",
...record,
});
setEditingKey(record.key);
};
const cancel = () => {
setEditingKey("");
};
// 添加阶梯
const onAdd = (values: any[], index: number) => {
const preTableData: any[] = [...values.map((i) => ({ ...i }))];
// 编辑不是最后一行,不需要增加阶梯
if (index !== preTableData.length - 1) {
return preTableData;
}
// 如果最后一行没有输入最大值,不需要增加阶梯
if (index === preTableData.length - 1) {
const endData = preTableData[index];
if (!endData.upper) {
return preTableData;
}
}
const newObj: { lower?: number; key?: number } = {};
const lastData = preTableData[preTableData.length - 1];
|
e66763d9
曾柯
考评bugfix
|
128
129
130
131
|
if (rankType == 2) {
newObj.lower = lastData.upper;
} else if (rankType == 1) {
newObj.lower = lastData.upper + 1;
|
27123514
曾柯
考评组排名倒数
|
132
133
|
} else {
newObj.lower = lastData.upper + 1;
|
e66763d9
曾柯
考评bugfix
|
134
|
}
|
4927eb1a
曾柯
考评组设置加列表及草稿
|
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
newObj.key = Number(lastData.key) + 1;
const pa = {
...newObj,
key: newObj.key?.toString(),
money: 0,
};
preTableData.push(pa);
return preTableData;
};
const checkRange = async (tempData: any, index: number) => {
const res = [...tempData.map((i: any) => ({ ...i }))];
const _tempData = res.concat();
for (let i = 0; i < _tempData.length; i++) {
const item = res[i];
|
e66763d9
曾柯
考评bugfix
|
153
|
if (item.upper && item.lower && item.lower > item.upper) {
|
4927eb1a
曾柯
考评组设置加列表及草稿
|
154
155
156
|
item.upper = item.lower + 1;
}
if (i >= index && i < res.length - 1) {
|
e66763d9
曾柯
考评bugfix
|
157
158
159
160
161
|
if (rankType == 2) {
res[i + 1].lower = item.upper;
} else if (rankType == 1) {
res[i + 1].lower = item.upper + 1;
}
|
4927eb1a
曾柯
考评组设置加列表及草稿
|
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
|
}
}
return res;
};
const _add = async (key: React.Key, record: Item) => {
try {
const row = (await form.validateFields()) as Item;
let newData = [...value.map((i) => ({ ...i }))];
const index = newData.findIndex((item) => key === item.key);
const tempData = [...newData].map((i) => (i.key == key ? { ...record, ...row } : { ...i }));
const res = await checkRange([...tempData], index);
const addRow = onAdd([...res], index);
if (index > -1) {
const item = addRow[index];
addRow.splice(index, 1, {
...row,
...item,
});
onChange && onChange([...addRow.map((i) => ({ ...i }))]);
setEditingKey("");
} else {
addRow.push(row);
onChange && onChange([...addRow.map((i) => ({ ...i }))]);
|
4927eb1a
曾柯
考评组设置加列表及草稿
|
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
|
setEditingKey("");
}
} catch (errInfo) {
console.log("Validate Failed:", errInfo);
}
};
const save = async (key: React.Key, record: Item) => {
try {
const row = (await form.validateFields()) as Item;
let newData = [...value.map((i) => ({ ...i }))];
const index = newData.findIndex((item) => key === item.key);
const tempData = [...newData].map((i) => (i.key == key ? { ...record, ...row } : { ...i }));
const res = await checkRange([...tempData], index);
const addRow = [...res];
if (index > -1) {
const item = addRow[index];
addRow.splice(index, 1, {
...row,
...item,
});
onChange && onChange([...addRow.map((i) => ({ ...i }))]);
setEditingKey("");
} else {
onChange && onChange([...addRow.map((i) => ({ ...i }))]);
setEditingKey("");
}
} catch (errInfo) {
console.log("Validate Failed:", errInfo);
}
};
// 删除阶梯区间
const _onDelete = (record: Item, index: number) => {
|
f2dd0995
曾柯
考评编辑bugfix
|
234
|
console.log(record);
|
4927eb1a
曾柯
考评组设置加列表及草稿
|
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
const tmpData = [...(value || [])];
const res = tmpData.filter((item) => item.key !== record.key);
if (index > 0 && index <= res.length - 1) {
res[index].lower = res[index - 1].upper;
}
//校准区间
res.forEach((item, ind) => {
if (ind === 0) {
res[0].lower = rankType == 1 ? 1 : 0;
}
});
onChange && onChange([...res]);
};
const columns = [
{
title: "区间",
editable: true,
children: [
{
|
e66763d9
曾柯
考评bugfix
|
255
|
title: `初始排名${rankType == 1 ? "(≥)" : "(>)"}`,
|
27123514
曾柯
考评组排名倒数
|
256
|
editable: true,
|
4927eb1a
曾柯
考评组设置加列表及草稿
|
257
|
dataIndex: "lower",
|
27123514
曾柯
考评组排名倒数
|
258
|
width: "15%",
|
4927eb1a
曾柯
考评组设置加列表及草稿
|
259
260
261
262
263
264
265
266
267
268
269
270
271
|
render: (value: number) => {
if (isPercent == 2) {
return value + "%";
} else if (isPercent == 1) {
return value;
} else if (isPercent == 0 && laddersType == 2) {
return value + "%";
} else {
return value;
}
},
},
{
|
27123514
曾柯
考评组排名倒数
|
272
|
title: `结束排名${rankType == 1 ? "(≤)" : "(≤)"}`,
|
4927eb1a
曾柯
考评组设置加列表及草稿
|
273
|
dataIndex: "upper",
|
27123514
曾柯
考评组排名倒数
|
274
|
width: "15%",
|
4927eb1a
曾柯
考评组设置加列表及草稿
|
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
|
editable: true,
render: (value: number) => {
if (value) {
if (isPercent == 2) {
return value + "%";
} else if (isPercent == 1) {
return value;
} else if (isPercent == 0 && laddersType == 2) {
return value + "%";
} else {
return value;
}
} else {
return "";
}
},
},
],
},
{
title: "金额 (元)",
dataIndex: "money",
|
27123514
曾柯
考评组排名倒数
|
297
|
width: "10%",
|
4927eb1a
曾柯
考评组设置加列表及草稿
|
298
299
300
301
302
303
304
305
306
307
308
|
editable: true,
render: (text: number) => (typeof text === "number" ? `${text}` : "--"),
},
{
title: "封顶金额 (元)",
dataIndex: "capMoney",
width: "20%",
editable: true,
render: (text: number) => (typeof text === "number" ? `${text}` : "--"),
},
{
|
27123514
曾柯
考评组排名倒数
|
309
310
311
312
313
314
315
|
title: "排名顺序类型",
dataIndex: "rankOrderType",
width: "20%",
editable: true,
render: (rankOrderType: number) => (rankOrderType === 2 ? "倒数排序" : "正数排序"),
},
{
|
4927eb1a
曾柯
考评组设置加列表及草稿
|
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
|
title: "操作",
width: "40%",
dataIndex: "operation",
render: (_: any, record: Item, index: number) => {
const editable = isEditing(record);
return editable ? (
<Space split={<Divider type="vertical" />}>
<Typography.Link onClick={() => _add(record.key, record)} style={{ marginRight: 8 }}>
保存并新增排名区间
</Typography.Link>
<Typography.Link onClick={() => save(record.key, record)} style={{ marginRight: 8 }}>
保存
</Typography.Link>
<Popconfirm title="确定取消?" onConfirm={cancel}>
<a>取消</a>
</Popconfirm>
</Space>
) : (
<Space split={<Divider type="vertical" />}>
<Typography.Link disabled={editingKey !== "" || readOnly} onClick={() => edit(record)}>
编辑
</Typography.Link>
{index !== 0 && (
<Typography.Link
disabled={editingKey !== "" || readOnly || value?.length === 1}
onClick={() => _onDelete(record, index)}
>
删除
</Typography.Link>
)}
</Space>
);
},
},
];
const getColumns = () => {
const _columns = columns;
if (readOnly) {
_columns.pop();
}
return _columns;
};
const calTypeColumns = () => {
const _columns = getColumns();
if (calType == 5) {
return _columns;
} else {
return _columns.filter((item) => item.dataIndex !== "capMoney");
}
};
const mergedColumns = calTypeColumns().map((col) => {
if (!col.editable) {
return col;
}
if (col.children) {
return {
...col,
children: [
{
...col.children[0],
|
27123514
曾柯
考评组排名倒数
|
376
377
378
379
380
381
382
383
384
|
onCell: (record: Item) => {
return {
record,
inputType: "number",
dataIndex: col.children[0].dataIndex,
title: col.children[0].title,
editing: isEditing(record),
};
},
|
4927eb1a
曾柯
考评组设置加列表及草稿
|
385
386
387
|
},
{
...col.children[1],
|
27123514
曾柯
考评组排名倒数
|
388
389
390
391
392
393
394
395
396
397
|
onCell: (record: Item) => {
console.log("recordrecord", record);
return {
record,
inputType: "number",
dataIndex: col.children[1].dataIndex,
title: col.children[1].title,
editing: isEditing(record),
};
},
|
4927eb1a
曾柯
考评组设置加列表及草稿
|
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
|
},
],
};
}
return {
...col,
onCell: (record: Item) => ({
record,
inputType: "number",
dataIndex: col.dataIndex,
title: col.title,
editing: isEditing(record),
}),
};
});
return (
<>
{type === 2 ? (
<Modal
title="查看指标"
visible={visible}
maskClosable={false}
footer={null}
width={700}
onCancel={() => setladderVisible(false)}
>
<Form form={form} component={false}>
<Table
components={{
body: {
cell: EditableCell,
},
}}
bordered
dataSource={value}
columns={mergedColumns}
rowClassName="editable-row"
pagination={{
onChange: cancel,
}}
/>
</Form>
|
ccdb0384
曾柯
考评组配置及数据导入
|
441
|
<div>金额可为负数,负数为负激励</div>
|
4927eb1a
曾柯
考评组设置加列表及草稿
|
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
|
</Modal>
) : (
<>
<Form form={form} component={false}>
<Table
components={{
body: {
cell: EditableCell,
},
}}
bordered
dataSource={value}
columns={mergedColumns}
rowClassName="editable-row"
pagination={{
onChange: cancel,
}}
/>
</Form>
|
7cf041ab
曾柯
考评组bugfix
|
461
|
<div>金额可为负数,负数为负激励</div>
|
4927eb1a
曾柯
考评组设置加列表及草稿
|
462
463
464
465
466
467
468
|
</>
)}
</>
);
};
export default TotalAmount;
|