Browse Source

Merge remote-tracking branch 'origin/optimize' into optimize

zhouna 6 years ago
parent
commit
67895ac61d
2 changed files with 60 additions and 11 deletions
  1. 33 10
      src/components/RadioInpDrop/index.jsx
  2. 27 1
      src/containers/RadioInpDrop.js

+ 33 - 10
src/components/RadioInpDrop/index.jsx

@@ -1,6 +1,6 @@
 import React,{Component} from 'react';
-import {handleEnter,getPageCoordinate,windowEventHandler} from '@utils/tools.js';
-import {DropList} from '@commonComp';
+import {handleEnter,getPageCoordinate,windowEventHandler,filterDataArr,getLabelIndex} from '@utils/tools.js';
+import {DropList,Notify} from '@commonComp';
 import config from '@config/index';
 import style from "./index.less";
 import classNames from 'classnames';
@@ -26,7 +26,8 @@ class RadioInpDrop extends Component{
       boxTop:0,
       tmpScroll:0,
       tmpTop:0,
-      texts:props.vals||{0:props.value||props.placeholder}
+      texts:props.vals||{0:props.value||props.placeholder},
+      over:false
     };
     this.$cont = React.createRef();
     this.isIE = navigator.appName=="Microsoft Internet Explorer" && navigator.appVersion.split(";")[1].replace(/[ ]/g,"")=="MSIE8.0";
@@ -147,22 +148,44 @@ class RadioInpDrop extends Component{
     handleDbclick&&handleDbclick({id:patId||id});
   }
   handleInnerInp(i,val){
-    const {ikey,boxMark,handleSaveInp} = this.props;
-    let vals = this.state.texts;
+    const {ikey,boxMark,handleSaveInp,mainSaveText} = this.props;
+    let vals = this.state.texts; 
+
+    // 主诉字数限制
+    if(boxMark==1){
+      let preText = vals[i].value;
+      let mainText = filterDataArr(mainSaveText);
+      let lengths = 0;
+      if(preText){
+        lengths = mainText.length + (val.length - preText.length);
+      }else{
+        lengths = mainText.length + val.length;
+      }
+      console.log("val:",val,"preVal:",preText,"mainText:",mainText,"lengths:",lengths,this.state.texts)
+      if(lengths >= config.limited){
+        Notify.info(config.limitText);
+        this.setState({
+          over:true
+        });
+        return
+      }
+    }
+    
     vals[i].value=val;
     this.setState({
-      texts:vals
+      texts:vals,
+      over:false
     });
-    handleSaveInp({values:vals,ikey,boxMark});
+    handleSaveInp({values:vals,ikey,boxMark,mainSaveText});
   }
   parseInputDom(){
     const {value,placeholder} = this.props;
-    const {texts} = this.state;
+    const {texts,over} = this.state;
     let temp='',list=[];
     for(let i in texts){
       temp = texts[i];
       if(typeof temp=='object'){
-        list.push(<InputComp handleInp={this.handleInnerInp} editable={true} index={i} value={temp.value}></InputComp>);
+        list.push(<InputComp handleInp={this.handleInnerInp} editable={true} index={i} value={temp.value} over={over}></InputComp>);
       }else{
         list.push(<span>&nbsp;{temp}</span>);
       }
@@ -207,7 +230,7 @@ class InputComp extends Component{
   handleBlur(e){
     e.stopPropagation();
     const text = e.target.innerText;
-    const {handleInp,index} = this.props;
+    const {handleInp,index,value} = this.props;
     e.target.innerText = '';
     handleInp(index,text);
   }

+ 27 - 1
src/containers/RadioInpDrop.js

@@ -150,9 +150,35 @@ function mapDispatchToProps(dispatch,store){
       });
     },
     handleSaveInp(params){
-      const {boxMark} = params;
+      const {boxMark,mainSaveText,values} = params;
       const index = params.ikey;
       let ikey = getLabelIndex(index);
+      // 输入框字数限制
+      /*if(boxMark==1){
+        if(values){
+          let str='',temp='';
+          for(let i in values){
+            temp = values[i];
+            if(typeof temp=='object'){
+              str+=temp.value;
+            }else{
+              str+=temp;
+            }
+          }
+          let oldVal = mainSaveText[ikey];
+          let mainText = filterDataArr(mainSaveText);
+          let lengths = 0;console.log("单选框输入:",params,oldVal,mainText.length)
+          if(oldVal && oldVal.length > str.length){
+            lengths = mainText.length + (str.length - oldVal.length);
+          }else{
+            lengths = mainText.length + str.length;
+          }  
+          if(lengths >= config.limited){
+            Notify.info(config.limitText);
+            return
+          }
+        }
+      }*/
       dispatch({
         type:InputActions[+boxMark],
         data:{values:params.values,ikey:params.ikey}