diff --git a/src/mes/common/commonModelComponent/index.js b/src/mes/common/commonModelComponent/index.js index 3d675e3..a5f1f41 100644 --- a/src/mes/common/commonModelComponent/index.js +++ b/src/mes/common/commonModelComponent/index.js @@ -2338,134 +2338,6 @@ const CommonViewTableComponent = props => { const { masterData, sModelsType, app } = props const { bCheck = false } = masterData || {} const imgSrc = commonBusiness.handleAddIcon(masterData, sModelsType, app); - - // 上报参数区域状态管理 - const [reportExpand, setReportExpand] = useState(true); - - // 解析上报参数 - let reportParam = null; - if(true || props.sModelsId === '17087428780006438414984564455000'){ - if(viewRow.sReportParam){ - reportParam = JSON.parse(viewRow.sReportParam); - } - } - - // 构建上报参数的配置 - const reportViewConfigs = reportParam ? Object.keys(reportParam).filter(key => key.startsWith('sParam') && !key.includes('Default') && !key.includes('NotEmpty') && !key.includes('DropDown')).map(key => { - const paramNum = key.replace('sParam', ''); - // 查找对应的下拉数据源 sParamDropDown1, sParamDropDown2... - const dropDownKey = `sParamDropDown${paramNum}`; - const hasDropDown = reportParam[dropDownKey] && Object.keys(reportParam[dropDownKey]).length > 0; - // 将下拉对象转换为数组格式 [{sId, sName}] - const dropDownArray = hasDropDown ? Object.keys(reportParam[dropDownKey]).map(dKey => ({ - sId: dKey, - sName: reportParam[dropDownKey][dKey] - })) : []; - - // 字段名映射:sParam1 -> sParamValue1, sParam2 -> sParamValue2 - const valueKey = `sParamValue${paramNum}`; - - return { - sId: valueKey, // 使用 sParamValue1, sParamValue2 作为字段名 - sName: valueKey, // 使用 sParamValue1, sParamValue2 作为字段名 - showName: reportParam[key] || key, - sControlName: `reportParam_${valueKey}`, - iColValue: 12, - iOrder: parseInt(paramNum) || 0, - bVisible: true, - bReadonly: false, // 允许编辑 - enabled: true, // 确保字段可编辑 - sDefault: '', // 不使用默认值,避免显示 new_type - sDropDownType: hasDropDown ? 'const' : '', // 使用 const 类型而不是 sql - showDropDown: hasDropDown ? dropDownArray : [], // 直接传入数组数据 - dropDownData: hasDropDown ? dropDownArray : [], // 备用数据源 - iTag: 3, // iTag=3 强制允许编辑 - specialControl: false // 确保不是特殊控件 - }; - }) : []; - - // 构建上报参数的视图数据,并合并到主视图数据中 - const reportViewRow = reportParam ? Object.keys(reportParam).filter(key => key.startsWith('sParam') && !key.includes('Default') && !key.includes('NotEmpty') && !key.includes('DropDown')).reduce((acc, key) => { - const paramNum = key.replace('sParam', ''); - const valueKey = `sParamValue${paramNum}`; // 使用 sParamValue1, sParamValue2 - - // 获取 viewRow 中的值 - const viewRowValue = viewRow[valueKey]; - - // 检查 viewRow 值是否有效(不是 undefined、空字符串、new_type、newType) - const isViewRowValueValid = viewRowValue !== undefined && viewRowValue !== '' && viewRowValue !== 'new_type' && viewRowValue !== 'newType'; - - // 获取默认值并检查是否有效 - const defaultValue = reportParam[`${key}Default`]; - const isDefaultValueValid = defaultValue !== undefined && defaultValue !== '' && defaultValue !== 'new_type' && defaultValue !== 'newType'; - - // 优先使用 viewRow 中的有效值,否则使用有效的默认值,否则为空 - acc[valueKey] = isViewRowValueValid ? viewRowValue : (isDefaultValueValid ? defaultValue : ''); - return acc; - }, {}) : {}; - - // 将上报参数数据合并到 viewRow,确保数据同步到主表 - Object.keys(reportViewRow).forEach(key => { - // 如果 viewRow 中已有值,检查是否是无效值(new_type),如果是则替换 - const existingValue = viewRow[key]; - if (existingValue === 'new_type' || existingValue === 'newType') { - viewRow[key] = reportViewRow[key]; - } else if (viewRow[key] === undefined) { - viewRow[key] = reportViewRow[key]; - } - }); - - // 组装 sParams 字段 - if (reportParam && commonUtils.isNotEmptyObject(reportParam)) { - const sParamData = []; - for (const key of Object.keys(reportParam)) { - if (key.startsWith('sParam') && !key.includes('NotEmpty') && !key.includes('DropDown') && !key.includes('Default')) { - const obj = {}; - obj.sId = commonUtils.createSid(); - obj.sParamKey = key; - obj.sParamName = reportParam[key]; - - // 找到数字 - const num = key.replace(/[^\d]/g, '').trim(); - if (Number(num)) { - const number = Number(num); - const sParamDropDownKey = `sParamDropDown${number}`; - obj.sDropDownData = reportParam[sParamDropDownKey]; - - // 从 viewRow 中获取用户输入的值 - const sParamValueKey = `sParamValue${number}`; - const sParamValue = viewRow[sParamValueKey]; - - // 如果有值且不是无效值,才添加到 sParams - if (sParamValue !== undefined && sParamValue !== '' && sParamValue !== 'new_type' && sParamValue !== 'newType') { - obj.sParamValue = sParamValue; - obj.bSelfCbx = true; - } - } - sParamData.push(obj); - } - } - - // 只保留用户选择了的值 - const sParamSeletedData = sParamData.filter(item => item.bSelfCbx); - if (commonUtils.isNotEmptyArr(sParamSeletedData)) { - viewRow.sParams = JSON.stringify(sParamSeletedData); - } else { - viewRow.sParams = ''; - } - } - - const reportProps = { - ...props, - viewConfigs: reportViewConfigs, - tableConfig: config, - iColValueView: 24, - viewRow: viewRow, // 使用合并后的 viewRow - tableName: sName, // 使用与报工信息相同的表名,确保数据正确存储 - enabled: props.enabled, // 继承父组件的 enabled 属性 - enabledNew: props.enabledNew, // 继承父组件的 enabledNew 属性 - onDataChange: props.onDataChange // 确保 onChange 事件能够正确触发 - }; return ( <> {sName === "master" ? ( @@ -2489,10 +2361,7 @@ const CommonViewTableComponent = props => { viewProps.enabledNew = false; } - // 传递上报参数给主视图 - if(reportParam){ - viewProps.reportParam = reportParam; - } + return ( <> @@ -2502,44 +2371,8 @@ const CommonViewTableComponent = props => { ); })} - {/* 上报参数区域 - 只显示一次,放在循环外面 */} - {reportParam && reportViewConfigs.length > 0 && ( -
- {/* 上报参数标题栏 */} -
setReportExpand(!reportExpand)} - > - - 上报参数 -
- - {/* 上报参数内容 */} - {reportExpand && ( -
- -
- )} -
- )} + {/* 上报参数区域 */} + {sName !== "master" ? ( ) : ( @@ -3347,6 +3180,161 @@ const CommonViewChooseComponent = props => { ); }; +// 上报参数组件 +const ReportParamComponent = props => { + const { viewRow, masterData, config, sName, onDataChange } = props; + + const [reportExpand, setReportExpand] = useState(true); + + if (!viewRow || !viewRow.sReportParam) { + return ''; + } + + const reportParam = JSON.parse(viewRow.sReportParam); + + if (!reportParam || !commonUtils.isNotEmptyObject(reportParam)) { + return ''; + } + + const reportViewConfigs = Object.keys(reportParam).filter(key => key.startsWith('sParam') && !key.includes('Default') && !key.includes('NotEmpty') && !key.includes('DropDown')).map(key => { + const paramNum = key.replace('sParam', ''); + const dropDownKey = `sParamDropDown${paramNum}`; + const hasDropDown = reportParam[dropDownKey] && Object.keys(reportParam[dropDownKey]).length > 0; + const dropDownArray = hasDropDown ? Object.keys(reportParam[dropDownKey]).map(dKey => ({ + sId: dKey, + sName: reportParam[dropDownKey][dKey] + })) : []; + + const valueKey = `sParamValue${paramNum}`; + + return { + sId: valueKey, + sName: valueKey, + showName: reportParam[key] || key, + sControlName: `reportParam_${valueKey}`, + iColValue: 12, + iOrder: parseInt(paramNum) || 0, + bVisible: true, + bReadonly: false, + enabled: true, + sDefault: '', + sDropDownType: hasDropDown ? 'const' : '', + showDropDown: hasDropDown ? dropDownArray : [], + dropDownData: hasDropDown ? dropDownArray : [], + iTag: 3, + specialControl: false + }; + }); + + if (reportViewConfigs.length === 0) { + return ''; + } + + const reportViewRow = Object.keys(reportParam).filter(key => key.startsWith('sParam') && !key.includes('Default') && !key.includes('NotEmpty') && !key.includes('DropDown')).reduce((acc, key) => { + const paramNum = key.replace('sParam', ''); + const valueKey = `sParamValue${paramNum}`; + const viewRowValue = viewRow[valueKey]; + const isViewRowValueValid = viewRowValue !== undefined && viewRowValue !== '' && viewRowValue !== 'new_type' && viewRowValue !== 'newType'; + const defaultValue = reportParam[`${key}Default`]; + const isDefaultValueValid = defaultValue !== undefined && defaultValue !== '' && defaultValue !== 'new_type' && defaultValue !== 'newType'; + acc[valueKey] = isViewRowValueValid ? viewRowValue : (isDefaultValueValid ? defaultValue : ''); + return acc; + }, {}); + + Object.keys(reportViewRow).forEach(key => { + const existingValue = viewRow[key]; + if (existingValue === 'new_type' || existingValue === 'newType') { + viewRow[key] = reportViewRow[key]; + } else if (viewRow[key] === undefined) { + viewRow[key] = reportViewRow[key]; + } + }); + + const sParamData = []; + for (const key of Object.keys(reportParam)) { + if (key.includes('sParam') && !key.includes('NotEmpty') && !key.includes('DropDown') && !key.includes('Default')) { + const obj = {}; + obj.sId = commonUtils.createSid(); + obj.sParamKey = key; + obj.sParamName = reportParam[key]; + const num = key.replace(/[^\d]/g, '').trim(); + if (Number(num)) { + const number = Number(num); + const sParamDropDownKey = `sParamDropDown${number}`; + obj.sDropDownData = reportParam[sParamDropDownKey]; + const sParamDefaultKey = `sParamDefault${number}`; + const defaultVal = reportParam[sParamDefaultKey]; + if (defaultVal !== undefined && defaultVal !== '' && defaultVal !== 'new_type' && defaultVal !== 'newType') { + obj.sParamValue = defaultVal; + } else { + obj.sParamValue = ''; + } + const sParamValueKey = `sParamValue${number}`; + const sParamValue = viewRow[sParamValueKey]; + if (commonUtils.isNotEmptyObject(sParamValue) && sParamValue !== '0') { + obj.sParamValue = sParamValue; + obj.bSelfCbx = true; + } + } + sParamData.push(obj); + } + } + + const sParamSeletedData = sParamData.filter(item => item.bSelfCbx); + if (commonUtils.isNotEmptyArr(sParamSeletedData)) { + viewRow.sParams = JSON.stringify(sParamSeletedData); + } else { + viewRow.sParams = ''; + } + + const reportProps = { + ...props, + viewConfigs: reportViewConfigs, + tableConfig: config, + iColValueView: 24, + viewRow: viewRow, + tableName: sName, + enabled: props.enabled, + enabledNew: props.enabledNew, + onDataChange: onDataChange + }; + + return ( +
+
setReportExpand(!reportExpand)} + > + + 上报参数 +
+ {reportExpand && ( +
+ +
+ )} +
+ ); +}; + // (定制功能)工单参数详情弹窗 const CommonParamsModalComponent = props => { const modalName = "sWorkParamsModalVisible"; // commonParamVisible