query-range.component.ts 5.5 KB

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