Commit 8a6c3d1a74bb352faad2504aaca533e8a6c6b09e

Authored by chenxt
1 parent 08dfb0ba

价格计算

src/components/Common/CommonHooks/commonKeyUp.js 0 → 100644
  1 +/* eslint-disable */
  2 +import * as commonUtils from '@/utils/utils';
  3 +import * as commonFunc from '@/components/Common/commonFunc';
  4 +
  5 +/**
  6 + * 自定义onChange事件处理函数 - 处理表格字段变更时的联动逻辑
  7 + *
  8 + * @param {string} name - 表名('master'表示主表,其他表示从表如slave,control,materials,process)
  9 + * @param {string} sFieldName - 触发变更的字段名称
  10 + * @param {Object} tableConfig - 表格配置对象,包含gdsconfigformslave配置数组
  11 + * @param {Object} masterData - 主表数据对象
  12 + * @param {Object} tableDataRow - 当前行数据对象(从表时使用)
  13 + * @param {boolean} isWait - 是否等待处理完成
  14 + * @param {Object} dataCollection - 所有表格数据集合
  15 + * @param {Object} dataSelected - 选中的数据对象
  16 + * @param {Object} app - 应用实例对象
  17 + * @returns {Object} 处理后的数据对象
  18 + */
  19 +export function getKeyUpEvent(name, sFieldName, tableConfig, masterData, tableDataRow, isWait, dataCollection, dataSelected, app) {
  20 + // 初始化数据对象和拷贝容器
  21 + let tableDataRowNew = {};
  22 + const newCopyTo = {};
  23 +
  24 + // 根据表名类型初始化数据
  25 + if (name === 'master') {
  26 + tableDataRowNew = masterData; // 主表使用masterData
  27 + } else {
  28 + tableDataRowNew = tableDataRow; // 从表使用当前行数据
  29 + newCopyTo.slave = tableDataRow; // 设置从表数据到拷贝容器
  30 + }
  31 +
  32 + // 检查表格配置是否存在且有效
  33 + if (commonUtils.isNotEmptyObject(tableConfig) && commonUtils.isNotEmptyArr(tableConfig.gdsconfigformslave)) {
  34 + // 查找对应字段的配置项
  35 + const iConfigIndex = tableConfig.gdsconfigformslave.findIndex(item => item.sName === sFieldName);
  36 + if (iConfigIndex > -1) {
  37 + // 设置主表数据到拷贝容器
  38 + newCopyTo.master = masterData;
  39 +
  40 + // 获取赋值字段配置和按钮参数
  41 + const sAssignField = tableConfig.gdsconfigformslave[iConfigIndex].sOnChangeAssignField;
  42 + const sButtonParam = tableConfig.gdsconfigformslave[iConfigIndex].sButtonParam; /* 设置多级联动 */
  43 +
  44 + console.log('sAssignField:', sAssignField);
  45 +
  46 + // 根据赋值字段类型分发处理逻辑
  47 + /* keyUp联动其他表 */
  48 + if (commonUtils.isNotEmptyObject(sAssignField) && (sAssignField.includes('@@@:') || sAssignField.includes(';,'))) {
  49 + // 多表联动处理(包含@@@:或;,分隔符)
  50 + return handleMultiTableLinkage(name, sAssignField, sButtonParam, tableDataRowNew, newCopyTo, masterData, tableDataRow, dataCollection, dataSelected, app);
  51 + } else if (commonUtils.isNotEmptyObject(sAssignField) && sAssignField.includes('_')) {
  52 + // 跨表联动处理(包含下划线_all汇总, _filter过滤)
  53 + return handleCrossTableLinkage(name, sAssignField, sButtonParam, tableDataRowNew, newCopyTo, masterData, tableDataRow, dataCollection, dataSelected, app);
  54 + } else if (commonUtils.isNotEmptyObject(sAssignField)) {
  55 + // 单表keyUp事件处理
  56 + return handleSingleTableEvent(name, sAssignField, tableDataRowNew, newCopyTo, masterData, tableDataRow, dataSelected, isWait);
  57 + } else {
  58 + // 无有效赋值字段,返回空对象
  59 + return {};
  60 + }
  61 + }
  62 + }
  63 +
  64 + // 未找到对应配置或配置无效,返回原始数据
  65 + return tableDataRowNew;
  66 +}
  67 +
  68 +// 辅助函数:处理多表联动
  69 +function handleMultiTableLinkage(name, sAssignField, sButtonParam, tableDataRowNew, newCopyTo, masterData, tableDataRow, dataCollection, dataSelected, app) {
  70 + const sAssignFieldObj = sAssignField.split(';,');
  71 + console.log('=====sAssignFieldObj', sAssignFieldObj);
  72 + let addState = {};
  73 +
  74 + if (name === 'master') {
  75 + sAssignFieldObj.forEach((sAssignFieldItem) => {
  76 + if (sAssignFieldItem?.indexOf('@@@:') !== -1) {
  77 + const sFormula = sAssignFieldItem.split('@@@:')[1];
  78 + const sAssignFieldV2 = commonFunc.getAssignFieldV2(sFormula, tableDataRowNew);
  79 + const result = commonFunc.getAssignFieldValue(sAssignFieldV2, tableDataRowNew, newCopyTo);
  80 + addState = { ...addState, ...result };
  81 + } else if (sAssignFieldItem?.includes('_all')) {
  82 + addState = { ...addState, ...handleAllTableLinkage(sAssignFieldItem, newCopyTo, masterData, dataCollection) };
  83 + } else {
  84 + addState = {
  85 + ...addState,
  86 + ...commonFunc.getAssignFieldValue(sAssignFieldItem, tableDataRowNew, newCopyTo),
  87 + };
  88 + }
  89 + });
  90 + } else {
  91 + sAssignFieldObj.forEach((sAssignFieldItem) => {
  92 + const tableConfigCopy = cloneDeep(tableConfig);
  93 + tableConfigCopy.gdsconfigformslave[iConfigIndex].sOnChangeAssignField = sAssignFieldItem;
  94 + const returnResult = getKeyUpEvent(name, sFieldName, tableConfigCopy, masterData, { ...tableDataRow, ...addState }, isWait, dataCollection, dataSelected, app);
  95 + addState = { ...addState, ...returnResult };
  96 + });
  97 + }
  98 +
  99 + console.log('=====KeyUpResult', addState);
  100 + return { ...tableDataRowNew, ...addState };
  101 +}
  102 +
  103 +// 辅助函数:处理_all类型的表联动
  104 +function handleAllTableLinkage(sAssignFieldItem, newCopyTo, masterData, dataCollection) {
  105 + const addState = {};
  106 + const leftFiled = sAssignFieldItem; /* 每一个赋值字段 */
  107 + if (commonUtils.isNotEmptyObject(leftFiled)) {
  108 + const tbName = leftFiled.substring(0, leftFiled.indexOf('_'));
  109 + const tableData = dataCollection[tbName];
  110 + if (commonUtils.isNotEmptyArr(tableData)) {
  111 + const sOnChangeAssignFieldNew = leftFiled.replace(`${tbName}_all.`, '').trim();
  112 + tableData.forEach((item, index) => {
  113 + newCopyTo[tbName] = item;
  114 + const tableRow = { ...item, ...commonFunc.getAssignFieldValue(sOnChangeAssignFieldNew, item, newCopyTo) }; // 取赋值字段
  115 + tableRow.handleType = commonUtils.isEmpty(tableRow.handleType) ? 'update' : tableRow.handleType;
  116 + tableData[index] = tableRow;
  117 + });
  118 + addState[tbName] = tableData;
  119 + masterData.handleType = commonUtils.isEmpty(masterData.handleType) ? 'update' : masterData.handleType;
  120 + addState.master = masterData;
  121 + addState.bMultiTable = true;
  122 + }
  123 + }
  124 + return addState;
  125 +}
  126 +
  127 +// 辅助函数:处理跨表联动
  128 +function handleCrossTableLinkage(name, sAssignField, sButtonParam, tableDataRowNew, newCopyTo, masterData, tableDataRow, dataCollection, dataSelected, app) {
  129 + const addState = {};
  130 + /* 主表联动其他表格 */
  131 + if (name === 'master' && (!sAssignField.includes('filter') && !sAssignField.includes('sum') )) {
  132 + const sAssignFieldObj = sAssignField.split(',');
  133 + if (commonUtils.isNotEmptyArr(sAssignFieldObj)) {
  134 + sAssignFieldObj.forEach((eachFiled) => {
  135 + if (eachFiled.includes('_')) {
  136 + const tbName = eachFiled.substring(0, eachFiled.indexOf('_'));
  137 + const tableData = dataCollection[tbName];
  138 + if (commonUtils.isNotEmptyArr(tableData)) {
  139 + const sOnChangeAssignFieldNew = eachFiled.replace(`${tbName}_all.`, '').trim();
  140 + console.log('333', sOnChangeAssignFieldNew);
  141 + tableData.forEach((item, index) => {
  142 + newCopyTo[tbName] = item;
  143 + newCopyTo.master = masterData;
  144 + let tableRow = { ...item, ...commonFunc.getAssignFieldValue(sOnChangeAssignFieldNew, item, newCopyTo, true, true) };
  145 + if (commonUtils.isNotEmptyObject(sButtonParam)) {
  146 + let sLinkFieldName = '';
  147 + if (commonUtils.isJSON(sButtonParam)) {
  148 + const linkObj = JSON.parse(sButtonParam);
  149 + let models = 'Product';
  150 + if (linkObj.linkMaterials) {
  151 + sLinkFieldName = linkObj.linkMaterials;
  152 + models = 'Materials';
  153 + } else if (linkObj.linkProduct) {
  154 + sLinkFieldName = linkObj.linkProduct;
  155 + models = 'Product';
  156 + }
  157 + console.log('sLinkFieldName', sLinkFieldName, models);
  158 + tableRow = this.getCalculateAllMoney(app, models, sLinkFieldName, masterData, tableRow);
  159 + }
  160 + }
  161 + tableRow.handleType = commonUtils.isEmpty(tableRow.handleType) ? 'update' : tableRow.handleType;
  162 + tableData[index] = tableRow;
  163 + });
  164 + addState[tbName] = tableData;
  165 + masterData.handleType = commonUtils.isEmpty(masterData.handleType) ? 'update' : masterData.handleType;
  166 + addState.master = commonUtils.isNotEmptyObject(addState.master) ? { ...addState.master, ...masterData } : masterData;
  167 + addState.bMultiTable = true;
  168 + }
  169 + } else {
  170 + if (commonUtils.isNotEmptyArr(dataCollection)) {
  171 + if (eachFiled.includes('master.')) {
  172 + newCopyTo.master = dataCollection.master;
  173 + } else if (eachFiled.includes('control.')) {
  174 + // const tbName = 'control';
  175 + }
  176 + }
  177 + tableDataRowNew = { ...tableDataRowNew, ...commonFunc.getAssignFieldValue(eachFiled, tableDataRowNew, newCopyTo) };
  178 + let { handleType } = masterData;
  179 + if (name !== 'master') {
  180 + // eslint-disable-next-line prefer-destructuring
  181 + handleType = tableDataRow.handleType;
  182 + }
  183 + addState.bMultiTable = true;
  184 + tableDataRowNew.handleType = commonUtils.isEmpty(handleType) ? 'update' : handleType;
  185 + addState.master = tableDataRowNew;
  186 + }
  187 + });
  188 + }
  189 + return addState;
  190 + } else {
  191 + const sAssignFieldObj = sAssignField.split(',');
  192 + if (commonUtils.isNotEmptyArr(sAssignFieldObj)) {
  193 + const leftFiled = sAssignFieldObj[0];
  194 + if (commonUtils.isNotEmptyObject(leftFiled)) {
  195 + const tbName = leftFiled.substring(0, leftFiled.indexOf('_'));
  196 + const tableData = dataCollection[name];
  197 + if (commonUtils.isNotEmptyArr(tableData)) {
  198 + if (sAssignField.indexOf('filter') > -1 && sAssignField.indexOf('sum') > -1) {
  199 + return handleFilterAndSum(sAssignField, tableDataRowNew, newCopyTo, masterData, tableDataRow, dataCollection, dataSelected, app);
  200 + } else if (sAssignField.indexOf('sum') > -1) {
  201 + return handleSumOnly(tbName, sAssignField, tableData, tableDataRowNew, newCopyTo, masterData, tableDataRow, app);
  202 + } else if (sAssignField.indexOf('filter') > -1) {
  203 + return handleFilterOnly(sAssignField, sButtonParam, tableDataRowNew, newCopyTo, masterData, tableDataRow, dataCollection, app);
  204 + }
  205 + }
  206 + }
  207 + }
  208 + return tableDataRowNew;
  209 + }
  210 +}
  211 +
  212 +// 辅助函数:处理过滤并汇总
  213 +function handleFilterAndSum(sAssignField, tableDataRowNew, newCopyTo, masterData, tableDataRow, dataCollection, dataSelected, app) {
  214 + console.log('赋值字段', sAssignField);
  215 + let sOnChangeAssignFieldNew = sAssignField;
  216 + const indexOf = sAssignField.indexOf('_');
  217 + const targetSumName = sAssignField.substring(0, indexOf);
  218 + let targetTbName = '';
  219 +
  220 + const fStartIndexOf = sAssignField.indexOf(':');
  221 + const fEndIndexOf = sAssignField.lastIndexOf('_filter');
  222 + console.log('拿目标要过滤的表名', targetSumName, fStartIndexOf, fEndIndexOf);
  223 + if (fStartIndexOf > -1 && fEndIndexOf > -1) {
  224 + targetTbName = sAssignField.substring(fStartIndexOf + 1, fEndIndexOf);
  225 + }
  226 + const targetTableData = dataCollection[targetTbName];
  227 + const targetData = dataCollection[targetSumName];
  228 + const targetRow = dataSelected[`${targetSumName}Row`];
  229 + const targetFieldName = sAssignField.substring(sAssignField.indexOf('.') + 1, sAssignField.indexOf(':'));
  230 + const baseFieldName = sAssignField.substring(sAssignField.lastIndexOf('.') + 1, sAssignField.length);
  231 + let filterTableData = [];
  232 + const leftIndexOf = sAssignField.indexOf('{');
  233 + const rightIndexOf = sAssignField.lastIndexOf('}');
  234 + if (leftIndexOf > -1 && rightIndexOf > -1) {
  235 + const condition = sAssignField.substring(leftIndexOf, rightIndexOf + 1);
  236 + const conditionStr = condition.toString();
  237 + sOnChangeAssignFieldNew = sAssignField.replace(`${targetTbName}_filter_${condition}.`, '').replace('_sum', '').trim();
  238 + console.log('sOnChangeAssignFieldNew', sOnChangeAssignFieldNew);
  239 + let jsonObj = {};
  240 + if (commonUtils.isNotEmptyObject(conditionStr) && commonUtils.isJSON(conditionStr)) {
  241 + jsonObj = JSON.parse(conditionStr);
  242 + const { ifdo: ifdoStr, condition, decimal = 0 } = jsonObj;
  243 + let ifdoResult = true;
  244 + if (ifdoStr) {
  245 + try {
  246 + let ifdoStrNew = "";
  247 + const reg = new RegExp(`master\.`, "g");
  248 + ifdoStrNew = ifdoStr.replace(reg, `masterData.`);
  249 + const reg1 = new RegExp(`slave\.`, "g");
  250 + ifdoStrNew = ifdoStrNew.replace(reg1, `tableDataRow.`);
  251 + const evalStr = eval("`" + ifdoStrNew + "`");
  252 + ifdoResult = eval(evalStr);
  253 + } catch (error) {
  254 + console.log('=====keyup ifdo 报错:', {
  255 + ifdoStr, error
  256 + })
  257 + }
  258 + }
  259 + if (!ifdoResult) {
  260 + return {};
  261 + }
  262 + if (commonUtils.isNotEmptyArr(condition)) {
  263 + filterTableData = applyFilterConditions(condition, targetTableData, masterData, tableDataRow, baseFieldName, app);
  264 + }
  265 + let sumData = 0;
  266 + if (commonUtils.isNotEmptyArr(filterTableData)) {
  267 + sumData = calculateSum(sFieldName, filterTableData, tableDataRow, targetTableData, decimal, newCopyTo, masterData, name, targetTbName, app);
  268 + if (commonUtils.isNotEmptyObject(targetRow)) {
  269 + targetRow[sFieldName] = sumData;
  270 + }
  271 + if (targetSumName === 'master') {
  272 + const targetDataNew = name === 'master' ? masterData : targetData;
  273 + targetDataNew[targetFieldName] = sumData;
  274 + targetDataNew.handleType = commonUtils.isEmpty(targetDataNew.handleType) ? 'update' : targetDataNew.handleType;
  275 + addState[targetSumName] = targetDataNew;
  276 + if(name === 'master') {
  277 + addState[targetTbName] = targetTableData;
  278 + return addState;
  279 + }
  280 + } else if (commonUtils.isNotEmptyArr(targetData)) {
  281 + targetRow[`${sFieldName}Sum`] = sumData;
  282 + const iSlaveIndex = targetData.findIndex(item => item.sId === targetRow.sId);
  283 + if (iSlaveIndex > -1) {
  284 + targetData[iSlaveIndex][`${sFieldName}Sum`] = sumData;
  285 + newCopyTo[targetSumName] = targetData[iSlaveIndex];
  286 + targetData[iSlaveIndex].dTotal_waste_qty = sumData;
  287 + targetData[iSlaveIndex].handleType = commonUtils.isEmpty(targetData[iSlaveIndex].handleType) ? 'update' : targetData[iSlaveIndex].handleType;
  288 + addState[targetData] = targetData;
  289 + }
  290 + }
  291 + addState[targetTbName] = targetTableData;
  292 + }
  293 + }
  294 + }
  295 + return addState;
  296 +}
  297 +
  298 +// 辅助函数:应用过滤条件
  299 +function applyFilterConditions(conditions, targetTableData, masterData, tableDataRow, baseFieldName, app) {
  300 + let filterTableData = [];
  301 + for (const item of conditions) {
  302 + const { bFilterName, bFilterCondition, bFilterValue } = item;
  303 + if (bFilterCondition === '>') {
  304 + if (bFilterValue.includes('.')) {
  305 + const indexs = bFilterValue.indexOf('.');
  306 + const sConditionTableName = bFilterValue.substring(0, indexs);
  307 + const sConditionFieldName = bFilterValue.substring(indexs + 1, bFilterValue.length);
  308 + if (sConditionFieldName === 'slave') {
  309 + if (commonUtils.isNotEmptyArr(targetTableData)) {
  310 + filterTableData = targetTableData.filter(item => item[bFilterName] > tableDataRow[sConditionTableName]);
  311 + }
  312 + }
  313 + } else {
  314 + filterTableData = targetTableData.filter(item => item[bFilterName] > bFilterValue);
  315 + }
  316 + } else if (bFilterCondition === '=') {
  317 + if (bFilterValue.includes('.')) {
  318 + const indexs = bFilterValue.indexOf('.');
  319 + const sConditionTableName = bFilterValue.substring(0, indexs);
  320 + const sConditionFieldName = bFilterValue.substring(indexs + 1, bFilterValue.length);
  321 + if (sConditionTableName === 'slave') {
  322 + if (commonUtils.isNotEmptyArr(targetTableData)) {
  323 + filterTableData = targetTableData.filter(item => item[bFilterName] === tableDataRow[sConditionFieldName]);
  324 + }
  325 + } else if (sConditionTableName === 'master') {
  326 + if (commonUtils.isNotEmptyArr(targetTableData)) {
  327 + filterTableData = targetTableData.filter(item => item[bFilterName] === masterData[sConditionFieldName]);
  328 + }
  329 + }
  330 + } else {
  331 + filterTableData = targetTableData.filter(item => item[bFilterName] === bFilterValue);
  332 + }
  333 + if(baseFieldName !== sFieldName) {
  334 + sFieldName = baseFieldName;
  335 + }
  336 + } else if (bFilterCondition === '<') {
  337 + if (bFilterValue.includes('.')) {
  338 + const indexs = bFilterValue.indexOf('.');
  339 + const sConditionTableName = bFilterValue.substring(0, indexs);
  340 + const sConditionFieldName = bFilterValue.substring(indexs + 1, bFilterValue.length);
  341 + if (sConditionTableName === 'slave') {
  342 + if (commonUtils.isNotEmptyArr(targetTableData)) {
  343 + filterTableData = targetTableData.filter(item => item[bFilterName] < tableDataRow[sConditionFieldName]);
  344 + }
  345 + }
  346 + } else {
  347 + filterTableData = targetTableData.filter(item => item[bFilterName] < bFilterValue);
  348 + }
  349 + }
  350 + }
  351 + return filterTableData;
  352 +}
  353 +
  354 +// 辅助函数:计算汇总值
  355 +function calculateSum(sFieldName, filterTableData, tableDataRow, targetTableData, decimal, newCopyTo, masterData, name, targetTbName, app) {
  356 + let sumData = 0;
  357 + filterTableData.forEach((item) => {
  358 + const iIndex = targetTableData.findIndex(itemNew => itemNew.sId === item.sId);
  359 + if (iIndex > -1) {
  360 + newCopyTo.master = masterData;
  361 + newCopyTo[targetTbName] = item;
  362 + newCopyTo[name] = tableDataRow;
  363 + newCopyTo.slaveInfo = item;
  364 + newCopyTo.slaveChild = item;
  365 + if (item.sId !== tableDataRow.sId) {
  366 + sumData += commonUtils.isNull(item[sFieldName], 0);
  367 + } else {
  368 + sumData += commonUtils.isNull(tableDataRow[sFieldName], 0);
  369 + }
  370 + }
  371 + });
  372 + if (decimal) {
  373 + sumData = Number(sumData.toFixed(decimal));
  374 + }
  375 + console.log('sumData', sumData);
  376 + return sumData;
  377 +}
  378 +
  379 +// 辅助函数:仅处理汇总
  380 +function handleSumOnly(tbName, sAssignField, tableData, tableDataRowNew, newCopyTo, masterData, tableDataRow, app) {
  381 + const addState = {};
  382 + const sOnChangeAssignFieldNew = sAssignField.replace(`${tbName}_sum.`, '').trim();
  383 + newCopyTo.master = masterData;
  384 + let sumData = 0;
  385 + tableData.forEach((item, index) => {
  386 + if (item.sId === tableDataRowNew.sId) {
  387 + item = tableDataRowNew;
  388 + tableData[index] = tableDataRowNew;
  389 + }
  390 + newCopyTo[name] = item;
  391 + const tableRow = { ...item, ...commonFunc.getAssignFieldValue(sOnChangeAssignFieldNew, item, newCopyTo) };
  392 + tableRow.handleType = commonUtils.isEmpty(tableRow.handleType) ? 'update' : tableRow.handleType;
  393 + const tempName = `${sFieldName}temp_sum`;
  394 + const tempData = tableRow[tempName];
  395 + if (!commonUtils.isEmpty(tempData)) {
  396 + sumData += tableRow[tempName];
  397 + sumData += tableRow[sFieldName];
  398 + }
  399 + tableData[index] = tableRow;
  400 + });
  401 + addState[name] = tableData;
  402 + masterData.handleType = commonUtils.isEmpty(masterData.handleType) ? 'update' : masterData.handleType;
  403 + masterData[sumData] = sumData;
  404 + addState.masterData = masterData;
  405 + return addState;
  406 +}
  407 +
  408 +// 辅助函数:仅处理过滤
  409 +function handleFilterOnly(sAssignField, sButtonParam, tableDataRowNew, newCopyTo, masterData, tableDataRow, dataCollection, app) {
  410 + const addState = {};
  411 + let sOnChangeAssignFieldNew = sAssignField;
  412 + const indexOf = sAssignField.indexOf('_');
  413 + const targetTbName = sAssignField.substring(0, indexOf);
  414 + const targetTableData = dataCollection[targetTbName];
  415 + let filterTableData = [];
  416 + const leftIndexOf = sAssignField.indexOf('{');
  417 + const rightIndexOf = sAssignField.lastIndexOf('}');
  418 + if (leftIndexOf > -1 && rightIndexOf > -1) {
  419 + const condition = sAssignField.substring(leftIndexOf, rightIndexOf + 1);
  420 + const conditionStr = condition.toString();
  421 + sOnChangeAssignFieldNew = sAssignField.replace(`${targetTbName}_filter_${condition}.`, '').trim();
  422 + let jsonObj = {};
  423 + if (commonUtils.isNotEmptyObject(conditionStr)) {
  424 + jsonObj = JSON.parse(conditionStr);
  425 + const { condition } = jsonObj;
  426 + if (commonUtils.isNotEmptyArr(condition)) {
  427 + filterTableData = applyFilterConditions(condition, targetTableData, masterData, tableDataRow, sFieldName, app);
  428 + }
  429 + if (commonUtils.isNotEmptyArr(filterTableData)) {
  430 + filterTableData.forEach((item) => {
  431 + const iIndex = targetTableData.findIndex(itemNew => itemNew.sId === item.sId);
  432 + if (iIndex > -1) {
  433 + newCopyTo.master = masterData;
  434 + newCopyTo[targetTbName] = item;
  435 + newCopyTo[name] = tableDataRow;
  436 + newCopyTo.slaveInfo = item;
  437 + const tableRowAfter = { ...item, ...commonFunc.getAssignFieldValue(sOnChangeAssignFieldNew, tableDataRow, newCopyTo) };
  438 + let tableNewRow = {};
  439 + if (commonUtils.isNotEmptyObject(sButtonParam)) {
  440 + newCopyTo[name] = tableRowAfter;
  441 + tableNewRow = { ...tableRowAfter, ...commonFunc.getAssignFieldValue(sButtonParam, tableRowAfter, newCopyTo) };
  442 + }
  443 + tableRowAfter.handleType = commonUtils.isEmpty(tableRowAfter.handleType) ? 'update' : tableRowAfter.handleType;
  444 + if (commonUtils.isNotEmptyObject(tableNewRow)) {
  445 + targetTableData[iIndex] = { ...tableRowAfter, ...tableNewRow };
  446 + } else {
  447 + targetTableData[iIndex] = { ...item, ...tableRowAfter };
  448 + }
  449 + }
  450 + });
  451 + addState[targetTbName] = targetTableData;
  452 + }
  453 + }
  454 + }
  455 + return addState;
  456 +}
  457 +
  458 +// 辅助函数:处理单表事件
  459 +function handleSingleTableEvent(name, sAssignField, tableDataRowNew, newCopyTo, masterData, tableDataRow, dataSelected, isWait) {
  460 + const bCrossTable = isCrossTableAssignment(sAssignField);
  461 + const tableNames = extractTableNames(sAssignField);
  462 +
  463 + const newTableSelectedMap = formatTableData(dataSelected);
  464 + const datasetMap = bCrossTable ? newTableSelectedMap : newCopyTo;
  465 +
  466 + // 使用新的变量名来接收处理后的数据
  467 + const processedData = {
  468 + ...tableDataRowNew,
  469 + ...commonFunc.getAssignFieldValue(sAssignField, tableDataRowNew, datasetMap, false, bCrossTable, tableNames)
  470 + };
  471 +
  472 + let { handleType } = masterData ? masterData : { handleType: '' };
  473 + if (name !== 'master') {
  474 + handleType = processedData.handleType;
  475 + }
  476 + processedData.handleType = commonUtils.isEmpty(handleType) ? 'update' : handleType;
  477 +
  478 + if (isWait) {
  479 + return processedData;
  480 + }
  481 +
  482 + return processedData;
  483 +}
  484 +
  485 +function extractTableNames(sAssignField) {
  486 + const tableNames = [];
  487 + const regex = /(\w+)\./g;
  488 + let match;
  489 + while ((match = regex.exec(sAssignField)) !== null) {
  490 + if (!tableNames.includes(match[1])) {
  491 + tableNames.push(match[1]);
  492 + }
  493 + }
  494 + return tableNames;
  495 +}
  496 +
  497 +// 辅助函数:格式化表格数据
  498 +function formatTableData(originObj) {
  499 + // 添加空值检查,防止undefined或null导致Object.entries报错
  500 + if (originObj == null || typeof originObj !== 'object') {
  501 + return {};
  502 + }
  503 +
  504 + const newObj = {};
  505 + // 遍历原始对象的键值对
  506 + Object.entries(originObj).forEach(([key, value]) => {
  507 + // 去掉末尾的Row后缀
  508 + const newKey = key.replace(/Row$/, '');
  509 + // 赋值到新对象(键名更新,数据不变)
  510 + newObj[newKey] = value;
  511 + });
  512 + return newObj;
  513 +}
  514 +
  515 +// 辅助函数:获取子级数据(递归)
  516 +function getChildData(parentId, tableData, childData = []) {
  517 + if (!commonUtils.isNotEmptyArr(tableData)) return childData;
  518 +
  519 + const children = tableData.filter(item => item.sParentId === parentId);
  520 + if (commonUtils.isNotEmptyArr(children)) {
  521 + childData.push(...children);
  522 + children.forEach(child => {
  523 + getChildData(child.sId, tableData, childData);
  524 + });
  525 + }
  526 + return childData;
  527 +}
  528 +
  529 +
  530 +
  531 +// 辅助函数:判断是否为跨表赋值
  532 +function isCrossTableAssignment(sAssignField) {
  533 + const crossTableKeywords = ['slave.', 'control.', 'materials.', 'process.', 'master.'];
  534 + return crossTableKeywords.some(keyword => sAssignField.includes(keyword));
  535 +}
