index.jsx 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import React, { Component } from 'react';
  2. import style from './index.less';
  3. import info2 from './../img/info2.png';
  4. import info3 from './../img/info3.png';
  5. import $ from "jquery";
  6. class AdverseReactions extends Component {
  7. constructor(props){
  8. super(props);
  9. this.state = {
  10. currentIndex: -1
  11. }
  12. this.handleMouseLeaveDrug = this.handleMouseLeaveDrug.bind(this);
  13. this.handleMouseLeaveImg = this.handleMouseLeaveImg.bind(this);
  14. this.setDrugInfo = this.setDrugInfo.bind(this);
  15. }
  16. changeReact(it, index) {
  17. this.props.changeReact(it, index);
  18. }
  19. handleMouseEnterDrug(index, item) {
  20. const drugNameWidth = parseInt($('#'+item.id)[0].offsetWidth)
  21. const imgLeft = drugNameWidth/2-8
  22. $('#'+item.id).find('img').css('left', imgLeft)
  23. this.setState({
  24. currentIndex: index,
  25. })
  26. }
  27. handleMouseLeaveDrug() {
  28. this.setState({
  29. currentIndex: -1,
  30. })
  31. }
  32. handleMouseEnterImg() {
  33. this.setState({
  34. hasEnterImg: true
  35. })
  36. }
  37. handleMouseLeaveImg() {
  38. this.setState({
  39. hasEnterImg: false
  40. })
  41. }
  42. setDrugInfo(item) {
  43. const { setDrugInfo } = this.props;
  44. setDrugInfo && setDrugInfo(item, 10, 6);
  45. }
  46. render() {
  47. const { icon, titleStyle,titleBg, filter, title, adversReactionList, showDrugInfo, setDrugInfo } = this.props
  48. const { currentIndex, hasEnterImg } = this.state
  49. return(
  50. <div className={style['last-treat-wrapper']}>
  51. <div className={style['last-treat-title-box']} style={titleStyle}></div>
  52. <div className={style['last-treat-title']} ><img className={style['last-treat-icon']} src={icon}/>{title}</div>
  53. {/* {console.log('adversReactionList', adversReactionList)} */}
  54. {adversReactionList.map((item, index) => {
  55. return (<div className={style['adverse-reactions-item']} key={item.id}>
  56. <span className={style['last-treat-name-box']}
  57. >
  58. <span id={item.id}
  59. className={style['last-treat-big-name-box']}
  60. onMouseEnter={this.handleMouseEnterDrug.bind(this, index, item)}
  61. onMouseLeave = {this.handleMouseLeaveDrug}
  62. >
  63. {item.tagName}:
  64. {<img className={style['info-img']}
  65. style ={currentIndex === index ? {display: "inline-block"} : {display: "none"}}
  66. src={currentIndex === index ?(hasEnterImg ? info3 : info2 ): info2}
  67. onMouseEnter={this.handleMouseEnterImg.bind(this)}
  68. onMouseLeave = {this.handleMouseLeaveImg}
  69. onClick={() =>{this.setDrugInfo(item);showDrugInfo();}}/>}
  70. </span>
  71. </span>
  72. {item.details.map((it, idx) => {
  73. return <span key={item.id + it.name}>
  74. <input type="checkbox" checked={it.value == 1} id={item.id + it.name} onChange={this.changeReact.bind(this, it, index)}/>
  75. <label for={item.id + it.name}> {it.name} </label>
  76. </span>
  77. })}
  78. </div>)
  79. })}
  80. </div>
  81. )
  82. }
  83. }
  84. export default AdverseReactions;