index.jsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import React, { Component } from "react";
  2. import style from "./index.less";
  3. import {
  4. timesYMDTime
  5. } from '@utils/tools';
  6. class PatInfo extends Component {
  7. constructor(props){
  8. super(props)
  9. this.state ={
  10. patientInfo: [
  11. {
  12. label: 'patientIdNo',
  13. id: 'patientIdNo',
  14. value: '330127198912311234',
  15. title: '卡号',
  16. maxlength: 50
  17. },
  18. {
  19. label: 'patientName',
  20. id: 'patientName',
  21. value: '王明明',
  22. title: '姓名',
  23. maxlength: 50
  24. },
  25. {
  26. label: 'patientAge',
  27. id: 'patientAge',
  28. value: '50',
  29. title: '年龄',
  30. maxlength: 11
  31. },
  32. {
  33. label: 'patientSex',
  34. id: 'patientSex',
  35. value: 2,
  36. title: '性别',
  37. maxlength: 11
  38. },
  39. {
  40. label: 'systemTime',
  41. id: 'systemTime',
  42. value: timesYMDTime(new Date().getTime()),
  43. title: '就诊时间',
  44. maxlength: 100
  45. },
  46. {
  47. label: 'hospitalDeptName',
  48. id: 'hospitalDeptName',
  49. value: '全科',
  50. title: '科室',
  51. maxlength: 50
  52. },
  53. {
  54. label: 'doctorName',
  55. id: 'doctorName',
  56. value: '付医生',
  57. title: '医生',
  58. maxlength: 50
  59. },
  60. {
  61. label: 'recordId',
  62. id: 'recordId',
  63. value: '4332',
  64. title: '门诊号',
  65. maxlength: 50
  66. }
  67. ]
  68. }
  69. this.handleChange = this.handleChange.bind(this)
  70. }
  71. componentWillMount() {
  72. const { getMessage, initPatInfoData } = this.props;
  73. getMessage && getMessage()
  74. initPatInfoData && initPatInfoData(this.state.patientInfo)
  75. // console.log(timesYMDTime(new Date().getTime()),'电脑时间');
  76. }
  77. componentWillReceiveProps(nextProps){
  78. // console.log(nextProps,'nextProps');
  79. const { patInfoData } = nextProps.patInfo
  80. this.setState({
  81. // patientInfo:patInfoData
  82. })
  83. }
  84. handleChange(e){
  85. const { initPatInfoData } = this.props;
  86. let { patientInfo } = this.state;
  87. let newInfo = Object.assign([], patientInfo);
  88. let patientItem = newInfo.find(item =>{
  89. return item.id === e.target.id
  90. })
  91. // 处理性别
  92. if (patientItem.id === 'patientSex'){
  93. if (e.target.value === '1') {
  94. patientItem.value = 1
  95. } else if (e.target.value === '2'){
  96. patientItem.value = 2
  97. } else {
  98. patientItem.value = 2 // 默认为女
  99. }
  100. } else if (patientItem.id === 'patientAge'){
  101. patientItem.value = e.target.value.replace(/[^\d]+/, '')
  102. } else {
  103. patientItem.value = e.target.value;
  104. }
  105. this.setState({
  106. patientInfo: newInfo
  107. })
  108. initPatInfoData && initPatInfoData(newInfo)
  109. }
  110. render(){
  111. const {message} = this.props.patInfo;
  112. return (
  113. <div className={style["infoContainer"]}>
  114. {
  115. this.state.patientInfo.map((item, index) => {
  116. return (
  117. <div className={style["infoItem"]} key={item.id}>
  118. <label for={item.label}>{item.title}:</label>
  119. {item.id === 'patientSex' && (
  120. <select id={item.id} value={item.value} onChange={this.handleChange}>
  121. <option value='1'>男</option>
  122. <option value='2'>女</option>
  123. </select>
  124. )}
  125. {item.id === 'patientAge' && (<input id={item.id} type="text" autocomplete="off" maxlength={11} value={item.value} onChange={this.handleChange} />)}
  126. {/* {item.id === 'patientSex' && (<input id={item.id} type="text" autocomplete="off" value={item.value == 1 ? '男' : '女'} onChange={this.handleChange} />)} */}
  127. {item.id === 'systemTime' && (<input id={item.id} type="text" autocomplete="off" disabled value={item.value } onChange={this.handleChange} />)}
  128. {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} />) }
  129. </div>
  130. )
  131. })
  132. }
  133. </div>
  134. );
  135. }
  136. }
  137. export default PatInfo;