index.jsx 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. import React from 'react';
  2. import ReactDOM from 'react-dom';
  3. import style from './index.less';
  4. import close from './img/close.png';
  5. import { Notify } from '@commonComp';
  6. import floderR from './img/floderR.png';
  7. import floderD from './img/floderD.png';
  8. import diagUp from '@common/images/diagUp.png';
  9. import diagDown from '@common/images/diagDown.png';
  10. class FolderOrder extends React.Component {
  11. constructor(props) {
  12. super(props);
  13. this.state = {
  14. folderModal:false,
  15. selectIndex: -1,
  16. folderList: null
  17. }
  18. this.textInput = React.createRef();
  19. this.orderFolder = this.orderFolder.bind(this)
  20. this.saveOrderFolder = this.saveOrderFolder.bind(this)
  21. }
  22. componentWillReceiveProps(props) {
  23. this.setState({
  24. folderList: JSON.parse(JSON.stringify(props.adminItems)),
  25. selectIndex: -1
  26. })
  27. }
  28. floderSlide(e,i) {
  29. const selectIndex = this.state.selectIndex
  30. if(selectIndex === i) {
  31. this.setState({
  32. selectIndex: -1
  33. })
  34. } else {
  35. this.setState({
  36. selectIndex: i
  37. })
  38. }
  39. }
  40. saveOrderFolder(){
  41. const {saveOrderFolder,patInfo,folderManage} = this.props
  42. const {folderList} = this.state
  43. let folderListFilter = []
  44. for(let i = 0; i < folderList.length; i++) {
  45. let templateList = []
  46. if(folderList[i].templateInfo) {
  47. for(let j = 0; j < folderList[i].templateInfo.length;j++) {
  48. const templateItem = folderList[i].templateInfo[j]
  49. templateList.push({
  50. "folderId": templateItem.folderId,
  51. "id": templateItem.folderMappingId,
  52. "isDeleted": "N",
  53. "orderNo": j,
  54. "templateId": templateItem.id
  55. })
  56. }
  57. }
  58. const item =
  59. {
  60. "doctorId": patInfo.doctorId,
  61. "hospitalId": patInfo.hospitalId,
  62. "id": folderList[i].id,
  63. "isDeleted": "N",
  64. "name": folderList[i].name,
  65. "orderNo": i,
  66. "templateSortVOList": templateList
  67. }
  68. folderListFilter.push(item)
  69. }
  70. saveOrderFolder(folderListFilter)
  71. folderManage(false)
  72. }
  73. orderFolder(index,e) {
  74. e.stopPropagation();
  75. const {selectIndex, folderList} = this.state
  76. const folderListCopy = JSON.parse(JSON.stringify(folderList))
  77. const item = folderListCopy[index]
  78. if(index > 0) {
  79. folderListCopy.splice(index, 1)
  80. folderListCopy.splice(index-1, 0 , item)
  81. if(index === selectIndex) {
  82. this.setState({
  83. selectIndex: selectIndex-1
  84. })
  85. }else if(index === selectIndex+1){
  86. this.setState({
  87. selectIndex: selectIndex+1
  88. })
  89. }
  90. } else {
  91. folderListCopy.splice(index, 1)
  92. folderListCopy.splice(index+1, 0 , item)
  93. this.setState({
  94. selectIndex: selectIndex+1
  95. })
  96. }
  97. this.setState({
  98. folderList: folderListCopy
  99. })
  100. }
  101. orderTemplate(i,index, e) {
  102. e.stopPropagation();
  103. const folderListCopy = JSON.parse(JSON.stringify(this.state.folderList))
  104. const olderItem = folderListCopy[i]
  105. const templateList = olderItem.templateInfo
  106. const templateItem = templateList[index]
  107. if(index > 0) {
  108. templateList.splice(index, 1)
  109. templateList.splice(index-1, 0 , templateItem)
  110. } else {
  111. templateList.splice(index, 1)
  112. templateList.splice(index+1, 0 , templateItem)
  113. }
  114. this.setState({
  115. folderList: folderListCopy
  116. })
  117. }
  118. genAdminItems(items,flg) {
  119. const Floder=[],Items = [];
  120. const {admin,checkItemsAdmin} = this.props;
  121. const { selectIndex } = this.state;
  122. for(let i = 0;i < items.length;i++){
  123. let tmpItm = items[i]
  124. Floder.push(
  125. <div className={style.floderBox}>
  126. <div className={style.floderItem} onClick={(e)=>{tmpItm.templateInfo&&tmpItm.templateInfo.length>0 ?this.floderSlide(e,i) :''}}>
  127. <img src={selectIndex == i?floderD:floderR} className={style.floderRD}/>
  128. {tmpItm.name}({tmpItm.templateInfoCount})
  129. <img class={style.orderIcon} src={i===0?diagDown:diagUp} alt="排序" onClick={this.orderFolder.bind(this, i)}/>
  130. {/* <span className={`${style.floderPartAction}`} id="floderActionBtn" onClick={(e)=>{this.floderAction(e,i)}}>...</span> */}
  131. </div>
  132. {
  133. i==selectIndex&&tmpItm.templateInfo&&tmpItm.templateInfo.length>0&&<div className={style.floderPartFr}>
  134. { tmpItm.templateInfo.map((templateItem, index) => {
  135. return (<div class={style.templateItem}>
  136. {templateItem.name}
  137. <img class={style.orderIcon} src={index===0?diagDown:diagUp} alt="排序" onClick={this.orderTemplate.bind(this, i, index)}/>
  138. </div>)
  139. })}
  140. </div>
  141. }
  142. </div>
  143. )
  144. }
  145. return Floder
  146. }
  147. onKeyPress(event){
  148. let e = event?event:window.event;
  149. if (e.keyCode == 13) {
  150. this.saveNewFolder()
  151. }
  152. }
  153. render() {
  154. const { folderOrderShow,title,folderManage,adminItems, } = this.props;
  155. const domNode = document.getElementById('root');
  156. const items = this.state.folderList
  157. return folderOrderShow&&ReactDOM.createPortal(
  158. <div className={style.newFolderWrap}>
  159. <div className={style.folderModal} onClick={()=>folderManage(false)}></div>
  160. <div className={style.nameWrap}>
  161. <div className={style.title}>
  162. {
  163. title?<div className={style.titleCon}>{title}</div>:null
  164. }
  165. <img src={close} alt="关闭" onClick={()=>folderManage(false)}/>
  166. </div>
  167. <div className={style['delContent']}>
  168. {this.genAdminItems(items,true)}
  169. </div>
  170. <div className={style['delFoot']}>
  171. <div className={style.halfBtn}>
  172. <span className={`${style['delBtn']} ${style['delDel']}`} onClick={this.saveOrderFolder}>保存</span>
  173. </div>
  174. <div className={style.halfBtn}>
  175. <span className={`${style['delBtn']} ${style['delCancel']}`} onClick={()=>folderManage(false)}>取消</span>
  176. </div>
  177. </div>
  178. </div>
  179. </div>,domNode)
  180. }
  181. }
  182. export default FolderOrder;