From 8a6c3d1a74bb352faad2504aaca533e8a6c6b09e Mon Sep 17 00:00:00 2001 From: chenxt <10125295+chen-xintao97@user.noreply.gitee.com> Date: Thu, 18 Dec 2025 13:53:59 +0800 Subject: [PATCH] 价格计算 --- src/components/Common/CommonHooks/commonKeyUp.js | 535 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/components/Common/CommonHooks/useCommonBase.js | 5 +++-- src/components/Common/CommonTable/index.js | 9 +++------ src/components/Common/commonBusiness.js | 22 ++++++++++++++-------- 4 files changed, 555 insertions(+), 16 deletions(-) create mode 100644 src/components/Common/CommonHooks/commonKeyUp.js diff --git a/src/components/Common/CommonHooks/commonKeyUp.js b/src/components/Common/CommonHooks/commonKeyUp.js new file mode 100644 index 0000000..9da2c9f --- /dev/null +++ b/src/components/Common/CommonHooks/commonKeyUp.js @@ -0,0 +1,535 @@ +/* eslint-disable */ +import * as commonUtils from '@/utils/utils'; +import * as commonFunc from '@/components/Common/commonFunc'; + +/** + * 自定义onChange事件处理函数 - 处理表格字段变更时的联动逻辑 + * + * @param {string} name - 表名('master'表示主表,其他表示从表如slave,control,materials,process) + * @param {string} sFieldName - 触发变更的字段名称 + * @param {Object} tableConfig - 表格配置对象,包含gdsconfigformslave配置数组 + * @param {Object} masterData - 主表数据对象 + * @param {Object} tableDataRow - 当前行数据对象(从表时使用) + * @param {boolean} isWait - 是否等待处理完成 + * @param {Object} dataCollection - 所有表格数据集合 + * @param {Object} dataSelected - 选中的数据对象 + * @param {Object} app - 应用实例对象 + * @returns {Object} 处理后的数据对象 + */ +export function getKeyUpEvent(name, sFieldName, tableConfig, masterData, tableDataRow, isWait, dataCollection, dataSelected, app) { + // 初始化数据对象和拷贝容器 + let tableDataRowNew = {}; + const newCopyTo = {}; + + // 根据表名类型初始化数据 + if (name === 'master') { + tableDataRowNew = masterData; // 主表使用masterData + } else { + tableDataRowNew = tableDataRow; // 从表使用当前行数据 + newCopyTo.slave = tableDataRow; // 设置从表数据到拷贝容器 + } + + // 检查表格配置是否存在且有效 + if (commonUtils.isNotEmptyObject(tableConfig) && commonUtils.isNotEmptyArr(tableConfig.gdsconfigformslave)) { + // 查找对应字段的配置项 + const iConfigIndex = tableConfig.gdsconfigformslave.findIndex(item => item.sName === sFieldName); + if (iConfigIndex > -1) { + // 设置主表数据到拷贝容器 + newCopyTo.master = masterData; + + // 获取赋值字段配置和按钮参数 + const sAssignField = tableConfig.gdsconfigformslave[iConfigIndex].sOnChangeAssignField; + const sButtonParam = tableConfig.gdsconfigformslave[iConfigIndex].sButtonParam; /* 设置多级联动 */ + + console.log('sAssignField:', sAssignField); + + // 根据赋值字段类型分发处理逻辑 + /* keyUp联动其他表 */ + if (commonUtils.isNotEmptyObject(sAssignField) && (sAssignField.includes('@@@:') || sAssignField.includes(';,'))) { + // 多表联动处理(包含@@@:或;,分隔符) + return handleMultiTableLinkage(name, sAssignField, sButtonParam, tableDataRowNew, newCopyTo, masterData, tableDataRow, dataCollection, dataSelected, app); + } else if (commonUtils.isNotEmptyObject(sAssignField) && sAssignField.includes('_')) { + // 跨表联动处理(包含下划线_all汇总, _filter过滤) + return handleCrossTableLinkage(name, sAssignField, sButtonParam, tableDataRowNew, newCopyTo, masterData, tableDataRow, dataCollection, dataSelected, app); + } else if (commonUtils.isNotEmptyObject(sAssignField)) { + // 单表keyUp事件处理 + return handleSingleTableEvent(name, sAssignField, tableDataRowNew, newCopyTo, masterData, tableDataRow, dataSelected, isWait); + } else { + // 无有效赋值字段,返回空对象 + return {}; + } + } + } + + // 未找到对应配置或配置无效,返回原始数据 + return tableDataRowNew; +} + +// 辅助函数:处理多表联动 +function handleMultiTableLinkage(name, sAssignField, sButtonParam, tableDataRowNew, newCopyTo, masterData, tableDataRow, dataCollection, dataSelected, app) { + const sAssignFieldObj = sAssignField.split(';,'); + console.log('=====sAssignFieldObj', sAssignFieldObj); + let addState = {}; + + if (name === 'master') { + sAssignFieldObj.forEach((sAssignFieldItem) => { + if (sAssignFieldItem?.indexOf('@@@:') !== -1) { + const sFormula = sAssignFieldItem.split('@@@:')[1]; + const sAssignFieldV2 = commonFunc.getAssignFieldV2(sFormula, tableDataRowNew); + const result = commonFunc.getAssignFieldValue(sAssignFieldV2, tableDataRowNew, newCopyTo); + addState = { ...addState, ...result }; + } else if (sAssignFieldItem?.includes('_all')) { + addState = { ...addState, ...handleAllTableLinkage(sAssignFieldItem, newCopyTo, masterData, dataCollection) }; + } else { + addState = { + ...addState, + ...commonFunc.getAssignFieldValue(sAssignFieldItem, tableDataRowNew, newCopyTo), + }; + } + }); + } else { + sAssignFieldObj.forEach((sAssignFieldItem) => { + const tableConfigCopy = cloneDeep(tableConfig); + tableConfigCopy.gdsconfigformslave[iConfigIndex].sOnChangeAssignField = sAssignFieldItem; + const returnResult = getKeyUpEvent(name, sFieldName, tableConfigCopy, masterData, { ...tableDataRow, ...addState }, isWait, dataCollection, dataSelected, app); + addState = { ...addState, ...returnResult }; + }); + } + + console.log('=====KeyUpResult', addState); + return { ...tableDataRowNew, ...addState }; +} + +// 辅助函数:处理_all类型的表联动 +function handleAllTableLinkage(sAssignFieldItem, newCopyTo, masterData, dataCollection) { + const addState = {}; + const leftFiled = sAssignFieldItem; /* 每一个赋值字段 */ + if (commonUtils.isNotEmptyObject(leftFiled)) { + const tbName = leftFiled.substring(0, leftFiled.indexOf('_')); + const tableData = dataCollection[tbName]; + if (commonUtils.isNotEmptyArr(tableData)) { + const sOnChangeAssignFieldNew = leftFiled.replace(`${tbName}_all.`, '').trim(); + tableData.forEach((item, index) => { + newCopyTo[tbName] = item; + const tableRow = { ...item, ...commonFunc.getAssignFieldValue(sOnChangeAssignFieldNew, item, newCopyTo) }; // 取赋值字段 + tableRow.handleType = commonUtils.isEmpty(tableRow.handleType) ? 'update' : tableRow.handleType; + tableData[index] = tableRow; + }); + addState[tbName] = tableData; + masterData.handleType = commonUtils.isEmpty(masterData.handleType) ? 'update' : masterData.handleType; + addState.master = masterData; + addState.bMultiTable = true; + } + } + return addState; +} + +// 辅助函数:处理跨表联动 +function handleCrossTableLinkage(name, sAssignField, sButtonParam, tableDataRowNew, newCopyTo, masterData, tableDataRow, dataCollection, dataSelected, app) { + const addState = {}; + /* 主表联动其他表格 */ + if (name === 'master' && (!sAssignField.includes('filter') && !sAssignField.includes('sum') )) { + const sAssignFieldObj = sAssignField.split(','); + if (commonUtils.isNotEmptyArr(sAssignFieldObj)) { + sAssignFieldObj.forEach((eachFiled) => { + if (eachFiled.includes('_')) { + const tbName = eachFiled.substring(0, eachFiled.indexOf('_')); + const tableData = dataCollection[tbName]; + if (commonUtils.isNotEmptyArr(tableData)) { + const sOnChangeAssignFieldNew = eachFiled.replace(`${tbName}_all.`, '').trim(); + console.log('333', sOnChangeAssignFieldNew); + tableData.forEach((item, index) => { + newCopyTo[tbName] = item; + newCopyTo.master = masterData; + let tableRow = { ...item, ...commonFunc.getAssignFieldValue(sOnChangeAssignFieldNew, item, newCopyTo, true, true) }; + if (commonUtils.isNotEmptyObject(sButtonParam)) { + let sLinkFieldName = ''; + if (commonUtils.isJSON(sButtonParam)) { + const linkObj = JSON.parse(sButtonParam); + let models = 'Product'; + if (linkObj.linkMaterials) { + sLinkFieldName = linkObj.linkMaterials; + models = 'Materials'; + } else if (linkObj.linkProduct) { + sLinkFieldName = linkObj.linkProduct; + models = 'Product'; + } + console.log('sLinkFieldName', sLinkFieldName, models); + tableRow = this.getCalculateAllMoney(app, models, sLinkFieldName, masterData, tableRow); + } + } + tableRow.handleType = commonUtils.isEmpty(tableRow.handleType) ? 'update' : tableRow.handleType; + tableData[index] = tableRow; + }); + addState[tbName] = tableData; + masterData.handleType = commonUtils.isEmpty(masterData.handleType) ? 'update' : masterData.handleType; + addState.master = commonUtils.isNotEmptyObject(addState.master) ? { ...addState.master, ...masterData } : masterData; + addState.bMultiTable = true; + } + } else { + if (commonUtils.isNotEmptyArr(dataCollection)) { + if (eachFiled.includes('master.')) { + newCopyTo.master = dataCollection.master; + } else if (eachFiled.includes('control.')) { + // const tbName = 'control'; + } + } + tableDataRowNew = { ...tableDataRowNew, ...commonFunc.getAssignFieldValue(eachFiled, tableDataRowNew, newCopyTo) }; + let { handleType } = masterData; + if (name !== 'master') { + // eslint-disable-next-line prefer-destructuring + handleType = tableDataRow.handleType; + } + addState.bMultiTable = true; + tableDataRowNew.handleType = commonUtils.isEmpty(handleType) ? 'update' : handleType; + addState.master = tableDataRowNew; + } + }); + } + return addState; + } else { + const sAssignFieldObj = sAssignField.split(','); + if (commonUtils.isNotEmptyArr(sAssignFieldObj)) { + const leftFiled = sAssignFieldObj[0]; + if (commonUtils.isNotEmptyObject(leftFiled)) { + const tbName = leftFiled.substring(0, leftFiled.indexOf('_')); + const tableData = dataCollection[name]; + if (commonUtils.isNotEmptyArr(tableData)) { + if (sAssignField.indexOf('filter') > -1 && sAssignField.indexOf('sum') > -1) { + return handleFilterAndSum(sAssignField, tableDataRowNew, newCopyTo, masterData, tableDataRow, dataCollection, dataSelected, app); + } else if (sAssignField.indexOf('sum') > -1) { + return handleSumOnly(tbName, sAssignField, tableData, tableDataRowNew, newCopyTo, masterData, tableDataRow, app); + } else if (sAssignField.indexOf('filter') > -1) { + return handleFilterOnly(sAssignField, sButtonParam, tableDataRowNew, newCopyTo, masterData, tableDataRow, dataCollection, app); + } + } + } + } + return tableDataRowNew; + } +} + +// 辅助函数:处理过滤并汇总 +function handleFilterAndSum(sAssignField, tableDataRowNew, newCopyTo, masterData, tableDataRow, dataCollection, dataSelected, app) { + console.log('赋值字段', sAssignField); + let sOnChangeAssignFieldNew = sAssignField; + const indexOf = sAssignField.indexOf('_'); + const targetSumName = sAssignField.substring(0, indexOf); + let targetTbName = ''; + + const fStartIndexOf = sAssignField.indexOf(':'); + const fEndIndexOf = sAssignField.lastIndexOf('_filter'); + console.log('拿目标要过滤的表名', targetSumName, fStartIndexOf, fEndIndexOf); + if (fStartIndexOf > -1 && fEndIndexOf > -1) { + targetTbName = sAssignField.substring(fStartIndexOf + 1, fEndIndexOf); + } + const targetTableData = dataCollection[targetTbName]; + const targetData = dataCollection[targetSumName]; + const targetRow = dataSelected[`${targetSumName}Row`]; + const targetFieldName = sAssignField.substring(sAssignField.indexOf('.') + 1, sAssignField.indexOf(':')); + const baseFieldName = sAssignField.substring(sAssignField.lastIndexOf('.') + 1, sAssignField.length); + let filterTableData = []; + const leftIndexOf = sAssignField.indexOf('{'); + const rightIndexOf = sAssignField.lastIndexOf('}'); + if (leftIndexOf > -1 && rightIndexOf > -1) { + const condition = sAssignField.substring(leftIndexOf, rightIndexOf + 1); + const conditionStr = condition.toString(); + sOnChangeAssignFieldNew = sAssignField.replace(`${targetTbName}_filter_${condition}.`, '').replace('_sum', '').trim(); + console.log('sOnChangeAssignFieldNew', sOnChangeAssignFieldNew); + let jsonObj = {}; + if (commonUtils.isNotEmptyObject(conditionStr) && commonUtils.isJSON(conditionStr)) { + jsonObj = JSON.parse(conditionStr); + const { ifdo: ifdoStr, condition, decimal = 0 } = jsonObj; + let ifdoResult = true; + if (ifdoStr) { + try { + let ifdoStrNew = ""; + const reg = new RegExp(`master\.`, "g"); + ifdoStrNew = ifdoStr.replace(reg, `masterData.`); + const reg1 = new RegExp(`slave\.`, "g"); + ifdoStrNew = ifdoStrNew.replace(reg1, `tableDataRow.`); + const evalStr = eval("`" + ifdoStrNew + "`"); + ifdoResult = eval(evalStr); + } catch (error) { + console.log('=====keyup ifdo 报错:', { + ifdoStr, error + }) + } + } + if (!ifdoResult) { + return {}; + } + if (commonUtils.isNotEmptyArr(condition)) { + filterTableData = applyFilterConditions(condition, targetTableData, masterData, tableDataRow, baseFieldName, app); + } + let sumData = 0; + if (commonUtils.isNotEmptyArr(filterTableData)) { + sumData = calculateSum(sFieldName, filterTableData, tableDataRow, targetTableData, decimal, newCopyTo, masterData, name, targetTbName, app); + if (commonUtils.isNotEmptyObject(targetRow)) { + targetRow[sFieldName] = sumData; + } + if (targetSumName === 'master') { + const targetDataNew = name === 'master' ? masterData : targetData; + targetDataNew[targetFieldName] = sumData; + targetDataNew.handleType = commonUtils.isEmpty(targetDataNew.handleType) ? 'update' : targetDataNew.handleType; + addState[targetSumName] = targetDataNew; + if(name === 'master') { + addState[targetTbName] = targetTableData; + return addState; + } + } else if (commonUtils.isNotEmptyArr(targetData)) { + targetRow[`${sFieldName}Sum`] = sumData; + const iSlaveIndex = targetData.findIndex(item => item.sId === targetRow.sId); + if (iSlaveIndex > -1) { + targetData[iSlaveIndex][`${sFieldName}Sum`] = sumData; + newCopyTo[targetSumName] = targetData[iSlaveIndex]; + targetData[iSlaveIndex].dTotal_waste_qty = sumData; + targetData[iSlaveIndex].handleType = commonUtils.isEmpty(targetData[iSlaveIndex].handleType) ? 'update' : targetData[iSlaveIndex].handleType; + addState[targetData] = targetData; + } + } + addState[targetTbName] = targetTableData; + } + } + } + return addState; +} + +// 辅助函数:应用过滤条件 +function applyFilterConditions(conditions, targetTableData, masterData, tableDataRow, baseFieldName, app) { + let filterTableData = []; + for (const item of conditions) { + const { bFilterName, bFilterCondition, bFilterValue } = item; + if (bFilterCondition === '>') { + if (bFilterValue.includes('.')) { + const indexs = bFilterValue.indexOf('.'); + const sConditionTableName = bFilterValue.substring(0, indexs); + const sConditionFieldName = bFilterValue.substring(indexs + 1, bFilterValue.length); + if (sConditionFieldName === 'slave') { + if (commonUtils.isNotEmptyArr(targetTableData)) { + filterTableData = targetTableData.filter(item => item[bFilterName] > tableDataRow[sConditionTableName]); + } + } + } else { + filterTableData = targetTableData.filter(item => item[bFilterName] > bFilterValue); + } + } else if (bFilterCondition === '=') { + if (bFilterValue.includes('.')) { + const indexs = bFilterValue.indexOf('.'); + const sConditionTableName = bFilterValue.substring(0, indexs); + const sConditionFieldName = bFilterValue.substring(indexs + 1, bFilterValue.length); + if (sConditionTableName === 'slave') { + if (commonUtils.isNotEmptyArr(targetTableData)) { + filterTableData = targetTableData.filter(item => item[bFilterName] === tableDataRow[sConditionFieldName]); + } + } else if (sConditionTableName === 'master') { + if (commonUtils.isNotEmptyArr(targetTableData)) { + filterTableData = targetTableData.filter(item => item[bFilterName] === masterData[sConditionFieldName]); + } + } + } else { + filterTableData = targetTableData.filter(item => item[bFilterName] === bFilterValue); + } + if(baseFieldName !== sFieldName) { + sFieldName = baseFieldName; + } + } else if (bFilterCondition === '<') { + if (bFilterValue.includes('.')) { + const indexs = bFilterValue.indexOf('.'); + const sConditionTableName = bFilterValue.substring(0, indexs); + const sConditionFieldName = bFilterValue.substring(indexs + 1, bFilterValue.length); + if (sConditionTableName === 'slave') { + if (commonUtils.isNotEmptyArr(targetTableData)) { + filterTableData = targetTableData.filter(item => item[bFilterName] < tableDataRow[sConditionFieldName]); + } + } + } else { + filterTableData = targetTableData.filter(item => item[bFilterName] < bFilterValue); + } + } + } + return filterTableData; +} + +// 辅助函数:计算汇总值 +function calculateSum(sFieldName, filterTableData, tableDataRow, targetTableData, decimal, newCopyTo, masterData, name, targetTbName, app) { + let sumData = 0; + filterTableData.forEach((item) => { + const iIndex = targetTableData.findIndex(itemNew => itemNew.sId === item.sId); + if (iIndex > -1) { + newCopyTo.master = masterData; + newCopyTo[targetTbName] = item; + newCopyTo[name] = tableDataRow; + newCopyTo.slaveInfo = item; + newCopyTo.slaveChild = item; + if (item.sId !== tableDataRow.sId) { + sumData += commonUtils.isNull(item[sFieldName], 0); + } else { + sumData += commonUtils.isNull(tableDataRow[sFieldName], 0); + } + } + }); + if (decimal) { + sumData = Number(sumData.toFixed(decimal)); + } + console.log('sumData', sumData); + return sumData; +} + +// 辅助函数:仅处理汇总 +function handleSumOnly(tbName, sAssignField, tableData, tableDataRowNew, newCopyTo, masterData, tableDataRow, app) { + const addState = {}; + const sOnChangeAssignFieldNew = sAssignField.replace(`${tbName}_sum.`, '').trim(); + newCopyTo.master = masterData; + let sumData = 0; + tableData.forEach((item, index) => { + if (item.sId === tableDataRowNew.sId) { + item = tableDataRowNew; + tableData[index] = tableDataRowNew; + } + newCopyTo[name] = item; + const tableRow = { ...item, ...commonFunc.getAssignFieldValue(sOnChangeAssignFieldNew, item, newCopyTo) }; + tableRow.handleType = commonUtils.isEmpty(tableRow.handleType) ? 'update' : tableRow.handleType; + const tempName = `${sFieldName}temp_sum`; + const tempData = tableRow[tempName]; + if (!commonUtils.isEmpty(tempData)) { + sumData += tableRow[tempName]; + sumData += tableRow[sFieldName]; + } + tableData[index] = tableRow; + }); + addState[name] = tableData; + masterData.handleType = commonUtils.isEmpty(masterData.handleType) ? 'update' : masterData.handleType; + masterData[sumData] = sumData; + addState.masterData = masterData; + return addState; +} + +// 辅助函数:仅处理过滤 +function handleFilterOnly(sAssignField, sButtonParam, tableDataRowNew, newCopyTo, masterData, tableDataRow, dataCollection, app) { + const addState = {}; + let sOnChangeAssignFieldNew = sAssignField; + const indexOf = sAssignField.indexOf('_'); + const targetTbName = sAssignField.substring(0, indexOf); + const targetTableData = dataCollection[targetTbName]; + let filterTableData = []; + const leftIndexOf = sAssignField.indexOf('{'); + const rightIndexOf = sAssignField.lastIndexOf('}'); + if (leftIndexOf > -1 && rightIndexOf > -1) { + const condition = sAssignField.substring(leftIndexOf, rightIndexOf + 1); + const conditionStr = condition.toString(); + sOnChangeAssignFieldNew = sAssignField.replace(`${targetTbName}_filter_${condition}.`, '').trim(); + let jsonObj = {}; + if (commonUtils.isNotEmptyObject(conditionStr)) { + jsonObj = JSON.parse(conditionStr); + const { condition } = jsonObj; + if (commonUtils.isNotEmptyArr(condition)) { + filterTableData = applyFilterConditions(condition, targetTableData, masterData, tableDataRow, sFieldName, app); + } + if (commonUtils.isNotEmptyArr(filterTableData)) { + filterTableData.forEach((item) => { + const iIndex = targetTableData.findIndex(itemNew => itemNew.sId === item.sId); + if (iIndex > -1) { + newCopyTo.master = masterData; + newCopyTo[targetTbName] = item; + newCopyTo[name] = tableDataRow; + newCopyTo.slaveInfo = item; + const tableRowAfter = { ...item, ...commonFunc.getAssignFieldValue(sOnChangeAssignFieldNew, tableDataRow, newCopyTo) }; + let tableNewRow = {}; + if (commonUtils.isNotEmptyObject(sButtonParam)) { + newCopyTo[name] = tableRowAfter; + tableNewRow = { ...tableRowAfter, ...commonFunc.getAssignFieldValue(sButtonParam, tableRowAfter, newCopyTo) }; + } + tableRowAfter.handleType = commonUtils.isEmpty(tableRowAfter.handleType) ? 'update' : tableRowAfter.handleType; + if (commonUtils.isNotEmptyObject(tableNewRow)) { + targetTableData[iIndex] = { ...tableRowAfter, ...tableNewRow }; + } else { + targetTableData[iIndex] = { ...item, ...tableRowAfter }; + } + } + }); + addState[targetTbName] = targetTableData; + } + } + } + return addState; +} + +// 辅助函数:处理单表事件 +function handleSingleTableEvent(name, sAssignField, tableDataRowNew, newCopyTo, masterData, tableDataRow, dataSelected, isWait) { + const bCrossTable = isCrossTableAssignment(sAssignField); + const tableNames = extractTableNames(sAssignField); + + const newTableSelectedMap = formatTableData(dataSelected); + const datasetMap = bCrossTable ? newTableSelectedMap : newCopyTo; + + // 使用新的变量名来接收处理后的数据 + const processedData = { + ...tableDataRowNew, + ...commonFunc.getAssignFieldValue(sAssignField, tableDataRowNew, datasetMap, false, bCrossTable, tableNames) + }; + + let { handleType } = masterData ? masterData : { handleType: '' }; + if (name !== 'master') { + handleType = processedData.handleType; + } + processedData.handleType = commonUtils.isEmpty(handleType) ? 'update' : handleType; + + if (isWait) { + return processedData; + } + + return processedData; +} + +function extractTableNames(sAssignField) { + const tableNames = []; + const regex = /(\w+)\./g; + let match; + while ((match = regex.exec(sAssignField)) !== null) { + if (!tableNames.includes(match[1])) { + tableNames.push(match[1]); + } + } + return tableNames; +} + +// 辅助函数:格式化表格数据 +function formatTableData(originObj) { + // 添加空值检查,防止undefined或null导致Object.entries报错 + if (originObj == null || typeof originObj !== 'object') { + return {}; + } + + const newObj = {}; + // 遍历原始对象的键值对 + Object.entries(originObj).forEach(([key, value]) => { + // 去掉末尾的Row后缀 + const newKey = key.replace(/Row$/, ''); + // 赋值到新对象(键名更新,数据不变) + newObj[newKey] = value; + }); + return newObj; +} + +// 辅助函数:获取子级数据(递归) +function getChildData(parentId, tableData, childData = []) { + if (!commonUtils.isNotEmptyArr(tableData)) return childData; + + const children = tableData.filter(item => item.sParentId === parentId); + if (commonUtils.isNotEmptyArr(children)) { + childData.push(...children); + children.forEach(child => { + getChildData(child.sId, tableData, childData); + }); + } + return childData; +} + + + +// 辅助函数:判断是否为跨表赋值 +function isCrossTableAssignment(sAssignField) { + const crossTableKeywords = ['slave.', 'control.', 'materials.', 'process.', 'master.']; + return crossTableKeywords.some(keyword => sAssignField.includes(keyword)); +} diff --git a/src/components/Common/CommonHooks/useCommonBase.js b/src/components/Common/CommonHooks/useCommonBase.js index 4ad68cd..38c11c4 100644 --- a/src/components/Common/CommonHooks/useCommonBase.js +++ b/src/components/Common/CommonHooks/useCommonBase.js @@ -8,6 +8,7 @@ import * as commonConfig from "@/utils/config"; import * as commonServices from "@/services/services"; import * as commonBusiness from "@/components/Common/commonBusiness"; import * as commonFunc from "@/components/Common/commonFunc"; +import * as commonKeyUp from './commonKeyUp'; import instructSet from "@/components/Common/CommonInstructSet"; import costomPageFun from "@/mes/costomPageFun"; const { reducer } = commonUtils; @@ -39,7 +40,7 @@ const getInitialState = props => { const useCommonBase = props => { const [state, dispatch] = useReducer(reducer, getInitialState(props)); const tempRef = useRef({}); - + let mounted = true const setTempRef = (params, bRewrite) => { if (bRewrite) { tempRef.current = params; @@ -466,7 +467,7 @@ const useCommonBase = props => { addState = { ...addState }; if (isWait) { return addState; - } else if (this.mounted) { + } else if (mounted) { handleSaveState(addState); } } else { diff --git a/src/components/Common/CommonTable/index.js b/src/components/Common/CommonTable/index.js index 4473992..08e24b7 100644 --- a/src/components/Common/CommonTable/index.js +++ b/src/components/Common/CommonTable/index.js @@ -213,11 +213,7 @@ class CommonTableRc extends React.Component { pdfFileUrl: "", currentHoverSid: "" }; - this.rowKey = - commonUtils.isNotEmptyObject(props.tableProps) && - !commonUtils.isEmpty(props.tableProps.rowKey) - ? props.tableProps.rowKey - : "sSlaveId"; /* 表格主键 */ + this.rowKey = commonUtils.isNotEmptyObject(props.tableProps) && !commonUtils.isEmpty(props.tableProps.rowKey) ? props.tableProps.rowKey : 'sId'; /* 表格主键 */ this.config = {}; /* 配置信息(基础)(数据格式:对象) */ this.tableColumn = []; /* table的表头信息(数据类型:数组对象) */ this.tableInfoColumn = []; @@ -3561,10 +3557,11 @@ class CommonTableRc extends React.Component { rowSelection = null; } const { expKeys } = this.state; + const {sModelType} = this.props?.parentProps || {} /* 返回值 */ return { components, - rowKey: this.rowKey, + rowKey: sModelType?.includes('/indexPage/commonList') ? 'sSlaveId' : this.rowKey, // size: 'middle', bordered: true /* 显示边框 */, className: !this.props.enabled diff --git a/src/components/Common/commonBusiness.js b/src/components/Common/commonBusiness.js index b791239..760e6c2 100644 --- a/src/components/Common/commonBusiness.js +++ b/src/components/Common/commonBusiness.js @@ -415,6 +415,7 @@ export function getCalculateByPrice(app, type, masterData, tableDataRow, sFieldN /* 待用数据赋值 */ const { dNetPrice, dNetMoney } = app.decimals; const { sModelsType } = app.currentPane; + if (!tableDataRow) return const dProductQty = commonUtils.convertToNum(tableDataRow[`d${type}Qty`]); /* 数量 */ const dProductPrice = commonUtils.convertToNum(tableDataRow[`d${type}Price`]); /* 价格 */ const dProductForeignPrice = commonUtils.convertToNum(tableDataRow[`d${type}ForeignPrice`]); /* 外币单价 */ @@ -424,7 +425,7 @@ export function getCalculateByPrice(app, type, masterData, tableDataRow, sFieldN const dLossMoney = commonUtils.convertToNum(tableDataRow.dLossMoney); /* 报损金额 */ const dTaxRate = commonUtils.convertToNum(tableDataRow.dTaxRate); /* 税率 */ - let dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData.dCurrencyRate); /* 汇率 */ + let dCurrencyRate = masterData?.dCurrencyRate ? commonUtils.convertIsNotNumToNumber1(masterData?.dCurrencyRate) : 1; /* 汇率 */ /* 报价单模块,工单模块、产品工艺卡 汇率取从表 */ if (commonUtils.isNotEmptyObject(sModelsType) && (sModelsType.includes('manufacture/') || sModelsType.includes('quotation/') || sModelsType.includes('processCard'))) { dCurrencyRate = commonUtils.convertIsNotNumToNumber1(tableDataRow.dCurrencyRate); /* 汇率 */ @@ -490,6 +491,7 @@ export function getCalculateByPriceNew(app, type, masterData, tableDataRow, sFil /* 待用数据赋值 */ const { dNetPrice, dNetMoney } = app.decimals; const { sModelsType } = app.currentPane; + if (!tableDataRow) return const dProductQty = commonUtils.convertToNum(tableDataRow[`d${type}Qty`]); /* 数量 */ const dProofingMoney = commonUtils.convertToNum(tableDataRow.dProofingMoney); /* 打样金额 */ const dPlateMoney = commonUtils.convertToNum(tableDataRow.dPlateMoney); /* 制版金额 */ @@ -500,7 +502,7 @@ export function getCalculateByPriceNew(app, type, masterData, tableDataRow, sFil let dProductForeignMoney = commonUtils.convertToNum(tableDataRow[`d${type}ForeignMoney`]); let dProductMoney = commonUtils.convertToNum(tableDataRow[`d${type}Money`]); /* 本币金额 */ const dTaxRate = commonUtils.convertToNum(tableDataRow.dTaxRate); /* 税率 */ - let dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData.dCurrencyRate); /* 汇率 */ + let dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData?.dCurrencyRate); /* 汇率 */ const dLossMoney = commonUtils.convertToNum(tableDataRow.dLossMoney); /* 报损金额 */ /* 报价单模块,工单模块、产品工艺卡 汇率取从表 */ if (commonUtils.isNotEmptyObject(sModelsType) && (sModelsType.includes('manufacture/') || sModelsType.includes('quotation/') || sModelsType.includes('processCard'))) { @@ -604,7 +606,7 @@ export function getCalculatedLossMoney(app, masterData, tableDataRow, type) { const dTaxRate = commonUtils.convertToNum(tableDataRow.dTaxRate); /* 税率 */ /* 数据赋值 */ tableDataRow.dLossMoney = commonUtils.convertFixNum(dLossMoney, dNetMoney); - const dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData.dCurrencyRate); /* 汇率 */ + const dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData?.dCurrencyRate); /* 汇率 */ const dSrcNoCheckMoney = commonUtils.isNull(tableDataRow.dSrcNoCheckMoney, 0); if (commonUtils.isNotEmptyNumber(dSrcNoCheckMoney) && commonUtils.isNotEmptyNumber(dLossMoney)) { const dMoney = commonUtils.convertFixNum(dSrcNoCheckMoney - dLossMoney, dNetMoney); @@ -719,9 +721,10 @@ export function getCalculateMoney(app, masterData, tableDataRow, type, sFieldNam /* 待用数据赋值 */ const { dNetPrice, dNetMoney } = app.decimals; const { sModelsType } = app.currentPane; + if (!tableDataRow) return const dProductQty = commonUtils.convertToNum(tableDataRow[`d${type}Qty`]); /* 数量 */ const dTaxRate = commonUtils.convertToNum(tableDataRow.dTaxRate); /* 税率 */ - let dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData.dCurrencyRate); /* 汇率 */ + let dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData?.dCurrencyRate); /* 汇率 */ /* 报价单模块,工单模块、产品工艺卡 汇率取从表 */ if (commonUtils.isNotEmptyObject(sModelsType) && (sModelsType.includes('manufacture/') || sModelsType.includes('quotation/') || sModelsType.includes('processCard'))) { dCurrencyRate = commonUtils.convertIsNotNumToNumber1(tableDataRow.dCurrencyRate); /* 汇率 */ @@ -769,9 +772,10 @@ export function getCalculateMoneyNew(app, masterData, tableDataRow, type, sField /* 待用数据赋值 */ const { dNetPrice, dNetMoney } = app.decimals; const { sModelsType } = app.currentPane; + if (!tableDataRow) return const dProductQty = commonUtils.convertToNum(tableDataRow[`d${type}Qty`]); /* 数量 */ const dTaxRate = commonUtils.convertToNum(tableDataRow.dTaxRate); /* 税率 */ - let dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData.dCurrencyRate); /* 汇率 */ + let dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData?.dCurrencyRate); /* 汇率 */ /* 报价单模块,工单模块、产品工艺卡 汇率取从表 */ if (commonUtils.isNotEmptyObject(sModelsType) && (sModelsType.includes('manufacture/') || sModelsType.includes('quotation/') || sModelsType.includes('processCard'))) { dCurrencyRate = commonUtils.convertIsNotNumToNumber1(tableDataRow.dCurrencyRate); /* 汇率 */ @@ -850,10 +854,11 @@ export function getCalculateNoTaxPrice(app, masterData, tableDataRow, type) { /* 待用数据赋值 */ const { dNetPrice, dNetMoney } = app.decimals; const { sModelsType } = app.currentPane; + if (!tableDataRow) return const dProductQty = commonUtils.convertToNum(tableDataRow[`d${type}Qty`]); /* 数量 */ const dProductNoTaxPrice = commonUtils.convertToNum(tableDataRow[`d${type}NoTaxPrice`]); /* 不含税价 */ const dTaxRate = commonUtils.convertToNum(tableDataRow.dTaxRate); /* 税率 */ - let dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData.dCurrencyRate); /* 汇率 */ + let dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData?.dCurrencyRate); /* 汇率 */ /* 报价单模块,工单模块、产品工艺卡 汇率取从表 */ if (commonUtils.isNotEmptyObject(sModelsType) && (sModelsType.includes('manufacture/') || sModelsType.includes('quotation/') || sModelsType.includes('processCard'))) { dCurrencyRate = commonUtils.convertIsNotNumToNumber1(tableDataRow.dCurrencyRate); /* 汇率 */ @@ -881,10 +886,11 @@ export function getCalculateNoTaxMoney(app, masterData, tableDataRow, type) { /* 待用数据赋值 */ const { dNetPrice, dNetMoney } = app.decimals; const { sModelsType } = app.currentPane; + if (!tableDataRow) return const dProductQty = commonUtils.convertToNum(tableDataRow[`d${type}Qty`]); const dProductNoTaxMoney = commonUtils.convertToNum(tableDataRow[`d${type}NoTaxMoney`]); const dTaxRate = commonUtils.convertToNum(tableDataRow.dTaxRate); - let dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData.dCurrencyRate); + let dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData?.dCurrencyRate); /* 报价单模块,工单模块、产品工艺卡 汇率取从表 */ if (commonUtils.isNotEmptyObject(sModelsType) && (sModelsType.includes('manufacture/') || sModelsType.includes('quotation/') || sModelsType.includes('processCard'))) { dCurrencyRate = commonUtils.convertIsNotNumToNumber1(tableDataRow.dCurrencyRate); /* 汇率 */ @@ -926,7 +932,7 @@ export function getCalculateMoneyByLossMoney(app, type, masterData, tableDataRow /* 待用数据赋值 */ const { dNetMoney } = app.decimals; const dProductForeignMoney = commonUtils.convertFixNum(dSrcNoCheckMoney - dLossMoney, dNetMoney); - const dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData.dCurrencyRate); /* 汇率 */ + const dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData?.dCurrencyRate); /* 汇率 */ const dProductMoney = commonUtils.convertFixNum(dCurrencyRate !== 0 ? dProductForeignMoney * dCurrencyRate : 0, dNetMoney); /* 本位币金额 */ /* 数据赋值 */ tableDataRow[`d${type}ForeignMoney`] = dProductForeignMoney; -- libgit2 0.22.2