... ...
src/components/Common/CommonHooks/useCommonBase.js
... ... @@ -8,6 +8,7 @@ import * as commonConfig from &quot;@/utils/config&quot;;
8 8 import * as commonServices from "@/services/services";
9 9 import * as commonBusiness from "@/components/Common/commonBusiness";
10 10 import * as commonFunc from "@/components/Common/commonFunc";
  11 +import * as commonKeyUp from './commonKeyUp';
11 12 import instructSet from "@/components/Common/CommonInstructSet";
12 13 import costomPageFun from "@/mes/costomPageFun";
13 14 const { reducer } = commonUtils;
... ... @@ -39,7 +40,7 @@ const getInitialState = props =&gt; {
39 40 const useCommonBase = props => {
40 41 const [state, dispatch] = useReducer(reducer, getInitialState(props));
41 42 const tempRef = useRef({});
42   -
  43 + let mounted = true
43 44 const setTempRef = (params, bRewrite) => {
44 45 if (bRewrite) {
45 46 tempRef.current = params;
... ... @@ -466,7 +467,7 @@ const useCommonBase = props =&gt; {
466 467 addState = { ...addState };
467 468 if (isWait) {
468 469 return addState;
469   - } else if (this.mounted) {
  470 + } else if (mounted) {
470 471 handleSaveState(addState);
471 472 }
472 473 } else {
... ...
src/components/Common/CommonTable/index.js
... ... @@ -213,11 +213,7 @@ class CommonTableRc extends React.Component {
213 213 pdfFileUrl: "",
214 214 currentHoverSid: ""
215 215 };
216   - this.rowKey =
217   - commonUtils.isNotEmptyObject(props.tableProps) &&
218   - !commonUtils.isEmpty(props.tableProps.rowKey)
219   - ? props.tableProps.rowKey
220   - : "sSlaveId"; /* 表格主键 */
  216 + this.rowKey = commonUtils.isNotEmptyObject(props.tableProps) && !commonUtils.isEmpty(props.tableProps.rowKey) ? props.tableProps.rowKey : 'sId'; /* 表格主键 */
221 217 this.config = {}; /* 配置信息(基础)(数据格式:对象) */
222 218 this.tableColumn = []; /* table的表头信息(数据类型:数组对象) */
223 219 this.tableInfoColumn = [];
... ... @@ -3561,10 +3557,11 @@ class CommonTableRc extends React.Component {
3561 3557 rowSelection = null;
3562 3558 }
3563 3559 const { expKeys } = this.state;
  3560 + const {sModelType} = this.props?.parentProps || {}
3564 3561 /* 返回值 */
3565 3562 return {
3566 3563 components,
3567   - rowKey: this.rowKey,
  3564 + rowKey: sModelType?.includes('/indexPage/commonList') ? 'sSlaveId' : this.rowKey,
3568 3565 // size: 'middle',
3569 3566 bordered: true /* 显示边框 */,
3570 3567 className: !this.props.enabled
... ...
src/components/Common/commonBusiness.js
... ... @@ -415,6 +415,7 @@ export function getCalculateByPrice(app, type, masterData, tableDataRow, sFieldN
415 415 /* 待用数据赋值 */
416 416 const { dNetPrice, dNetMoney } = app.decimals;
417 417 const { sModelsType } = app.currentPane;
  418 + if (!tableDataRow) return
418 419 const dProductQty = commonUtils.convertToNum(tableDataRow[`d${type}Qty`]); /* 数量 */
419 420 const dProductPrice = commonUtils.convertToNum(tableDataRow[`d${type}Price`]); /* 价格 */
420 421 const dProductForeignPrice = commonUtils.convertToNum(tableDataRow[`d${type}ForeignPrice`]); /* 外币单价 */
... ... @@ -424,7 +425,7 @@ export function getCalculateByPrice(app, type, masterData, tableDataRow, sFieldN
424 425 const dLossMoney = commonUtils.convertToNum(tableDataRow.dLossMoney); /* 报损金额 */
425 426  
426 427 const dTaxRate = commonUtils.convertToNum(tableDataRow.dTaxRate); /* 税率 */
427   - let dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData.dCurrencyRate); /* 汇率 */
  428 + let dCurrencyRate = masterData?.dCurrencyRate ? commonUtils.convertIsNotNumToNumber1(masterData?.dCurrencyRate) : 1; /* 汇率 */
428 429 /* 报价单模块,工单模块、产品工艺卡 汇率取从表 */
429 430 if (commonUtils.isNotEmptyObject(sModelsType) && (sModelsType.includes('manufacture/') || sModelsType.includes('quotation/') || sModelsType.includes('processCard'))) {
430 431 dCurrencyRate = commonUtils.convertIsNotNumToNumber1(tableDataRow.dCurrencyRate); /* 汇率 */
... ... @@ -490,6 +491,7 @@ export function getCalculateByPriceNew(app, type, masterData, tableDataRow, sFil
490 491 /* 待用数据赋值 */
491 492 const { dNetPrice, dNetMoney } = app.decimals;
492 493 const { sModelsType } = app.currentPane;
  494 + if (!tableDataRow) return
493 495 const dProductQty = commonUtils.convertToNum(tableDataRow[`d${type}Qty`]); /* 数量 */
494 496 const dProofingMoney = commonUtils.convertToNum(tableDataRow.dProofingMoney); /* 打样金额 */
495 497 const dPlateMoney = commonUtils.convertToNum(tableDataRow.dPlateMoney); /* 制版金额 */
... ... @@ -500,7 +502,7 @@ export function getCalculateByPriceNew(app, type, masterData, tableDataRow, sFil
500 502 let dProductForeignMoney = commonUtils.convertToNum(tableDataRow[`d${type}ForeignMoney`]);
501 503 let dProductMoney = commonUtils.convertToNum(tableDataRow[`d${type}Money`]); /* 本币金额 */
502 504 const dTaxRate = commonUtils.convertToNum(tableDataRow.dTaxRate); /* 税率 */
503   - let dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData.dCurrencyRate); /* 汇率 */
  505 + let dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData?.dCurrencyRate); /* 汇率 */
504 506 const dLossMoney = commonUtils.convertToNum(tableDataRow.dLossMoney); /* 报损金额 */
505 507 /* 报价单模块,工单模块、产品工艺卡 汇率取从表 */
506 508 if (commonUtils.isNotEmptyObject(sModelsType) && (sModelsType.includes('manufacture/') || sModelsType.includes('quotation/') || sModelsType.includes('processCard'))) {
... ... @@ -604,7 +606,7 @@ export function getCalculatedLossMoney(app, masterData, tableDataRow, type) {
604 606 const dTaxRate = commonUtils.convertToNum(tableDataRow.dTaxRate); /* 税率 */
605 607 /* 数据赋值 */
606 608 tableDataRow.dLossMoney = commonUtils.convertFixNum(dLossMoney, dNetMoney);
607   - const dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData.dCurrencyRate); /* 汇率 */
  609 + const dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData?.dCurrencyRate); /* 汇率 */
608 610 const dSrcNoCheckMoney = commonUtils.isNull(tableDataRow.dSrcNoCheckMoney, 0);
609 611 if (commonUtils.isNotEmptyNumber(dSrcNoCheckMoney) && commonUtils.isNotEmptyNumber(dLossMoney)) {
610 612 const dMoney = commonUtils.convertFixNum(dSrcNoCheckMoney - dLossMoney, dNetMoney);
... ... @@ -719,9 +721,10 @@ export function getCalculateMoney(app, masterData, tableDataRow, type, sFieldNam
719 721 /* 待用数据赋值 */
720 722 const { dNetPrice, dNetMoney } = app.decimals;
721 723 const { sModelsType } = app.currentPane;
  724 + if (!tableDataRow) return
722 725 const dProductQty = commonUtils.convertToNum(tableDataRow[`d${type}Qty`]); /* 数量 */
723 726 const dTaxRate = commonUtils.convertToNum(tableDataRow.dTaxRate); /* 税率 */
724   - let dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData.dCurrencyRate); /* 汇率 */
  727 + let dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData?.dCurrencyRate); /* 汇率 */
725 728 /* 报价单模块,工单模块、产品工艺卡 汇率取从表 */
726 729 if (commonUtils.isNotEmptyObject(sModelsType) && (sModelsType.includes('manufacture/') || sModelsType.includes('quotation/') || sModelsType.includes('processCard'))) {
727 730 dCurrencyRate = commonUtils.convertIsNotNumToNumber1(tableDataRow.dCurrencyRate); /* 汇率 */
... ... @@ -769,9 +772,10 @@ export function getCalculateMoneyNew(app, masterData, tableDataRow, type, sField
769 772 /* 待用数据赋值 */
770 773 const { dNetPrice, dNetMoney } = app.decimals;
771 774 const { sModelsType } = app.currentPane;
  775 + if (!tableDataRow) return
772 776 const dProductQty = commonUtils.convertToNum(tableDataRow[`d${type}Qty`]); /* 数量 */
773 777 const dTaxRate = commonUtils.convertToNum(tableDataRow.dTaxRate); /* 税率 */
774   - let dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData.dCurrencyRate); /* 汇率 */
  778 + let dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData?.dCurrencyRate); /* 汇率 */
775 779 /* 报价单模块,工单模块、产品工艺卡 汇率取从表 */
776 780 if (commonUtils.isNotEmptyObject(sModelsType) && (sModelsType.includes('manufacture/') || sModelsType.includes('quotation/') || sModelsType.includes('processCard'))) {
777 781 dCurrencyRate = commonUtils.convertIsNotNumToNumber1(tableDataRow.dCurrencyRate); /* 汇率 */
... ... @@ -850,10 +854,11 @@ export function getCalculateNoTaxPrice(app, masterData, tableDataRow, type) {
850 854 /* 待用数据赋值 */
851 855 const { dNetPrice, dNetMoney } = app.decimals;
852 856 const { sModelsType } = app.currentPane;
  857 + if (!tableDataRow) return
853 858 const dProductQty = commonUtils.convertToNum(tableDataRow[`d${type}Qty`]); /* 数量 */
854 859 const dProductNoTaxPrice = commonUtils.convertToNum(tableDataRow[`d${type}NoTaxPrice`]); /* 不含税价 */
855 860 const dTaxRate = commonUtils.convertToNum(tableDataRow.dTaxRate); /* 税率 */
856   - let dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData.dCurrencyRate); /* 汇率 */
  861 + let dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData?.dCurrencyRate); /* 汇率 */
857 862 /* 报价单模块,工单模块、产品工艺卡 汇率取从表 */
858 863 if (commonUtils.isNotEmptyObject(sModelsType) && (sModelsType.includes('manufacture/') || sModelsType.includes('quotation/') || sModelsType.includes('processCard'))) {
859 864 dCurrencyRate = commonUtils.convertIsNotNumToNumber1(tableDataRow.dCurrencyRate); /* 汇率 */
... ... @@ -881,10 +886,11 @@ export function getCalculateNoTaxMoney(app, masterData, tableDataRow, type) {
881 886 /* 待用数据赋值 */
882 887 const { dNetPrice, dNetMoney } = app.decimals;
883 888 const { sModelsType } = app.currentPane;
  889 + if (!tableDataRow) return
884 890 const dProductQty = commonUtils.convertToNum(tableDataRow[`d${type}Qty`]);
885 891 const dProductNoTaxMoney = commonUtils.convertToNum(tableDataRow[`d${type}NoTaxMoney`]);
886 892 const dTaxRate = commonUtils.convertToNum(tableDataRow.dTaxRate);
887   - let dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData.dCurrencyRate);
  893 + let dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData?.dCurrencyRate);
888 894 /* 报价单模块,工单模块、产品工艺卡 汇率取从表 */
889 895 if (commonUtils.isNotEmptyObject(sModelsType) && (sModelsType.includes('manufacture/') || sModelsType.includes('quotation/') || sModelsType.includes('processCard'))) {
890 896 dCurrencyRate = commonUtils.convertIsNotNumToNumber1(tableDataRow.dCurrencyRate); /* 汇率 */
... ... @@ -926,7 +932,7 @@ export function getCalculateMoneyByLossMoney(app, type, masterData, tableDataRow
926 932 /* 待用数据赋值 */
927 933 const { dNetMoney } = app.decimals;
928 934 const dProductForeignMoney = commonUtils.convertFixNum(dSrcNoCheckMoney - dLossMoney, dNetMoney);
929   - const dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData.dCurrencyRate); /* 汇率 */
  935 + const dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData?.dCurrencyRate); /* 汇率 */
930 936 const dProductMoney = commonUtils.convertFixNum(dCurrencyRate !== 0 ? dProductForeignMoney * dCurrencyRate : 0, dNetMoney); /* 本位币金额 */
931 937 /* 数据赋值 */
932 938 tableDataRow[`d${type}ForeignMoney`] = dProductForeignMoney;
... ...