index.jsx 17 KB

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