Browse Source

edit 规则维护 :功能完成,未测试

reaper 4 years ago
parent
commit
fbb1b7e0e1

+ 275 - 42
src/components/knowledgeExtra/AddNewRule.vue

@@ -24,6 +24,11 @@
   .el-select {
     width: 100%;
   }
+  .tip_text {
+    margin-top: -8px;
+    font-size: 12px;
+    color: red;
+  }
 }
 </style>
 <template>
@@ -34,7 +39,7 @@
       linkTo="ZskRuleManager"
     ></crumbs>
     <div class="AddRuleContent">
-      <el-form ref="form" size="mini" :model="form" :rules="rules">
+      <el-form size="mini" :model="form" :rules="rules" ref="ruleForm">
         <div class="table_form">
           <!-- 规则名称 -->
           <el-form-item
@@ -65,9 +70,9 @@
               >
               </el-option>
             </el-select>
-            <!-- <div class="tip-text">
+            <div class="tip_text">
               注:更改规则类型,将会清空已填写的规则内容~
-            </div> -->
+            </div>
           </el-form-item>
           <!-- 规则术语类型: -->
           <el-form-item
@@ -89,9 +94,9 @@
               >
               </el-option>
             </el-select>
-            <!-- <div class="tip-text">
+            <div class="tip_text">
               注:更改规则术语类型,将会清空已填写的规则内容~
-            </div> -->
+            </div>
           </el-form-item>
           <!-- 医学标准术语 -->
           <el-form-item
@@ -106,6 +111,7 @@
               remote
               :remote-method="searchConcept"
               v-model.trim="form.parConceptId"
+              @change="parConceptIdChange"
             >
               <el-option
                 v-for="item in conceptList"
@@ -150,16 +156,21 @@
         </div>
         <!-- 表格 -->
         <AddNewRuleTable
-          v-if="form.parHasSub === 1"
-          :klRuleInfoSaveSub="form.klRuleInfoSaveSub"
-          :baseTermTypeList="baseTermTypeList"
+          v-if="form.parHasSub"
+          :klRuleByIdSub="form.klRuleByIdSub"
           :maxNum="subRuleMaxNum"
           @subTypeChange="subTypeChange"
           @searchConcept="searchConcept"
           @addGroup="addGroup"
           @delGroup="delGroup"
           @delGroupChild="delGroupChild"
+          @setFormData="setFormData"
         />
+        <el-form-item>
+          <el-button type="primary" @click="submitForm('ruleForm')"
+            >立即创建</el-button
+          >
+        </el-form-item>
       </el-form>
     </div>
   </div>
@@ -182,6 +193,7 @@ export default {
       isCopy: false,
       parId: null,
       msgDict: "", //显示附加信息的类型
+      firstPlace: null,
       form: {
         parDescription: "",
         parRuleType: "",
@@ -191,7 +203,7 @@ export default {
         parHasSub: undefined,
         parLenCode: "",
         parMsg: "",
-        klRuleInfoSaveSub: []
+        klRuleByIdSub: []
       },
       rules: formRules
     };
@@ -205,15 +217,120 @@ export default {
       this.parId = info.parId;
       this.isCopy = param.copy;
       this.title = "规则维护-" + (this.isCopy ? "复制" : "修改") + "规则";
+      this.form = JSON.parse(JSON.stringify(info));
+      // 编辑初始化选择框
+      this.initEdidData();
     }
   },
