index.jsx 9.4 KB

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