index.jsx 6.5 KB

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