-  computed: {},
   methods: {
+    // 编辑初始化
+    async initEdidData() {
+      // 规则术语类型初始化
+      const newruleTermTypeList = await this.ruleTypeList.find(
+        (it) => it.id == this.form.parRuleType
+      );
+      this.ruleTermTypeList = await newruleTermTypeList.subMenuList;
+      // 基础规则类型初始化
+      const obj = await this.ruleTermTypeList.find(
+        (it1) => it1.code == this.form.parLenCode
+      );
+      this.baseTypeList = obj.subMenuList;
+      this.subRuleMaxNum = obj.number;
+
+      this.conceptList = [
+        { conceptName: this.form.parlibName, conceptId: this.form.parConceptId }
+      ];
+      if (this.form.parConceptId && this.checkFirstPlace && this.conceptList) {
+        console.log("this.conceptList", this.conceptList);
+        this.firstPlace = this.conceptList.find(
+          (it) => it.conceptId === this.form.parConceptId
+        );
+        console.log("firstPlace", this.firstPlace);
+        if (this.firstPlace) {
+          this.firstPlace["checkedType"] = this.ruleTermCodeStr;
+        }
+      } else if (!this.form.parConceptId) {
+        this.setInitGroupData();
+        this.firstPlace = null;
+      } else {
+        this.firstPlace = null;
+      }
+      await this.form.klRuleByIdSub.forEach((item, i, arr) => {
+        item.groupId = "groupId" + item.groupType;
+        item.groupChildId = "child" + item.subId;
+        //TODO => 赋值时一定要注意set更新页面
+        this.$set(item, "baseTypes", [...this.baseTypeList]);
+        this.$set(
+          item,
+          "baseTermTypeList",
+          item.baseTypes.find((it2) => it2.type === item.subType).subMenuList
+        );
+        this.$set(item, "conceptList", [
+          {
+            conceptName: item.subLibName || item.subConceptName,
+            conceptId: item.subConceptId
+          }
+        ]);
+        if (item.subMaxOperator || item.subMinOperator) {
+          item.dataType = "1";
+        } else if (item.subEqValue) {
+          item.dataType = "2";
+        }
+
+        // disable
+        console.log(this.form.parHasSub, 1312321, this.firstPlace);
+        if (arr[i - 1] && arr[i - 1].groupId == item.groupId) {
+          this.$set(item, "disabled", false);
+        } else {
+          this.$set(item, "disabled", true);
+        }
+      });
+    },
+    // 提交
+    submitForm(formName) {
+      this.$refs[formName].validate((valid) => {
+        if (valid) {
+          let params = JSON.parse(JSON.stringify(this.form));
+          params.klRuleInfoSaveSub = params.klRuleByIdSub;
+          delete params.klRuleByIdSub;
+          params.klRuleInfoSaveSub.forEach((item, i, arr) => {
+            if (i === 0) {
+              item.groupType = 1;
+            } else {
+              if (item.groupId == arr[i - 1].groupId) {
+                item.groupType = arr[i - 1].groupType;
+              } else {
+                item.groupType = arr[i - 1].groupType + 1;
+              }
+            }
+          });
+          params.klRuleInfoSaveSub.forEach((ite) => {
+            delete ite.groupId;
+            delete ite.groupChildId;
+            delete ite.baseTypes;
+            delete ite.baseTermTypeList;
+            delete ite.conceptList;
+          });
+          if (this.parId) {
+            params.parId = this.isCopy ? undefined : this.parId;
+            params.parStatus = this.isCopy ? 1 : this.form.parStatus;
+          }
+          console.log(params);
+          this.saveRule(params);
+        } else {
+          return false;
+        }
+      });
+    },
+    // 子集修改父级的数组
+    setFormData(index, data) {
+      this.form.klRuleByIdSub[index].conceptList = data;
+    },
     // table_form 规则类型选中
     ruleTypeChange(val) {
       this.form.parLenCode = "";
       this.form.parMsg = "";
-      const obj = this.ruleTypeList.find((it) => it.id === val); //console.log('???',val,obj)
+      const obj = this.ruleTypeList.find((it) => it.id === val);
       this.ruleTermTypeList = obj.subMenuList;
       this.subRuleMaxNum = undefined;
       this.setInitGroupData();
@@ -225,18 +342,66 @@ export default {
       this.form.parLenName = obj.name;
       this.baseTypeList = obj.subMenuList;
       this.subRuleMaxNum = obj.number;
-      this.setInitGroupData();
       this.form.parHasSub = obj.subMenuList.length ? 1 : 0;
+      this.setInitGroupData();
+    },
+    // 医学标准术语
+    parConceptIdChange(val) {
+      console.log(this.form.klRuleByIdSub);
+      this.$nextTick(() => {
+        if (val && this.checkFirstPlace && this.conceptList) {
+          console.log("this.conceptList", this.conceptList);
+          this.firstPlace = this.conceptList.find((it) => it.conceptId === val);
+          console.log("firstPlace", this.firstPlace);
+          if (this.firstPlace) {
+            this.firstPlace["checkedType"] = this.ruleTermCodeStr;
+          }
+        } else if (!val) {
+          this.setInitGroupData();
+          this.firstPlace = null;
+        } else {
+          this.firstPlace = null;
+        }
+        if (this.form.parHasSub && this.firstPlace) {
+          const dict =
+            localStorage
+              .getItem("zskDicts")
+              .match(new RegExp(this.firstPlace.checkedType + "-\\d+", "g")) ||
+            [];
+          const types = dict[0].split("-");
+          let obj = this.form.klRuleByIdSub;
+          obj.forEach((item, i, arr) => {
+            if (arr[i - 1] && arr[i - 1].groupId == item.groupId) {
+              this.$set(item, "disabled", false);
+            } else {
+              this.$set(item, "disabled", true);
+              this.$set(item, "subType", parseInt(types[2]));
+              const subobj = this.baseTypeList.find(
+                (it) => it.type == types[2]
+              );
+              console.log("adwafvadc", subobj);
+              this.$set(item, "baseTermTypeList", subobj.subMenuList);
+              this.$set(item, "subLenCode", types[1]);
+              this.$set(item, "subDescription", this.firstPlace.conceptName);
+              this.$set(item, "subConceptId", this.firstPlace.conceptId);
+              this.$set(item, "subConceptName", this.firstPlace.conceptName);
+              this.$set(item, "conceptList", [this.firstPlace]);
+            }
+          });
+          this.$set(this.form, "klRuleByIdSub", obj);
+        }
+      });
     },
     // 初始化表格
     setInitGroupData() {
       const date = new Date().valueOf();
-      this.form.klRuleInfoSaveSub = [
+      this.$set(this.form, "klRuleByIdSub", [
         {
           groupId: date,
           groupChildId: "child" + new Date().valueOf(),
           baseTypes: this.baseTypeList,
           baseTermTypeList: [],
+          conceptList: [],
           subDescription: "",
           parRuleType: "",
           subConceptId: "",
@@ -251,44 +416,41 @@ export default {
           subLenCode: "",
           dataType: ""
         }
-      ];
+      ]);
       this.form.parConceptId = ""; //医学标准术语清空
       this.conceptList = []; //下拉列表清空
     },
     // 有无子条件切换
     hasSubChange(val) {
       if (val) {
-        console.log(val);
         this.setInitGroupData();
       } else {
-        this.form.klRuleInfoSaveSub = [];
+        this.form.klRuleByIdSub = [];
       }
     },
     // 基础规则类型切换
     subTypeChange(val, index) {
       // index
       const obj = this.baseTypeList.find((it) => it.type === val);
-      console.log("subMenuList", obj.subMenuList);
-      console.log("baseTermTypeList", this.form.klRuleInfoSaveSub[index]);
-      this.form.klRuleInfoSaveSub[index].baseTermTypeList = obj.subMenuList;
-      this.form.klRuleInfoSaveSub[index].subLenCode = "";
-      this.form.klRuleInfoSaveSub[index].dataType = "";
+      this.form.klRuleByIdSub[index].baseTermTypeList = obj.subMenuList;
+      this.form.klRuleByIdSub[index].subLenCode = "";
+      this.form.klRuleByIdSub[index].dataType = "";
       this.clearConcept(index);
       this.clearNumText(index);
     },
     clearConcept(index) {
-      this.form.klRuleInfoSaveSub[index].subConceptId = "";
+      this.form.klRuleByIdSub[index].subConceptId = "";
       this.conceptList = [];
     },
     clearNumText(index) {
-      this.form.klRuleInfoSaveSub[index].subMaxOperator = "";
-      this.form.klRuleInfoSaveSub[index].subMaxValue = "";
-      this.form.klRuleInfoSaveSub[index].subMaxUnit = "";
-      this.form.klRuleInfoSaveSub[index].subMinOperator = "";
-      this.form.klRuleInfoSaveSub[index].subMinValue = "";
-      this.form.klRuleInfoSaveSub[index].subMinUnit = "";
-      this.form.klRuleInfoSaveSub[index].subEqValue = "";
-      this.form.klRuleInfoSaveSub[index].subEqOperator = "";
+      this.form.klRuleByIdSub[index].subMaxOperator = "";
+      this.form.klRuleByIdSub[index].subMaxValue = "";
+      this.form.klRuleByIdSub[index].subMaxUnit = "";
+      this.form.klRuleByIdSub[index].subMinOperator = "";
+      this.form.klRuleByIdSub[index].subMinValue = "";
+      this.form.klRuleByIdSub[index].subMinUnit = "";
+      this.form.klRuleByIdSub[index].subEqValue = "";
+      this.form.klRuleByIdSub[index].subEqOperator = "";
     },
     // 添加分组 || 规则
     addGroup(date, arg = { index: null, groupId: null }) {
@@ -303,6 +465,7 @@ export default {
         groupChildId: "child" + new Date().valueOf(),
         baseTypes: this.baseTypeList,
         baseTermTypeList: [],
+        conceptList: [],
         subDescription: "",
         parRuleType: "",
         subConceptId: "",
@@ -319,34 +482,52 @@ export default {
       };
       if (typeof arg.index == "number") {
         // 添加规则 直接在当前位置之后添加
-        this.form.klRuleInfoSaveSub.splice(arg.index + 1, 0, obj);
+        this.form.klRuleByIdSub.splice(arg.index + 1, 0, obj);
       } else {
         // 添加分组 在列表中相同groupId之后添加
+        // 添加分组时判断是否需要加disabled和添加默认值
+
+        if (this.form.parHasSub && this.firstPlace) {
+          obj.disabled = true;
+          const dict =
+            localStorage
+              .getItem("zskDicts")
+              .match(new RegExp(this.firstPlace.checkedType + "-\\d+", "g")) ||
+            [];
+          const types = dict[0].split("-");
+          this.$set(obj, "disabled", true);
+          this.$set(obj, "subType", parseInt(types[2]));
+          const subobj = this.baseTypeList.find((it) => it.type == types[2]);
+          console.log("adwafvadc", subobj);
+          this.$set(obj, "baseTermTypeList", subobj.subMenuList);
+          this.$set(obj, "subLenCode", types[1]);
+          this.$set(obj, "subDescription", this.firstPlace.conceptName);
+          this.$set(obj, "subConceptId", this.firstPlace.conceptId);
+          this.$set(obj, "subConceptName", this.firstPlace.conceptName);
+          this.$set(obj, "conceptList", [this.firstPlace]);
+        }
         var i = -1;
-        this.form.klRuleInfoSaveSub.forEach((item, inx) => {
-          console.log("look", item.groupId, arg.groupId);
+        this.form.klRuleByIdSub.forEach((item, inx) => {
           if (item.groupId === arg.groupId) {
             i = inx;
           }
         });
-        console.log("inx", i);
-        this.form.klRuleInfoSaveSub.splice(i + 1, 0, obj);
+        this.form.klRuleByIdSub.splice(i + 1, 0, obj);
       }
     },
     // 删除分组
     delGroup(groupId) {
-      console.log("groupId", groupId);
-      const list = this.form.klRuleInfoSaveSub.filter(
+      const list = this.form.klRuleByIdSub.filter(
         (item) => item.groupId != groupId
       );
-      this.form.klRuleInfoSaveSub = list;
+      this.form.klRuleByIdSub = list;
     },
     // 删除规则
     delGroupChild(groupChildId) {
-      const newGroupList = this.form.klRuleInfoSaveSub.filter(
+      const newGroupList = this.form.klRuleByIdSub.filter(
         (item) => item.groupChildId != groupChildId
       );
-      this.form.klRuleInfoSaveSub = newGroupList;
+      this.form.klRuleByIdSub = newGroupList;
     },
     setDict() {
       this.dict = localStorage.getItem("zskDicts");
@@ -383,7 +564,6 @@ export default {
     },
     getTypeList() {
       this.ruleTypeList = JSON.parse(localStorage.getItem("zskTypesList"));
-      console.log("ruleTypeList", this.ruleTypeList);
     },
     saveRule(params) {
       api.saveRule(params).then((res) => {
@@ -406,6 +586,9 @@ export default {
     }
   },
   computed: {
+    disable: function () {
+      return Object.keys(this.firstPlace || {}).length > 0;
+    },
     ruleTermCodeStr: function () {
       return this.form.parRuleType + "-" + this.form.parLenCode;
     },
@@ -417,12 +600,16 @@ export default {
     },
     showHasSub() {
       return this.subDict.indexOf(this.ruleTermCodeStr) > -1;
+    },
+    checkFirstPlace: function () {
+      return this.dict.indexOf(this.ruleTermCodeStr) > -1;
     }
   },
   watch: {
     // "form.parRuleType": function (val) {
     //   const obj = this.ruleTypeList.find((it) => it.id === val);
     //   this.ruleTermTypeList = obj.subMenuList;
+    //   console.log("this.ruleTermTypeList", this.ruleTermTypeList);
     // },
     // "form.parLenCode": function (val) {
     //   if (!val) {
@@ -433,9 +620,55 @@ export default {
     //   this.baseTypeList = obj.subMenuList;
     //   this.subRuleMaxNum = obj.number;
     // },
+    // firstPlace: {
+    //   handler: function (val) {
+    //     console.log(val);
+    //     console.log(this.form.klRuleByIdSub);
+    //     if (!val) return;
+    //     const dict =
+    //       localStorage
+    //         .getItem("zskDicts")
+    //         .match(new RegExp(val.checkedType + "-\\d+", "g")) || [];
+    //     const types = dict[0].split("-");
+    //     console.log('types',types);
+    //     this.form.klRuleByIdSub.forEach((item,i,arr)=>{
+    //       if (!arr[i - 1]) {
+    //           // item.disabled = true;
+    //           this.$set(item, "subType", parseInt(types[2]));
+    //           this.$set(item, "subLenCode", types[1]);
+    //           this.$set(item, "subDescription", val.conceptName);
+    //           this.$set(item, "subConceptId", val.conceptId);
+    //           this.$set(item, "subConceptName", val.conceptName);
+    //           this.$set(item, "conceptList", [val]);
+    //         }
+    //     })
+    //   },
+    //   deep: true
+    // },
     // "form.parConceptId": function (val) {
+    //   // setTimeout(() => {
+    //     if (val && this.checkFirstPlace && this.conceptList) {
+    //       console.log("this.conceptList", this.conceptList);
+    //       this.firstPlace = this.conceptList.find((it) => it.conceptId === val);
+    //       console.log("firstPlace", this.firstPlace);
+    //       if (this.firstPlace) {
+    //         this.firstPlace["checkedType"] = this.ruleTermCodeStr;
+    //       }
+    //     } else if (!val) {
+    //       this.setInitGroupData();
+    //       this.firstPlace = null;
+    //     } else {
+    //       this.firstPlace = null;
+    //     }
+    //   // }, 500);
+    // }
+  },
+  mounted() {
+    // this.$watch("form.parConceptId", function (val) {
     //   if (val && this.checkFirstPlace && this.conceptList) {
+    //     console.log("this.conceptList", this.conceptList);
     //     this.firstPlace = this.conceptList.find((it) => it.conceptId === val);
+    //     console.log("firstPlace", this.firstPlace);
     //     this.firstPlace["checkedType"] = this.ruleTermCodeStr;
     //   } else if (!val) {
     //     this.setInitGroupData();
@@ -443,7 +676,7 @@ export default {
     //   } else {
     //     this.firstPlace = null;
     //   }
-    // }
+    // });
   },
   components: { AddNewRuleTable }
 };

+ 178 - 173
src/components/knowledgeExtra/AddNewRuleTable.vue

@@ -29,7 +29,7 @@
     }
   }
   .inp_box {
-    width: 100px;
+    // width: 100px;
     height: 100%;
     margin: 0 auto;
   }
@@ -42,20 +42,33 @@
     display: flex;
     // flex-wrap: wrap;
     .type_content_item {
+      padding: 10px 0;
       // flex: 1;
       // min-width: 200px;
     }
   }
+  .custom_table_header {
+    vertical-align: middle;
+    &::before {
+      content: "*";
+      color: red;
+      font-size: 12px;
+      margin-right: 4px;
+    }
+  }
+  /deep/ .el-form-item__error {
+    position: relative;
+  }
 }
 </style>
 
 <template>
-  <!-- :prop="`klRuleInfoSaveSub[${scope.$index}].subDescription`" -->
+  <!-- :prop="`klRuleByIdSub[${scope.$index}].subDescription`" -->
   <div class="AddNewRuleTable">
-    <h4 style="marginBottom:20px">规则内容</h4>
+    <h4 style="marginbottom: 20px">规则内容</h4>
     <el-table
       border
-      :data="klRuleInfoSaveSub"
+      :data="klRuleByIdSub"
       style="width: 100%"
       size="mini"
       stripe
@@ -103,7 +116,7 @@
             <div class="btn_div">
               <img
                 @click="$emit('delGroupChild', scope.row.groupChildId)"
-                v-if="klRuleInfoSaveSub.length > 1"
+                v-if="klRuleByIdSub.length > 1 && !scope.row.disabled"
                 src="../../images/add-new-rule-del.png"
                 alt=""
               />
@@ -111,15 +124,19 @@
           </div>
         </template>
       </el-table-column>
-      <el-table-column width="170px" label="基础规则名称" prop="subDescription">
+      <el-table-column width="170px" prop="subDescription">
+        <template slot="header" slot-scope="scope">
+          <div class="custom_table_header">基础规则名称</div>
+        </template>
         <template slot-scope="scope">
           <el-form-item
             class="inp_box"
-            :prop="`klRuleInfoSaveSub[${scope.$index}].subDescription`"
+            :prop="`klRuleByIdSub[${scope.$index}].subDescription`"
             :rules="rules.subDescription"
           >
             <el-input
               type="text"
+              :disabled="scope.row.disabled"
               v-model="scope.row.subDescription"
               clearable
               placeholder="请输入"
@@ -127,15 +144,19 @@
           </el-form-item>
         </template>
       </el-table-column>
-      <el-table-column width="170px" label="基础规则类型" prop="subType">
+      <el-table-column width="170px" prop="subType">
+        <template slot="header" slot-scope="scope">
+          <div class="custom_table_header">基础规则类型</div>
+        </template>
         <template slot-scope="scope">
           <el-form-item
             class="inp_box"
-            :prop="`klRuleInfoSaveSub[${scope.$index}].subType`"
+            :prop="`klRuleByIdSub[${scope.$index}].subType`"
             :rules="rules.subType"
           >
             <el-select
               v-model="scope.row.subType"
+              :disabled="scope.row.disabled"
               placeholder="请选择"
               @change="subTypeChange($event, scope.$index)"
             >
@@ -150,14 +171,18 @@
           </el-form-item>
         </template>
       </el-table-column>
-      <el-table-column width="170px" label="基础规则术语类型" prop="subLenCode">
+      <el-table-column width="170px" prop="subLenCode">
+        <template slot="header" slot-scope="scope">
+          <div class="custom_table_header">基础规则术语类型</div>
+        </template>
         <template slot-scope="scope">
           <el-form-item
             class="inp_box"
-            :prop="`klRuleInfoSaveSub[${scope.$index}].subLenCode`"
+            :prop="`klRuleByIdSub[${scope.$index}].subLenCode`"
             :rules="rules.subLenCode"
           >
             <el-select
+              :disabled="scope.row.disabled"
               v-model="scope.row.subLenCode"
               placeholder="请选择"
               @change="subCodeChange($event, scope.$index)"
@@ -174,22 +199,26 @@
         </template>
       </el-table-column>
       <el-table-column width="170px" label="医学标准术语" prop="subConceptId">
+        <template slot="header" slot-scope="scope">
+          <div class="custom_table_header">医学标准术语</div>
+        </template>
         <template slot-scope="scope">
           <el-form-item
             class="inp_box"
-            :prop="`klRuleInfoSaveSub[${scope.$index}].subConceptId`"
+            :prop="`klRuleByIdSub[${scope.$index}].subConceptId`"
             :rules="rules.subConceptId"
           >
             <el-select
               clearable
               remote
               filterable
+              :disabled="scope.row.disabled"
               @focus="subConceptIdfocus(scope.$index)"
               :remote-method="searchConcept"
               v-model.trim="scope.row.subConceptId"
             >
               <el-option
-                v-for="item in conceptList"
+                v-for="item in scope.row.conceptList"
                 :key="item.conceptId"
                 :label="item.conceptName"
                 :value="item.conceptId"
@@ -204,18 +233,23 @@
           <div class="type_content">
             <el-form-item
               class="type_content_item"
-              style="width:240px;marginRight:20px"
+              style="width: 240px; marginright: 20px"
               label="选择类型:"
               label-width="100px"
-              :prop="`klRuleInfoSaveSub[${scope.$index}].dataType`"
+              :prop="`klRuleByIdSub[${scope.$index}].dataType`"
               :rules="rules.dataType"
+              v-if="scope.row.subType === 2 && showDataType(scope.$index)"
             >
-              <el-select v-model="scope.row.dataType" placeholder="请选择">
+              <el-select
+                v-model="scope.row.dataType"
+                placeholder="请选择"
+                @change="dataTypeChange($event, scope.$index)"
+              >
                 <el-option label="数值类型" value="1"> </el-option>
                 <el-option label="文本类型" value="2"> </el-option>
               </el-select>
             </el-form-item>
-            <!-- v-if="klRuleInfoSaveSub[scope.$index].dataType === '1'" -->
+            <!-- v-if="klRuleByIdSub[scope.$index].dataType === '1'" -->
             <el-form-item
               class="type_content_item"
               style="flex: 2"
@@ -225,26 +259,11 @@
               <div>
                 <el-col :span="6">
                   <el-form-item
-                    :prop="`klRuleInfoSaveSub[${scope.$index}].subMaxOperator`"
+                    :prop="`klRuleByIdSub[${scope.$index}].subMaxOperator`"
                     :rules="[
                       {
                         validator: (rule, value, callback) => {
-                          const {
-                            subMaxValue,
-                            subMinOperator,
-                            subMinValue
-                          } = scope.row;
-                          const val =
-                            value + subMinOperator + subMinValue + subMaxValue;
-                          if (!val || (!value && subMaxValue !== '')) {
-                            callback(
-                              new Error(
-                                '最大值和最小值至少完整填写一个,单位不必填'
-                              )
-                            );
-                          } else {
-                            callback();
-                          }
+                          subMaxOperator(scope, rule, value, callback);
                         },
                         trigger: 'blur'
                       }
@@ -267,32 +286,11 @@
                 </el-col>
                 <el-col :span="6">
                   <el-form-item
-                    :prop="`klRuleInfoSaveSub[${scope.$index}].subMaxValue`"
+                    :prop="`klRuleByIdSub[${scope.$index}].subMaxValue`"
                     :rules="[
                       {
                         validator: (rule, value, callback) => {
-                          const {
-                            subMaxOperator,
-                            subMinOperator,
-                            subMinValue
-                          } = scope.row;
-                          const val =
-                            value +
-                            subMaxOperator +
-                            subMinValue +
-                            subMinOperator;
-                          const isNum = /^(\-|\+)?\d+(\.\d+)?$/.test(value);
-                          if (!val || (value == '' && subMaxOperator)) {
-                            callback(
-                              new Error(
-                                '最大值和最小值至少完整填写一个,单位不必填'
-                              )
-                            );
-                          } else if (value !== '' && !isNum) {
-                            callback(new Error('只能输入数字'));
-                          } else {
-                            callback();
-                          }
+                          subMaxValue(scope, rule, value, callback);
                         },
                         trigger: 'blur'
                       }
@@ -307,7 +305,7 @@
                 </el-col>
                 <el-col :span="6">
                   <el-form-item
-                    :prop="`klRuleInfoSaveSub[${scope.$index}].subMaxUnit`"
+                    :prop="`klRuleByIdSub[${scope.$index}].subMaxUnit`"
                     :rules="rules.subMaxUnit"
                   >
                     <el-input
@@ -328,31 +326,11 @@
               <div class="select-item clearfix">
                 <el-col :span="6">
                   <el-form-item
-                    :prop="`klRuleInfoSaveSub[${scope.$index}].subMinOperator`"
+                    :prop="`klRuleByIdSub[${scope.$index}].subMinOperator`"
                     :rules="[
                       {
                         validator: (rule, value, callback) => {
-                          const {
-                            subMaxValue,
-                            subMaxOperator,
-                            subMinValue
-                          } = scope.row;
-                          const val =
-                            value + subMaxOperator + subMinValue + subMaxValue;
-                          if (
-                            !val ||
-                            (!value &&
-                              subMinValue !==
-                                '最大值和最小值至少完整填写一个,单位不必填')
-                          ) {
-                            callback(
-                              new Error(
-                                '最大值和最小值至少完整填写一个,单位不必填'
-                              )
-                            );
-                          } else {
-                            callback();
-                          }
+                          subMinOperatorRule(scope, rule, value, callback);
                         },
                         trigger: 'blur'
                       }
@@ -375,32 +353,11 @@
                 </el-col>
                 <el-col :span="6">
                   <el-form-item
-                    :prop="`klRuleInfoSaveSub[${scope.$index}].subMinValue`"
+                    :prop="`klRuleByIdSub[${scope.$index}].subMinValue`"
                     :rules="[
                       {
                         validator: (rule, value, callback) => {
-                          const {
-                            subMaxValue,
-                            subMinOperator,
-                            subMaxOperator
-                          } = scope.row;
-                          const val =
-                            value +
-                            subMaxOperator +
-                            subMaxValue +
-                            subMinOperator;
-                          const isNum = /^(\-|\+)?\d+(\.\d+)?$/.test(value);
-                          if (!val || (value == '' && subMinOperator)) {
-                            callback(
-                              new Error(
-                                '最大值和最小值至少完整填写一个,单位不必填'
-                              )
-                            );
-                          } else if (value !== '' && !isNum) {
-                            callback(new Error('只能输入数字'));
-                          } else {
-                            callback();
-                          }
+                          subMinValueRule(scope, rule, value, callback);
                         },
                         trigger: 'blur'
                       }
@@ -415,7 +372,7 @@
                 </el-col>
                 <el-col :span="6">
                   <el-form-item
-                    :prop="`klRuleInfoSaveSub[${scope.$index}].subMinUnit`"
+                    :prop="`klRuleByIdSub[${scope.$index}].subMinUnit`"
                     :rules="rules.subMinUnit"
                   >
                     <el-input
@@ -427,26 +384,18 @@
                 </el-col>
               </div>
             </el-form-item>
-            <!-- v-if="klRuleInfoSaveSub[scope.$index].subType !== 6 && klRuleInfoSaveSub[scope.$index].dataType === '2'" -->
+            <!-- v-if="klRuleByIdSub[scope.$index].subType !== 6 && klRuleByIdSub[scope.$index].dataType === '2'" -->
             <el-form-item
               class="type_content_item"
               style="flex: 2"
               v-if="scope.row.subType !== 6 && scope.row.dataType === '2'"
               label="医学内容:"
               label-width="100px"
-              :prop="`klRuleInfoSaveSub[${scope.$index}].subEqValue`"
+              :prop="`klRuleByIdSub[${scope.$index}].subEqValue`"
               :rules="[
                 {
                   validator: (rule, value, callback) => {
-                    if (value === '') {
-                      callback(new Error('请输入' + textName(scope.$index)));
-                    } else if (value.length > 200) {
-                      callback(
-                        new Error(textName(scope.$index) + '不能超过200字')
-                      );
-                    } else {
-                      callback();
-                    }
+                    subEqValue(scope, rule, value, callback);
                   },
                   trigger: 'blur'
                 }
@@ -463,19 +412,14 @@
             <el-form-item
               class="type_content_item"
               label="正则表达式:"
+              label-width="120px"
               style="flex: 2"
               v-if="scope.row.subType === 6"
-              :prop="`klRuleInfoSaveSub[${scope.$index}].subEqValue`"
+              :prop="`klRuleByIdSub[${scope.$index}].subEqValue`"
               :rules="[
                 {
                   validator: (rule, value, callback) => {
-                    if (value === '') {
-                      callback(new Error('请输入' + this.textName));
-                    } else if (value.length > 200) {
-                      callback(new Error(this.textName + '不能超过200字'));
-                    } else {
-                      callback();
-                    }
+                    subEqValuerule(scope, rule, value, callback);
                   },
                   trigger: 'blur'
                 }
@@ -502,7 +446,6 @@ export default {
   name: "AddNewRuleTable",
   data() {
     return {
-      conceptList: [],
       numTypes: "",
       subConceptIdIndex: "",
       operMaxList: [
@@ -517,18 +460,86 @@ export default {
     };
   },
   methods: {
+    // 最大值 选择rule
+    subMaxOperator(scope, rule, value, callback) {
+      const { subMaxValue, subMinOperator, subMinValue } = scope.row;
+      const val = value + subMinOperator + subMinValue + subMaxValue;
+      if (!val || (!value && subMaxValue !== "")) {
+        callback(new Error("最大值和最小值至少完整填写一个,单位不必填"));
+      } else {
+        callback();
+      }
+    },
+    // 最大值 数值rule
+    subMaxValue(scope, rule, value, callback) {
+      const { subMaxOperator, subMinOperator, subMinValue } = scope.row;
+      const val = value + subMaxOperator + subMinValue + subMinOperator;
+      const isNum = /^(\-|\+)?\d+(\.\d+)?$/.test(value);
+      if (!val || (value == "" && subMaxOperator)) {
+        callback(new Error("最大值和最小值至少完整填写一个,单位不必填"));
+      } else if (value !== "" && !isNum) {
+        callback(new Error("只能输入数字"));
+      } else {
+        callback();
+      }
+    },
+    // 最小值 选择rule
+    subMinOperatorRule(scope, rule, value, callback) {
+      const { subMaxValue, subMaxOperator, subMinValue } = scope.row;
+      const val = value + subMaxOperator + subMinValue + subMaxValue;
+      if (
+        !val ||
+        (!value && subMinValue !== "最大值和最小值至少完整填写一个,单位不必填")
+      ) {
+        callback(new Error("最大值和最小值至少完整填写一个,单位不必填"));
+      } else {
+        callback();
+      }
+    },
+    // 最小值 数值rule
+    subMinValueRule(scope, rule, value, callback) {
+      const { subMaxValue, subMinOperator, subMaxOperator } = scope.row;
+      const val = value + subMaxOperator + subMaxValue + subMinOperator;
+      const isNum = /^(\-|\+)?\d+(\.\d+)?$/.test(value);
+      if (!val || (value == "" && subMinOperator)) {
+        callback(new Error("最大值和最小值至少完整填写一个,单位不必填"));
+      } else if (value !== "" && !isNum) {
+        callback(new Error("只能输入数字"));
+      } else {
+        callback();
+      }
+    },
+    // 医学内容rule
+    subEqValue(scope, rule, value, callback) {
+      if (value === "") {
+        callback(new Error("请输入" + this.textName(scope.$index)));
+      } else if (value.length > 200) {
+        callback(new Error(this.textName(scope.$index) + "不能超过200字"));
+      } else {
+        callback();
+      }
+    },
+    // 正则rule
+    subEqValuerule(scope, rule, value, callback) {
+      if (value === "") {
+        callback(new Error("请输入" + this.textName));
+      } else if (value.length > 200) {
+        callback(new Error(this.textName + "不能超过200字"));
+      } else {
+        callback();
+      }
+    },
     // 判断是否为最后一条规则
     isLastDate(id) {
-      const tableLength = this.klRuleInfoSaveSub.filter(
+      const tableLength = this.klRuleByIdSub.filter(
         (item) => item.groupId !== id
       ).length;
       return tableLength === 0;
     },
     // 是否超出最大规则数
     isMax(id) {
-      const typeNum = this.klRuleInfoSaveSub.filter(
-        (item) => item.groupId === id
-      ).length;
+      const typeNum = this.klRuleByIdSub.filter((item) => item.groupId === id)
+        .length;
       return typeNum >= this.maxNum;
     },
     // 基础规则类型选择
@@ -539,26 +550,26 @@ export default {
     subCodeChange(val, index) {
       //基础规则术语类型修改
       if ((this.numTypes + ",").indexOf(val + ",") > -1) {
-        this.klRuleInfoSaveSub[index].dataType = "1";
+        this.klRuleByIdSub[index].dataType = "1";
       } else {
-        this.klRuleInfoSaveSub[index].dataType = "";
+        this.klRuleByIdSub[index].dataType = "";
       }
       this.clearConcept(index);
       this.clearNumText(index);
     },
     clearConcept(index) {
-      this.klRuleInfoSaveSub[index].subConceptId = "";
-      this.conceptList = [];
+      this.klRuleByIdSub[index].subConceptId = "";
+      this.klRuleByIdSub[index].conceptList = [];
     },
     clearNumText(index) {
-      this.klRuleInfoSaveSub[index].subMaxOperator = "";
-      this.klRuleInfoSaveSub[index].subMaxValue = "";
-      this.klRuleInfoSaveSub[index].subMaxUnit = "";
-      this.klRuleInfoSaveSub[index].subMinOperator = "";
-      this.klRuleInfoSaveSub[index].subMinValue = "";
-      this.klRuleInfoSaveSub[index].subMinUnit = "";
-      this.klRuleInfoSaveSub[index].subEqValue = "";
-      this.klRuleInfoSaveSub[index].subEqOperator = "";
+      this.klRuleByIdSub[index].subMaxOperator = "";
+      this.klRuleByIdSub[index].subMaxValue = "";
+      this.klRuleByIdSub[index].subMaxUnit = "";
+      this.klRuleByIdSub[index].subMinOperator = "";
+      this.klRuleByIdSub[index].subMinValue = "";
+      this.klRuleByIdSub[index].subMinUnit = "";
+      this.klRuleByIdSub[index].subEqValue = "";
+      this.klRuleByIdSub[index].subEqOperator = "";
     },
     //医学标准术语change
     subConceptIdfocus(index) {
@@ -567,11 +578,12 @@ export default {
     },
     // 医学标准术语
     searchConcept(val) {
+      console.log(val);
       const param = {
         excludedConceptIds: [
-          this.klRuleInfoSaveSub[this.subConceptIdIndex].subType
+          this.klRuleByIdSub[this.subConceptIdIndex].subType
         ],
-        libType: this.klRuleInfoSaveSub[this.subConceptIdIndex].subLenCode,
+        libType: this.klRuleByIdSub[this.subConceptIdIndex].subLenCode,
         name: val
       };
       api
@@ -579,13 +591,19 @@ export default {
         .then((res) => {
           if (res.data.code == "0") {
             const data = res.data.data;
-            this.conceptList = data;
+            this.$emit("setFormData", this.subConceptIdIndex, data);
           }
         })
         .catch((error) => {
           console.log(error);
         });
     },
+    dataTypeChange(val, index) {
+      this.klRuleByIdSub[index].subEqOperator = val === "2" ? "=" : "";
+      this.clearNumText(index);
+      delete this.klRuleByIdSub[index].dataType; //触发更新
+      this.$set(this.klRuleByIdSub[index], "dataType", val);
+    },
     // 处理要合并相同行的列
     getSpanArr(data) {
       this.spanArr = [];
@@ -625,56 +643,43 @@ export default {
           colspan: _col
         };
       }
-    }
-  },
-  components: {
+    },
     showDataType(index) {
       return (
         (this.numTypes + ",").indexOf(
-          this.klRuleInfoSaveSub[index].subLenCode + ","
+          this.klRuleByIdSub[index].subLenCode + ","
         ) === -1
       );
     },
     textName(index) {
-      return this.klRuleInfoSaveSub[index].subType !== 6 &&
-        this.klRuleInfoSaveSub[index].dataType === "2"
+      return this.klRuleByIdSub[index].subType !== 6 &&
+        this.klRuleByIdSub[index].dataType === "2"
         ? "医学内容"
         : "正则表达式";
     }
   },
+  components: {},
   created() {
     this.numTypes = localStorage.getItem("zskNumDict");
-    this.getSpanArr(this.klRuleInfoSaveSub);
+    this.getSpanArr(this.klRuleByIdSub);
     console.log("maxNum", this.maxNum);
+    console.log("c_created", this.klRuleByIdSub);
   },
   beforeUpdate() {
-    this.getSpanArr(this.klRuleInfoSaveSub);
+    this.getSpanArr(this.klRuleByIdSub);
+  },
+  watch: {
+    klRuleByIdSub: {
+      handler(val, old) {
+        console.log("afaw", val, old);
+      },
+      deep: true
+    }
   },
   props: {
-    klRuleInfoSaveSub: {
+    klRuleByIdSub: {
       type: Array,
       required: true
-      // subDescription: "",
-      // parRuleType: "",
-      // subConceptId: "",
-      // subType: "",
-      // subMaxOperator: "",
-      // subMaxUnit: "",
-      // subMaxValue: "",
-      // subMinOperator: "",
-      // subMinUnit: "",
-      // subMinValue: "",
-      // subEqValue: "",
-      // subLenCode: "",
-      // dataType: ""
-    },
-    // baseTypes: {
-    //   type: Array,
-    //   default: []
-    // },
-    baseTermTypeList: {
-      type: Array,
-      default: []
     },
     maxNum: {
       default: null

src/components/knowledgeExtra/SubConditions.vue → src/components/knowledgeExtra/_SubConditions.vue


+ 1 - 1
src/components/knowledgeExtra/SubRulesGroup.vue

@@ -29,7 +29,7 @@
   </div>
 </template>
 <script>
-import SubConditions from "./SubConditions.vue";
+import SubConditions from "./_SubConditions.vue";
 export default {
   name: "SubRulesGroup",
   props: ["data", "inx", "isLast", "baseTypes", "maxNum", "firstPlace"],