index.jsx 8.9 KB

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