import { Subject } from 'rxjs'; import { debounceTime } from 'rxjs/operators'; 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-phone-search-more', templateUrl: './phone-search-more.component.html', styleUrls: ['./phone-search-more.component.less'] }) export class PhoneSearchMoreComponent implements OnInit { @Output() submitEvent = new EventEmitter(); @Output() cancelEvent = new EventEmitter(); @Input() fieldConfig: any = { fields: [], config: [] }; @Input() hosId: any; @Input() parentDutyId: any; @Input() dutyId: any; @Input() queryType: any; validateForm: FormGroup;//表单 searchTimerSubject = new Subject(); constructor( private fb: FormBuilder, private tool: ToolService, private mainService: MainService, ) { } ngOnInit() { this.searchTimerSubject.pipe(debounceTime(500)).subscribe((v) => { let fun = v[0]; fun.call(this, v[1]); }); this.initForm(); this.getSourceList(); } // 隐藏模态框 hideModal() { this.cancelEvent.emit() } // 初始化form表单 initForm() { this.groupList = this.fieldConfig.fields.groupDTO ? [this.fieldConfig.fields.groupDTO] : []; this.userList = this.fieldConfig.fields.userDTO ? [this.fieldConfig.fields.userDTO] : []; this.statisticsTypeList = this.fieldConfig.fields.statisticsTypeDTO ? [this.fieldConfig.fields.statisticsTypeDTO] : []; this.buildingList = this.fieldConfig.fields.buildingDTO ? [this.fieldConfig.fields.buildingDTO] : []; this.taskTypeList = this.fieldConfig.fields.taskTypeDTO ? [this.fieldConfig.fields.taskTypeDTO] : []; this.deptList = this.fieldConfig.fields.deptDTO ? [this.fieldConfig.fields.deptDTO] : []; this.validateForm = this.fb.group({ groupId: [this.fieldConfig.fields.groupId || null], userId: [this.fieldConfig.fields.userId === undefined ? null : this.fieldConfig.fields.userId], statisticsTypeId: [this.fieldConfig.fields.statisticsTypeId || null], buildingId: [this.fieldConfig.fields.buildingId || null], taskTypeId: [this.fieldConfig.fields.taskTypeDTO ? this.fieldConfig.fields.taskTypeDTO.id : null], deptId: [this.fieldConfig.fields.deptDTO ? this.fieldConfig.fields.deptDTO.id : null], }); } // 表单提交 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 fields:any = {} if(this.fieldConfig.config.groupAndUser){ fields.groupId = this.validateForm.value.groupId; fields.groupDTO = this.groupList.find(item => item.id == this.validateForm.value.groupId); fields.userId = this.validateForm.value.userId; fields.userDTO = this.userList.find(item => item.id == this.validateForm.value.userId); } if(this.fieldConfig.config.statisticsType){ fields.statisticsTypeId = this.validateForm.value.statisticsTypeId; fields.statisticsTypeDTO = this.statisticsTypeList.find(item => item.id == this.validateForm.value.statisticsTypeId); } if(this.fieldConfig.config.building){ fields.buildingId = this.validateForm.value.buildingId; fields.buildingDTO = this.buildingList.find(item => item.id == this.validateForm.value.buildingId); } if(this.fieldConfig.config.taskType){ fields.taskTypeId = this.validateForm.value.taskTypeId; fields.taskTypeDTO = this.taskTypeList.find(item => item.id == this.validateForm.value.taskTypeId); } if(this.fieldConfig.config.dept){ fields.deptId = this.validateForm.value.deptId; fields.deptDTO = this.deptList.find(item => item.id == this.validateForm.value.deptId); } this.submitEvent.emit(fields); this.hideModal(); } get getHosId(){ return this.parentDutyId || this.dutyId || this.hosId; } // 防抖 isLoading = false; isSelecting:boolean = false; // 是否在选中状态 searchTimer(fun, e) { if (this.isSelecting) { this.isSelecting = false; // 重置标志 return; // 跳过处理 } this.isLoading = true; this.searchTimerSubject.next([fun, e]); } // 设置标志 setIsSelecting(flag){ this.isSelecting = flag; // 设置标志 } // =================分组=================== // 分组搜索 changeGroupInp(e) { this.searchTimer(this.getGroupList, e); } // 获取分组列表 groupList:any[] = []; getGroupList(keyword?){ let postData: any = { idx: 0, sum: 20, group2: { statisticalHosId: this.getHosId, groupName: keyword, type: 1, }, }; this.isLoading = true; this.mainService.getFetchDataList("simple/data", "group2", postData).subscribe(result => { this.isLoading = false; if(result.status == 200){ this.groupList = result.list || []; }else{ this.groupList = []; } }); } openChangeGroup(flag){ flag && this.setIsSelecting(false); flag && this.getGroupList(); } changeGroup(id){ this.setIsSelecting(true); this.userList = []; this.validateForm.controls.userId.setValue(null); this.getUserList(); } // =================人员=================== // 人员搜索 changeUserInp(e) { this.searchTimer(this.getUserList, e); } // 获取人员列表 userList:any[] = []; getUserList(keyword = ''){ if(!this.validateForm.value.groupId){ this.isLoading = false; this.userList = []; return; } let postData: any = { idx: 0, sum: 20, user: { name: keyword, simpleQuery: true, groupdata: { id: this.validateForm.value.groupId }, }, }; this.isLoading = true; this.mainService.getFetchDataList("simple/data", "user", postData).subscribe(result => { this.isLoading = false; if(result.status == 200){ this.userList = result.list || []; }else{ this.userList = []; } }); } openChangeUser(flag){ flag && this.setIsSelecting(false); flag && this.getUserList(); } // =================统计分类=================== // 获取统计分类列表 statisticsTypeList:any[] = []; getSourceList(){ this.mainService.getDictionary("list", "statistics_date_type").subscribe(result => { this.statisticsTypeList = result; }); } // =================楼栋=================== // 楼栋搜索 changeBuildingInp(e) { this.searchTimer(this.getBuildingList, e); } // 获取楼栋列表 buildingList:any[] = []; getBuildingList(keyword?){ let postData: any = { idx: 0, sum: 20, building: { simpleQuery: true, buildingName: keyword, statisticalHosId:this.getHosId, }, }; this.isLoading = true; this.mainService.getFetchDataList("simple/data", "building", postData).subscribe(result => { this.isLoading = false; if(result.status == 200){ this.buildingList = result.list || []; }else{ this.buildingList = []; } }); } openChangeBuilding(flag){ flag && this.setIsSelecting(false); flag && this.getBuildingList(); } // =================任务类型=================== // 任务类型搜索 changeTaskTypeInp(e) { this.searchTimer(this.getTaskTypeList, e); } // 获取任务类型列表 taskTypeList:any[] = []; getTaskTypeList(keyword?){ let postData: any = { idx: 0, sum: 20, taskType: { simpleQuery: true, taskName: keyword, statisticalHosId: this.getHosId, }, }; this.isLoading = true; this.mainService.getFetchDataList("simple/data", "taskType", postData).subscribe(result => { this.isLoading = false; if(result.status == 200){ this.taskTypeList = result.list || []; }else{ this.taskTypeList = []; } }); } openChangeTaskType(flag){ flag && this.setIsSelecting(false); flag && this.getTaskTypeList(); } // =================科室=================== // 科室搜索 changeRepairDeptInp(e) { this.searchTimer(this.getRepairDeptList, e); } // 获取科室列表 deptList:any[] = []; getRepairDeptList(keyword?){ let postData: any = { idx: 0, sum: 20, department: { statisticalHosId: this.getHosId, dept: keyword, searchType: 1, }, }; this.isLoading = true; this.mainService.getFetchDataList("simple/data", "department", postData).subscribe(result => { this.isLoading = false; if(result.status == 200){ this.deptList = result.list || []; }else{ this.deptList = []; } }); } openChangeRepairDept(flag){ flag && this.setIsSelecting(false); flag && this.getRepairDeptList(); } }