index.jsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. import React, { Component } from "react";
  2. import style from "./index.less";
  3. import Select from './Select/index'
  4. import { timesYMDTime, timestampToTime} from '@utils/tools';
  5. import config from '@config/index';
  6. import Notify from '@commonComp/Notify';
  7. import { getHospitalInfo } from '@store/async-actions/historyTemplates';
  8. import store from '@store';
  9. import { embedPush } from '../../store/async-actions/pushMessage'
  10. class PatInfo extends Component {
  11. constructor(props){
  12. super(props)
  13. this.state ={
  14. patientInfo: [
  15. {
  16. label: 'patientIdNo',
  17. id: 'patientIdNo',
  18. value: '330127198912311234',
  19. title: '卡号',
  20. maxlength: 50
  21. },
  22. {
  23. label: 'patientName',
  24. id: 'patientName',
  25. value: '王明明',
  26. title: '姓名',
  27. maxlength: 50
  28. },
  29. {
  30. label: 'patientAge',
  31. id: 'patientAge',
  32. value: '50',
  33. title: '年龄',
  34. maxlength: 11
  35. },
  36. {
  37. label: 'patientSex',
  38. id: 'patientSex',
  39. value: 2,
  40. title: '性别',
  41. maxlength: 11
  42. },
  43. {
  44. label: 'systemTime',
  45. id: 'systemTime',
  46. // value: timesYMDTime(new Date().getTime()),
  47. value: timestampToTime(new Date().getTime()),
  48. title: '就诊时间',
  49. maxlength: 100
  50. },
  51. {
  52. label: 'hospitalDeptName',
  53. id: 'hospitalDeptName',
  54. value: '全科',
  55. title: '科室',
  56. maxlength: 50
  57. },
  58. {
  59. label: 'doctorName',
  60. id: 'doctorName',
  61. value: '付医生',
  62. title: '医生',
  63. maxlength: 50
  64. },
  65. {
  66. label: 'recordId',
  67. id: 'recordId',
  68. value: '4332',
  69. title: '门诊号',
  70. maxlength: 50
  71. }
  72. ],
  73. timer: null,
  74. }
  75. this.handleChange = this.handleChange.bind(this)
  76. this.handleSexChange = this.handleSexChange.bind(this)
  77. this.inputOnFocus = this.inputOnFocus.bind(this)
  78. }
  79. componentWillMount() {
  80. const { getMessage, initPatInfoData } = this.props;
  81. getMessage && getMessage()
  82. initPatInfoData && initPatInfoData(this.state.patientInfo)
  83. store.dispatch(getHospitalInfo())
  84. // console.log(timesYMDTime(new Date().getTime()),'电脑时间');
  85. }
  86. componentWillReceiveProps(nextProps){
  87. // console.log(nextProps,'nextProps');
  88. const { patInfoData } = nextProps.patInfo
  89. this.setState({
  90. patientInfo:patInfoData
  91. })
  92. }
  93. handleChange(e){
  94. const tempTimer = this.state.timer
  95. const { initPatInfoData } = this.props;
  96. let { patientInfo } = this.state;
  97. let newInfo = Object.assign([], patientInfo);
  98. let patientItem = newInfo.find(item =>{
  99. return item.id === e.target.id
  100. })
  101. // if (patientItem.id === 'patientAge'){
  102. // let temp = Math.round(e.target.value.replace(/[^\d\.]+/, ''))
  103. // if (isNaN(temp)){
  104. // patientItem.value = 50
  105. // Notify.info('请输入正确的年龄')
  106. // return
  107. // }else {
  108. // patientItem.value = temp
  109. // }
  110. // } else {
  111. // patientItem.value = e.target.value;
  112. // }
  113. patientItem.value = e.target.value; // 20201014 取消年龄格式限制 lcq
  114. if (patientItem.id === 'patientAge' && +patientItem.value > 200) {
  115. Notify.info('年龄不能超过200')
  116. // return false
  117. }
  118. this.setState({
  119. patientInfo: newInfo
  120. })
  121. initPatInfoData && initPatInfoData(newInfo)
  122. // 年龄/科室改变时,默认延迟推送
  123. if (patientItem.id === 'patientAge' || patientItem.id === 'hospitalDeptName') {
  124. clearTimeout(tempTimer)
  125. let timer =setTimeout(() => {
  126. store.dispatch(embedPush({
  127. action: "patientia",
  128. mode: 1
  129. }))
  130. clearTimeout(tempTimer)
  131. }, config.delayPushTime);
  132. this.setState({
  133. timer
  134. })
  135. }
  136. }
  137. handleSexChange (item){
  138. const { initPatInfoData } = this.props;
  139. let { patientInfo } = this.state;
  140. let newInfo = Object.assign([], patientInfo);
  141. newInfo[3] = item
  142. this.setState({
  143. patientInfo: newInfo
  144. })
  145. initPatInfoData && initPatInfoData(newInfo)
  146. }
  147. // 获取焦点推送
  148. inputOnFocus(){
  149. store.dispatch(embedPush({
  150. action: "info",
  151. mode: 1
  152. }))
  153. }
  154. render(){
  155. const {message} = this.props.patInfo;
  156. return (
  157. <div className={style["infoContainer"]}>
  158. {
  159. this.state.patientInfo.map((item, index) => {
  160. return (
  161. <div className={style["infoItem"]} key={item.id}>
  162. <label for={item.label}>{item.title}:</label>
  163. {item.id === 'patientSex' && (
  164. <Select
  165. default={this.state.patientInfo[3]}
  166. label=""
  167. placeholder="请选择"
  168. onChange={(item) => this.handleSexChange(item)}
  169. ></Select>
  170. )}
  171. {item.id === 'patientAge' && (<input id={item.id} type="text" autocomplete="off" maxlength={11} value={item.value} onChange={this.handleChange} onFocus={this.inputOnFocus}/>)}
  172. {item.id === 'systemTime' && (<input id={item.id} type="text" autocomplete="off" disabled value={item.value.split(' ')[0]} onChange={this.handleChange} onFocus={this.inputOnFocus}/>)}
  173. {item.id !== 'patientAge' && item.id !== 'patientSex' && item.id !== 'systemTime' && (<input id={item.id} type="text" maxlength={item.maxlength} autocomplete="off" value={item.value} onChange={this.handleChange} onFocus={this.inputOnFocus}/>) }
  174. </div>
  175. )
  176. })
  177. }
  178. </div>
  179. );
  180. }
  181. }
  182. export default PatInfo;