index.jsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import React,{Component} from 'react';
  2. import {Button,InlineTag,ItemBox,Textarea,Notify} from '@commonComp';
  3. import chooseType from '@containers/eleType.js';
  4. import SearchDrop from '@components/SearchDrop';
  5. import {filterDataArr,getPageCoordinate,windowEventHandler,isIE} from '@utils/tools'
  6. import $ from 'jquery';
  7. class OtherHistory extends Component{
  8. constructor(props){
  9. super(props);
  10. this.state = {
  11. boxMark:'3',
  12. editable:true,
  13. boxLeft:0,
  14. boxTop:0
  15. };
  16. this.handleClick = this.handleClick.bind(this);
  17. this.handleSearchSelect = this.handleSearchSelect.bind(this);
  18. this.getData = this.getData.bind(this);
  19. }
  20. handleSearchSelect(obj){
  21. const {questionId,name} = obj;
  22. const {fetchModules,focusTextIndex,span,searchInEnd} = this.props;
  23. fetchModules&&fetchModules({id:questionId,index:focusTextIndex,name,span,searchInEnd});
  24. }
  25. getLabels(){
  26. const {data,showArr,saveText} = this.props;
  27. const {boxMark} = this.state;
  28. let list = data.map((item,i)=>{
  29. return chooseType({item,boxMark,i,hideTag:false,showArr,saveText});
  30. });
  31. return list;
  32. }
  33. getData(){
  34. //第一次聚焦其他史时,主诉有数据则获取最近一次其他史记录(没有的话显示初始模板),主诉无数据则显示提示;其他时间其他史模板数据不调接口
  35. const {hasMain,type,setInitData,isEmpty} = this.props;
  36. //无主诉提示在EditableSpan里
  37. //智能模式有主诉或者文本模式获取最近历史
  38. if(hasMain&&isEmpty!=false){
  39. setInitData();
  40. }
  41. }
  42. handleClick(e){
  43. //e.stopPropagation();
  44. //搜索框位置
  45. const ele = document.activeElement;
  46. const height = ele.offsetHeight;
  47. let boxTop = (+(ele.offsetTop)+height);
  48. let boxLeft = ele.offsetLeft;
  49. this.setState({
  50. boxLeft:boxLeft+50,
  51. boxTop:boxTop
  52. });
  53. //若使用e.target,因为是onClick事件中,值可能是itembox的而不是span因此会有bug
  54. this.getData();
  55. }
  56. render(){
  57. const {readMode,hasMain,hideAllDrop,searchData,isRead,type,fetchPushInfos,handleInput,saveText} = this.props;
  58. const {boxLeft,boxTop} = this.state;
  59. const mode = readMode===null||readMode===-1?type:readMode;
  60. //智能模式有数据时不切换文本,文本模式有数据时不切换智能
  61. if(+mode===1){ //文本模式
  62. return <Textarea title='其他史' boxMark='3'
  63. isRead={isRead}
  64. value={saveText[0]}
  65. handlePush={fetchPushInfos}
  66. handleInput={handleInput}
  67. handleFocus={this.getData}
  68. hasMain={hasMain}/>;
  69. }
  70. return <div>
  71. <ItemBox title='其他史' isRead={isRead} handleClick={this.handleClick} hideAllDrop={hideAllDrop}>
  72. {this.getLabels()}
  73. {searchData && searchData.length>0?<SearchDrop data={searchData} show={true} top={boxTop} left={boxLeft} onSelect={this.handleSearchSelect}></SearchDrop>:''}
  74. </ItemBox>
  75. </div>
  76. }
  77. }
  78. export default OtherHistory;