index.jsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. import PropTypes from "prop-types"
  2. import React from "react"
  3. import style from "./index.less"
  4. import TemplateItem from './TemplateItem'
  5. import check_circle from './TemplateItem/img/check-circle.png';
  6. import delIcon from '@common/images/del_nor.png';
  7. import check_right from './TemplateItem/img/check-right.png';
  8. import tempTip from './TemplateItem/img/tempTip.png';
  9. import tempTrd from './TemplateItem/img/tempTrd.png';
  10. import tmpAllCircle from './TemplateItem/img/tmpAllCircle.png';
  11. import tmpAllRight from './TemplateItem/img/tmpAllRight.png';
  12. import floderR from './TemplateItem/img/floderR.png';
  13. import floderD from './TemplateItem/img/floderD.png';
  14. import Empty from '@components/Empty';
  15. import $ from 'jquery';
  16. import {windowEventHandler,getWindowInnerHeight} from '@utils/tools'
  17. class TemplateItems extends React.Component {
  18. constructor(props) {
  19. super(props);
  20. this.state = {
  21. msg:'还没有保存模板',
  22. val:'',
  23. height:'',
  24. showTipContent:false
  25. }
  26. this.$cont = React.createRef();
  27. this.$conts = React.createRef();
  28. this.$search = React.createRef();
  29. this.genItems = this.genItems.bind(this);
  30. this.templateSearch = this.templateSearch.bind(this);
  31. this.handleEnter = this.handleEnter.bind(this);
  32. this.handleChange = this.handleChange.bind(this);
  33. this.clear = this.clear.bind(this);
  34. this.showTipContent = this.showTipContent.bind(this);
  35. this.getFloderLis = this.getFloderLis.bind(this);
  36. }
  37. componentDidMount(){
  38. const height = getWindowInnerHeight()-195;
  39. this.setState({
  40. height:height
  41. })
  42. windowEventHandler('resize', ()=>{
  43. if(this.$conts.current){
  44. const height = getWindowInnerHeight()-195;
  45. this.setState({
  46. height:height
  47. })
  48. }
  49. });
  50. $(document).click((event) => {
  51. let _del = $('#floderAction')[0]; // 弹窗
  52. let _dels = $(event.target).attr("id"); // 触发弹窗列表
  53. if (_del) {//onMousedown的目标为滚动条时,删除弹窗不关闭
  54. if (!event.target.isEqualNode(_del) && event.target.parentNode != _del &&_dels != 'floderActionBtn') {
  55. this.floderAction(false,'none')
  56. }
  57. }
  58. })
  59. }
  60. showTipContent(){
  61. let show = this.state.showTipContent
  62. this.setState({
  63. showTipContent:!show
  64. })
  65. }
  66. floderSlide(e,item){
  67. const {floderSlide} = this.props
  68. if(!item.templateInfo){
  69. return;
  70. }
  71. $(e.target).next().slideToggle()
  72. let domLis = $(e.target).parent().siblings()
  73. for(let i = 0;i < domLis.length;i++){
  74. let tmpD = domLis[i]
  75. $(tmpD).children().eq(1).slideUp()
  76. }
  77. floderSlide(item.id)
  78. }
  79. floderAction(e,id){
  80. e&&e.stopPropagation()
  81. const {floderAction} = this.props;
  82. floderAction(id)
  83. }
  84. genItems(items,flg) {
  85. const Items = [];
  86. const {admin,checkItems,allCheckShow,handleContentClick,handleTemplateDel,handleTitleChange,checkItemsAdmin,allCheckShowAdmin} = this.props;
  87. items.forEach((v,idx) => {
  88. Items.push(
  89. <TemplateItem
  90. {...v}
  91. key={v.id}
  92. idx={idx}
  93. checkItems={checkItems}
  94. allCheckShow={allCheckShow}
  95. handleContentClick={handleContentClick}
  96. handleTemplateDel={handleTemplateDel}
  97. handleTitleChange={handleTitleChange}
  98. admin={admin}
  99. adminflg={flg}
  100. checkItemsAdmin={checkItemsAdmin}
  101. allCheckShowAdmin={allCheckShowAdmin}
  102. />
  103. );
  104. });
  105. return Items;
  106. }
  107. floderRename(e){
  108. e.stopPropagation()
  109. this.props.floderAction(false,'none')
  110. this.props.floderRename()
  111. }
  112. floderDelete(e){
  113. e.stopPropagation()
  114. this.props.floderAction(false,'none')
  115. this.props.floderDelete()
  116. }
  117. genAdminItems(items,flg) {
  118. const Floder=[],Items = [];
  119. const {admin,checkItemsAdmin} = this.props;
  120. for(let i = 0;i < items.length;i++){
  121. let tmpItm = items[i]
  122. Floder.push(
  123. <div className={style.floderPart}>
  124. <div className={style.floderPartFl} onClick={(e)=>this.floderSlide(e,tmpItm)}>
  125. <img src={tmpItm.slide == 1?floderD:floderR} className={style.floderRD}/>
  126. {tmpItm.name}
  127. <span className={`${style.floderPartAction}`} id="floderActionBtn" onClick={(e)=>{this.floderAction(e,tmpItm.id)}}>...</span>
  128. {tmpItm.action == 1&&<div className={style.floderAction} id="floderAction">
  129. <p onClick={(e)=>{this.floderRename(e)}}>重命名文件夹</p>
  130. <p onClick={(e)=>{this.floderDelete(e)}}>删除文件夹</p>
  131. </div>}
  132. </div>
  133. {
  134. tmpItm.templateInfo&&tmpItm.templateInfo.length>0&&<div className={style.floderPartFr}>
  135. {
  136. this.getFloderLis(tmpItm.templateInfo,flg)
  137. }
  138. </div>
  139. }
  140. </div>
  141. )
  142. }
  143. return Floder
  144. }
  145. getFloderLis(items,flg){//文件夹内的模板明细
  146. const Items = [];
  147. const {admin,checkItemsAdmin} = this.props;
  148. items.forEach((v,idx) => {
  149. Items.push(
  150. <TemplateItem
  151. {...v}
  152. key={v.id}
  153. idx={idx}
  154. checkItems={this.props.checkItems}
  155. allCheckShow={this.props.allCheckShow}
  156. handleContentClick={this.props.handleContentClick}
  157. handleTemplateDel={this.props.handleTemplateDel}
  158. handleTitleChange={this.props.handleTitleChange}
  159. admin={this.props.admin}
  160. adminflg={flg}
  161. checkItemsAdmin={checkItemsAdmin}
  162. allCheckShowAdmin={this.props.allCheckShowAdmin}
  163. />
  164. );
  165. });
  166. return Items;
  167. }
  168. getCheckIcon() {
  169. const {admin,checkItems,items,checkItemsAdmin,adminItems} = this.props;
  170. if(admin){
  171. if (adminItems.length == checkItemsAdmin.length && checkItemsAdmin.length != 0) {
  172. return check_right;
  173. } else {
  174. return check_circle;
  175. }
  176. }
  177. if (items.length == checkItems.length && checkItems.length != 0) {
  178. return tmpAllRight;
  179. } else {
  180. return tmpAllCircle;
  181. }
  182. }
  183. templateSearch(){
  184. const {templateSearch} = this.props
  185. templateSearch((this.$search.current.value).trim())
  186. if(this.$search.current.value.trim()){
  187. this.setState({
  188. msg:'暂无模板信息'
  189. })
  190. }else{
  191. this.setState({
  192. msg:'还没有保存模板'
  193. })
  194. }
  195. }
  196. handleEnter(e){
  197. if(e.keyCode==13){
  198. this.templateSearch();
  199. }
  200. }
  201. handleChange(){
  202. const value = (this.$search.current.value).substring(0,30);
  203. // this.$search.current.value = value
  204. setTimeout(() => {
  205. this.setState({
  206. val: value
  207. });
  208. }, 30);
  209. }
  210. clear(){
  211. this.$search.current.value = '';
  212. this.setState({
  213. val:''
  214. });
  215. this.$search.current.focus();
  216. this.templateSearch();
  217. }
  218. clickTabChange(){
  219. }
  220. componentWillReceiveProps(next){
  221. //点清空恢复初始状态
  222. if(this.props.clearSearch!==next.clearSearch){
  223. this.clear();
  224. }
  225. }
  226. render() {
  227. const {selectTemp,whichTemp, checkItemsAdmin,handleAllCheckboxAdmin,handleMangerTemplateAdmin,allCheckShowAdmin,admin,adminItems,allCheckShow, handleMangerTemplate,handleClickGetMore, handleDelList, handleAllCheckbox, items,checkItems,current,hasMore } = this.props;
  228. const {height,showTipContent} = this.state
  229. return (
  230. <div className={style.wrapper} >
  231. {//管理员操作
  232. adminItems&&admin ? (allCheckShowAdmin ?
  233. <div className={style.wrapperTop}>
  234. <div className={style['check-wrap']} onClick={handleAllCheckboxAdmin} style={{paddingLeft:'10px'}}>
  235. <img className={`${style['fl-element']} ${style['check-box']}`} src={this.getCheckIcon()} />
  236. </div>
  237. <span onClick={handleAllCheckboxAdmin}>全选</span>
  238. <span className={`${style['fr-element']} ${style['done']}`} onClick={handleMangerTemplateAdmin}>完成</span>
  239. {
  240. checkItemsAdmin.length>0?<span className={`${style['fr-element']} ${style['del-items']}`} onClick={handleDelList}>删除</span>:
  241. <span className={`${style['fr-element']} ${style['del-items-gray']}`}>删除</span>
  242. }
  243. </div> :
  244. <div className={style.wrapperTop}>
  245. <div className={style.templateSearch}>
  246. <input placeholder="模板搜索" id="searchTmp" maxLength="30" ref={this.$search} type="text" onInput={this.handleChange} onPropertyChange={this.handleChange} onKeyUp={this.handleEnter}/>
  247. {this.state.val?<img src={delIcon} id='clearTemplateSearch' alt="清空" onClick={this.clear}/>:''}
  248. <div className={style.search} onClick={this.templateSearch}>搜索</div>
  249. </div>
  250. {
  251. adminItems.length > 0&&<span className={`${style['fr-element']} ${style['manger']}`} onClick={handleMangerTemplateAdmin}>管理</span>
  252. }
  253. </div>) : null
  254. }
  255. {//个人
  256. items&&!admin ?
  257. <div className={style.wrapperTop}>
  258. <div className={style.templateSearch}>
  259. <input placeholder="模板搜索" id="searchTmp" maxLength="30" ref={this.$search} type="text" onInput={this.handleChange} onPropertyChange={this.handleChange} onKeyUp={this.handleEnter}/>
  260. {this.state.val?<img src={delIcon} alt="清空" onClick={this.clear}/>:''}
  261. <div className={style.search} onClick={this.templateSearch}>搜索</div>
  262. </div>
  263. </div> : null
  264. }
  265. {
  266. <div className={style.comAdminWrp}>
  267. <div className={`${style.tempLists} ${style.tempListsP}`} ref={this.$cont} style={{display:admin?'none':'block',border:'1px solid #EAEDF1'}}>
  268. {//个人
  269. allCheckShow ?<div className={`${style.wrapperTop} ${style.wrapperTopM} ${style.personalTmp} ${selectTemp==1?style.personalTmpOwn:null}`} onClick={()=>whichTemp(1)}>
  270. <i></i>
  271. <i></i>
  272. <div className={style['check-wrap']} onClick={handleAllCheckbox}>
  273. <img className={`${style['fl-element']} ${style['check-box']}`} src={this.getCheckIcon()} />
  274. </div>
  275. <span onClick={handleAllCheckbox}>全选</span>
  276. <span className={`${style['fr-element']} ${style['done']}`} onClick={handleMangerTemplate}>完成</span>
  277. {checkItems.length>0&&<span className={`${style['fr-element']} ${style['del-items']}`} onClick={handleDelList}>删除</span>}
  278. {/* {
  279. checkItems.length>0?<span className={`${style['fr-element']} ${style['del-items']}`} onClick={handleDelList}>删除</span>:
  280. <span className={`${style['fr-element']} ${style['del-items-gray']}`}>删除</span>
  281. } */}
  282. </div>:null
  283. }
  284. {
  285. <div className={`${style.topBorder} clearfix`}>
  286. {
  287. !allCheckShow&&<div className={`${style.personalTmp} ${selectTemp==1?style.personalTmpOwn:''} clearfix`} onClick={()=>whichTemp(1)}>
  288. <span className={style.tip}>个人模板</span>
  289. <i></i>
  290. {
  291. items.length > 0&&<span className={`${style['fr-element']} ${style['manger']}`} onClick={handleMangerTemplate}>管理</span>
  292. }
  293. </div>
  294. }
  295. {
  296. !admin?!allCheckShowAdmin&&<div
  297. className={`${style.personalTmp} ${style.personalTmpStatand} ${selectTemp==2?style.personalTmpOwn:''}`}
  298. onClick={()=>{whichTemp(2);allCheckShow&&handleMangerTemplate()}}
  299. >标准模板 {selectTemp==2&&<img src={tempTip} className={style.tempTip} alt="" onMouseEnter={this.showTipContent} onMouseLeave={this.showTipContent}/>}
  300. {
  301. showTipContent&&<div className={style.tempTipContent}>
  302. <img src={tempTrd} alt=""/>
  303. <p>1. 标准模版中的科室,对应的是经朗通医疗团队整理的,符合临床医学意义的科室。</p>
  304. <p>2.只有特定的“管理员”账号,可对“标准模板”进行修改,普通账号仅可进行“引用”;</p>
  305. </div>
  306. }
  307. </div>:''
  308. }
  309. </div>
  310. }
  311. {
  312. <div style={{height:height-54+'px',overflow:'auto'}}>
  313. {
  314. selectTemp==1&&this.genItems(items).length > 0?this.genItems(items):selectTemp==2&&this.genAdminItems(adminItems,true).length > 0?this.genAdminItems(adminItems,true): <Empty message={this.state.msg}></Empty>
  315. }
  316. </div>
  317. }
  318. </div>
  319. {
  320. admin&&<div className={style.tempLists} ref={this.$conts} style={{border:admin?'0':'1px solid #EAEDF1'}}>
  321. <div style={{height:height+'px',overflow:'auto'}}>
  322. {this.genAdminItems(adminItems,true).length > 0?this.genAdminItems(adminItems,true): <Empty message={this.state.msg}></Empty>}
  323. </div>
  324. </div>
  325. }
  326. </div>
  327. }
  328. {/* <div className={style.tempLists} ref={this.$cont}>
  329. {
  330. this.genItems().length > 0?this.genItems(): <Empty message={this.state.msg}></Empty>
  331. }
  332. {//注释掉的暂时没有分也功能
  333. hasMore?<p onClick={()=>handleClickGetMore(current)} className={style.loadMore}>点击查看更多</p>:null
  334. }
  335. </div> */}
  336. </div>
  337. )
  338. }
  339. }
  340. export default TemplateItems;
  341. TemplateItems.propTypes = {
  342. items: PropTypes.arrayOf(PropTypes.object),
  343. handleContentClick: PropTypes.func,
  344. handleUpdate: PropTypes.func,
  345. handleTemplateDel: PropTypes.func,
  346. handleTitleChange: PropTypes.func
  347. };