index.jsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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 check_circle from './img/check-circle.png';
  10. import check_right from './img/check-right.png';
  11. import {getAllDataList,getAllDataStringList,isAllClear,filterDataArr,readyKeepHistory} from '@utils/tools';
  12. import store from '@store';
  13. import $ from 'jquery';
  14. class Operation extends Component {
  15. constructor(props) {
  16. super(props)
  17. this.state = {
  18. title: '',
  19. okText: '',
  20. borderColor: '',
  21. okColor: '',
  22. oKBg: '',
  23. msg: '',
  24. type: '',
  25. zIndex:40,
  26. sex:'3',
  27. le:'',
  28. }
  29. this.showPrint = this.showPrint.bind(this);
  30. this.closePrint = this.closePrint.bind(this);
  31. this.showPreview = this.showPreview.bind(this);
  32. this.closePreview = this.closePreview.bind(this);
  33. this.saveAll = this.saveAll.bind(this);
  34. this.clearAll = this.clearAll.bind(this);
  35. this.saveHis = this.saveHis.bind(this);
  36. this.keypress = this.keypress.bind(this);
  37. }
  38. showPrint() {
  39. this.setState({
  40. zIndex:240
  41. })
  42. this.props.showPrintPreview()
  43. }
  44. closePrint() {
  45. this.setState({
  46. zIndex:40
  47. })
  48. this.props.closePrintPreview()
  49. }
  50. showPreview() {
  51. this.setState({
  52. zIndex:240
  53. })
  54. this.props.showPreview()
  55. }
  56. closePreview() {
  57. this.setState({
  58. zIndex:40
  59. })
  60. this.props.closePreview()
  61. }
  62. saveAll(type) {
  63. let keepState = readyKeepHistory();
  64. if(keepState == 1){
  65. Notify.info('主诉不能为空');
  66. return;
  67. }else if(keepState == 2){
  68. Notify.info('诊断不能为空');
  69. return;
  70. }else{
  71. this.setState({
  72. type: type,
  73. okText: '保存',
  74. borderColor: '#3B9ED0',
  75. okColor: '#fff',
  76. oKBg: '#3B9ED0',
  77. msg: <p className={style['msg']}>是否保存该病历?</p>
  78. })
  79. this.props.diagShowTmp(true)
  80. }
  81. }
  82. clearAll(type) {
  83. let baseList = store.getState();
  84. let jsonData = getAllDataList(baseList);
  85. let jsonStr = getAllDataStringList(baseList);
  86. let flg = isAllClear(jsonData,jsonStr,baseList);
  87. if(flg){
  88. this.setState({
  89. type: type,
  90. okText: '清除',
  91. borderColor: 'red',
  92. okColor: 'red',
  93. oKBg: '#fff',
  94. msg: <p className={style['msg']}>是否清空所有内容?</p>
  95. })
  96. this.props.diagShowTmp(true)
  97. }else{
  98. Notify.info('当前页面数据已清空');
  99. }
  100. }
  101. onchange(val) {
  102. this.setState({
  103. title: val
  104. })
  105. }
  106. handleInput(e){
  107. let val = e.target.value
  108. if(e.target.value.length > 30){
  109. e.target.value = val.substring(0,30)
  110. this.onchange(val.substring(0,30))
  111. }else{
  112. this.onchange(e.target.value)
  113. }
  114. }
  115. keypress(event) {
  116. let e = event?event:window.event;
  117. if (e.keyCode == 13) {
  118. this.makeSure()
  119. }
  120. }
  121. saveHis(type) {
  122. const { diagShowTmp } = this.props;
  123. let flg = this.getAllData();
  124. if(flg){
  125. this.setState({
  126. title: '',
  127. sex:'3',
  128. type: type,
  129. okText: '保存',
  130. borderColor: '#3B9ED0',
  131. okColor: '#fff',
  132. oKBg: '#3B9ED0',
  133. msg: this.changeTitle()
  134. })
  135. diagShowTmp(true)
  136. }
  137. }
  138. getAllData(){
  139. let baseList = store.getState();
  140. let jsonData = getAllDataList(baseList);
  141. let jsonStr = getAllDataStringList(baseList);
  142. let whichSign = baseList.typeConfig.typeConfig;
  143. let tmpLis = baseList.tabTemplate.items;
  144. let flg = isAllClear(jsonData,jsonStr,baseList)
  145. if(!flg){
  146. Notify.info('模板数据不能为空')
  147. return false
  148. }
  149. console.log(jsonStr,'文本')
  150. console.log(jsonData,'结构') //测试需要用到,不要删了
  151. for(let i = 0;i <tmpLis.length;i++){
  152. let dataStr = tmpLis[i].preview;
  153. let dataJson = tmpLis[i].dataJson;
  154. // console.log(jsonStr.chief , JSON.stringify(eval('('+JSON.parse(dataStr).chief+')')))
  155. // console.log(jsonData.chief , JSON.parse(dataJson).chief)
  156. if(whichSign == 0){
  157. if(
  158. jsonStr.chief == JSON.stringify(eval('('+JSON.parse(dataStr).chief+')')) &&
  159. jsonStr.present == JSON.stringify(eval('('+JSON.parse(dataStr).present+')')) &&
  160. jsonStr.other == JSON.stringify(eval('('+JSON.parse(dataStr).other+')')) &&
  161. jsonStr.vital == JSON.stringify(eval('('+JSON.parse(dataStr).vital+')')) &&
  162. JSON.stringify(jsonData.chief) == JSON.stringify(JSON.parse(dataJson).chief) &&
  163. JSON.stringify(jsonData.present) == JSON.stringify(JSON.parse(dataJson).present) &&
  164. JSON.stringify(jsonData.other) == JSON.stringify(JSON.parse(dataJson).other) &&
  165. JSON.stringify(jsonData.vital) == JSON.stringify(JSON.parse(dataJson).vital) &&
  166. JSON.stringify(jsonData.lis) == JSON.stringify(JSON.parse(dataJson).lis) &&
  167. JSON.stringify(jsonData.pacs) == JSON.stringify(JSON.parse(dataJson).pacs) &&
  168. JSON.stringify(jsonData.diag) == JSON.stringify(JSON.parse(dataJson).diag) &&
  169. JSON.stringify(jsonData.advice) == JSON.stringify(JSON.parse(dataJson).advice) &&
  170. JSON.stringify(jsonData.mainSuitSelecteds) == JSON.stringify(JSON.parse(dataJson).mainSuitSelecteds) &&
  171. JSON.stringify(jsonData.currentIllSelecteds) == JSON.stringify(JSON.parse(dataJson).currentIllSelecteds) &&
  172. JSON.stringify(jsonData.otherHistorySelecteds) == JSON.stringify(JSON.parse(dataJson).otherHistorySelecteds) &&
  173. JSON.stringify(jsonData.checkBodySelecteds) == JSON.stringify(JSON.parse(dataJson).checkBodySelecteds) &&
  174. JSON.stringify(jsonData.addItems) == JSON.stringify(JSON.parse(dataJson).addItems)
  175. ){
  176. Notify.info('该模板已保存');
  177. return false;
  178. }
  179. }else if(whichSign == 1){
  180. if(
  181. jsonStr.chief == JSON.stringify(eval('('+JSON.parse(dataStr).chief+')')) &&
  182. jsonStr.present == JSON.stringify(eval('('+JSON.parse(dataStr).present+')')) &&
  183. jsonStr.other == JSON.stringify(eval('('+JSON.parse(dataStr).other+')')) &&
  184. jsonStr.vital == JSON.stringify(eval('('+JSON.parse(dataStr).vital+')')) &&
  185. JSON.stringify(jsonData.vital) == JSON.stringify(JSON.parse(dataJson).vital) &&
  186. JSON.stringify(jsonData.lis) == JSON.stringify(JSON.parse(dataJson).lis) &&
  187. JSON.stringify(jsonData.pacs) == JSON.stringify(JSON.parse(dataJson).pacs) &&
  188. JSON.stringify(jsonData.diag) == JSON.stringify(JSON.parse(dataJson).diag) &&
  189. JSON.stringify(jsonData.advice) == JSON.stringify(JSON.parse(dataJson).advice) &&
  190. JSON.stringify(jsonData.addItems) == JSON.stringify(JSON.parse(dataJson).addItems)
  191. ){
  192. Notify.info('该模板已保存');
  193. return false;
  194. }
  195. }
  196. }
  197. return true;
  198. }
  199. changeTitle() {
  200. return <div className={style['box']}>
  201. <input className={style['ipt']}
  202. placeholder="请输入模板名称"
  203. type="text"
  204. maxLength='30'
  205. onInput={(e) => {
  206. this.handleInput(e)
  207. }}
  208. onPropertyChange={(e) => { // 兼容ie
  209. this.handleInput(e)
  210. }}
  211. onKeyPress={e => this.keypress(e)}
  212. />
  213. <div className={style['line']}></div>
  214. <div className={style['iptWrap']}>
  215. <p>请选择模板性别归属(错误引用,显示可能有误)</p>
  216. <span className={style['commonSex']} id="commonSex" onClick={this.changeRadio.bind(this,1)}><img src={check_right} alt=""/><i style={{color:'#000'}}>通用</i></span>
  217. <span id="maleSex" onClick={this.changeRadio.bind(this,2)}><img src={check_circle} alt=""/><i>男</i></span>
  218. <span id="femaleSex" onClick={this.changeRadio.bind(this,3)}><img src={check_circle} alt=""/><i>女</i></span>
  219. </div>
  220. </div>
  221. }
  222. changeRadio(sex){
  223. if(sex == 1){
  224. $('#commonSex img').attr('src',check_right)
  225. $('#maleSex img').attr('src',check_circle)
  226. $('#femaleSex img').attr('src',check_circle)
  227. $('#commonSex i').css('color','#000')
  228. $('#maleSex i').css('color','#6b6969')
  229. $('#femaleSex i').css('color','#6b6969')
  230. this.setState({sex:'3'})
  231. }else if(sex == 2){
  232. $('#commonSex img').attr('src',check_circle)
  233. $('#maleSex img').attr('src',check_right)
  234. $('#femaleSex img').attr('src',check_circle)
  235. $('#commonSex i').css('color','#6b6969')
  236. $('#maleSex i').css('color','#000')
  237. $('#femaleSex i').css('color','#6b6969')
  238. this.setState({sex:'1'})
  239. }else if(sex == 3){
  240. $('#commonSex img').attr('src',check_circle)
  241. $('#maleSex img').attr('src',check_circle)
  242. $('#femaleSex img').attr('src',check_right)
  243. $('#commonSex i').css('color','#6b6969')
  244. $('#maleSex i').css('color','#6b6969')
  245. $('#femaleSex i').css('color','#000')
  246. this.setState({sex:'2'})
  247. }
  248. }
  249. makeSure() {
  250. const { save, clear, saveDataAll,diagShowTmp ,chronicMagItem,chronicDesease} = this.props;
  251. const { type } = this.state;
  252. if (type == 1) {
  253. diagShowTmp(false)
  254. this.setState({ title: '' })
  255. save();
  256. } else if (type == 2) {
  257. diagShowTmp(false)
  258. this.setState({ title: '' })
  259. // 慢病标识
  260. const chronicFlag = chronicMagItem&&chronicMagItem.name || chronicDesease&&chronicDesease.name?true:false;
  261. clear(chronicFlag);
  262. } else if (type == 3) {
  263. if (this.state.title.trim() == '') {
  264. Notify.error('请输入模板名称')
  265. return;
  266. }
  267. saveDataAll(this.state.title,this.state.sex);
  268. }
  269. }
  270. closeDiagBox(){
  271. const { diagShowTmp } = this.props;
  272. const { type } = this.state;
  273. if (type == 3){
  274. diagShowTmp(false)
  275. this.setState({ title: '' })
  276. }else{
  277. diagShowTmp(false)
  278. this.setState({ title: '' })
  279. }
  280. }
  281. componentWillReceiveProps(next){//监听滚动事件
  282. const that = this;
  283. if(next.winWidth <= 1024){
  284. /*$(document).on('scroll',function(){
  285. let left = -($(document).scrollLeft() - 10) + 'px';
  286. that.setState({
  287. le:left
  288. })
  289. })*/
  290. $(window).scroll(function(){
  291. let scrollLeft = document.body.scrollLeft || document.documentElement.scrollLeft;
  292. let left = -(scrollLeft - 10) +'px';
  293. that.setState({
  294. le:left
  295. })
  296. })
  297. }
  298. }
  299. render() {
  300. const { showPrint, closePrint, showPreview, closePreview } = this;
  301. const { visible, preVisible,diagShow } = this.props.print;
  302. const {winWidth} = this.props;
  303. const {zIndex,type,le} = this.state;
  304. return <div className={style['container']} style={{zIndex:zIndex,left:le}}>
  305. <span className={style['button']} onClick={showPrint}><img src={printImg} /> 打印病历</span>
  306. <span className={style['preButton']} onClick={showPreview}><img src={preview} /> 预览</span>
  307. <span className={style['preButton']} onClick={() => { this.saveHis(3) }}><img src={saveHistory} /> 保存病历模板</span>
  308. <span className={winWidth<=1082?`${style['saveButton']} ${style['minstyle']}`: style['saveButton']} onClick={() => { this.saveAll(1) }}>保存</span>
  309. <span className={winWidth<=1082?`${style['clearButton']} ${style['saveButton']} ${style['minstyle']}`:`${style['clearButton']} ${style['saveButton']}`} onClick={() => { this.clearAll(2) }}>清除</span>
  310. <PrintPreviewContainer visible={visible} onClose={closePrint} />
  311. <PreviewContainer visible={preVisible} onClose={closePreview} />
  312. <ConfirmModal
  313. visible={diagShow} //改为全局控制
  314. confirm={() => { this.makeSure() }}
  315. close={() => { this.closeDiagBox()}}
  316. cancel={() => {this.closeDiagBox()}}
  317. okText={this.state.okText}
  318. height={type==3?228:200}
  319. width={type==3?400:300}
  320. okBorderColor={this.state.borderColor}
  321. okColor={this.state.okColor}
  322. oKBg={this.state.oKBg}
  323. >
  324. {this.state.msg}
  325. </ConfirmModal>
  326. </div>;
  327. }
  328. }
  329. export default Operation;