Explorar el Código

量表添加去重1601

zhouna hace 6 años
padre
commit
b19b9c0cd8
Se han modificado 2 ficheros con 22 adiciones y 4 borrados
  1. 1 1
      src/containers/ChronicInfo.js
  2. 21 3
      src/store/reducers/assessResult.js

+ 1 - 1
src/containers/ChronicInfo.js

@@ -66,7 +66,7 @@ function mapDispatchToProps(dispatch){
         data:obj,
         index:pIndex,
         subIndex:i,
-        id:it.type==1?it.content.id:undefined,      //只有量表需要记录id,去重用
+        id:it.type==1?it.content.conceptId:undefined,      //只有量表需要记录id,去重用
       })
     },
     addScaleItems(obj,id){

+ 21 - 3
src/store/reducers/assessResult.js

@@ -78,12 +78,30 @@ export default (state=init,action)=>{
       res.wholeAssess[action.index] = action.data;
       let arr = res.wholeIndexs[action.index];
       res.wholeIndexs[action.index] = arr?[...arr,action.subIndex]:[action.subIndex];
-      action.id?res.addedScaleIds.push(action.id):'';
+      //已从全部量表中加入过,加入新的,删除原来的
+      if(res.addedScaleIds.includes(action.id)){
+        delete res.wholeScaleItems[action.id];
+      }else{
+        action.id?res.addedScaleIds.push(action.id):'';
+      }
       res.update1 = Math.random();   //对象更新,与其他字段名不同因为绑定在pushItems,避免不必要的渲染
       return res;
-    case ADD_WHOLE_SCALE_ITEMS:
+    case ADD_WHOLE_SCALE_ITEMS:        //从全部量表中加入量表
       res.wholeScaleItems[action.id] = action.data;
-      res.addedScaleIds.push(action.id);
+      //已从指标推送中添加过该量表,加入新的,删除原来的
+      let inx = -1,subInx = -1;
+      if(res.addedScaleIds.includes(action.id)){
+        const inx = res.wholeAssess.findIndex((it)=>{
+          subInx = it.details.findIndex((i)=>{
+            return i.type==1&&i.content.conceptId==action.id;
+          });
+          return subInx!=-1;
+        });
+        const trueInx = res.wholeIndexs[inx].findIndex((i)=>i==subInx);
+        res.wholeIndexs[inx].splice(trueInx,1);
+      }else{
+        res.addedScaleIds.push(action.id);
+      }
       res.update1 = Math.random();
       return res;
     case REMOVE_ASSESS_ITEMS: