Commit ff5cef99b31de0a28a08e307d033adfa1e616c47
1 parent
885f6965
1.系统单据如果勾选了bMark,在表格Footer增加部分勾选合计数据展示
Showing
3 changed files
with
119 additions
and
3 deletions
src/components/Common/CommonTable/index.js
| ... | ... | @@ -200,6 +200,8 @@ class CommonTableRc extends React.Component { |
| 200 | 200 | currentHoverSid: '', |
| 201 | 201 | simpleModalVisible: false, |
| 202 | 202 | simpleModalWord: '', |
| 203 | + selectedSumData: {}, /* 部分勾选合计数据 */ | |
| 204 | + selectedRowCount: 0, /* 部分勾选行数 */ | |
| 203 | 205 | }; |
| 204 | 206 | this.rowKey = commonUtils.isNotEmptyObject(props.tableProps) && !commonUtils.isEmpty(props.tableProps.rowKey) ? props.tableProps.rowKey : 'sId'; /* 表格主键 */ |
| 205 | 207 | this.config = {}; /* 配置信息(基础)(数据格式:对象) */ |
| ... | ... | @@ -2371,7 +2373,7 @@ class CommonTableRc extends React.Component { |
| 2371 | 2373 | let showConfig = []; |
| 2372 | 2374 | /* 通过sName过滤出对应的showConfig */ |
| 2373 | 2375 | /* 通过sName过滤出对应的showConfig */ |
| 2374 | - | |
| 2376 | + | |
| 2375 | 2377 | if (this.props.customConfig) { |
| 2376 | 2378 | const showConfigArr = this.props.customConfig.filter(item => commonUtils.isNotEmptyObject(item.sName) && commonUtils.isNotEmptyObject(item.sColorTerms) && item.bVisible); |
| 2377 | 2379 | if (commonUtils.isNotEmptyArr(showConfigArr)) { |
| ... | ... | @@ -4494,7 +4496,11 @@ class CommonTableRc extends React.Component { |
| 4494 | 4496 | const sumset = commonFunc.showMessage(this.props.app.commonConst, 'sumSet') || '合计'; |
| 4495 | 4497 | |
| 4496 | 4498 | let colSpan = 0; |
| 4497 | - if ((!totalData.length && !totalData1.length) || this.props.footer !== undefined) { | |
| 4499 | + if (this.props.footer !== undefined) { | |
| 4500 | + return (<></>); | |
| 4501 | + } | |
| 4502 | + // 即使 totalData 和 totalData1 都为空,也要显示部分勾选合计 | |
| 4503 | + if (!totalData.length && !totalData1.length && !this.state.selectedRowCount) { | |
| 4498 | 4504 | return (<></>); |
| 4499 | 4505 | } |
| 4500 | 4506 | if (this.props.tableProps.rowSelection !== null && !(this.props.config && !this.props.config.bisMutiSelect)) { |
| ... | ... | @@ -4692,9 +4698,59 @@ class CommonTableRc extends React.Component { |
| 4692 | 4698 | } |
| 4693 | 4699 | }); |
| 4694 | 4700 | } |
| 4701 | + // 部分勾选合计 | |
| 4702 | + const { selectedSumData, selectedRowCount } = this.state; | |
| 4703 | + const selectedCells = []; | |
| 4704 | + if (selectedRowCount > 0) { | |
| 4705 | + let selectedSummaryCellTotal = ''; | |
| 4706 | + selectedSummaryCellTotal = ( | |
| 4707 | + <Table.Summary.Cell key={0} colSpan={colSpan ? colSpan : 1} index={0}> | |
| 4708 | + <span className={styles.summaryCellTotal}>已选{selectedRowCount}行</span> | |
| 4709 | + </Table.Summary.Cell> | |
| 4710 | + ); | |
| 4711 | + selectedCells.push(selectedSummaryCellTotal); | |
| 4712 | + | |
| 4713 | + tableColumn.forEach((item, index) => { | |
| 4714 | + if (colSpan === 0 && index === 0) { | |
| 4715 | + return; | |
| 4716 | + } | |
| 4717 | + let iTag = index + colSpan; | |
| 4718 | + if (tableColumn[index].children !== undefined && tableColumn[index].children.length > 0) { | |
| 4719 | + tableColumn[index].children.forEach((itemChild, i) => { | |
| 4720 | + const sValue = selectedSumData[itemChild.dataIndex] || 0; | |
| 4721 | + const cellChild = ( | |
| 4722 | + <Table.Summary.Cell key={itemChild.dataIndex} index={iTag + i}> | |
| 4723 | + <Tooltip title={this.formatThousands(sValue)}><span | |
| 4724 | + className={styles.summaryCell} | |
| 4725 | + >{this.formatThousands(sValue)}</span></Tooltip> | |
| 4726 | + </Table.Summary.Cell> | |
| 4727 | + ); | |
| 4728 | + selectedCells.push(cellChild); | |
| 4729 | + }); | |
| 4730 | + } else { | |
| 4731 | + const sValue = selectedSumData[item.dataIndex] || 0; | |
| 4732 | + const cell = ( | |
| 4733 | + <Table.Summary.Cell key={item.dataIndex} index={iTag}> | |
| 4734 | + <Tooltip title={this.formatThousands(sValue)}><span | |
| 4735 | + className={styles.summaryCell} | |
| 4736 | + >{this.formatThousands(sValue)}</span></Tooltip> | |
| 4737 | + </Table.Summary.Cell> | |
| 4738 | + ); | |
| 4739 | + selectedCells.push(cell); | |
| 4740 | + } | |
| 4741 | + }); | |
| 4742 | + } | |
| 4743 | + | |
| 4695 | 4744 | return ( |
| 4696 | 4745 | <Table.Summary fixed> |
| 4697 | 4746 | { |
| 4747 | + selectedRowCount > 0 ? ( | |
| 4748 | + <Table.Summary.Row> | |
| 4749 | + {selectedCells} | |
| 4750 | + </Table.Summary.Row> | |
| 4751 | + ) : '' | |
| 4752 | + } | |
| 4753 | + { | |
| 4698 | 4754 | totalData.length ? ( |
| 4699 | 4755 | <Table.Summary.Row> |
| 4700 | 4756 | {cells} |
| ... | ... | @@ -4783,6 +4839,64 @@ class CommonTableRc extends React.Component { |
| 4783 | 4839 | } |
| 4784 | 4840 | } |
| 4785 | 4841 | |
| 4842 | + | |
| 4843 | + handleSelectColumn = (config, dataSource) => { | |
| 4844 | + const tableDataTotal = {}; | |
| 4845 | + // 添加防御性检查 | |
| 4846 | + if (!config || !config.gdsconfigformslave || !Array.isArray(config.gdsconfigformslave)) { | |
| 4847 | + return; | |
| 4848 | + } | |
| 4849 | + const sumConfig = config.gdsconfigformslave.filter(item => item && item.sName !== '' && item.bVisible && item.bSum); | |
| 4850 | + if (commonUtils.isNotEmptyArr(sumConfig)) { | |
| 4851 | + if (commonUtils.isNotEmptyObject(config) && commonUtils.isNotEmptyArr(dataSource)) { | |
| 4852 | + // 筛选出 bMark === true 的行 | |
| 4853 | + const selectedRows = dataSource.filter(tableDataRow => tableDataRow && tableDataRow.bMark === true); | |
| 4854 | + selectedRows.forEach((tableDataRow) => { | |
| 4855 | + sumConfig.forEach((sumItem) => { | |
| 4856 | + if (tableDataRow && tableDataRow.handleType !== 'del' && sumItem && sumItem.sName) { | |
| 4857 | + if (sumItem.sName.substring(sumItem.sName.length - 5, sumItem.sName.length).toLowerCase() === 'Price'.toLowerCase()) { | |
| 4858 | + tableDataTotal[sumItem.sName] = commonUtils.convertFixNum(commonUtils.convertToNum(tableDataTotal[sumItem.sName]) + | |
| 4859 | + commonUtils.convertToNum(tableDataRow[sumItem.sName]), this.props.getFloatNum ? this.props.getFloatNum(sumItem.sName) : 2); | |
| 4860 | + } else { | |
| 4861 | + /* 如果设置格式 按照设置格式来,否则按照系统设定 */ | |
| 4862 | + const sFieldConfigArr = config.gdsconfigformslave.filter(item => item.sName === sumItem.sName && item.bVisible); | |
| 4863 | + if (commonUtils.isNotEmptyArr(sFieldConfigArr)) { | |
| 4864 | + const { sFieldValidation: sFieldValidationOld, sName } = sFieldConfigArr[0]; | |
| 4865 | + if (commonUtils.isNotEmptyObject(sFieldValidationOld)) { | |
| 4866 | + const [length1, length2] = sFieldValidationOld.split(','); | |
| 4867 | + if (commonUtils.isNotEmptyNumber(length2)) { | |
| 4868 | + tableDataTotal[sumItem.sName] = commonUtils.convertFixNum(commonUtils.convertToNum(tableDataTotal[sumItem.sName]) + | |
| 4869 | + commonUtils.convertToNum(tableDataRow[sumItem.sName]), this.props.getFloatNum(length2)); | |
| 4870 | + } | |
| 4871 | + } else { | |
| 4872 | + tableDataTotal[sumItem.sName] = commonUtils.convertFixNum(commonUtils.convertToNum(tableDataTotal[sumItem.sName]) + | |
| 4873 | + commonUtils.convertToNum(tableDataRow[sumItem.sName]), this.props.getFloatNum(sumItem.sName)); | |
| 4874 | + } | |
| 4875 | + } | |
| 4876 | + } | |
| 4877 | + } | |
| 4878 | + }); | |
| 4879 | + }); | |
| 4880 | + } else { | |
| 4881 | + sumConfig.forEach((sumItem) => { | |
| 4882 | + tableDataTotal[sumItem.sName] = 0; | |
| 4883 | + }); | |
| 4884 | + } | |
| 4885 | + tableDataTotal.bSum = true; | |
| 4886 | + tableDataTotal.key = '0000'; | |
| 4887 | + console.log('tableDat212222222aTotal', tableDataTotal); | |
| 4888 | + | |
| 4889 | + if (this.mounted) { | |
| 4890 | + // 计算选中的行数,添加防御性检查 | |
| 4891 | + const selectedRowCount = commonUtils.isNotEmptyArr(dataSource) ? dataSource.filter(row => row && row.bMark === true).length : 0; | |
| 4892 | + this.setState({ | |
| 4893 | + selectedSumData: tableDataTotal, | |
| 4894 | + selectedRowCount: selectedRowCount | |
| 4895 | + }); | |
| 4896 | + } | |
| 4897 | + } | |
| 4898 | + } | |
| 4899 | + | |
| 4786 | 4900 | handleSumOtherColumn = (config, dataSource) => { |
| 4787 | 4901 | const tableDataTotal = {}; |
| 4788 | 4902 | const sumConfig = config.gdsconfigformslave.filter(item => item.sName !== '' && item.bVisible && item.bSum); |
| ... | ... | @@ -6185,6 +6299,7 @@ class CommonTableRc extends React.Component { |
| 6185 | 6299 | } else if (name === 'slaveChild') { |
| 6186 | 6300 | this.handleSumChildColumn(props.config, props.data); |
| 6187 | 6301 | } else { |
| 6302 | + this.handleSelectColumn(props.config, props.data); | |
| 6188 | 6303 | this.handleSumAllColumn(props.config, props.data); |
| 6189 | 6304 | } |
| 6190 | 6305 | } | ... | ... |
src/components/Common/commonFunc.js
| ... | ... | @@ -104,6 +104,7 @@ export function getHeaderConfig(config) { |
| 104 | 104 | sTitleColor: child.sFontColor, /* 设置表格标题字体颜色 */ |
| 105 | 105 | bCheckBox: child.bCheckBox, /* 是否支持表头多选 */ |
| 106 | 106 | bReadonly: child.bReadonly, /* 是否只读 */ |
| 107 | + bSum: child.bSum, /* 设置表格必填项*号 */ | |
| 107 | 108 | }); |
| 108 | 109 | } |
| 109 | 110 | } | ... | ... |
src/utils/utils.js
| ... | ... | @@ -157,7 +157,7 @@ export function convertStrToObj(str, defaultObj = {}) { |
| 157 | 157 | try { |
| 158 | 158 | result = JSON.parse(str.replace(/\r\n|\n|\r|\t/g, ' ')); |
| 159 | 159 | } catch (error) { |
| 160 | - console.log(`${str}JSON报错:`, e.message); | |
| 160 | + // console.log(`${str}JSON报错:`, e.message); | |
| 161 | 161 | result = defaultObj; |
| 162 | 162 | } |
| 163 | 163 | } | ... | ... |