index.jsx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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} 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. //const {inpText} = this.state;console.log(inpText,boxMark,hasMain)
  29. if(boxMark!='1'&&!hasMain&&!e.target.innerText){
  30. //现病史、其他史无主诉且本身无内容是聚焦提示无法操作
  31. this.setState({
  32. editable:false
  33. });
  34. e.target.blur();
  35. Notify.error("无法操作,请先输入主诉");
  36. return;
  37. }else{
  38. this.setState({
  39. editable:true
  40. });
  41. }
  42. handleFocus&&handleFocus(); //其他史、查体获取数据的方法
  43. /*if(fuzhen&& !isChronic&&!(this.$dom.current.innerText?this.$dom.current.innerText:this.$dom.current.innerHTML)){
  44. const text = config.currentText.replace("(**)",fuzhen.replace(";",''));
  45. this.$dom.current.innerText?(this.$dom.current.innerText = text):(this.$dom.current.innerHTML = text);
  46. handleInput&&handleInput({text});
  47. }*/
  48. }
  49. handleInput(e){
  50. const {handleInput,boxMark,handlePush,value} = this.props;
  51. const {inpText,overFlag,editable} = this.state;
  52. const text = e.target.innerText || e.target.innerHTML;
  53. const stimer = this.state.timer;
  54. if(!editable){
  55. e.target.innerText='';
  56. return ;
  57. }
  58. if(boxMark=='1'&&text.length>config.limited){ //主诉字符数限制
  59. e.target.innerText?(e.target.innerText = text.substr(0,config.limited)):(e.target.innerHTML = text.substr(0,config.limited));
  60. e.target.blur();
  61. Notify.error(config.limitText);
  62. if(overFlag){
  63. e.target.innerText?(e.target.innerText = inpText):(e.target.innerHTML = inpText);
  64. return
  65. }
  66. this.setState({
  67. inpText:text.substr(0,config.limited),
  68. overFlag:true
  69. });
  70. handleInput&&handleInput({text:text.substr(0,config.limited).replace('<br>','')});
  71. return;
  72. }
  73. /*if(boxMark=='3'&&!hasMain){
  74. e.target.innerText = '';
  75. return;
  76. }*/
  77. this.setState({
  78. inpText:text,
  79. overFlag:false
  80. })
  81. //存值到store FF26 会有一个<br>
  82. handleInput&&handleInput({text:text.replace('<br>','')});
  83. //右侧推送--延时推送
  84. clearTimeout(stimer);
  85. let timer = setTimeout(function(){
  86. handlePush&&handlePush();
  87. clearTimeout(stimer);
  88. },config.delayPushTime);
  89. this.setState({
  90. timer
  91. });
  92. }
  93. //除主诉外 其他是否为空
  94. ifClear(){
  95. let baseList = store.getState();
  96. let jsonData = getAllDataList(baseList);
  97. let jsonStr = getAllDataStringList(baseList);
  98. let flg = ifOtherClear(jsonData,jsonStr,baseList);
  99. return flg;
  100. }
  101. handleBlur(e){
  102. const {saveChronic} = this.props;
  103. const text = e.target.innerText || e.target.innerHTML;
  104. getFeature(text).then((res)=>{
  105. if(res.data.code==0){
  106. const result = res.data.data;
  107. // 慢病
  108. if(result && result[0].chronicLabel==1){
  109. let flg = this.ifClear();
  110. if(!flg){
  111. saveChronic && saveChronic(result[0],true);
  112. }
  113. }
  114. }
  115. })
  116. }
  117. handleKeydown(e){
  118. const {boxMark} = this.props;
  119. const ev = e||window.event;
  120. if(+boxMark===1){
  121. //禁止回车事件
  122. if(ev.keyCode==13){return false;}
  123. }
  124. }
  125. shouldComponentUpdate(next){
  126. if(JSON.stringify(next) == JSON.stringify(this.props)){
  127. return false;
  128. }
  129. return true;
  130. }
  131. componentWillReceiveProps(next){
  132. const isRead = this.props.isRead;
  133. if(next.isRead != isRead||(next.value!=this.props.value&&next.value&&next.value.indexOf("复诊")!=-1)){ //value对比解决复诊不显示bug,复诊对比解决关标跳到前面bug
  134. this.$dom.current.innerText?(this.$dom.current.innerText = next.value||''):(this.$dom.current.innerHTML = next.value||'');
  135. this.setState({
  136. inpText:''
  137. });
  138. }
  139. }
  140. componentDidMount(){
  141. const {value} = this.props;
  142. if(value){
  143. this.$dom.current.innerText?(this.$dom.current.innerText = value||''):(this.$dom.current.innerText=value||'');
  144. }
  145. if(isIE()){
  146. $(this.$dom.current).onIe8Input(function(e){
  147. this.handleInput(e)
  148. },this);
  149. }
  150. }
  151. render() {
  152. const { title,boxMark } = this.props;
  153. return (
  154. <div className={style["box"]}>
  155. <div className={style["title"]}>{title}</div>
  156. {/*{isRead?<div className={style["content"]+" "+'11'} contentEditable={true} onFocus={this.handleFocus}>{value}</div>:''}*/}
  157. <div className={style["content"]}
  158. onFocus={this.handleFocus}
  159. ref={this.$dom}
  160. contentEditable={true}
  161. onInput={this.handleInput}
  162. onkeydown={this.handleKeydown}
  163. onBlur={+boxMark===1?this.handleBlur:null}>
  164. </div>
  165. </div>
  166. );
  167. }
  168. }
  169. export default Textarea;