index.jsx 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import React, { Component } from 'react';
  2. import style from './index.less';
  3. import $ from "jquery";
  4. import close from './img/close.png';
  5. import info from './img/info.png';
  6. import info1 from './img/info1.png';
  7. import info2 from './img/info2.png';
  8. import info3 from './img/info3.png';
  9. import packUp from './img/packUp.png';
  10. class TreatDesc extends Component {
  11. constructor(props){
  12. super(props);
  13. this.state = {
  14. currentIndex: -1,
  15. hasEnterImg: false
  16. }
  17. this.hideTreatDesc = this.hideTreatDesc.bind(this);
  18. this.handleSelect= this.handleSelect.bind(this);
  19. this.handleMouseEnterDrug = this.handleMouseEnterDrug.bind(this)
  20. this.handleMouseLeaveDrug = this.handleMouseLeaveDrug.bind(this)
  21. this.handleMouseEnterImg = this.handleMouseEnterImg.bind(this)
  22. this.handleMouseLeaveImg = this.handleMouseLeaveImg.bind(this)
  23. }
  24. handleMouseEnterDrug( index, item) {
  25. // console.log('item', item)
  26. // const drugNameWidth = parseInt($('#'+item.medicitionName)[0].offsetWidth)
  27. // const imgLeft = drugNameWidth/2-10
  28. // console.log('imgLeft', imgLeft)
  29. // $('#'+item.medicitionName).find('img').css('left', imgLeft)
  30. this.setState({
  31. currentIndex: index,
  32. })
  33. }
  34. handleMouseLeaveDrug() {
  35. this.setState({
  36. currentIndex: -1,
  37. })
  38. }
  39. handleMouseEnterImg() {
  40. this.setState({
  41. hasEnterImg: true
  42. })
  43. }
  44. handleMouseLeaveImg() {
  45. this.setState({
  46. hasEnterImg: false
  47. })
  48. }
  49. handleSelect(index,ii) {
  50. const { selectDrug } = this.props;
  51. selectDrug && selectDrug(index,ii);
  52. }
  53. hideTreatDesc() {
  54. $('#treatDescBox').css({'display': 'none'});
  55. $('#treatDescBox').animate({'display': 'none'}, 500);
  56. $('#dragModalWrap').animate({'margin-left': '-340px','left':'50%'}, 500);
  57. }
  58. render(){
  59. const { treatment, treatDesc, setDrugInfo} = this.props
  60. const { title, basic, otherDrugIndex, drugDesc} = treatDesc
  61. const { currentIndex, hasEnterImg } = this.state
  62. return (treatment && treatment.length >0 && <div className={style['treat-desc-box']}>
  63. {title && title === '药品推荐' ? <div className={style['similar-drug-box']} id='treatDescBox'>
  64. {/* { basic && basic.length > 0 && <div> //推荐依据不需要展示
  65. <h3 className={style['recommend-title']}>推荐依据</h3>
  66. {basic.map((item, index) =>{
  67. return (<div className={style['drug-desc-item']} dangerouslySetInnerHTML ={{__html: item.content}}>
  68. </div>)
  69. })}
  70. </div> } */}
  71. { otherDrugIndex > -1 && <div className={style['similar-drug']}>
  72. <h3 className={style['drug-desc-title']}><span className={style['drug-desc-class-title']} title={'同类药物(' + treatment[otherDrugIndex].bigdrugsName + ')'}>同类药物({treatment[otherDrugIndex].bigdrugsName})</span> <img src={packUp} onClick={this.hideTreatDesc} className={style['close-drug-desc']} /></h3>
  73. {treatment[otherDrugIndex].medicitionsList.map((item, index) =>{
  74. return (<span >
  75. {index === 0 ? '' : ', '}
  76. <span className={style['drug-name-box']}
  77. onMouseEnter={this.handleMouseEnterDrug.bind(this, index, item )}
  78. onMouseLeave = {this.handleMouseLeaveDrug}
  79. id={item.medicitionName}
  80. >
  81. <span className={style['drug-name']}
  82. // onDoubleClick={() =>{setDrugInfo(item);showDrugInfo();}}
  83. onClick={()=>{item.forbidden === '2' ? '' : this.handleSelect(otherDrugIndex,index)}}
  84. style={item.forbidden === '2' ? {opacity: '0.3', filter:'alpha(opacity=30)',filter:'progid:DXImageTransform.Microsoft.Alpha(opacity=30)'} : item.selected ? {color: '#3B9ED0'}:''}
  85. >
  86. {item.medicitionName}
  87. </span>
  88. {<img className={style['info-img']}
  89. style ={currentIndex === index ? {display: "inline-block"} : {display: "none"}}
  90. src={currentIndex === index ? (hasEnterImg ? info3 : info2) : info2}
  91. onMouseEnter={this.handleMouseEnterImg.bind(this, index)}
  92. onMouseLeave = {this.handleMouseLeaveImg}
  93. onClick={() =>{setDrugInfo({name: item.medicitionName, type: 8, position: 5})}}
  94. />}
  95. </span>
  96. {/* {<img className={style['info-img']}
  97. src={currentIndex === index ? info1 : info}
  98. onMouseEnter={this.handleMouseEnterImg.bind(this, index)}
  99. onMouseLeave = {this.handleMouseLeaveImg}
  100. onClick={() =>{setDrugInfo(item,8,5);showDrugInfo();}}/>} */}
  101. {item.forbidden === '1' ? <span className={style['info-flag']} style={{border: '1px solid #F4C051', background: '#F4C051',marginLeft: '5px'}}>慎用</span>: item.forbidden === '2' ? <span className={style['info-flag']} style={{opacity: '0.3', filter:'alpha(opacity=30)',filter:'progid:DXImageTransform.Microsoft.Alpha(opacity=30)',border: '1px solid #000',marginLeft: '5px'}}>禁用</span> : ''},
  102. <span style={item.forbidden === '2' ? {opacity: '0.3', filter:'alpha(opacity=30)',filter:'progid:DXImageTransform.Microsoft.Alpha(opacity=30)'} : ''}> 使用率{item.rate}</span>
  103. </span>)
  104. })}
  105. </div> }
  106. </div>: '' }
  107. {/* { title !== '药品推荐' ? <div>
  108. { drugDesc && drugDesc.length > 0 && <div className={style['drug-desc-wrapper']}>
  109. <h3 className={style['drug-title']}>说明</h3>
  110. {drugDesc.map((item, index) =>{
  111. return <div className={style['drug-desc-item']}>{item.title}: <span dangerouslySetInnerHTML ={{__html: item.content}}></span> </div>
  112. })}
  113. </div> }
  114. </div>: '' } */}
  115. </div>)
  116. }
  117. }
  118. export default TreatDesc;