index.jsx 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import React, { Component } from 'react';
  2. import style from './index.less';
  3. import close from './../img/close.png';
  4. import imgCurrent from '@common/images/icon-current.png';
  5. import $ from "jquery";
  6. import {dragBoxs} from '@utils/drag'
  7. import { imageUrlPrefix } from '@utils/config.js';
  8. class DrugInfo extends Component {
  9. constructor(props) {
  10. super(props);
  11. this.state = {
  12. currentIndex: 0,
  13. zIndex:302
  14. }
  15. this.setDragBox = this.setDragBox.bind(this)
  16. }
  17. componentDidMount(){
  18. dragBoxs('add')
  19. }
  20. handleClickMenu(index, item, drugDesc) {
  21. const that = this
  22. setTimeout(function(){
  23. that.setState({
  24. currentIndex: index
  25. })
  26. },0)
  27. let scrollTop = 60; //标题高度为60px
  28. drugDesc.map((it, ii) => {
  29. if( ii < index) {
  30. scrollTop = scrollTop + parseInt($('#' + it.title.trim()).css('height'))
  31. }
  32. })
  33. $('#drugDesc').scrollTop(scrollTop)
  34. }
  35. handleScrollModal(drugDesc) {
  36. const scrollTop = $('#drugDesc').scrollTop()
  37. let divHeight = 60; //标题高度为60px
  38. for (let i = 0; i < drugDesc.length; i++) {
  39. divHeight = divHeight + parseInt($('#' + drugDesc[i].title.trim()).css('height')) -5
  40. if(divHeight > scrollTop) {
  41. this.setState({
  42. currentIndex: i
  43. })
  44. return
  45. }
  46. }
  47. }
  48. setDragBox(){
  49. $('#dragModalWrap').css({'z-index': 110});
  50. $('#drugWrapper').css({'z-index': 120});
  51. }
  52. render() {
  53. const { drugInfo, hideDrugInfo, drugInfoList,hideDrugInfoMore } = this.props
  54. const { currentIndex } = this.state
  55. return (<div className={style['drug-info-wrapper']} id="drugWrapper">
  56. <img src={close} onClick={hideDrugInfo} className={style['close-drug-desc']}/>
  57. <h1 onMouseDown={this.setDragBox} id="drugTitle" className={style['drug-title']}>{drugInfo.tagType == 8 ? drugInfo.title+'说明书' : drugInfo.tagType == 10 ? drugInfo.title+ '说明': ''}</h1>
  58. { drugInfo && drugInfo.drugDesc.length > 0 && <div className={style['drug-desc-wrapper']} id='drugDesc' onScroll={this.handleScrollModal.bind(this, drugInfo.drugDesc)}>
  59. {/* <div className={style['drug-title1']} >{drugInfo.tagType == 8 ? drugInfo.title+'说明书' : drugInfo.tagType == 10 ? drugInfo.title+ '说明': ''}</div> */}
  60. {drugInfo.drugDesc.map((item, index) =>{
  61. return <div className={style['drug-desc-item']} id={item.title.trim()}>
  62. <div className={style['details-content-title-box']} >
  63. <span className={style['details-content-title-name']}>{item.title}</span>
  64. <div className={style['details-content-title-circle-box']}><span className={style['details-content-title-circle']}></span></div>
  65. </div>
  66. <pre className={style['drug-desc-content']} dangerouslySetInnerHTML ={{__html: item.content.replace(/{imageUrlPrefix}/g, imageUrlPrefix)}}></pre>
  67. </div>
  68. })}
  69. <div className={style['content-menu-box']}>
  70. <div className={style['content-menu-wrapper']}>
  71. <div className={style['content-menu']}>
  72. <div className={style['content-menu-border']}>
  73. {drugInfo.drugDesc.map((item, index) => {
  74. return (<div class={style['details-menu-title-wrapper']}>
  75. <div className={style['details-menu-title-box']}>
  76. {index === 0 ? '' : <div className={style['details-content-menu-line']}></div>}
  77. <span onClick={this.handleClickMenu.bind(this, index, item, drugInfo.drugDesc)} className={style['details-content-menu-name']} style = {index === currentIndex ? {color:'#0089be'} : ''}>
  78. <div className={style['details-content-menu-circle-box']}>
  79. {index !== currentIndex&&<span className={style['details-content-menu-circle']} ></span>}
  80. {index === currentIndex&&<img className={style['details-content-menu-img']} src ={imgCurrent}/>}
  81. </div>
  82. {item.title}
  83. </span>
  84. </div>
  85. </div>)
  86. })}
  87. </div>
  88. </div>
  89. </div>
  90. </div>
  91. </div> }
  92. { !drugInfo || (drugInfo && drugInfo.drugDesc.length === 0) && <div className={style['drug-desc-wrapper']}>
  93. <div>
  94. {drugInfo.tagType == 8 ? '该药品暂无说明' : drugInfo.tagType == 10 ?'该不良反应暂无说明': ''}
  95. </div>
  96. </div> }
  97. </div>)
  98. //多个药品药品说明书(添加数据时查看药品说明书用)
  99. // return (<div className={style['drug-info-wrapper']}>
  100. // <h3 className={style['drug-title']}>说明书 <img src={close} onClick={hideDrugInfoMore} className={style['close-drug-desc']}/> </h3>
  101. // { drugInfoList && drugInfoList.length > 0 && <div className={style['drug-desc-wrapper']}>
  102. // {drugInfoList.map((item,index) => {
  103. // return <div>
  104. // <h3 style={{height:' 50px', fontSize:'40px', fontWeight: '800'}}>{'【'+item.id+'】'}{item.name}说明书 </h3>
  105. // {item.introduceDetailList&&item.introduceDetailList.length>0&&item.introduceDetailList.map((it, index) =>{
  106. // return <div className={style['drug-desc-item']}><span className={style['drug-desc-title']}>{it.title.trim()}</span> <div className={style['drug-desc-content']} dangerouslySetInnerHTML ={{__html: it.content}}></div> </div>
  107. // })}
  108. // <br/>
  109. // <br/> <br/> <br/> <br/>
  110. // </div>
  111. // })}
  112. // </div> }
  113. // </div>)
  114. }
  115. }
  116. export default DrugInfo;