index.jsx 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. import React, { Component } from "react";
  2. import style from "./index.less";
  3. import printImg from '@common/images/icon_print_blue.png';
  4. import preview from '@common/images/preview.png';
  5. import saveHistory from '@common/images/saveHistory.png';
  6. import PrintPreviewContainer from '@containers/PrintPreviewContainer';
  7. import PreviewContainer from '@containers/PreviewContainer';
  8. import { ConfirmModal, Notify } from '@commonComp';
  9. import {getAllDataList,getAllDataStringList} from '@utils/tools';
  10. import store from '@store';
  11. class Operation extends Component {
  12. constructor(props) {
  13. super(props)
  14. this.state = {
  15. title: '',
  16. okText: '',
  17. borderColor: '',
  18. okColor: '',
  19. oKBg: '',
  20. msg: '',
  21. type: '',
  22. zIndex:40
  23. }
  24. this.showPrint = this.showPrint.bind(this);
  25. this.closePrint = this.closePrint.bind(this);
  26. this.showPreview = this.showPreview.bind(this);
  27. this.closePreview = this.closePreview.bind(this);
  28. this.saveAll = this.saveAll.bind(this);
  29. this.clearAll = this.clearAll.bind(this);
  30. this.saveHis = this.saveHis.bind(this);
  31. this.keypress = this.keypress.bind(this);
  32. }
  33. showPrint() {
  34. this.setState({
  35. zIndex:240
  36. })
  37. this.props.showPrintPreview()
  38. }
  39. closePrint() {
  40. this.setState({
  41. zIndex:40
  42. })
  43. this.props.closePrintPreview()
  44. }
  45. showPreview() {
  46. this.setState({
  47. zIndex:240
  48. })
  49. this.props.showPreview()
  50. }
  51. closePreview() {
  52. this.setState({
  53. zIndex:40
  54. })
  55. this.props.closePreview()
  56. }
  57. saveAll(type) {
  58. let flg = this.keepHistory();
  59. if(flg){
  60. this.setState({
  61. type: type,
  62. okText: '保存',
  63. borderColor: '#3B9ED0',
  64. okColor: '#fff',
  65. oKBg: '#3B9ED0',
  66. msg: <p className={style['msg']}>是否保存该病历?</p>
  67. })
  68. this.props.diagShowTmp(true)
  69. }
  70. }
  71. keepHistory(){
  72. let baseList = store.getState();
  73. let jsonStr = getAllDataStringList(baseList);
  74. if(JSON.parse(jsonStr.chief).length == 1 && JSON.parse(jsonStr.chief)[0].trim() ==''){
  75. Notify.info('主诉不能为空');
  76. return false;
  77. }else if(jsonStr.chief && JSON.parse(jsonStr.chief).length < 1){
  78. Notify.info('主诉不能为空');
  79. return false;
  80. }else if(!jsonStr.diag || jsonStr.diag.trim().length < 1){
  81. Notify.info('诊断不能为空');
  82. return false;
  83. }else{
  84. return true;
  85. }
  86. }
  87. clearAll(type) {
  88. let flg = this.isClear();
  89. if(flg){
  90. this.setState({
  91. type: type,
  92. okText: '清除',
  93. borderColor: 'red',
  94. okColor: 'red',
  95. oKBg: '#fff',
  96. msg: <p className={style['msg']}>是否清空所有内容?</p>
  97. })
  98. this.props.diagShowTmp(true)
  99. }
  100. }
  101. isClear(){
  102. let baseList = store.getState();
  103. let jsonData = getAllDataList(baseList);
  104. let jsonStr = getAllDataStringList(baseList);
  105. if ( //结构化和文本数据都为空
  106. JSON.stringify(jsonData.advice) == '{}' &&
  107. jsonData.chief.length < 1 &&
  108. jsonData.diag.length < 1 &&
  109. jsonData.vital.length < 1 &&
  110. jsonData.other.length < 1 &&
  111. jsonData.pacs.length < 1 &&
  112. jsonData.present.length < 1 &&
  113. jsonData.lis.labelList.length < 1 &&
  114. jsonData.lis.getExcelDataList.length < 1 &&
  115. JSON.stringify(jsonData.advice) == '{}' &&
  116. jsonStr.chief == '[]' &&
  117. jsonStr.present == '[]' &&
  118. jsonStr.other == '[]' &&
  119. jsonData.vital.length < 1 &&
  120. jsonData.diag.length < 1 &&
  121. jsonData.pacs.length < 1 &&
  122. jsonData.lis.labelList.length < 1 &&
  123. jsonData.lis.getExcelDataList.length < 1
  124. ) {
  125. Notify.info('当前页面数据已清空');
  126. return false;
  127. }else{
  128. return true;
  129. }
  130. }
  131. onchange(val) {
  132. this.setState({
  133. title: val
  134. })
  135. }
  136. handleInput(e){
  137. let val = e.target.value
  138. if(e.target.value.length > 30){
  139. e.target.value = val.substring(0,30)
  140. this.onchange(val.substring(0,30))
  141. }else{
  142. this.onchange(e.target.value)
  143. }
  144. }
  145. keypress(event) {
  146. let e = event?event:window.event;
  147. if (e.keyCode == 13) {
  148. this.makeSure()
  149. }
  150. }
  151. saveHis(type) {
  152. const { diagShowTmp } = this.props;
  153. let flg = this.getAllData();
  154. if(flg){
  155. this.setState({
  156. title: '',
  157. type: type,
  158. okText: '保存',
  159. borderColor: '#3B9ED0',
  160. okColor: '#fff',
  161. oKBg: '#3B9ED0',
  162. msg: this.changeTitle()
  163. })
  164. diagShowTmp(true)
  165. }
  166. }
  167. getAllData(){
  168. let baseList = store.getState();
  169. let jsonData = getAllDataList(baseList);
  170. let jsonStr = getAllDataStringList(baseList);
  171. let whichSign = baseList.typeConfig.typeConfig;
  172. let tmpLis = baseList.tabTemplate.items;
  173. for(let i = 0;i <tmpLis.length;i++){
  174. let dataStr = tmpLis[i].preview;
  175. let jsStr = tmpLis[i].dataJson;
  176. // console.log(JSON.stringify(JSON.parse(dataStr)))
  177. // console.log(JSON.stringify(jsonStr))
  178. if(JSON.stringify(JSON.parse(dataStr)) == JSON.stringify(jsonStr) && jsStr == JSON.stringify(jsonData)){
  179. Notify.info('该模板已保存');
  180. return false;
  181. }
  182. }
  183. if (whichSign == 0) {
  184. if (
  185. JSON.stringify(jsonData.advice) == '{}' &&
  186. (jsonData.chief.length < 1 && jsonStr.chief == '[]') &&
  187. jsonData.diag.length < 1 &&
  188. jsonData.vital.length < 1 &&
  189. jsonData.other.length < 1 &&
  190. jsonData.pacs.length < 1 &&
  191. jsonData.present.length < 1 &&
  192. jsonData.lis.labelList.length < 1 &&
  193. jsonData.lis.getExcelDataList.length < 1
  194. ) {
  195. Notify.info('模板数据不能为空');
  196. return false;
  197. }else{
  198. return true;
  199. }
  200. } else if(whichSign == 1) {
  201. if (JSON.stringify(jsonData.advice) == '{}' &&
  202. jsonStr.chief == '[]' &&
  203. jsonStr.present == '[]' &&
  204. jsonStr.other == '[]' &&
  205. jsonData.vital.length < 1 &&
  206. jsonData.diag.length < 1 &&
  207. jsonData.pacs.length < 1 &&
  208. jsonData.lis.labelList.length < 1 &&
  209. jsonData.lis.getExcelDataList.length < 1
  210. ) {
  211. Notify.info('模板数据不能为空');
  212. return false;
  213. }else{
  214. return true;
  215. }
  216. }else{
  217. return true;
  218. }
  219. }
  220. changeTitle() {
  221. return <div className={style['box']}>
  222. <input className={style['ipt']}
  223. placeholder="请输入模板名称"
  224. type="text"
  225. maxLength='30'
  226. onInput={(e) => {
  227. this.handleInput(e)
  228. }}
  229. onPropertyChange={(e) => { // 兼容ie
  230. this.handleInput(e)
  231. }}
  232. onKeyPress={e => this.keypress(e)}
  233. />
  234. <div className={style['line']}></div>
  235. </div>
  236. }
  237. makeSure() {
  238. const { save, clear, saveDataAll,diagShowTmp } = this.props;
  239. const { type } = this.state;
  240. if (type == 1) {
  241. diagShowTmp(false)
  242. this.setState({ title: '' })
  243. save();
  244. } else if (type == 2) {
  245. diagShowTmp(false)
  246. this.setState({ title: '' })
  247. clear();
  248. } else if (type == 3) {
  249. if (this.state.title.trim() == '') {
  250. Notify.error('请输入模板名称')
  251. return;
  252. }
  253. // diagShowTmp(false)
  254. saveDataAll(this.state.title);
  255. }
  256. }
  257. closeDiagBox(){
  258. const { diagShowTmp } = this.props;
  259. const { type } = this.state;
  260. if (type == 3){
  261. diagShowTmp(false)
  262. this.setState({ title: '' })
  263. }else{
  264. diagShowTmp(false)
  265. this.setState({ title: '' })
  266. }
  267. }
  268. render() {
  269. const { showPrint, closePrint, showPreview, closePreview } = this;
  270. const { visible, preVisible,diagShow } = this.props.print;
  271. const {zIndex} = this.state;
  272. return <div className={style['container']} style={{zIndex:zIndex}}>
  273. <span className={style['button']} onClick={showPrint}><img src={printImg} /> 打印病历</span>
  274. <span className={style['preButton']} onClick={showPreview}><img src={preview} /> 预览</span>
  275. <span className={style['preButton']} onClick={() => { this.saveHis(3) }}><img src={saveHistory} /> 保存病历模板</span>
  276. <span className={style['saveButton']} onClick={() => { this.saveAll(1) }}>保存</span>
  277. <span className={`${style['clearButton']} ${style['saveButton']}`} onClick={() => { this.clearAll(2) }}>清除</span>
  278. <PrintPreviewContainer visible={visible} onClose={closePrint} />
  279. <PreviewContainer visible={preVisible} onClose={closePreview} />
  280. <ConfirmModal
  281. visible={diagShow} //改为全局控制
  282. confirm={() => { this.makeSure() }}
  283. close={() => { this.closeDiagBox()}}
  284. cancel={() => {this.closeDiagBox()}}
  285. okText={this.state.okText}
  286. okBorderColor={this.state.borderColor}
  287. okColor={this.state.okColor}
  288. oKBg={this.state.oKBg}
  289. >
  290. {this.state.msg}
  291. </ConfirmModal>
  292. </div>;
  293. }
  294. }
  295. export default Operation;