123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- import { ToolService } from './../../../../services/tool.service';
- import { Component, OnInit, Output, Input } from '@angular/core';
- import { FormGroup, FormBuilder, Validators } from '@angular/forms';
- import { EventEmitter } from '@angular/core';
- import { MainService } from 'src/app/services/main.service';
- @Component({
- selector: 'app-query-range',
- templateUrl: './query-range.component.html',
- styleUrls: ['./query-range.component.less']
- })
- export class QueryRangeComponent implements OnInit {
- @Output() submitQueryRange = new EventEmitter();
- @Output() cancelQueryRange = new EventEmitter();
- @Input() queryType: number;
- @Input() hospital: any;
- @Input() duty: any;
- @Input() parent: any;
- validateForm: FormGroup;//表单
- constructor(
- private fb: FormBuilder,
- private tool: ToolService,
- private mainService: MainService,
- ) { }
- ngOnInit() {
- this.getHospitalList();
- this.queryType == 3 && this.getDutyList(this.hospital.id);
- this.getDutyOneList();
- this.initForm();
- }
- // 隐藏模态框
- hideModal() {
- this.cancelQueryRange.emit()
- }
- // 初始化新增form表单
- initForm() {
- this.validateForm = this.fb.group({
- queryType: [this.queryType, [Validators.required]],
- hospital: [(this.hospital && (this.queryType == 2 || this.queryType == 3)) ? this.hospital.id : null],
- duty: [(this.duty && this.queryType == 3) ? this.duty.id : null],
- dutyOne: [(this.duty && this.queryType == 4) ? this.duty.id : null],
- parent :[this.parent?1:0, [Validators.required]]
- });
- }
- // 表单提交
- submitForm(): void {
- for (const i in this.validateForm.controls) {
- this.validateForm.controls[i].markAsDirty({ onlySelf: true });
- this.validateForm.controls[i].updateValueAndValidity();
- }
- if (this.validateForm.invalid) return;
- let queryType = this.validateForm.value.queryType;
- let hospital;
- let duty;
- switch (queryType) {
- case 1:
- break;
- case 2:
- hospital = this.hospitalList.find(v => v.id == this.validateForm.value.hospital);
- break;
- case 3:
- hospital = this.hospitalList.find(v => v.id == this.validateForm.value.hospital);
- duty = this.dutyList.find(v => v.id == this.validateForm.value.duty);
- break;
- case 4:
- hospital = this.dutyOneList.find(v => v.id == this.validateForm.value.dutyOne).parent;
- duty = this.dutyOneList.find(v => v.id == this.validateForm.value.dutyOne);
- break;
- }
- this.submitQueryRange.emit({queryType, hospital, duty});
- this.hideModal();
- }
- // 选择查询范围
- changeQueryType(queryType){
- this.validateForm.controls.hospital.setValue(null);
- this.validateForm.controls.duty.setValue(null);
- this.validateForm.controls.dutyOne.setValue(null);
- this.dutyList = [];
- switch (queryType) {
- case 1:
- this.requiredChange(false, 'hospital');
- this.requiredChange(false, 'duty');
- this.requiredChange(false, 'dutyOne');
- break;
- case 2:
- this.requiredChange(true, 'hospital');
- this.requiredChange(false, 'duty');
- this.requiredChange(false, 'dutyOne');
- break;
- case 3:
- this.requiredChange(true, 'hospital');
- this.requiredChange(true, 'duty');
- this.requiredChange(false, 'dutyOne');
- break;
- case 4:
- this.requiredChange(false, 'hospital');
- this.requiredChange(false, 'duty');
- this.requiredChange(true, 'dutyOne');
- break;
- }
- }
- // 选择院区
- changeHospital(hosId){
- if(this.validateForm.value.queryType == 3){
- this.dutyList = [];
- this.getDutyList(hosId);
- }
- }
- requiredChange(required: boolean, field: string): void {
- if (!required) {
- this.validateForm.get(field)!.clearValidators();
- this.validateForm.get(field)!.markAsPristine();
- } else {
- this.validateForm.get(field)!.setValidators(Validators.required);
- this.validateForm.get(field)!.markAsDirty();
- }
- this.validateForm.get(field)!.updateValueAndValidity();
- }
- // 获取所有的院区
- hospitalList:any[] = [];
- getHospitalList(){
- let postData: any = {
- idx: 0,
- sum: 99999,
- hospital: {
- selectType: "level1",
- },
- };
- this.mainService.getFetchDataList("data", "hospital", postData).subscribe(result => {
- if(result.status == 200){
- this.hospitalList = result.list || [];
- }else{
- this.hospitalList = [];
- }
- });
- }
- // 获取所有的责任部门
- dutyList:any[] = [];
- getDutyList(parentId){
- if(!parentId){
- this.dutyList = [];
- return;
- }
- let postData: any = {
- idx: 0,
- sum: 99999,
- hospital: {
- parent: { id: parentId },
- selectType: "branch",
- },
- };
- this.mainService.getFetchDataList("data", "hospital", postData).subscribe(result => {
- if(result.status == 200){
- this.dutyList = result.list || [];
- }else{
- this.dutyList = [];
- }
- });
- }
- // 获取所有的一级责任部门
- dutyOneList:any[] = [];
- getDutyOneList(){
- let postData: any = {
- idx: 0,
- sum: 99999,
- hospital: {
- selectType: "verticalBranch",
- },
- };
- this.mainService.getFetchDataList("data", "hospital", postData).subscribe(result => {
- if(result.status == 200){
- this.dutyOneList = result.list || [];
- }else{
- this.dutyOneList = [];
- }
- });
- }
- }
|