diff --git a/src/components/Common/CommonComponent/index.js b/src/components/Common/CommonComponent/index.js index a196054..42d1438 100644 --- a/src/components/Common/CommonComponent/index.js +++ b/src/components/Common/CommonComponent/index.js @@ -1764,6 +1764,8 @@ export default class CommonComponent extends Component { obj.onBlur = this.onBlur; obj.onMouseEnter = this.onFocus; obj.id = `${this.props.showConfig.sName}${this.props.record ? this.props.record.sId : commonUtils.createSid()}`; /* 所有从表组件添加id */ + obj["data-name"] = this.props.showConfig.sName; + obj["data-control-name"] = this.props.showConfig.sControlName; obj.placeholder = this.props.showConfig.placeholder || ""; /* 返回值 */ return obj; diff --git a/src/components/Common/CommonTable/index.js b/src/components/Common/CommonTable/index.js index e155930..4efa621 100644 --- a/src/components/Common/CommonTable/index.js +++ b/src/components/Common/CommonTable/index.js @@ -829,22 +829,25 @@ class CommonTableRc extends React.Component { }; handleContextMenu = (event) => { - // 判断右键位置是否有选中文本 - if (!window.getSelection().toString()) { - const { target } = event; - const { tagName } = target; - const oDiv = { - 'span': target.parentNode, - 'td': target.childNodes[0].childNodes[0], - 'div': target.getAttribute('data-name') ? target : target.childNodes[0], - }[tagName.toLowerCase()]; - - if (!oDiv) return; - if (!oDiv.getAttribute('data-control-name')?.includes('_Sum')) return; - // 阻止右键菜单 - event.preventDefault(); - this.setState({ totalDataNew: undefined, sumGroup: {} }); - } + try { + // 判断右键位置是否有选中文本 + if (!window.getSelection().toString()) { + const { target } = event; + const { tagName } = target; + const oDiv = { + 'span': target.getAttribute('data-name') ? target : target.parentNode, + 'td': target?.childNodes[0]?.childNodes[0], + 'div': target.getAttribute('data-name') ? target : target.childNodes[0], + 'input': target, + }[tagName.toLowerCase()]; + + if (!oDiv) return; + if (!oDiv.getAttribute('data-control-name')?.includes('_Sum')) return; + // 阻止右键菜单 + event.preventDefault(); + this.setState({ totalDataNew: undefined, sumGroup: {} }); + } + } catch (error) {} } @@ -4159,55 +4162,58 @@ class CommonTableRc extends React.Component { } handleCellClick = (record) => { - const { enabled } = this.props; - if (enabled) return false; - - const { target } = event; - const { tagName } = target; - const oDiv = { - 'span': target.parentNode, - 'td': target.childNodes[0].childNodes[0], - 'div': target.getAttribute('data-name') ? target : target.childNodes[0], - }[tagName.toLowerCase()]; - - if (!oDiv || window.getSelection().toString()) return false; - - const [sName, sControlName] = [oDiv.getAttribute('data-name'), oDiv.getAttribute('data-control-name')]; - if (sControlName?.includes('_Sum')) { - const { sumGroup = {}, totalData = [{}], totalDataNew: totalDataNew0 = [{}] } = this.state; - const { dNetMoney, dNetPrice } = this.props.app.decimals; - sumGroup[sName] = sumGroup[sName] || []; - if (sumGroup[sName].includes(record[this.rowKey])) { - sumGroup[sName] = sumGroup[sName].filter(item => item !== record[this.rowKey]); - } else { - sumGroup[sName].push(record[this.rowKey]); - } - - let totalDataNew = [...totalDataNew0]; - if (sumGroup[sName].length) { - const sum = sumGroup[sName].reduce((pre, cur) => { - const curData = this.props.data.find(item => item[this.rowKey] === cur); - if (curData) { - let tempValue = 0; - if (sName.toLowerCase().endsWith('price')) { /* 价格 */ - tempValue = commonUtils.convertFixNum(commonUtils.convertFixNum(commonUtils.isNull(curData[sName], 0), dNetPrice) + commonUtils.convertFixNum(commonUtils.isNull(pre, 0), dNetPrice), dNetPrice); - } else { /* 金额 */ - tempValue = commonUtils.convertFixNum(commonUtils.convertFixNum(commonUtils.isNull(curData[sName], 0), dNetMoney) + commonUtils.convertFixNum(commonUtils.isNull(pre, 0), dNetMoney), dNetMoney); + try { + const { target } = event; + + const { tagName } = target; + const oDiv = { + 'span': target.getAttribute('data-name') ? target : target.parentNode, + 'td': target?.childNodes[0]?.childNodes[0], + 'div': target.getAttribute('data-name') ? target : target.childNodes[0], + 'input': target, + }[tagName.toLowerCase()]; + + if (!oDiv || window.getSelection().toString()) return false; + + const [sName, sControlName] = [oDiv.getAttribute('data-name'), oDiv.getAttribute('data-control-name')]; + if (sControlName?.includes('_Sum')) { + const { sumGroup = {}, totalData = [{}], totalDataNew: totalDataNew0 = [{}] } = this.state; + const { dNetMoney, dNetPrice } = this.props.app.decimals; + sumGroup[sName] = sumGroup[sName] || []; + if (sumGroup[sName].includes(record[this.rowKey])) { + sumGroup[sName] = sumGroup[sName].filter(item => item !== record[this.rowKey]); + } else { + sumGroup[sName].push(record[this.rowKey]); + } + + let totalDataNew = [...totalDataNew0]; + if (sumGroup[sName].length) { + const sum = sumGroup[sName].reduce((pre, cur) => { + const curData = this.props.data.find(item => item[this.rowKey] === cur); + if (curData) { + let tempValue = 0; + if (sName.toLowerCase().endsWith('price')) { /* 价格 */ + tempValue = commonUtils.convertFixNum(commonUtils.convertFixNum(commonUtils.isNull(curData[sName], 0), dNetPrice) + commonUtils.convertFixNum(commonUtils.isNull(pre, 0), dNetPrice), dNetPrice); + } else { /* 金额 */ + tempValue = commonUtils.convertFixNum(commonUtils.convertFixNum(commonUtils.isNull(curData[sName], 0), dNetMoney) + commonUtils.convertFixNum(commonUtils.isNull(pre, 0), dNetMoney), dNetMoney); + } + return tempValue; } - return tempValue; - } - return pre; - }, 0); - - totalDataNew = [{ ...totalData[0], ...totalDataNew[0], [sName]: sum }]; - } else { - totalDataNew[0][sName] = totalData[0][sName]; + return pre; + }, 0); + + totalDataNew = [{ ...totalData[0], ...totalDataNew[0], [sName]: sum }]; + } else { + totalDataNew[0][sName] = totalData[0][sName]; + } + + this.setState({ sumGroup, totalDataNew }); + return !this.props.enabled; } - - this.setState({ sumGroup, totalDataNew }); - return true; + return false; + } catch (error) { + return false; } - return false; } handleGetSumStyle = (sName, index) => { @@ -5818,7 +5824,12 @@ class CommonTableRc extends React.Component { this.hasSpanBgColor = true; } - res = ( {(commonUtils.isNotEmptyObject(sName) && sName.substring(0, 1) === 'b') || (imgBox !== '') ? '' : + res = ( {(commonUtils.isNotEmptyObject(sName) && sName.substring(0, 1) === 'b') || (imgBox !== '') ? '' : { + if (sumGroup[sName].length) { + const sum = sumGroup[sName].reduce((pre, cur) => { + const curData = this.props.data.find(item => item[this.rowKey] === cur); + if (curData) { + let tempValue = 0; + if (sName.toLowerCase().endsWith('price')) { /* 价格 */ + tempValue = commonUtils.convertFixNum(commonUtils.convertFixNum(commonUtils.isNull(curData[sName], 0), dNetPrice) + commonUtils.convertFixNum(commonUtils.isNull(pre, 0), dNetPrice), dNetPrice); + } else { /* 金额 */ + tempValue = commonUtils.convertFixNum(commonUtils.convertFixNum(commonUtils.isNull(curData[sName], 0), dNetMoney) + commonUtils.convertFixNum(commonUtils.isNull(pre, 0), dNetMoney), dNetMoney); + } + return tempValue; + } + return pre; + }, 0); + + sumData[sName] = sum; + } + }); + + totalDataNew = [{ ...totalData[0], ...sumData }]; + stateValue.totalDataNew = totalDataNew; + } + if (this.mounted) { this.setState(stateValue); // 生成merge maps;