소스 검색

增加字数限制,已经存值到localStorage

liucf 5 년 전
부모
커밋
a56800bf6b

+ 13 - 10
src/common/components/SearchBox/index.jsx

@@ -34,27 +34,30 @@ class SearchBox extends React.Component {
       // this.props.handleChangeValue('');
     }
     handleClearVal(){
-        const { handleChangeValue } = this.props;
+        const { clearSearch } = this.props;
         this.textInput.current.value = '';
         this.textInput.current.focus();
         this.setState({
             val:'',
             show:false
         });
-        handleChangeValue('');
+        clearSearch&&clearSearch();
     }
     handleSearchSelect(e,item){
       e.stopPropagation();
       e.preventDefault();
-      const {cliIndex,chooseSearch,clearSearch} = this.props;
-      console.log("选择数据:",item);
-      this.setState({
+      const {cliIndex,chooseSearch,clearSearch,onSelect} = this.props;
+      onSelect();//上一级的“确定”
+      /*this.setState({
         val:'',
         show:false
-      });
-      chooseSearch&&chooseSearch({item:item,index:cliIndex})
+      });*/
+      setTimeout(()=>{
+        chooseSearch&&chooseSearch({item:item,index:cliIndex})
+      },200)
+      
       clearSearch&&clearSearch();
-      this.textInput.current.innerText = "";
+      this.textInput.current.value = "";
     }
     handleInput(e){
       e.stopPropagation();
@@ -104,7 +107,7 @@ class SearchBox extends React.Component {
       const { clearSearch } = this.props;
       if(!next.show && next.show != this.props.show){
         clearSearch();
-        this.textInput.current.innerText = "";
+        this.textInput.current.value = "";
         this.setState({
           showBox:false,
           val:'',
@@ -129,7 +132,7 @@ class SearchBox extends React.Component {
           background:'#f1f1f1'};
         const barStyle={background:'#777',width:'100%'};
         return (
-            <div className={classNames(styles['search'])} onClick={(e)=>{e.stopPropagation();}}>
+            <div className={classNames(styles['search'])} onClick={(e)=>{e.stopPropagation();}} onBlur={(e)=>{e.stopPropagation();}}>
                 <img className={styles.searchVal} src={search} alt="搜索" onClick={this.clickIcon}/>
                 <img style={{display:show?'block':'none'}} className={styles.clearVal} src={clear} onClick={this.handleClearVal} alt="清空" />
                 <input

+ 2 - 2
src/components/MainSuit/index.jsx

@@ -236,9 +236,9 @@ class MainSuit extends Component{
     const {freeText,saveText,datas,clearSearch,getSymptomFeature,currentData,saveChronic} = this.props;
     const that = this;
     let data = this.state.inpText;
-    const inner = e.target.innerText || e.target.innerHTML ;console.log("触发了主诉失焦事件")
+    const inner = e.target.innerText || e.target.innerHTML ;
     //分词-现病史没有模板的时候才去获取
-    if(inner.trim() && currentData&&currentData.length==0 && datas.length==0){
+    if(inner.trim() && currentData&&currentData.length==0){
       getFeature(inner.replace('<br>','')).then((res)=>{
         if(res.data.code==0){
           const result = res.data.data;

+ 5 - 5
src/components/SpreadDrop/index.jsx

@@ -201,7 +201,7 @@ class SpreadDrop extends Component{
     this.clearState();
   }
   handleConfirm(e){
-    e.stopPropagation();
+    // e.stopPropagation();
     const {handleConfirm,ikey,type,tagType,order,mainSaveText,copyType,value,mainData} = this.props;
     const params = Object.assign({},this.state,{ikey,type,tagType,order,mainSaveText,copyType,value,mainData});
     delete params.tmpDom;       //避免上面deepClone selecteds报错
@@ -437,7 +437,7 @@ class ListItems extends Component{
         
         {boxMark==1 && tagType==11 && <div className="search">
                   <div className={style["line"]}></div>
-                  <SearchBox show={show} cliIndex={cliIndex}/>
+                  <SearchBox show={show} cliIndex={cliIndex} onSelect={handleConfirm}/>
                 </div>}
       </div>
   }
@@ -542,9 +542,9 @@ class ListItem extends Component{
       }*/
       return <li onClick={(e)=>this.handleClick(e,it,i)} 
             className={this.getClass(it.id)} 
-            title={it.name.length>8?it.name:''}
-            style={{'width':'85px','display':'inline-block'}}>
-            {it.name&&it.name.length>8?it.name.slice(0,8)+'...':it.name}
+            title={it.name.length>4?it.name:''}
+            style={{'width':'55px','display':'inline-block'}}>
+            {it.name&&it.name.length>4?it.name.slice(0,4)+'...':it.name}
           </li>
     });
   }

+ 4 - 1
src/components/SpreadDrop/index.less

@@ -21,8 +21,11 @@
     border-bottom: 1px @disable-border-color solid;
   }
   .mainUl{
-    width: 425px;
+    width: 495px;
     white-space: normal;
+    li{
+      width: 99px !important;
+    }
   }
   .line{
     width: 100%;

+ 12 - 2
src/containers/SearchBox.js

@@ -5,11 +5,14 @@ import {CLEAR_ADD_SEARCH,SET_ADD_SEARCH,CHOOSE_SEARCH} from '@store/types/mainSu
 import {ISREAD} from '@store/types/homePage.js';
 import {billing} from '@store/async-actions/pushMessage';
 import {Notify} from '@commonComp';
+import {filterDataArr} from '@utils/tools.js';
+import store from '@store';
+import config from '@config/index.js';
 
 function mapStateToProps(state){
   return{
     mainSearchData:state.mainSuit.addSearchData,//主诉-添加症状-搜索结果
-    mainIds:state.mainSuit.mainIds  //搜索去重id
+    mainIds:state.mainSuit.mainIds,  //搜索去重id
   }
 }
 
@@ -32,7 +35,14 @@ function mapDispatchToProps(dispatch){
     },
     chooseSearch(obj){
       // 主诉字数限制
-
+      let state = store.getState();
+      let mainSaveText = state.mainSuit.saveText;
+      let text = filterDataArr(mainSaveText);
+      let total = text.length + obj.item.name.length + 1; //+1是因为顿号
+      if(total >= config.limited){
+        Notify.info(config.limitText);
+        return
+      }
       dispatch({
         type: CHOOSE_SEARCH,
         item:obj.item,

+ 23 - 6
src/store/actions/mainSuit.js

@@ -406,9 +406,6 @@ export const setSearch = (state,action)=>{
 // 主诉-添加症状-选中搜索结果
 export const chooseSearch = (state,action)=>{
   const res = Object.assign({},state);
-  // 缓存到localStorage中
-
-  // 插入data中
   const index = parseInt(action.index);
   const item = action.item;
   let data = res.data;
@@ -426,13 +423,33 @@ export const chooseSearch = (state,action)=>{
   }else{//第二及以上病程
     nText = Object.assign({},text);
   }
-  res.data.splice(index,0,nText);
-  res.saveText[index] = item.name;
+
+  // 缓存到localStorage中
+  const mainSymp = storageLocal.get('mainSymp');
+  if(mainSymp){
+    let localArr = JSON.parse(mainSymp);
+    let sympArr = JSON.parse(JSON.stringify(localArr));
+    for(let k=0; k<localArr.length; k++){//判断是否已存在
+      if(localArr[k].conceptId==item.conceptId){
+        sympArr.splice(k,1);
+      }
+    }
+    sympArr.push(nText);
+    if(sympArr.length>5){
+      storageLocal.set('mainSymp',sympArr.slice(sympArr.length-5,));
+    }else{
+      storageLocal.set('mainSymp',sympArr);
+    }
+  }
+  // 插入data中
+  // res.data.splice(index,0,nText);
+  res.data.splice(index,0,Object.assign({},nText,{name:'、'+item.name,value:'、'+item.name}));
+  res.saveText.splice(index,0,'、'+item.name);
   res.mainIds.push(item.conceptId);
   if(item.questionId){
     res.mainTailIds.push(item.questionId);
   }
-  res.update=Math.random();console.log("action111",action,res)
+  res.update=Math.random();
   return res;
 }