edit-inspect-info2.component.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. import { Component, OnInit, Output, Input } from '@angular/core';
  2. import { EventEmitter } from '@angular/core';
  3. import { NzMessageService } from 'ng-zorro-antd';
  4. import { addDays, startOfMinute, format, addMinutes } from 'date-fns';
  5. import { Subject } from "rxjs";
  6. import { debounceTime } from "rxjs/operators";
  7. import { ToolService } from 'src/app/services/tool.service';
  8. import { MainService } from '../../services/main.service';
  9. @Component({
  10. selector: 'app-edit-inspect-info2',
  11. templateUrl: './edit-inspect-info2.component.html',
  12. styleUrls: ['./edit-inspect-info2.component.less']
  13. })
  14. export class EditInspectInfo2Component implements OnInit {
  15. @Input() date:any;
  16. @Input() execDeptId:any;
  17. @Input() remarkText:any;
  18. @Input() applyDept:any = {};
  19. @Input() patient:any = {};
  20. @Input() execDeptList:any;
  21. @Input() inspectAndPatientTransportConfig:any = {};
  22. @Output() submitFormHand = new EventEmitter();
  23. @Output() cancelFlagHand = new EventEmitter();
  24. yyDate = null; //预约日期-患者其他服务
  25. yyTime = null; //预约时间-患者其他服务
  26. deptId = null;
  27. remark = '';
  28. deptList:any[] = [];
  29. isLoading:boolean = false;
  30. hosId;
  31. changePatientSubject = new Subject(); //防抖
  32. changeApplyDeptSubject = new Subject(); //防抖
  33. constructor(
  34. private message: NzMessageService,
  35. private tool: ToolService,
  36. private mainService: MainService,
  37. ) { }
  38. ngOnInit() {
  39. this.changePatientSubject.pipe(debounceTime(500)).subscribe((v) => {
  40. this.getPatientList(v[0]);
  41. });
  42. this.changeApplyDeptSubject.pipe(debounceTime(500)).subscribe((v) => {
  43. this.getApplyDeptList(v[0]);
  44. });
  45. this.hosId = this.tool.getCurrentHospital().id;
  46. if(this.applyDept){
  47. this.inspectData.applyDeptId = this.applyDept.id;
  48. this.applyDeptList = [this.applyDept];
  49. }
  50. if(this.patient){
  51. this.inspectData.patientId = this.patient.id;
  52. this.patientList = [this.patient];
  53. this.patientDTO = this.patient;
  54. }
  55. if(this.date){
  56. this.yyDate = new Date(this.date);
  57. this.yyTime = new Date(this.date);
  58. this.mdData = format(this.yyDate, 'yyyy-MM-dd')
  59. this.setTimeData();
  60. }
  61. if(this.execDeptList){
  62. this.deptList = this.execDeptList;
  63. }
  64. console.log('this.remarkText:', this.remarkText)
  65. if(this.remarkText){
  66. this.remark = this.remarkText;
  67. }
  68. if(this.execDeptId){
  69. let flag = this.deptList.some(v => v.id == this.execDeptId);
  70. if(flag){
  71. this.deptId = this.execDeptId;
  72. }
  73. }
  74. }
  75. patientDTO:any = {};
  76. inspectData:any = {}; //检查项目
  77. changePatient(e){
  78. this.patientDTO = this.patientList.find(v => v.id == this.inspectData.patientId) || {};
  79. }
  80. changeApplyDept(e){
  81. this.inspectData.patientId = undefined;
  82. }
  83. // 选择日期
  84. mdData:any;
  85. dateChange(e){
  86. if(e){
  87. this.mdData = format(e, 'yyyy-MM-dd')
  88. this.setTimeData();
  89. }else{
  90. this.endTime = null
  91. }
  92. }
  93. // 选择时间
  94. endTime:any;
  95. timeChange(e){
  96. if(e){
  97. this.mdData = format(this.yyDate, 'yyyy-MM-dd')
  98. this.setTimeData();
  99. }else{
  100. this.endTime = null
  101. }
  102. }
  103. // 设置结束时间
  104. setTimeData(){
  105. if(this.mdData && this.yyTime){
  106. let num = this.execDeptList.extra1 ? Number(this.execDeptList.extra1) : undefined
  107. let time = addMinutes(this.yyTime, num ? num : this.inspectAndPatientTransportConfig.yytimeGapMinute)
  108. let time2 = format(time, 'HH:mm')
  109. this.endTime = this.mdData +' '+ time2
  110. let date = new Date(this.endTime);
  111. this.inspectData.endCheckTime = date.getTime()
  112. }
  113. }
  114. // =========================申请科室=====================
  115. applyDeptList: Array<any>; //申请科室列表
  116. // 获取申请科室
  117. getApplyDeptList(keyword = '') {
  118. let postData = {
  119. idx: 0,
  120. sum: 10,
  121. department:{
  122. hospital: {
  123. id: this.hosId
  124. },
  125. dept: keyword
  126. }
  127. };
  128. this.isLoading = true;
  129. this.mainService
  130. .getFetchDataList("data", "department",postData)
  131. .subscribe((data:any) => {
  132. this.isLoading = false;
  133. this.applyDeptList = data.list || [];
  134. });
  135. }
  136. // 边输边搜节流阀
  137. searchApplyDept(e) {
  138. this.isLoading = true;
  139. this.changeApplyDeptSubject.next([e]);
  140. }
  141. // 打开
  142. openApplyDept(e){
  143. if(e){
  144. this.getApplyDeptList();
  145. }
  146. }
  147. // =========================申请科室=====================
  148. // =========================患者=====================
  149. patientList: Array<any>; //患者列表
  150. // 获取患者
  151. getPatientList(keyword = '') {
  152. let postData = {
  153. idx: 0,
  154. sum: 10,
  155. hosId: this.hosId,
  156. patientName: keyword || undefined,
  157. hasBedNum: 1,//有床号
  158. department: this.inspectData.applyDeptId,
  159. };
  160. this.isLoading = true;
  161. this.mainService
  162. .listMsgByMain('listPatient',postData)
  163. .subscribe((data:any) => {
  164. this.isLoading = false;
  165. this.patientList = data.list || [];
  166. });
  167. }
  168. // 边输边搜节流阀
  169. searchPatient(e) {
  170. this.isLoading = true;
  171. this.changePatientSubject.next([e]);
  172. }
  173. // 打开
  174. openPatient(e){
  175. if(e){
  176. this.getPatientList();
  177. }
  178. }
  179. // =========================患者=====================
  180. // 下一日(患者其他服务)
  181. nextDay() {
  182. this.yyDate = addDays(this.yyDate, 1);
  183. }
  184. // 隐藏模态框
  185. hideModal() {
  186. this.cancelFlagHand.emit(false)
  187. }
  188. // 表单提交
  189. submitForm(): void {
  190. if(!this.inspectData.applyDeptId) {
  191. this.message.warning('请选择申请科室!');
  192. return;
  193. }
  194. if(!this.inspectData.patientId) {
  195. this.message.warning('请选择患者信息!');
  196. return;
  197. }
  198. if(!this.deptId) {
  199. this.message.warning('请选择检查科室!');
  200. return;
  201. }
  202. if(!this.yyDate || !this.yyTime) {
  203. this.message.warning('请选择完整预约时间!');
  204. return;
  205. }
  206. this.submitFormHand.emit({
  207. applyDeptId: this.inspectData.applyDeptId,
  208. patientDTO: this.patientDTO,
  209. deptId: this.deptId,
  210. remark: this.remark,
  211. date: format(this.yyDate, 'yyyy-MM-dd') + ' ' + format(startOfMinute(this.yyTime), 'HH:mm:ss'),
  212. endCheckTime: this.inspectData.endCheckTime
  213. });
  214. }
  215. }