index.jsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. import React, { Component } from "react";
  2. import style from "./index.less";
  3. import Notify from '../Notify';
  4. import config from '@config/index';
  5. import {isIE} from '@utils/tools.js';
  6. import {getFeature} from '@store/async-actions/fetchModules';
  7. import {getAllDataList,getAllDataStringList,ifOtherClear,setFontColorSize} from "@utils/tools.js";
  8. import store from '@store';
  9. import $ from "jquery";
  10. class Textarea extends Component {
  11. constructor(props) {
  12. super(props);
  13. this.state = {
  14. timer:null,
  15. inpText:'',
  16. overFlag:false,
  17. editable:true,
  18. };
  19. this.$dom = React.createRef();
  20. this.handleInput = this.handleInput.bind(this);
  21. this.handleFocus = this.handleFocus.bind(this);
  22. //this.handleBlur = this.handleBlur.bind(this);
  23. this.handleKeydown = this.handleKeydown.bind(this);
  24. this.handleBlur = this.handleBlur.bind(this);
  25. }
  26. handleFocus(e){ //初始显示props中的值,focus已经显示输入的值,避免值更新闪烁
  27. const {handleFocus,fuzhen,handleInput,isChronic,hasMain,boxMark} = this.props;
  28. //黏贴时去掉html格式
  29. const that = this;
  30. let txt = '';
  31. $(this.$dom.current).on("paste",function(e){
  32. setTimeout(function(){
  33. txt = that.$dom.current.innerText||that.$dom.current.innerHTML;
  34. that.$dom.current.innerHTML = txt;
  35. that.moveEnd($(that.$dom.current)[0]); //光标落到最后去
  36. });
  37. });
  38. //const {inpText} = this.state;console.log(inpText,boxMark,hasMain)
  39. if(boxMark!='1'&&boxMark!='2'&&!hasMain&&!e.target.innerText){
  40. //现病史、其他史无主诉且本身无内容是聚焦提示无法操作
  41. this.setState({
  42. editable:false
  43. });
  44. e.target.blur();
  45. Notify.error("无法操作,请先输入主诉");
  46. return;
  47. }else{
  48. this.setState({
  49. editable:true
  50. });
  51. }
  52. handleFocus&&handleFocus(); //其他史、查体获取数据的方法
  53. /*if(fuzhen&& !isChronic&&!(this.$dom.current.innerText?this.$dom.current.innerText:this.$dom.current.innerHTML)){
  54. const text = config.currentText.replace("(**)",fuzhen.replace(";",''));
  55. this.$dom.current.innerText?(this.$dom.current.innerText = text):(this.$dom.current.innerHTML = text);
  56. handleInput&&handleInput({text});
  57. }*/
  58. }
  59. handleInput(e){
  60. const {handleInput,boxMark,handlePush,value} = this.props;
  61. const {inpText,overFlag,editable} = this.state;
  62. const text = e.target.innerText || e.target.innerHTML;
  63. const stimer = this.state.timer;
  64. if(!editable){
  65. e.target.innerText='';
  66. return ;
  67. }
  68. if(boxMark=='1'&&text.length>config.limited){ //主诉字符数限制
  69. e.target.innerText?(e.target.innerText = text.substr(0,config.limited)):(e.target.innerHTML = text.substr(0,config.limited));
  70. e.target.blur();
  71. Notify.error(config.limitText);
  72. if(overFlag){
  73. e.target.innerText?(e.target.innerText = inpText):(e.target.innerHTML = inpText);
  74. return
  75. }
  76. this.setState({
  77. inpText:text.substr(0,config.limited),
  78. overFlag:true
  79. });
  80. handleInput&&handleInput({text:text.substr(0,config.limited).replace('<br>','')});
  81. return;
  82. }
  83. /*if(boxMark=='3'&&!hasMain){
  84. e.target.innerText = '';
  85. return;
  86. }*/
  87. this.setState({
  88. inpText:text,
  89. overFlag:false
  90. })
  91. //存值到store FF26 会有一个<br>
  92. handleInput&&handleInput({text:text.replace('<br>','')});
  93. //右侧推送--延时推送
  94. clearTimeout(stimer);
  95. let timer = setTimeout(function(){
  96. handlePush&&handlePush();
  97. clearTimeout(stimer);
  98. },config.delayPushTime);
  99. this.setState({
  100. timer
  101. });
  102. }
  103. //除主诉外 其他是否为空
  104. ifClear(){
  105. let baseList = store.getState();
  106. let jsonData = getAllDataList(baseList);
  107. let jsonStr = getAllDataStringList(baseList);
  108. let flg = ifOtherClear(jsonData,jsonStr,baseList);
  109. return flg;
  110. }
  111. handleBlur(e){
  112. const {saveChronic} = this.props;
  113. const text = e.target.innerText || e.target.innerHTML;
  114. //解除绑定事件
  115. $(this.$dom.current).off("paste");
  116. getFeature(text).then((res)=>{
  117. if(res.data.code==0){
  118. const result = res.data.data;
  119. // 慢病
  120. if(result && result[0].chronicLabel==1){
  121. let flg = this.ifClear();
  122. if(!flg){
  123. saveChronic && saveChronic(result[0],true);
  124. }
  125. }
  126. }
  127. })
  128. }
  129. handleKeydown(e){
  130. const {boxMark} = this.props;
  131. const ev = e||window.event;
  132. if(+boxMark===1){
  133. //禁止回车事件
  134. if(ev.keyCode==13){return false;}
  135. }
  136. }
  137. // shouldComponentUpdate(next){ 切换字体设置不渲染
  138. // if(JSON.stringify(next) == JSON.stringify(this.props)){
  139. // return false;
  140. // }
  141. // return true;
  142. // }
  143. componentWillReceiveProps(next){
  144. const isRead = this.props.isRead;
  145. if(next.isRead != isRead||(next.value!=this.props.value&&next.value&&next.value.indexOf("复诊")!=-1)){ //value对比解决复诊不显示bug,复诊对比解决关标跳到前面bug
  146. this.$dom.current.innerText?(this.$dom.current.innerText = next.value||''):(this.$dom.current.innerHTML = next.value||'');
  147. this.setState({
  148. inpText:''
  149. });
  150. }
  151. }
  152. componentDidMount(){
  153. const {value} = this.props;
  154. if(value){
  155. this.$dom.current.innerText?(this.$dom.current.innerText = value||''):(this.$dom.current.innerText=value||'');
  156. }
  157. if(isIE()){
  158. $(this.$dom.current).onIe8Input(function(e){
  159. this.handleInput(e)
  160. },this);
  161. }
  162. }
  163. render() {
  164. const { title,boxMark } = this.props;
  165. return (
  166. <div className={style["box"]}>
  167. <div className={`${style["title"]} ${setFontColorSize(2,4)}`}>{title}</div>
  168. {/*{isRead?<div className={style["content"]+" "+'11'} contentEditable={true} onFocus={this.handleFocus}>{value}</div>:''}*/}
  169. <div className={`${style["content"]} ${setFontColorSize(2,5)}`}
  170. onFocus={this.handleFocus}
  171. ref={this.$dom}
  172. contentEditable={true}
  173. onInput={this.handleInput}
  174. onkeydown={this.handleKeydown}
  175. onBlur={+boxMark===1?this.handleBlur:null}>
  176. </div>
  177. </div>
  178. );
  179. }
  180. }
  181. export default Textarea;