Commit 96afaf25ea235015e138fa3ab40ec8bc9895da15

Authored by Min
1 parent 9a6fc48a

1.放大镜支持若数据根据条件已存在则修改,不存在插入

src/components/Common/CommonBase.js
@@ -2651,8 +2651,54 @@ export default (ChildComponent) => { @@ -2651,8 +2651,54 @@ export default (ChildComponent) => {
2651 if (iControlIndex > -1) { 2651 if (iControlIndex > -1) {
2652 newCopyTo.control = controlData[iControlIndex]; 2652 newCopyTo.control = controlData[iControlIndex];
2653 } 2653 }
2654 - /* 第一条数据若字段值为空或者只有一条数据时 则添加到该行 否则新增一行 */  
2655 - if (selectData.length === 1 || (index === 0 && commonUtils.isEmptyObject(sValue))) { 2654 + if (selectConfig?.sControlName?.toLowerCase().includes('_edit')) {
  2655 + const sActiveKey = selectConfig.sDefault;
  2656 + // 检查当前 item 的 sActiveKey 是否已经在 tableData 中存在
  2657 + const existRowIndex = tableData.findIndex(row => row?.[sActiveKey] === item?.[sActiveKey]);
  2658 + console.log('existRowInd1ex', sActiveKey, existRowIndex);
  2659 + if ( sActiveKey && existRowIndex !== -1 ) {
  2660 + let tableDataRow = { ...tableData[existRowIndex] };
  2661 + if (tbName === 'slave') {
  2662 + tableDataRow.sSqlConditionId = tableDataRow.sId;
  2663 + }
  2664 + // 赋值字段
  2665 + tableDataRow = {...commonFunc.getAssignFieldValue(selectConfig.sAssignField, item, newCopyTo), ...tableDataRow };
  2666 + tableData[existRowIndex] = tableDataRow;
  2667 + tableData[existRowIndex].handleType = 'update';
  2668 + // 异步价格处理
  2669 + tableData[existRowIndex] = await setProductPrice(tableData[existRowIndex], item, this.props);
  2670 +
  2671 + // 指令执行
  2672 + if (instructType) {
  2673 + this.handleExecInstructSet({
  2674 + type,
  2675 + sInstruct: instructType,
  2676 + showName: `${showName}-${type === 'blur' ? '离焦' : '变化'}`,
  2677 + });
  2678 + }
  2679 +
  2680 + // 分页 & 状态保存
  2681 + pagination.total = tableData.length;
  2682 + const addState = { [`${tbName}Data`]: tableData, [`${tbName}Pagination`]: pagination };
  2683 + if (typeof isWait !== 'boolean') this.handleSaveState(addState);
  2684 + return; // 直接结束本次循环,不走下面原有逻辑
  2685 + } else{
  2686 + let tableDataRowAdd = this.handleTableAdd(tbName, true);
  2687 + if (tbName === 'slave') {
  2688 + tableDataRowAdd.sSqlConditionId = tableDataRowAdd.sId;
  2689 + }
  2690 + tableDataRowAdd = { ...tableDataRowAdd, ...commonFunc.getAssignFieldValue(selectConfig.sAssignField, item, newCopyTo) }; // 取赋值字段
  2691 + tableDataRowAdd = await setProductPrice(tableDataRowAdd, item, this.props);
  2692 + if (instructType) {
  2693 + this.handleExecInstructSet({
  2694 + type,
  2695 + sInstruct: instructType,
  2696 + showName: `${showName}-${type === 'blur' ? '离焦' : '变化'}`,
  2697 + });
  2698 + }
  2699 + tableData.push(tableDataRowAdd);
  2700 + }
  2701 + } else if (selectData.length === 1 || (index === 0 && commonUtils.isEmptyObject(sValue))) {
2656 let tableDataRow = {}; // 取默认值 2702 let tableDataRow = {}; // 取默认值
2657 if (tbName === 'master') { 2703 if (tbName === 'master') {
2658 tableDataRow = { ...tableData, ...commonFunc.getAssignFieldValue(selectConfig.sAssignField, item, newCopyTo) }; // 取赋值字段 2704 tableDataRow = { ...tableData, ...commonFunc.getAssignFieldValue(selectConfig.sAssignField, item, newCopyTo) }; // 取赋值字段
src/components/Common/CommonNewBill.js
@@ -2685,7 +2685,7 @@ const BillComponent = Form.create({ @@ -2685,7 +2685,7 @@ const BillComponent = Form.create({
2685 separateTabName10 = separateTabConfig.showName; 2685 separateTabName10 = separateTabConfig.showName;
2686 } 2686 }
2687 } 2687 }
2688 - console.log('333props', props); 2688 +
2689 2689
2690 const flexRowStyle = bFlow ? { display: "flex", flexDirection: "row" } : {}; 2690 const flexRowStyle = bFlow ? { display: "flex", flexDirection: "row" } : {};
2691 const flexContentStyle = bFlow ? { width: "75%" } : {}; 2691 const flexContentStyle = bFlow ? { width: "75%" } : {};