fix(资产规则表单): 修正隐患级别和数量字段的绑定逻辑
- 将资产规则数据结构从 `{ 0: level, 1: quantity }` 改为 `{ level: quantity }`
- 修复更新条件时字段绑定错误的问题,确保级别和数量正确关联
- 当未选择隐患级别时禁用数量输入框,防止无效输入
- 在表单视图中添加中文注释以提升代码可读性
| | |
| | | |
| | | // 资产项目规则 |
| | | assetRules: { |
| | | a: [[{ 0: undefined, 1: undefined }]], |
| | | b: [[{ 0: undefined, 1: undefined }]], |
| | | c: [[{ 0: undefined, 1: undefined }]], |
| | | a: [[{}]], |
| | | b: [[{}]], |
| | | c: [[{}]], |
| | | }, |
| | | |
| | | // 权限表头开关 |
| | |
| | | |
| | | // 解析 assetProject |
| | | let assetRules = { |
| | | a: [[{ 0: undefined, 1: undefined }]], |
| | | b: [[{ 0: undefined, 1: undefined }]], |
| | | c: [[{ 0: undefined, 1: undefined }]], |
| | | a: [[{}]], |
| | | b: [[{}]], |
| | | c: [[{}]], |
| | | }; |
| | | if (data.assetProject) { |
| | | try { |
| | |
| | | ...prev.assetRules, |
| | | [type]: [ |
| | | ...prev.assetRules[type], |
| | | [{ 0: undefined, 1: undefined }], |
| | | [{}], |
| | | ], |
| | | }, |
| | | })); |
| | |
| | | ...prev.assetRules, |
| | | [type]: rules.length |
| | | ? rules |
| | | : [[{ 0: undefined, 1: undefined }]], // 至少保留一组 |
| | | : [[{}]], // 至少保留一组 |
| | | }, |
| | | }; |
| | | }); |
| | |
| | | |
| | | // 如果该类下没有任何规则了,保留一个空的 |
| | | if (rules.length === 0) { |
| | | rules.push([{ 0: undefined, 1: undefined }]); |
| | | rules.push([{}]); |
| | | } |
| | | |
| | | return { |
| | |
| | | const rules = [...prev.assetRules[type]]; |
| | | rules[orIndex] = [ |
| | | ...rules[orIndex], |
| | | { 0: undefined, 1: undefined }, |
| | | {}, |
| | | ]; |
| | | return { assetRules: { ...prev.assetRules, [type]: rules } }; |
| | | }); |
| | |
| | | updateCondition = (type, orIndex, andIndex, key, value) => { |
| | | this.setState((prev) => { |
| | | const rules = [...prev.assetRules[type]]; |
| | | rules[orIndex][andIndex][key] = value; |
| | | const item = rules[orIndex][andIndex]; |
| | | const currentLevel = Object.keys(item)[0]; |
| | | const currentQuantity = item[currentLevel]; |
| | | |
| | | if (key === 'level') { |
| | | // 修改隐患等级 (key) |
| | | // 如果之前有数量,保留数量 |
| | | rules[orIndex][andIndex] = { [value]: currentQuantity }; |
| | | } else if (key === 'quantity') { |
| | | // 修改数量 (value) |
| | | if (currentLevel) { |
| | | rules[orIndex][andIndex] = { [currentLevel]: value }; |
| | | } |
| | | } |
| | | return { assetRules: { ...prev.assetRules, [type]: rules } }; |
| | | }); |
| | | }; |
| | |
| | | )} |
| | | |
| | | <div style={{ border: '1px dashed #ccc', padding: 5, borderRadius: 4, display: 'flex', flexWrap: 'wrap', alignItems: 'center' }}> |
| | | {orGroup.map((andItem, andIndex) => ( |
| | | {orGroup.map((andItem, andIndex) => { |
| | | const level = Object.keys(andItem)[0]; |
| | | const quantity = andItem[level]; |
| | | return ( |
| | | <div key={andIndex} style={{ display: "flex", alignItems: "center", margin: '2px 0' }}> |
| | | {andIndex > 0 && ( |
| | | <div style={{ display: 'flex', alignItems: 'center' }}> |
| | |
| | | <Select |
| | | style={{ width: 120 }} |
| | | placeholder="隐患级别" |
| | | value={andItem['0']} |
| | | onChange={(val) => this.updateCondition(type, orIndex, andIndex, "0", val)} |
| | | value={level ? Number(level) : undefined} |
| | | onChange={(val) => this.updateCondition(type, orIndex, andIndex, "level", val)} |
| | | > |
| | | <Option value={1}>一级隐患</Option> |
| | | <Option value={2}>二级隐患</Option> |
| | |
| | | style={{ width: 80, marginLeft: 8 }} |
| | | type="number" |
| | | placeholder="数量" |
| | | value={andItem['1']} |
| | | onChange={(e) => this.updateCondition(type, orIndex, andIndex, "1", e.target.value)} |
| | | value={quantity} |
| | | disabled={!level} |
| | | onChange={(e) => this.updateCondition(type, orIndex, andIndex, "quantity", e.target.value)} |
| | | /> |
| | | </div> |
| | | ))} |
| | | )})} |
| | | <Icon |
| | | type="plus-circle" |
| | | theme="filled" |
| | |
| | | {{ screenData.projectTotal }} |
| | | </div> |
| | | </div> |
| | | <!-- 在建工程tab --> |
| | | <div class="ml--18 flex1" v-if="activeTab == 1"> |
| | | <div |
| | | @click="toPorjectList" |
| | |
| | | </div> |
| | | <div class="ml--11 txt-center"> |
| | | <div class="c-fff fs--22 lh--22 SHSBold"> |
| | | {{ screenData.municipalInspectionCoverage }} |
| | | {{ screenData.municipalProjectCount }} |
| | | </div> |
| | | <div |
| | | v-if="!dateRange.length" |
| | | class="mt--9 fs--10 lh--12 color4 SHSM" |
| | | > |
| | | {{ screenData.municipalProjectCount }}% |
| | | {{ screenData.municipalInspectionCoverage }}% |
| | | </div> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | <!-- 固定资产tab --> |
| | | <div class="ml--18 flex1" v-else> |
| | | <div |
| | | class="mt--13 flex a-center j-between bgcolor2 pl--9 pb--5 pt--4 pr--10" |