Commit 8e749bb778fe1abbc5480749d35f9e02b6b92030
1 parent
9ef9a524
新增commonNewBill的sBmRule功能;
Showing
2 changed files
with
56 additions
and
0 deletions
src/components/Common/CommonNewBill.js
| ... | ... | @@ -3369,12 +3369,65 @@ const BillComponent = Form.create({ |
| 3369 | 3369 | <AssignmentField {...assignmentFieldProps} /> |
| 3370 | 3370 | </div> |
| 3371 | 3371 | <ModalComponent {...props} /> |
| 3372 | + <CommonEffectEvent {...props} /> | |
| 3372 | 3373 | </Layout> |
| 3373 | 3374 | </Layout> |
| 3374 | 3375 | </Form> |
| 3375 | 3376 | ); |
| 3376 | 3377 | }); |
| 3377 | 3378 | |
| 3379 | +// 函数式组件 | |
| 3380 | +const CommonEffectEvent = props => { | |
| 3381 | + const { masterData = {} } = props; | |
| 3382 | + const { sBmRule } = masterData; | |
| 3383 | + | |
| 3384 | + const [watchFields, setWatchFields] = useState([]); | |
| 3385 | + const preValue = useRef(""); | |
| 3386 | + | |
| 3387 | + useEffect(() => { | |
| 3388 | + if (!sBmRule) { | |
| 3389 | + setWatchFields([]); | |
| 3390 | + preValue.current = ""; | |
| 3391 | + return; | |
| 3392 | + } | |
| 3393 | + | |
| 3394 | + const sBmRuleObj = commonUtils.convertStrToObj(sBmRule); | |
| 3395 | + const { showName = "" } = sBmRuleObj; | |
| 3396 | + setWatchFields(showName.split(",")); | |
| 3397 | + }, [sBmRule]); | |
| 3398 | + | |
| 3399 | + useEffect(() => { | |
| 3400 | + if (!watchFields.length) return; | |
| 3401 | + const newValue = watchFields.map(key => masterData[key] || "").join(""); | |
| 3402 | + if (preValue.current === newValue) return; | |
| 3403 | + preValue.current = newValue; | |
| 3404 | + | |
| 3405 | + const sBmRuleObj = commonUtils.convertStrToObj(sBmRule); | |
| 3406 | + const addState = Object.keys(sBmRuleObj).filter(key => key !== "showName").reduce((result, key) => { | |
| 3407 | + const list = sBmRuleObj[key]?.split("+") || []; | |
| 3408 | + result[key] = list.map(item => item.trim().replace(/\'/g, '')).map(item => { | |
| 3409 | + if (item !== '.' && item?.includes('.')) { | |
| 3410 | + const [tableName, sFieldName] = item.split('.'); | |
| 3411 | + return props[`${tableName}Data`]?.[sFieldName] || ""; | |
| 3412 | + } | |
| 3413 | + return item; | |
| 3414 | + }).join(''); | |
| 3415 | + return result; | |
| 3416 | + }, {}); | |
| 3417 | + | |
| 3418 | + props.onSaveState({ | |
| 3419 | + masterData: { | |
| 3420 | + ...masterData, | |
| 3421 | + ...addState, | |
| 3422 | + handleType: masterData.handleType || 'update', | |
| 3423 | + } | |
| 3424 | + }); | |
| 3425 | + | |
| 3426 | + }, [watchFields, masterData]); | |
| 3427 | + | |
| 3428 | + return null; | |
| 3429 | +} | |
| 3430 | + | |
| 3378 | 3431 | // 工艺参数弹窗 |
| 3379 | 3432 | const ModalComponent = props => { |
| 3380 | 3433 | if (!props.sParamsModalVisible && !props.sParamsNewModalVisible) return ""; | ... | ... |
src/components/Common/commonBusiness.js
| ... | ... | @@ -1004,6 +1004,9 @@ export function getKeyUpEvent(name, sFieldName, tableConfig, masterData, tableDa |
| 1004 | 1004 | tableDataRowNew = tableDataRow; |
| 1005 | 1005 | newCopyTo.slave = tableDataRow; |
| 1006 | 1006 | } |
| 1007 | + if (tableDataRowNew.sBmRule) { | |
| 1008 | + return tableDataRowNew; | |
| 1009 | + } | |
| 1007 | 1010 | if (commonUtils.isNotEmptyObject(tableConfig) && commonUtils.isNotEmptyArr(tableConfig.gdsconfigformslave)) { |
| 1008 | 1011 | const iConfigIndex = tableConfig.gdsconfigformslave.findIndex(item => item.sName === sFieldName); |
| 1009 | 1012 | if (iConfigIndex > -1) { | ... | ... |