ChangeOrder.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 className = "change-order-form" >
  90. <input className = "appointment admin-form order-change-input" readOnly={true} id={this.state.order.orderNumber}
  91. defaultValue={this.state.order.orderNumber}
  92. />
  93. <input className = "appointment admin-form" readOnly={true} id={this.state.order.spec._id}
  94. defaultValue={this.state.order.spec.name}
  95. />
  96. <input className = "appointment admin-form" readOnly={true} id={this.state.order.doctor._id}
  97. defaultValue={this.state.order.doctor.name}
  98. />
  99. <input className = "appointment admin-form" readOnly={true} id={this.state.order.user._id}
  100. defaultValue={this.state.order.user.email}
  101. />
  102. <input className = "appointment admin-form" readOnly={true} id={this.state.order.date}
  103. defaultValue={this.state.order.date}
  104. />
  105. <input className = "appointment admin-form" readOnly={true} id={this.state.order.time}
  106. defaultValue={this.state.order.time}
  107. />
  108. <input className = "appointment admin-form" readOnly={true} id={this.state.order.comment}
  109. defaultValue={this.state.order.comment}
  110. />
  111. <button className = "btn service-btn" onClick={this.changeOrder}>Изменить заказ</button>
  112. {this.state.flag &&
  113. <div className = "order-change-input">
  114. <input className = "appointment admin-form" readOnly={true} id={this.state.order.orderNumber}
  115. defaultValue={this.state.order.orderNumber}
  116. />
  117. <CustomSelect
  118. label="Выбор врача"
  119. emptyLine={false}
  120. options={doctors}
  121. clickOptionEvent={this.setDoctor}
  122. />
  123. {appointment.doctorId &&
  124. <CustomSelect
  125. label="Выбор услуги"
  126. emptyLine={false}
  127. options={appointment.doctorId ? doctors.find(el => el._id === appointment.doctorId).speciality : []}
  128. clickOptionEvent={this.setSpec}
  129. />
  130. }
  131. {appointment.specId &&
  132. <Calendar
  133. doctor={doctors.find(el => el._id === appointment.doctorId)}
  134. action={this.setShedule}
  135. />
  136. }
  137. {appointment.sheduleId && (
  138. <div className="appointment-time">
  139. <div className="btn-box">
  140. {timeArray.map((el, index) => (
  141. <div className="radio-btn" key={Object.keys(el)}>
  142. <input
  143. type="radio"
  144. className="radio"
  145. name="choise-time"
  146. id={index}
  147. onChange={this.setTime}
  148. value={Object.keys(el)}
  149. />
  150. <label htmlFor={index}>{Object.keys(el)}</label>
  151. </div>
  152. ))}
  153. </div>
  154. {appointment.time && (
  155. <textarea
  156. className="appointment comment"
  157. rows="2"
  158. placeholder="Добавить комментарий "
  159. onChange={this.setComment}
  160. />
  161. )}
  162. </div>
  163. )}
  164. {appointment.time &&
  165. <button className="btn link" onClick={this.changeConfirm}>Подтвердите запись
  166. </button>
  167. }
  168. </div>
  169. }
  170. </div>
  171. <div className="wrap-check-off" onClick={this.props.clearOrder}></div>
  172. </>
  173. )
  174. }
  175. }
  176. export default ChangeOrder;