query-range.component.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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?1:0, [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. switch (queryType) {
  55. case 1:
  56. break;
  57. case 2:
  58. hospital = this.hospitalList.find(v => v.id == this.validateForm.value.hospital);
  59. break;
  60. case 3:
  61. hospital = this.hospitalList.find(v => v.id == this.validateForm.value.hospital);
  62. duty = this.dutyList.find(v => v.id == this.validateForm.value.duty);
  63. break;
  64. case 4:
  65. hospital = this.dutyOneList.find(v => v.id == this.validateForm.value.dutyOne).parent;
  66. duty = this.dutyOneList.find(v => v.id == this.validateForm.value.dutyOne);
  67. break;
  68. }
  69. this.submitQueryRange.emit({queryType, hospital, duty});
  70. this.hideModal();
  71. }
  72. // 选择查询范围
  73. changeQueryType(queryType){
  74. this.validateForm.controls.hospital.setValue(null);
  75. this.validateForm.controls.duty.setValue(null);
  76. this.validateForm.controls.dutyOne.setValue(null);
  77. this.dutyList = [];
  78. switch (queryType) {
  79. case 1:
  80. this.requiredChange(false, 'hospital');
  81. this.requiredChange(false, 'duty');
  82. this.requiredChange(false, 'dutyOne');
  83. break;
  84. case 2:
  85. this.requiredChange(true, 'hospital');
  86. this.requiredChange(false, 'duty');
  87. this.requiredChange(false, 'dutyOne');
  88. break;
  89. case 3:
  90. this.requiredChange(true, 'hospital');
  91. this.requiredChange(true, 'duty');
  92. this.requiredChange(false, 'dutyOne');
  93. break;
  94. case 4:
  95. this.requiredChange(false, 'hospital');
  96. this.requiredChange(false, 'duty');
  97. this.requiredChange(true, 'dutyOne');
  98. break;
  99. }
  100. }
  101. // 选择院区
  102. changeHospital(hosId){
  103. if(this.validateForm.value.queryType == 3){
  104. this.dutyList = [];
  105. this.getDutyList(hosId);
  106. }
  107. }
  108. requiredChange(required: boolean, field: string): void {
  109. if (!required) {
  110. this.validateForm.get(field)!.clearValidators();
  111. this.validateForm.get(field)!.markAsPristine();
  112. } else {
  113. this.validateForm.get(field)!.setValidators(Validators.required);
  114. this.validateForm.get(field)!.markAsDirty();
  115. }
  116. this.validateForm.get(field)!.updateValueAndValidity();
  117. }
  118. // 获取所有的院区
  119. hospitalList:any[] = [];
  120. getHospitalList(){
  121. let postData: any = {
  122. idx: 0,
  123. sum: 99999,
  124. hospital: {
  125. selectType: "level1",
  126. },
  127. };
  128. this.mainService.getFetchDataList("data", "hospital", postData).subscribe(result => {
  129. if(result.status == 200){
  130. this.hospitalList = result.list || [];
  131. }else{
  132. this.hospitalList = [];
  133. }
  134. });
  135. }
  136. // 获取所有的责任部门
  137. dutyList:any[] = [];
  138. getDutyList(parentId){
  139. if(!parentId){
  140. this.dutyList = [];
  141. return;
  142. }
  143. let postData: any = {
  144. idx: 0,
  145. sum: 99999,
  146. hospital: {
  147. parent: { id: parentId },
  148. selectType: "branch",
  149. },
  150. };
  151. this.mainService.getFetchDataList("data", "hospital", postData).subscribe(result => {
  152. if(result.status == 200){
  153. this.dutyList = result.list || [];
  154. }else{
  155. this.dutyList = [];
  156. }
  157. });
  158. }
  159. // 获取所有的一级责任部门
  160. dutyOneList:any[] = [];
  161. getDutyOneList(){
  162. let postData: any = {
  163. idx: 0,
  164. sum: 99999,
  165. hospital: {
  166. selectType: "verticalBranch",
  167. },
  168. };
  169. this.mainService.getFetchDataList("data", "hospital", postData).subscribe(result => {
  170. if(result.status == 200){
  171. this.dutyOneList = result.list || [];
  172. }else{
  173. this.dutyOneList = [];
  174. }
  175. });
  176. }
  177. }