ChangeOrder.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import React from 'react';
  2. import {CustomSelect} from "../../hooks/select";
  3. import Calendar from "../../Calendar";
  4. import ConfirmButton from "../../ConfirmButton";
  5. class ChangeOrder extends React.Component {
  6. state = {
  7. order: {
  8. spec: '',
  9. doctor: '',
  10. time: '',
  11. comment: '',
  12. orderNumber: null,
  13. user: '',
  14. },
  15. flag: false,
  16. showConfirm: false,
  17. };
  18. changeConfirm = () => {
  19. this.setState({showConfirm: !this.state.showConfirm})
  20. };
  21. componentDidMount() {
  22. this.setState({
  23. order: {
  24. spec: this.props.order.spec,
  25. doctor: this.props.order.doctor,
  26. time: this.props.order.time,
  27. comment: this.props.order.comment,
  28. orderNumber: this.props.order.orderNumber,
  29. date: this.props.order.date.split('T')[0],
  30. user: this.props.order.user,
  31. }
  32. });
  33. }
  34. componentWillUnmount() {
  35. this.props.clearAppointment()
  36. }
  37. changeOrder = () => {
  38. this.setState({flag: !this.state.flag})
  39. };
  40. setDoctor = (e) => {
  41. this.props.setAppointmentDoctor(this.props.doctors.find(el => el.name === e)._id)
  42. };
  43. setSpec = (e) => {
  44. this.props.setAppointmentSpec({services: this.props.services, data: e})
  45. };
  46. setShedule = (e) => {
  47. this.props.setAppointmentShedule({
  48. data: e.target.id,
  49. services: this.props.services,
  50. doctors: this.props.doctors
  51. })
  52. };
  53. setTime = (e) => {
  54. this.props.setAppointmentTime(e.target.value)
  55. };
  56. setComment = (e) => {
  57. this.props.setAppointmentComment(e.target.value)
  58. };
  59. deleteAndPostNewOrder = () => {
  60. this.props.deleteOrder({
  61. id: this.props.order._id,
  62. newOrder: {
  63. spec: this.props.appointment.specId,
  64. doctor: this.props.appointment.doctorId,
  65. shedule: this.props.appointment.sheduleId,
  66. time: this.props.appointment.time,
  67. comment: this.props.appointment.comment,
  68. orderNumber: this.state.order.orderNumber,
  69. user:this.state.order.user._id
  70. }
  71. });
  72. this.changeConfirm()
  73. };
  74. render() {
  75. const {
  76. doctors,
  77. appointment,
  78. timeArray
  79. } = this.props;
  80. return (
  81. <>
  82. {this.state.showConfirm &&
  83. <ConfirmButton
  84. yes={this.deleteAndPostNewOrder}
  85. no={this.changeConfirm}
  86. text={'Уверены что хотите изменить заказ?'}
  87. />
  88. }
  89. <div style={{
  90. position: 'fixed',
  91. right: '0',
  92. left: '0',
  93. display: 'flex',
  94. flexDirection: 'column',
  95. justifyContent: 'center',
  96. backgroundColor: 'black',
  97. margin: '-3% auto',
  98. width: '80%',
  99. fontSize: '12px',
  100. zIndex: '5',
  101. }}>
  102. <input readOnly={true} id={this.state.order.orderNumber}
  103. defaultValue={this.state.order.orderNumber}
  104. />
  105. <input readOnly={true} id={this.state.order.spec._id}
  106. defaultValue={this.state.order.spec.name}
  107. />
  108. <input readOnly={true} id={this.state.order.doctor._id}
  109. defaultValue={this.state.order.doctor.name}
  110. />
  111. <input readOnly={true} id={this.state.order.user._id}
  112. defaultValue={this.state.order.user.email}
  113. />
  114. <input readOnly={true} id={this.state.order.date}
  115. defaultValue={this.state.order.date}
  116. />
  117. <input readOnly={true} id={this.state.order.time}
  118. defaultValue={this.state.order.time}
  119. />
  120. <input readOnly={true} id={this.state.order.comment}
  121. defaultValue={this.state.order.comment}
  122. />
  123. <button onClick={this.changeOrder}>Change Order</button>
  124. {this.state.flag &&
  125. <div>
  126. <input readOnly={true} id={this.state.order.orderNumber}
  127. defaultValue={this.state.order.orderNumber}
  128. />
  129. <CustomSelect
  130. label="Выбор врача"
  131. emptyLine={false}
  132. options={doctors}
  133. clickOptionEvent={this.setDoctor}
  134. />
  135. {appointment.doctorId &&
  136. <CustomSelect
  137. label="Выбор услуги"
  138. emptyLine={false}
  139. options={appointment.doctorId ? doctors.find(el => el._id === appointment.doctorId).speciality : []}
  140. clickOptionEvent={this.setSpec}
  141. />
  142. }
  143. {appointment.specId &&
  144. <Calendar
  145. doctor={doctors.find(el => el._id === appointment.doctorId)}
  146. action={this.setShedule}
  147. />
  148. }
  149. {appointment.sheduleId && (
  150. <div className="appointment-time">
  151. <div className="btn-box">
  152. {timeArray.map((el, index) => (
  153. <div className="radio-btn" key={Object.keys(el)}>
  154. <input
  155. type="radio"
  156. className="radio"
  157. name="choise-time"
  158. id={index}
  159. onChange={this.setTime}
  160. value={Object.keys(el)}
  161. />
  162. <label htmlFor={index}>{Object.keys(el)}</label>
  163. </div>
  164. ))}
  165. </div>
  166. {appointment.time && (
  167. <textarea
  168. className="appointment comment"
  169. rows="2"
  170. placeholder="Добавить комментарий "
  171. onChange={this.setComment}
  172. />
  173. )}
  174. </div>
  175. )}
  176. {appointment.time &&
  177. <button className="btn link" onClick={this.changeConfirm}>Подтвердите запись
  178. </button>
  179. }
  180. </div>
  181. }
  182. </div>
  183. <div className="wrap-check-off" onClick={this.props.clearOrder}></div>
  184. </>
  185. )
  186. }
  187. }
  188. export default ChangeOrder;