custom/鲁控数字-薪资核算列表页面批量编辑

custom/鲁控数字-薪资核算列表页面批量编辑
黎永顺 1 year ago
parent 10e09b2a3a
commit 3b8a2218a5

@ -32,7 +32,7 @@ interface EditableCellProps {
record?: any;
pattern?: number;
rowIndex?: number;
handleSave?: (record: any) => void;
handleSave?: (type: string, record: any) => void;
}
type Props = OwnProps;
@ -106,16 +106,31 @@ const Index: FunctionComponent<Props> = (props) => {
}
});
};
const handleSave = (row: any) => {
const handleSave = (salaryItemId: string, row: any) => {
setDataSource(prevState => {
const newData = [...prevState];
const index = newData.findIndex(item => row.id === item.id);
const item = newData[index];
if (!_.isEmpty(getDifferentValues(item, row))) {
if (editItemList.current.findIndex(g => !_.isEmpty(g[_.keys(getDifferentValues(item, row))[0]]) && g.id === row.id) !== -1) {
editItemList.current.splice(editItemList.current.findIndex(g => !_.isEmpty(g[_.keys(getDifferentValues(item, row))[0]])), 1);
if (_.map(editItemList.current, t => t.id).includes(row.id)) {
editItemList.current = _.reduce(editItemList.current, (pre: any, cur: any) => {
if (cur.id === row.id) {
return [...pre, {
id: row.id, items: _.map(cur.items, h => h.salaryItemId).includes(salaryItemId) ?
_.map(cur.items, k => {
if (k.salaryItemId === salaryItemId) {
return { ...k, salaryItemId, resultValue: row[salaryItemId] };
}
editItemList.current.push({ id: row.id, ...getDifferentValues(item, row) });
return { ...k };
})
: [...cur.items, { salaryItemId, resultValue: row[salaryItemId] }]
}];
}
return [...pre, cur];
}, []);
} else {
editItemList.current.push({
id: row.id, items: [{ salaryItemId, resultValue: row[salaryItemId] }]
});
}
window.parent.postMessage(
{
@ -128,20 +143,6 @@ const Index: FunctionComponent<Props> = (props) => {
return newData;
});
};
const getDifferentValues = (obj1: any, obj2: any) => {
const differentProperties = {};
for (const key in obj1) {
if (obj1.hasOwnProperty(key) && obj2.hasOwnProperty(key)) {
if (obj1[key] !== obj2[key]) {
differentProperties[key] = {
obj1Value: obj1[key],
obj2Value: obj2[key]
};
}
}
}
return differentProperties;
};
const handleChange = (rowIndex: any, dataIndex: any, v: any, dataSource: any[]) => {
setDataSource(() => {
@ -261,11 +262,11 @@ const EditableCell: React.FC<EditableCellProps> = (props) => {
[_.keys(values)[0]]: !_.isNil(_.get(values, _.keys(values)[0])) ? toDecimal_n(_.get(values, _.keys(values)[0]), restProps?.pattern) : toDecimal_n(0, restProps?.pattern)
};
}
handleSave?.({ ...record, ...values });
handleSave?.(_.keys(values)[0], { ...record, ...values });
} catch (errInfo) {
console.log("Save failed:", errInfo);
}
}, 500);
}, 200);
let childNode = children;
if (editable) {
childNode = editing ? (

Loading…
Cancel
Save