Browse Source

fixbug : findIdex is not defined

reaper 4 years ago
parent
commit
f4ca25392e
1 changed files with 8 additions and 5 deletions
  1. 8 5
      src/components/cdssManage/plan/AddPlan.vue

+ 8 - 5
src/components/cdssManage/plan/AddPlan.vue

@@ -460,7 +460,6 @@ export default {
               status: item.status
             };
           });
-          console.log("params", params);
           api.savePlanInfoDatas(params).then((res) => {
             if (res.data.code === "0") {
               this.$message({
@@ -615,18 +614,22 @@ export default {
           (ite) => ite.name === item.name
         );
         // 第一层数据不存在的话,直接加入进去
+
         if (oneIndex === -1) {
           item.status = 0;
           this.form.planDetailSub.push(item);
+        } else if (!this.form.planDetailSub[oneIndex].planDetails) {
+          this.form.planDetailSub[oneIndex].planDetails = item.planDetails;
         } else {
           // 第一层数据存在,验证第二层
           item.planDetails &&
             item.planDetails.forEach((child) => {
-              const childIndex = this.form.planDetailSub[
-                oneIndex
-              ].planDetails.findIndex((it) => it.name === child.name);
+              const twoArr = this.form.planDetailSub[oneIndex].planDetails;
+              const childIndex = twoArr
+                ? twoArr.findIndex((it) => it.name === child.name)
+                : null;
               // 第二层数据不存在,直接添加进去
-              if (childIndex === -1) {
+              if (childIndex && childIndex === -1) {
                 child.status = 0;
                 this.form.planDetailSub[oneIndex].planDetails.push(child);
               }