index.jsx 18 KB

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