Commit 8e23cad238c986ea79bcc43903723dfd6b921440
1 parent
72cc653e
1.增加上报参数下拉选择的功能
Showing
1 changed file
with
80 additions
and
14 deletions
src/mes/common/commonModelComponent/index.js
| ... | ... | @@ -2356,42 +2356,108 @@ const CommonViewTableComponent = props => { |
| 2356 | 2356 | // 查找对应的下拉数据源 sParamDropDown1, sParamDropDown2... |
| 2357 | 2357 | const dropDownKey = `sParamDropDown${paramNum}`; |
| 2358 | 2358 | const hasDropDown = reportParam[dropDownKey] && Object.keys(reportParam[dropDownKey]).length > 0; |
| 2359 | + // 将下拉对象转换为数组格式 [{sId, sName}] | |
| 2360 | + const dropDownArray = hasDropDown ? Object.keys(reportParam[dropDownKey]).map(dKey => ({ | |
| 2361 | + sId: dKey, | |
| 2362 | + sName: reportParam[dropDownKey][dKey] | |
| 2363 | + })) : []; | |
| 2364 | + | |
| 2365 | + // 字段名映射:sParam1 -> sParamValue1, sParam2 -> sParamValue2 | |
| 2366 | + const valueKey = `sParamValue${paramNum}`; | |
| 2359 | 2367 | |
| 2360 | 2368 | return { |
| 2361 | - sId: key, | |
| 2362 | - sName: key, | |
| 2369 | + sId: valueKey, // 使用 sParamValue1, sParamValue2 作为字段名 | |
| 2370 | + sName: valueKey, // 使用 sParamValue1, sParamValue2 作为字段名 | |
| 2363 | 2371 | showName: reportParam[key] || key, |
| 2364 | - sControlName: `reportParam_${key}`, | |
| 2365 | - iColValue: 8, | |
| 2372 | + sControlName: `reportParam_${valueKey}`, | |
| 2373 | + iColValue: 12, | |
| 2366 | 2374 | iOrder: parseInt(paramNum) || 0, |
| 2367 | 2375 | bVisible: true, |
| 2368 | 2376 | bReadonly: false, // 允许编辑 |
| 2369 | 2377 | enabled: true, // 确保字段可编辑 |
| 2370 | - sDefault: reportParam[`${key}Default`] || '', | |
| 2371 | - sDropDownType: hasDropDown ? 'sql' : '', | |
| 2372 | - sChineseDropDown: hasDropDown ? JSON.stringify(reportParam[dropDownKey]) : '', | |
| 2373 | - showDropDropDown: hasDropDown ? JSON.stringify(reportParam[dropDownKey]) : '', | |
| 2374 | - iTag: 3, // iTag=3 强制允许编辑(CommonViewTable中iTag=3时enabledNew=true) | |
| 2378 | + sDefault: '', // 不使用默认值,避免显示 new_type | |
| 2379 | + sDropDownType: hasDropDown ? 'const' : '', // 使用 const 类型而不是 sql | |
| 2380 | + showDropDown: hasDropDown ? dropDownArray : [], // 直接传入数组数据 | |
| 2381 | + dropDownData: hasDropDown ? dropDownArray : [], // 备用数据源 | |
| 2382 | + iTag: 3, // iTag=3 强制允许编辑 | |
| 2375 | 2383 | specialControl: false // 确保不是特殊控件 |
| 2376 | 2384 | }; |
| 2377 | 2385 | }) : []; |
| 2378 | 2386 | |
| 2379 | - // 构建上报参数的视图数据 | |
| 2387 | + // 构建上报参数的视图数据,并合并到主视图数据中 | |
| 2380 | 2388 | const reportViewRow = reportParam ? Object.keys(reportParam).filter(key => key.startsWith('sParam') && !key.includes('Default') && !key.includes('NotEmpty') && !key.includes('DropDown')).reduce((acc, key) => { |
| 2381 | - acc[key] = reportParam[`${key}Default`] || ''; | |
| 2389 | + const paramNum = key.replace('sParam', ''); | |
| 2390 | + const valueKey = `sParamValue${paramNum}`; // 使用 sParamValue1, sParamValue2 | |
| 2391 | + // 使用 viewRow 中已有的值,如果没有则使用空字符串(不使用 reportParam 中的默认值) | |
| 2392 | + const defaultValue = reportParam[`${key}Default`]; | |
| 2393 | + const isValidValue = defaultValue !== 'new_type' && defaultValue !== 'newType'; | |
| 2394 | + acc[valueKey] = viewRow[valueKey] !== undefined ? viewRow[valueKey] : (isValidValue ? defaultValue : ''); | |
| 2382 | 2395 | return acc; |
| 2383 | 2396 | }, {}) : {}; |
| 2384 | 2397 | |
| 2398 | + // 将上报参数数据合并到 viewRow,确保数据同步到主表 | |
| 2399 | + Object.keys(reportViewRow).forEach(key => { | |
| 2400 | + // 如果 viewRow 中已有值,检查是否是无效值(new_type),如果是则替换 | |
| 2401 | + const existingValue = viewRow[key]; | |
| 2402 | + if (existingValue === 'new_type' || existingValue === 'newType') { | |
| 2403 | + viewRow[key] = reportViewRow[key]; | |
| 2404 | + } else if (viewRow[key] === undefined) { | |
| 2405 | + viewRow[key] = reportViewRow[key]; | |
| 2406 | + } | |
| 2407 | + }); | |
| 2408 | + | |
| 2409 | + // 组装 sParams 字段 | |
| 2410 | + if (reportParam && commonUtils.isNotEmptyObject(reportParam)) { | |
| 2411 | + const sParamData = []; | |
| 2412 | + for (const key of Object.keys(reportParam)) { | |
| 2413 | + if (key.startsWith('sParam') && !key.includes('NotEmpty') && !key.includes('DropDown') && !key.includes('Default')) { | |
| 2414 | + const obj = {}; | |
| 2415 | + obj.sId = commonUtils.createSid(); | |
| 2416 | + obj.sParamKey = key; | |
| 2417 | + obj.sParamName = reportParam[key]; | |
| 2418 | + | |
| 2419 | + // 找到数字 | |
| 2420 | + const num = key.replace(/[^\d]/g, '').trim(); | |
| 2421 | + if (Number(num)) { | |
| 2422 | + const number = Number(num); | |
| 2423 | + const sParamDropDownKey = `sParamDropDown${number}`; | |
| 2424 | + obj.sDropDownData = reportParam[sParamDropDownKey]; | |
| 2425 | + | |
| 2426 | + // 从 viewRow 中获取用户输入的值 | |
| 2427 | + const sParamValueKey = `sParamValue${number}`; | |
| 2428 | + const sParamValue = viewRow[sParamValueKey]; | |
| 2429 | + | |
| 2430 | + // 如果有值且不是无效值,才添加到 sParams | |
| 2431 | + if (sParamValue !== undefined && sParamValue !== '' && sParamValue !== 'new_type' && sParamValue !== 'newType') { | |
| 2432 | + obj.sParamValue = sParamValue; | |
| 2433 | + obj.bSelfCbx = true; | |
| 2434 | + } | |
| 2435 | + } | |
| 2436 | + sParamData.push(obj); | |
| 2437 | + } | |
| 2438 | + } | |
| 2439 | + | |
| 2440 | + // 只保留用户选择了的值 | |
| 2441 | + const sParamSeletedData = sParamData.filter(item => item.bSelfCbx); | |
| 2442 | + if (commonUtils.isNotEmptyArr(sParamSeletedData)) { | |
| 2443 | + viewRow.sParams = JSON.stringify(sParamSeletedData); | |
| 2444 | + } else { | |
| 2445 | + viewRow.sParams = ''; | |
| 2446 | + } | |
| 2447 | + } | |
| 2448 | + | |
| 2385 | 2449 | const reportProps = { |
| 2386 | 2450 | ...props, |
| 2387 | 2451 | viewConfigs: reportViewConfigs, |
| 2388 | 2452 | tableConfig: config, |
| 2389 | 2453 | iColValueView: 24, |
| 2390 | - viewRow: reportViewRow, | |
| 2391 | - tableName: `${sName}_report`, | |
| 2454 | + viewRow: viewRow, // 使用合并后的 viewRow | |
| 2455 | + tableName: sName, // 使用与报工信息相同的表名,确保数据正确存储 | |
| 2392 | 2456 | enabled: props.enabled, // 继承父组件的 enabled 属性 |
| 2393 | - enabledNew: props.enabledNew // 继承父组件的 enabledNew 属性 | |
| 2457 | + enabledNew: props.enabledNew, // 继承父组件的 enabledNew 属性 | |
| 2458 | + onDataChange: props.onDataChange // 确保 onChange 事件能够正确触发 | |
| 2394 | 2459 | }; |
| 2460 | + console.log('222', props); | |
| 2395 | 2461 | |
| 2396 | 2462 | return ( |
| 2397 | 2463 | <> | ... | ... |