Commit c15081d923707357df1a59a0ecc96b6394336886

Authored by zhangzzzz
1 parent 7384baf9

sum功能支持bill类型;

src/components/Common/CommonComponent/index.js
... ... @@ -1764,6 +1764,8 @@ export default class CommonComponent extends Component {
1764 1764 obj.onBlur = this.onBlur;
1765 1765 obj.onMouseEnter = this.onFocus;
1766 1766 obj.id = `${this.props.showConfig.sName}${this.props.record ? this.props.record.sId : commonUtils.createSid()}`; /* 所有从表组件添加id */
  1767 + obj["data-name"] = this.props.showConfig.sName;
  1768 + obj["data-control-name"] = this.props.showConfig.sControlName;
1767 1769 obj.placeholder = this.props.showConfig.placeholder || "";
1768 1770 /* 返回值 */
1769 1771 return obj;
... ...
src/components/Common/CommonTable/index.js
... ... @@ -829,22 +829,25 @@ class CommonTableRc extends React.Component {
829 829 };
830 830  
831 831 handleContextMenu = (event) => {
832   - // 判断右键位置是否有选中文本
833   - if (!window.getSelection().toString()) {
834   - const { target } = event;
835   - const { tagName } = target;
836   - const oDiv = {
837   - 'span': target.parentNode,
838   - 'td': target.childNodes[0].childNodes[0],
839   - 'div': target.getAttribute('data-name') ? target : target.childNodes[0],
840   - }[tagName.toLowerCase()];
841   -
842   - if (!oDiv) return;
843   - if (!oDiv.getAttribute('data-control-name')?.includes('_Sum')) return;
844   - // 阻止右键菜单
845   - event.preventDefault();
846   - this.setState({ totalDataNew: undefined, sumGroup: {} });
847   - }
  832 + try {
  833 + // 判断右键位置是否有选中文本
  834 + if (!window.getSelection().toString()) {
  835 + const { target } = event;
  836 + const { tagName } = target;
  837 + const oDiv = {
  838 + 'span': target.getAttribute('data-name') ? target : target.parentNode,
  839 + 'td': target?.childNodes[0]?.childNodes[0],
  840 + 'div': target.getAttribute('data-name') ? target : target.childNodes[0],
  841 + 'input': target,
  842 + }[tagName.toLowerCase()];
  843 +
  844 + if (!oDiv) return;
  845 + if (!oDiv.getAttribute('data-control-name')?.includes('_Sum')) return;
  846 + // 阻止右键菜单
  847 + event.preventDefault();
  848 + this.setState({ totalDataNew: undefined, sumGroup: {} });
  849 + }
  850 + } catch (error) {}
848 851  
849 852 }
850 853  
... ... @@ -4159,55 +4162,58 @@ class CommonTableRc extends React.Component {
4159 4162 }
4160 4163  
4161 4164 handleCellClick = (record) => {
4162   - const { enabled } = this.props;
4163   - if (enabled) return false;
4164   -
4165   - const { target } = event;
4166   - const { tagName } = target;
4167   - const oDiv = {
4168   - 'span': target.parentNode,
4169   - 'td': target.childNodes[0].childNodes[0],
4170   - 'div': target.getAttribute('data-name') ? target : target.childNodes[0],
4171   - }[tagName.toLowerCase()];
4172   -
4173   - if (!oDiv || window.getSelection().toString()) return false;
4174   -
4175   - const [sName, sControlName] = [oDiv.getAttribute('data-name'), oDiv.getAttribute('data-control-name')];
4176   - if (sControlName?.includes('_Sum')) {
4177   - const { sumGroup = {}, totalData = [{}], totalDataNew: totalDataNew0 = [{}] } = this.state;
4178   - const { dNetMoney, dNetPrice } = this.props.app.decimals;
4179   - sumGroup[sName] = sumGroup[sName] || [];
4180   - if (sumGroup[sName].includes(record[this.rowKey])) {
4181   - sumGroup[sName] = sumGroup[sName].filter(item => item !== record[this.rowKey]);
4182   - } else {
4183   - sumGroup[sName].push(record[this.rowKey]);
4184   - }
4185   -
4186   - let totalDataNew = [...totalDataNew0];
4187   - if (sumGroup[sName].length) {
4188   - const sum = sumGroup[sName].reduce((pre, cur) => {
4189   - const curData = this.props.data.find(item => item[this.rowKey] === cur);
4190   - if (curData) {
4191   - let tempValue = 0;
4192   - if (sName.toLowerCase().endsWith('price')) { /* 价格 */
4193   - tempValue = commonUtils.convertFixNum(commonUtils.convertFixNum(commonUtils.isNull(curData[sName], 0), dNetPrice) + commonUtils.convertFixNum(commonUtils.isNull(pre, 0), dNetPrice), dNetPrice);
4194   - } else { /* 金额 */
4195   - tempValue = commonUtils.convertFixNum(commonUtils.convertFixNum(commonUtils.isNull(curData[sName], 0), dNetMoney) + commonUtils.convertFixNum(commonUtils.isNull(pre, 0), dNetMoney), dNetMoney);
  4165 + try {
  4166 + const { target } = event;
  4167 +
  4168 + const { tagName } = target;
  4169 + const oDiv = {
  4170 + 'span': target.getAttribute('data-name') ? target : target.parentNode,
  4171 + 'td': target?.childNodes[0]?.childNodes[0],
  4172 + 'div': target.getAttribute('data-name') ? target : target.childNodes[0],
  4173 + 'input': target,
  4174 + }[tagName.toLowerCase()];
  4175 +
  4176 + if (!oDiv || window.getSelection().toString()) return false;
  4177 +
  4178 + const [sName, sControlName] = [oDiv.getAttribute('data-name'), oDiv.getAttribute('data-control-name')];
  4179 + if (sControlName?.includes('_Sum')) {
  4180 + const { sumGroup = {}, totalData = [{}], totalDataNew: totalDataNew0 = [{}] } = this.state;
  4181 + const { dNetMoney, dNetPrice } = this.props.app.decimals;
  4182 + sumGroup[sName] = sumGroup[sName] || [];
  4183 + if (sumGroup[sName].includes(record[this.rowKey])) {
  4184 + sumGroup[sName] = sumGroup[sName].filter(item => item !== record[this.rowKey]);
  4185 + } else {
  4186 + sumGroup[sName].push(record[this.rowKey]);
  4187 + }
  4188 +
  4189 + let totalDataNew = [...totalDataNew0];
  4190 + if (sumGroup[sName].length) {
  4191 + const sum = sumGroup[sName].reduce((pre, cur) => {
  4192 + const curData = this.props.data.find(item => item[this.rowKey] === cur);
  4193 + if (curData) {
  4194 + let tempValue = 0;
  4195 + if (sName.toLowerCase().endsWith('price')) { /* 价格 */
  4196 + tempValue = commonUtils.convertFixNum(commonUtils.convertFixNum(commonUtils.isNull(curData[sName], 0), dNetPrice) + commonUtils.convertFixNum(commonUtils.isNull(pre, 0), dNetPrice), dNetPrice);
  4197 + } else { /* 金额 */
  4198 + tempValue = commonUtils.convertFixNum(commonUtils.convertFixNum(commonUtils.isNull(curData[sName], 0), dNetMoney) + commonUtils.convertFixNum(commonUtils.isNull(pre, 0), dNetMoney), dNetMoney);
  4199 + }
  4200 + return tempValue;
4196 4201 }
4197   - return tempValue;
4198   - }
4199   - return pre;
4200   - }, 0);
4201   -
4202   - totalDataNew = [{ ...totalData[0], ...totalDataNew[0], [sName]: sum }];
4203   - } else {
4204   - totalDataNew[0][sName] = totalData[0][sName];
  4202 + return pre;
  4203 + }, 0);
  4204 +
  4205 + totalDataNew = [{ ...totalData[0], ...totalDataNew[0], [sName]: sum }];
  4206 + } else {
  4207 + totalDataNew[0][sName] = totalData[0][sName];
  4208 + }
  4209 +
  4210 + this.setState({ sumGroup, totalDataNew });
  4211 + return !this.props.enabled;
4205 4212 }
4206   -
4207   - this.setState({ sumGroup, totalDataNew });
4208   - return true;
  4213 + return false;
  4214 + } catch (error) {
  4215 + return false;
4209 4216 }
4210   - return false;
4211 4217 }
4212 4218  
4213 4219 handleGetSumStyle = (sName, index) => {
... ... @@ -5818,7 +5824,12 @@ class CommonTableRc extends React.Component {
5818 5824 this.hasSpanBgColor = true;
5819 5825 }
5820 5826  
5821   - res = (<span className={`noInput readonlySpanStyle ${bReadonlyField ? "readonlyField" : ""}`} style={{ color: `${cellColor}`, backgroundColor: `${backgroundColor}` }} > {(commonUtils.isNotEmptyObject(sName) && sName.substring(0, 1) === 'b') || (imgBox !== '') ? '' :
  5827 + res = (<span
  5828 + className={`noInput readonlySpanStyle ${bReadonlyField ? "readonlyField" : ""}`}
  5829 + style={{ color: `${cellColor}`, backgroundColor: `${backgroundColor}` }}
  5830 + data-name={showConfig.sName}
  5831 + data-control-name={showConfig.sControlName}
  5832 + > {(commonUtils.isNotEmptyObject(sName) && sName.substring(0, 1) === 'b') || (imgBox !== '') ? '' :
5822 5833 <Tooltip
5823 5834 placement={bSpecialTitle ? 'right' : 'bottomLeft'}
5824 5835 overlayClassName={bSpecialTitle ? 'commonSpecialTitle' : 'commonTitle'}
... ... @@ -6192,6 +6203,36 @@ class CommonTableRc extends React.Component {
6192 6203 stateValue.tableInfoColumn = stateValue.tableInfoColumn.sort(compare('sortIndex'));
6193 6204 }
6194 6205 }
  6206 +
  6207 + if (enabled) {
  6208 + const { sumGroup = {}, totalDataNew: totalDataNew0 = [{}] } = this.state;
  6209 + const { dNetMoney, dNetPrice } = this.props.app.decimals;
  6210 + let totalDataNew = [...totalDataNew0];
  6211 + const sumData = {};
  6212 + Object.keys(sumGroup).forEach(sName => {
  6213 + if (sumGroup[sName].length) {
  6214 + const sum = sumGroup[sName].reduce((pre, cur) => {
  6215 + const curData = this.props.data.find(item => item[this.rowKey] === cur);
  6216 + if (curData) {
  6217 + let tempValue = 0;
  6218 + if (sName.toLowerCase().endsWith('price')) { /* 价格 */
  6219 + tempValue = commonUtils.convertFixNum(commonUtils.convertFixNum(commonUtils.isNull(curData[sName], 0), dNetPrice) + commonUtils.convertFixNum(commonUtils.isNull(pre, 0), dNetPrice), dNetPrice);
  6220 + } else { /* 金额 */
  6221 + tempValue = commonUtils.convertFixNum(commonUtils.convertFixNum(commonUtils.isNull(curData[sName], 0), dNetMoney) + commonUtils.convertFixNum(commonUtils.isNull(pre, 0), dNetMoney), dNetMoney);
  6222 + }
  6223 + return tempValue;
  6224 + }
  6225 + return pre;
  6226 + }, 0);
  6227 +
  6228 + sumData[sName] = sum;
  6229 + }
  6230 + });
  6231 +
  6232 + totalDataNew = [{ ...totalData[0], ...sumData }];
  6233 + stateValue.totalDataNew = totalDataNew;
  6234 + }
  6235 +
6195 6236 if (this.mounted) {
6196 6237 this.setState(stateValue);
6197 6238 // 生成merge maps;
... ...