custom/鲁控数字-薪资核算列

表页面批量编辑
custom/鲁控数字-薪资核算列表页面批量编辑
黎永顺 2 years ago
parent e944adbe0d
commit 60e9a4af52

@ -49,7 +49,7 @@ const Index: FunctionComponent<Props> = (props) => {
const [sumRowlistUrl, setSumRowlistUrl] = useState<string>("");
const [payload, setPayload] = useState<string>("");
const [form] = Form.useForm();
const dataList = useRef<any[]>([]);
const editItemList = useRef<any[]>([]);
useEffect(() => {
window.parent.postMessage({ type: "init" }, "*");
@ -71,7 +71,6 @@ const Index: FunctionComponent<Props> = (props) => {
setPayload(payload);
setPageInfo(pageInfo);
setDataSource(dataSource);
dataList.current = dataSource;
setSelectedRowKeys(selectedRowKeys);
setColumns([...convertColumns(_.map(columns, o => ({ ...o, i18n: i18nRes }))), {
title: i18nRes["操作"], dataIndex: "operate", fixed: "right", width: 120,
@ -109,10 +108,38 @@ const Index: FunctionComponent<Props> = (props) => {
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);
}
editItemList.current.push({ id: row.id, ...getDifferentValues(item, row) });
}
window.parent.postMessage(
{
type: "turn",
payload: { id: "BEATCHUPDATE", params: { resultValueList: JSON.stringify(editItemList.current) } }
},
"*"
);
newData.splice(index, 1, { ...item, ...row });
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(() => {
return _.map([...dataSource], (item, index) => {

Loading…
Cancel
Save