index.jsx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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} = 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. return;
  71. }
  72. /*if(boxMark=='3'&&!hasMain){
  73. e.target.innerText = '';
  74. return;
  75. }*/
  76. this.setState({
  77. inpText:text,
  78. overFlag:false
  79. })
  80. //存值到store
  81. handleInput&&handleInput({text});
  82. //右侧推送--延时推送
  83. clearTimeout(stimer);
  84. let timer = setTimeout(function(){
  85. handlePush&&handlePush();
  86. clearTimeout(stimer);
  87. },config.delayPushTime);
  88. this.setState({
  89. timer
  90. });
  91. }
  92. //除主诉外 其他是否为空
  93. ifClear(){
  94. let baseList = store.getState();
  95. let jsonData = getAllDataList(baseList);
  96. let jsonStr = getAllDataStringList(baseList);
  97. let flg = ifOtherClear(jsonData,jsonStr,baseList);
  98. return flg;
  99. }
  100. handleBlur(e){
  101. const {saveChronic} = this.props;
  102. const text = e.target.innerText;
  103. getFeature(text).then((res)=>{
  104. if(res.data.code==0){
  105. const result = res.data.data;
  106. // 慢病
  107. if(result && result[0].chronicLabel==1){
  108. let flg = this.ifClear();
  109. if(!flg){
  110. saveChronic && saveChronic(result[0],true);
  111. }
  112. }
  113. }
  114. })
  115. }
  116. handleKeydown(e){
  117. const {boxMark} = this.props;
  118. const ev = e||window.event;
  119. if(+boxMark===1){
  120. //禁止回车事件
  121. if(ev.keyCode==13){return false;}
  122. }
  123. }
  124. shouldComponentUpdate(next){
  125. if(JSON.stringify(next) == JSON.stringify(this.props)){
  126. return false;
  127. }
  128. return true;
  129. }
  130. componentWillReceiveProps(next){
  131. const isRead = this.props.isRead;
  132. if(next.isRead != isRead||(next.value!=this.props.value&&next.value&&next.value.indexOf("复诊")!=-1)){ //value对比解决复诊不显示bug,复诊对比解决关标跳到前面bug
  133. this.$dom.current.innerText?(this.$dom.current.innerText = next.value||''):(this.$dom.current.innerHTML = next.value||'');
  134. this.setState({
  135. inpText:''
  136. });
  137. }
  138. }
  139. componentDidMount(){
  140. const {value} = this.props;
  141. if(value){
  142. this.$dom.current.innerText?(this.$dom.current.innerText = value||''):(this.$dom.current.innerText=value||'');
  143. }
  144. if(isIE()){
  145. $(this.$dom.current).onIe8Input(function(e){
  146. this.handleInput(e)
  147. },this);
  148. }
  149. }
  150. render() {
  151. const { title,boxMark } = this.props;
  152. return (
  153. <div className={style["box"]}>
  154. <div className={style["title"]}>{title}</div>
  155. {/*{isRead?<div className={style["content"]+" "+'11'} contentEditable={true} onFocus={this.handleFocus}>{value}</div>:''}*/}
  156. <div className={style["content"]}
  157. onFocus={this.handleFocus}
  158. ref={this.$dom}
  159. contentEditable={true}
  160. onInput={this.handleInput}
  161. onkeydown={this.handleKeydown}
  162. onBlur={+boxMark===1?this.handleBlur:null}>
  163. </div>
  164. </div>
  165. );
  166. }
  167. }
  168. export default Textarea;