liucf %!s(int64=5) %!d(string=hai) anos
pai
achega
82982a2257
Modificáronse 4 ficheiros con 40 adicións e 81 borrados
  1. 7 36
      src/common/CheckBox.vue
  2. 8 40
      src/common/Radio.vue
  3. 3 4
      src/components/Detail.vue
  4. 22 1
      src/utils/tools.js

+ 7 - 36
src/common/CheckBox.vue

@@ -23,7 +23,7 @@
   </div>
 </template>
 <script type="text/javascript">
-import {imageUrlPrefix,patt} from '@utils/tools.js';
+import {imageUrlPrefix,patt,concatVal} from '@utils/tools.js';
 import icon from '../images/check-default.png';
 import checkIcon from '../images/check.png';
 import MultiLineInput from '../common/MultiLineInput.vue';
@@ -77,48 +77,19 @@ import OptionInp from '../common/OptionInp.vue';
             this.exclusion = filArr1[0].exclusion;
           }
         }
-        let value = ""; //医生
-        let valueP = ""; //患者
-        for(let k in data){
-          if(data[k].select==1){
-            // 选中该项时,带的输入框内有值则加上
-            if(data[k].value){
-              let newVal = '#{' + data[k].value + '}';
-              let str = data[k].name.replace(patt,newVal);
-              let strP = (data[k].description || data[k].name).replace(patt,newVal);
-              value += str + ',';
-              valueP += strP + ',';
-            }else{
-              value += data[k].name + ',';
-              valueP += (data[k].description || data[k].name) + ',';
-            }
-            
-          }
-        }
-        const newData = Object.assign({},this.datas,{questionDetailList:data},{value:value?value.substring(0,value.length-1):''},{valueP:valueP?valueP.substring(0,valueP.length-1):''});
+        let temp = concatVal(data);
+        const newData = Object.assign({},this.datas,{questionDetailList:data},{value:temp.value?temp.value.substring(0,temp.value.length-1):''},{valueP:temp.valueP?temp.valueP.substring(0,temp.valueP.length-1):''});
         this.$emit("updata",newData);
       },
       inpVal(val,index){//输入框失焦处理
-        let valueStr = this.datas.value;
-        if(valueStr){
-          // let patt = /\$\{[^\]]+\}/g;
-          let rePatt = /\#\{[^\]]+\}/g;
-          let newVal = '#{' +val+'}';
-          let str = "";
-          // 区分第一次输入还是修改
-          if(valueStr.indexOf("${") !== -1){
-            str = valueStr.replace(patt,newVal);
-          }else{//修改
-            str = valueStr.replace(rePatt,newVal);
-          }
-          this.datas.value = str;
-          this.datas.valueP = str;
-        }
-        
         // 输入框回读
         let detailList = this.datas.questionDetailList;
         let currItem = detailList[index];
         currItem.value = val;
+        // 输入框失焦重新拼接父级的value
+        let temp = concatVal(detailList);
+        this.datas.value = temp.value;
+        this.datas.valueP = temp.valueP;
         this.$emit("updata",this.datas);
       },
       resetExc(){

+ 8 - 40
src/common/Radio.vue

@@ -20,7 +20,7 @@
 <script type="text/javascript">
 import icon from '../images/radio-default.png'
 import checkIcon from '../images/radio-check.png'
-import {patt,imageUrlPrefix} from '@utils/tools.js'
+import {patt,imageUrlPrefix,concatVal} from '@utils/tools.js'
 import MultiLineInput from '../common/MultiLineInput.vue';
 import OptionInp from '../common/OptionInp.vue';
   export default{
@@ -40,59 +40,27 @@ import OptionInp from '../common/OptionInp.vue';
     },
     methods:{
       handleClick(it,index){
-        // let patt = /\$\{[^\]]+\}/g;
         const list = this.datas;
         let data = list.questionDetailList&&list.questionDetailList.slice(0); //数组深拷贝?
-        let value = "";
-        let valueP = "";
         for(let i=0;i<data.length; i++){
           data[i].select = 0
           if(i==index){
             data[i].select = 1;
-            // value = data[i].name;
-            // 选中该项时,带的输入框内有值则加上
-            if(data[i].value){
-              let newVal = '#{' + data[i].value + '}';
-              let str = data[i].name.replace(patt,newVal);//医生
-              let strP = (data[i].description ||data[i].name).replace(patt,newVal);//患者
-              value = str ;
-              valueP = strP ;
-            }else{
-              value = data[i].name ;
-              valueP = data[i].description ||data[i].name ;
-            }
           }
         }
-        // const newData = Object.assign({},this.datas,{questionDetailList:data},{value:value})
-        const newData = Object.assign({},this.datas,{questionDetailList:data,value:value,valueP:valueP})
+        let temp = concatVal(data);
+        const newData = Object.assign({},this.datas,{questionDetailList:data,value:temp.value,valueP:temp.valueP})
         this.$emit("updata",newData);
       },
-      inpVal(val,index){//输入框失焦处理
-        let valueStr = this.datas.value;
-        /*if(valueStr){
-          // let patt = /\$\{[^\]]+\}/g;
-          let newVal =  val;//修改时替换值用
-          const str = valueStr.replace(patt,newVal);
-          this.datas.value = str;
-        }*/
-        if(valueStr){
-          let rePatt = /\#\{[^\]]+\}/g;
-          let newVal = '#{' +val+'}';
-          let str = "";
-          // 区分第一次输入还是修改
-          if(valueStr.indexOf("${") !== -1){
-            str = valueStr.replace(patt,newVal);
-          }else{//修改
-            str = valueStr.replace(rePatt,newVal);
-          }
-          this.datas.value = str;
-          this.datas.valueP = str;//输入框内容无医生患者之分
-        }
-        
+      inpVal(val,index){//输入框失焦处理  
         // 输入框回读
         let detailList = this.datas.questionDetailList;
         let currItem = detailList[index];
         currItem.value = val; 
+        // 输入框失焦重新拼接父级的value
+        let temp = concatVal(detailList);
+        this.datas.value = temp.value;
+        this.datas.valueP = temp.valueP;
         this.$emit("updata",this.datas);
       },
     },

+ 3 - 4
src/components/Detail.vue

@@ -110,10 +110,10 @@ import {patt,trimDots,imageUrlPrefix} from '@utils/tools.js'
         const datas = this.checkDatas.questionMapping;
         let text = ""; //医生
         let textP = "";//患者
-        for(let i in datas){// 输入框的值用占位符#{}标识,便于修改
+        for(let i in datas){
           if(datas[i].value){
-            text += datas[i].value.replace(patt,'').replace(/\#\{/g,'').replace(/\}/g,'')+',';
-            textP += datas[i].valueP.replace(patt,'').replace(/\#\{/g,'').replace(/\}/g,'')+',';
+            text += datas[i].value+',';
+            textP += datas[i].valueP+',';
           }
         }
         
@@ -130,7 +130,6 @@ import {patt,trimDots,imageUrlPrefix} from '@utils/tools.js'
         }
         this.$store.commit('setDatas',{data:this.checkDatas,pId:this.checkDatas.id,type:this.type,ppId:this.ppId});
         // flag是区分点开已选症状 未点完成
-        // this.$store.commit('setText',{text:newMsg.replace(patt,''),pId:this.checkDatas.id,type:this.type,flag:true});
         this.$store.commit('setText',{text:trimDots(newMsg),textP:trimDots(newMsgP),pId:this.checkDatas.id,type:this.type,flag:true});
       },
       clearData(){//清空

+ 22 - 1
src/utils/tools.js

@@ -232,6 +232,26 @@ function trimDots(str){
   }).replace(/^[,,.。::"“??”;;、!!\s]+/,'');
 }
 
+// 拼值,并去掉占位符
+function concatVal(data){
+  let value = ""; //医生
+  let valueP = ""; //患者
+  for(let k in data){
+    if(data[k].select==1){
+      if(data[k].value){
+        let str = data[k].name.replace(patt,data[k].value);
+        let strP = (data[k].description || data[k].name).replace(patt,data[k].value);
+        value += str + ',';
+        valueP += strP + ',';
+      }else{
+        value += data[k].name.replace(patt,'') + ',';
+        valueP += (data[k].description || data[k].name).replace(patt,'') + ',';
+      }
+    }
+  }
+  return {value,valueP};
+}
+
 module.exports =  {
   imageUrlPrefix,
   getUrlArgObject,
@@ -245,7 +265,8 @@ module.exports =  {
   fixedKeyboard,
   scrollToV,
   isIos,
-  trimDots
+  trimDots,
+  concatVal
 }