query-range.component.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. import { ToolService } from './../../../../services/tool.service';
  2. import { Component, OnInit, Output, Input } from '@angular/core';
  3. import { FormGroup, FormBuilder, Validators } from '@angular/forms';
  4. import { EventEmitter } from '@angular/core';
  5. import { MainService } from 'src/app/services/main.service';
  6. @Component({
  7. selector: 'app-query-range',
  8. templateUrl: './query-range.component.html',
  9. styleUrls: ['./query-range.component.less']
  10. })
  11. export class QueryRangeComponent implements OnInit {
  12. @Output() submitQueryRange = new EventEmitter();
  13. @Output() cancelQueryRange = new EventEmitter();
  14. @Input() queryType: number;
  15. @Input() hospital: any;
  16. @Input() duty: any;
  17. @Input() parent: any;
  18. validateForm: FormGroup;//表单
  19. constructor(
  20. private fb: FormBuilder,
  21. private tool: ToolService,
  22. private mainService: MainService,
  23. ) { }
  24. ngOnInit() {
  25. this.getHospitalList();
  26. this.queryType == 3 && this.getDutyList(this.hospital.id);
  27. this.getDutyOneList();
  28. this.initForm();
  29. }
  30. // 隐藏模态框
  31. hideModal() {
  32. this.cancelQueryRange.emit()
  33. }
  34. // 初始化新增form表单
  35. initForm() {
  36. this.validateForm = this.fb.group({
  37. queryType: [this.queryType, [Validators.required]],
  38. hospital: [(this.hospital && (this.queryType == 2 || this.queryType == 3)) ? this.hospital.id : null],
  39. duty: [(this.duty && this.queryType == 3) ? this.duty.id : null],
  40. dutyOne: [(this.duty && this.queryType == 4) ? this.duty.id : null],
  41. parent :[this.parent, [Validators.required]]
  42. });
  43. }
  44. // 表单提交
  45. submitForm(): void {
  46. for (const i in this.validateForm.controls) {
  47. this.validateForm.controls[i].markAsDirty({ onlySelf: true });
  48. this.validateForm.controls[i].updateValueAndValidity();
  49. }
  50. if (this.validateForm.invalid) return;
  51. let queryType = this.validateForm.value.queryType;
  52. let hospital;
  53. let duty;
  54. let parent = this.validateForm.value.parent;
  55. switch (queryType) {
  56. case 1:
  57. break;
  58. case 2:
  59. hospital = this.hospitalList.find(v => v.id == this.validateForm.value.hospital);
  60. break;
  61. case 3:
  62. hospital = this.hospitalList.find(v => v.id == this.validateForm.value.hospital);
  63. duty = this.dutyList.find(v => v.id == this.validateForm.value.duty);
  64. break;
  65. case 4:
  66. hospital = this.dutyOneList.find(v => v.id == this.validateForm.value.dutyOne).parent;
  67. duty = this.dutyOneList.find(v => v.id == this.validateForm.value.dutyOne);
  68. break;
  69. }
  70. this.submitQueryRange.emit({queryType, hospital, duty, parent});
  71. this.hideModal();
  72. }
  73. // 选择查询范围
  74. changeQueryType(queryType){
  75. this.validateForm.controls.hospital.setValue(null);
  76. this.validateForm.controls.duty.setValue(null);
  77. this.validateForm.controls.dutyOne.setValue(null);
  78. this.dutyList = [];
  79. switch (queryType) {
  80. case 1:
  81. this.requiredChange(false, 'hospital');
  82. this.requiredChange(false, 'duty');
  83. this.requiredChange(false, 'dutyOne');
  84. break;
  85. case 2:
  86. this.requiredChange(true, 'hospital');
  87. this.requiredChange(false, 'duty');
  88. this.requiredChange(false, 'dutyOne');
  89. break;
  90. case 3:
  91. this.requiredChange(true, 'hospital');
  92. this.requiredChange(true, 'duty');
  93. this.requiredChange(false, 'dutyOne');
  94. break;
  95. case 4:
  96. this.requiredChange(false, 'hospital');
  97. this.requiredChange(false, 'duty');
  98. this.requiredChange(true, 'dutyOne');
  99. break;
  100. }
  101. }
  102. // 选择院区
  103. changeHospital(hosId){
  104. if(this.validateForm.value.queryType == 3){
  105. this.dutyList = [];
  106. this.getDutyList(hosId);
  107. }
  108. }
  109. requiredChange(required: boolean, field: string): void {
  110. if (!required) {
  111. this.validateForm.get(field)!.clearValidators();
  112. this.validateForm.get(field)!.markAsPristine();
  113. } else {
  114. this.validateForm.get(field)!.setValidators(Validators.required);
  115. this.validateForm.get(field)!.markAsDirty();
  116. }
  117. this.validateForm.get(field)!.updateValueAndValidity();
  118. }
  119. // 获取所有的院区
  120. hospitalList:any[] = [];
  121. getHospitalList(){
  122. let postData: any = {
  123. idx: 0,
  124. sum: 99999,
  125. hospital: {
  126. selectType: "level1",
  127. },
  128. };
  129. this.mainService.getFetchDataList("data", "hospital", postData).subscribe(result => {
  130. if(result.status == 200){
  131. this.hospitalList = result.list || [];
  132. }else{
  133. this.hospitalList = [];
  134. }
  135. });
  136. }
  137. // 获取所有的责任部门
  138. dutyList:any[] = [];
  139. getDutyList(parentId){
  140. if(!parentId){
  141. this.dutyList = [];
  142. return;
  143. }
  144. let postData: any = {
  145. idx: 0,
  146. sum: 99999,
  147. hospital: {
  148. parent: { id: parentId },
  149. selectType: "branch",
  150. },
  151. };
  152. this.mainService.getFetchDataList("data", "hospital", postData).subscribe(result => {
  153. if(result.status == 200){
  154. this.dutyList = result.list || [];
  155. }else{
  156. this.dutyList = [];
  157. }
  158. });
  159. }
  160. // 获取所有的一级责任部门
  161. dutyOneList:any[] = [];
  162. getDutyOneList(){
  163. let postData: any = {
  164. idx: 0,
  165. sum: 99999,
  166. hospital: {
  167. selectType: "verticalBranch",
  168. },
  169. };
  170. this.mainService.getFetchDataList("data", "hospital", postData).subscribe(result => {
  171. if(result.status == 200){
  172. this.dutyOneList = result.list || [];
  173. }else{
  174. this.dutyOneList = [];
  175. }
  176. });
  177. }
  178. }