diff --git a/src/pages/calcTable/index.tsx b/src/pages/calcTable/index.tsx index db7ebfe..dca62f5 100644 --- a/src/pages/calcTable/index.tsx +++ b/src/pages/calcTable/index.tsx @@ -49,7 +49,7 @@ const Index: FunctionComponent = (props) => { const [sumRowlistUrl, setSumRowlistUrl] = useState(""); const [payload, setPayload] = useState(""); const [form] = Form.useForm(); - const dataList = useRef([]); + const editItemList = useRef([]); useEffect(() => { window.parent.postMessage({ type: "init" }, "*"); @@ -71,7 +71,6 @@ const Index: FunctionComponent = (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) => { 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) => {