import { Component, OnInit, ViewChild } from "@angular/core"; import { ActivatedRoute } from "@angular/router"; import { Subject } from 'rxjs'; import { debounceTime } from 'rxjs/operators'; import { MainService } from "../../../services/main.service"; import { Validators, FormGroup, FormBuilder } from '@angular/forms'; import { ToolService } from 'src/app/services/tool.service'; import { OverlayScrollbarsComponent } from 'overlayscrollbars-ngx'; @Component({ selector: "app-configuration-category", templateUrl: "./configuration-category.component.html", styleUrls: ["./configuration-category.component.less"], }) export class ConfigurationCategoryComponent implements OnInit { constructor( private route: ActivatedRoute, private mainService: MainService, private fb: FormBuilder, private tool: ToolService, ) {} @ViewChild("osComponentRef1", { read: OverlayScrollbarsComponent, static: false, }) osComponentRef1: OverlayScrollbarsComponent; @ViewChild("osComponentRef2", { read: OverlayScrollbarsComponent, static: false, }) osComponentRef2: OverlayScrollbarsComponent; @ViewChild("osComponentRef3", { read: OverlayScrollbarsComponent, static: false, }) osComponentRef3: OverlayScrollbarsComponent; coopData: any = {}; //当前操作列 currentHospital; //当前院区 // 部门设置、全院设置 hospitalConfig:any = 2; hospitalConfigList:any = [ // { id: 1, name: '部门设置',}, { id: 2, name: '全院设置',}, ]; changeInpSubject = new Subject(); //防抖 debounceSubject = new Subject(); //防抖 ngOnInit() { //防抖 this.changeInpSubject.pipe(debounceTime(500)).subscribe((v) => { if(v[0] === 'user'){ this.getUsers(v[1]); } else if(v[0] === 'group'){ this.getGroups(v[1]); } }); this.debounceSubject.pipe(debounceTime(500)).subscribe((v) => { if(v[0]){ this.getCategoryList(v[0], v[1].id); } this.getCategoryConfigList(v[1].id); }); this.currentHospital = this.tool.getCurrentHospital(); // 故障现象 setTimeout(() => { this.tableCategoryHeight = document.querySelector('#categoryTable').clientHeight - 8 - document.querySelector('#categoryTable .thead').clientHeight; }, 0) let { hospital, type } = this.tool.getHospitalOrDuty(); if(type === 'duty'){ // 是责任部门 let flag = this.hospitalConfigList.some(v => v.id === 1); !flag && this.hospitalConfigList.unshift({ id: 1, name: '部门设置',}); } this.getCategoryList(1); this.getHospitals(1); this.getHospitals(2); this.getPrioritys(); this.getScores(); } // 获取优先级 priority_c_List: any = []; getPrioritys() { let postData = { priority: {}, idx: 0, sum: 9999, }; this.mainService .getFetchDataList("simple/data", "priority", postData) .subscribe((data) => { this.isLoading = false; this.priority_c_List = data.list || []; }); } // 获取积分 scoreList: any = []; getScores() { let postData = { dictionary: { key: "incident_category_score" }, idx: 0, sum: 10, }; this.mainService .getFetchDataList("simple/data", "dictionary", postData) .subscribe((data) => { this.isLoading = false; this.scoreList = data.list || []; }); } // 边输边搜节流阀 isLoading = false; changeInp(model, e) { this.isLoading = true; this.changeInpSubject.next([model, e]); } // 搜索 // 获取用户 userList: any = []; getUsers(keyword = '', isShowValue = false) { if((!this.validateConfigForm.value.groupId && this.validateConfigForm.value.userGroup === 1) || this.validateConfigForm.value.userGroup === 2){ this.isLoading = false; this.userList = []; return; } let postData = { user: { hospital: { id: this.validateConfigForm.value.dutyId }, name: keyword, simpleQuery: true, groupdata: { id: this.validateConfigForm.value.groupId }, roleCodes: 'first-line support', engineer: 1, }, idx: 0, sum: 10, }; this.mainService .getFetchDataList("data", "user", postData) .subscribe((data) => { this.isLoading = false; let userList = data.list || []; if(isShowValue && this.coopData && this.coopData.userId){ userList = userList.filter(v => v.id !== this.coopData.userId) userList.unshift(this.coopData.userDTO); } this.userList = userList; }); } // 获取组 groupList: any = []; //所有所属科室(搜索) getGroups(keyword = '', isShowValue = false) { if(!this.validateConfigForm.value.dutyId){ this.isLoading = false; this.groupList = []; return; } let postData = { group2: { groupName: keyword, hospitals: this.validateConfigForm.value.dutyId, type: 3, }, idx: 0, sum: 10, }; this.mainService .getFetchDataList("data", "group2", postData) .subscribe((data) => { this.isLoading = false; let groupList = data.list || []; if(isShowValue && this.coopData && this.coopData.groupId){ groupList = groupList.filter(v => v.id !== this.coopData.groupId) groupList.unshift(this.coopData.groupDTO); } this.groupList = groupList; }); } // 点击故障现象 activeCategory1:any = {}; activeCategory2:any = {}; activeCategory3:any = {}; clickCategory(item, type:number){ this.categoryConfigList = []; switch(type){ case 1: this.categoryList2 = []; this.categoryList3 = []; this.activeCategory2 = {}; this.activeCategory3 = {}; break; case 2: this.categoryList3 = []; this.activeCategory3 = {}; break; } this['activeCategory' + type] = item; console.log(this['activeCategory' + type]) switch(type){ case 1: this.categoryLoading2 = true; this.loading1 = true; this.debounceSubject.next([2, item]); break; case 2: this.categoryLoading3 = true; this.loading1 = true; this.debounceSubject.next([3, item]); break; case 3: this.loading1 = true; this.debounceSubject.next([0, item]); break; } } // 选择部门设置或全院设置 changeHospitalConfig(e){ console.log(e); this.getCategoryList(1); this.categoryList2 = []; this.categoryList3 = []; this.activeCategory1 = {}; this.activeCategory2 = {}; this.activeCategory3 = {}; this.categoryConfigList = []; } // 获取当前选中的故障现象索引 get currentCategoryIndex(){ if(this.activeCategory3.id){ return 3; } if(this.activeCategory2.id){ return 2; } if(this.activeCategory1.id){ return 1; } } // 获取当前选中的故障现象索引 get currentCategory(){ if(this.activeCategory3.id){ return this.activeCategory3; } if(this.activeCategory2.id){ return this.activeCategory2; } if(this.activeCategory1.id){ return this.activeCategory1; } } // 获取当前选中的故障现象有没有子故障现象 get currentChildrenCategoryList(){ return this.currentCategoryIndex && this.currentCategoryIndex < 3 && this['categoryList' + (this.currentCategoryIndex + 1)].length; } categoryConfigList:any[] = []; getCategoryConfigList(parentId = 0) { this.loading1 = true; let postData = { idx: 0, sum: 9999, incidentCategoryConfig: { categoryId: parentId, dutyId: this.hospitalConfig === 1 ? this.currentHospital.id : undefined, }, }; this.mainService.getFetchDataList("simple/data", "incidentCategoryConfig", postData).subscribe(res => { this.loading1 = false; this.categoryConfigList = res.list || []; }) } // 修改院区 changeHospital(id){ this.validateConfigForm.controls.dutyId.setValue(null); this.validateConfigForm.controls.userId.setValue(null); this.validateConfigForm.controls.groupId.setValue(null); // this.dutyList = []; this.userList = []; this.groupList = []; // this.getHospitals(2, id); } // 获取院区 hospitalList: any = []; dutyList: any = []; getHospitals(type:number, parentId?) { if(type === 1){ this.isLoading = false; this.hospitalList = this.tool.getHospitalList().filter(v => !v.parent); return; } // if(type === 2 && !parentId){ // this.isLoading = false; // this.dutyList = []; // return; // } let postData = { hospital: { // parent: { id: parentId }, type: { key: 'hospital_type', value: '6' }, }, idx: 0, sum: 9999, }; this.mainService .getFetchDataList("data", "hospital", postData) .subscribe((data) => { this.isLoading = false; this.dutyList = data.list || []; }); } // 修改责任部门 changeDuty(id){ this.validateConfigForm.controls.userId.setValue(null); this.validateConfigForm.controls.groupId.setValue(null); this.userList = []; this.groupList = []; this.getGroups(); } // 一级故障现象 loading1:boolean = false; tableCategoryHeight:number = 0; categoryList1: any[] = []; categoryList2: any[] = []; categoryList3: any[] = []; categoryLoading1:boolean = false; categoryLoading2:boolean = false; categoryLoading3:boolean = false; getCategoryList(type:number, parentId = 0) { setTimeout(() => { this['categoryLoading' + type] = true; }, 0) let postData = { category: { hierarchy: type === 1 ? 1 : undefined, dutyIds: this.hospitalConfig === 1 ? this.currentHospital.id.toString() : undefined, parent: type === 1 ? undefined : { id: parentId }, }, }; this.mainService.incidentPost("listIncidentCategory", postData).subscribe(res => { this['categoryLoading' + type] = false; this['categoryList' + type] = res.data || []; }) } // 新增故障现象弹框 modelName = ""; //模态框名称 add: boolean; //true:新增;false:编辑 modalCategory: boolean = false; //新增/编辑模态框 coopType: number = 0; addCategoryModal(type:number) { this.coopType = type; this.modelName = "新增"; this.add = true; //新增 this.modalCategory = true; this.initCategoryForm(); } //关闭新增/编辑弹框 hideCategoryModal() { this.modalCategory = false; } // 初始化新增form表单 validateCategoryForm: FormGroup; //新增/编辑表单 initCategoryForm() { this.validateCategoryForm = this.fb.group({ name: [null, [Validators.required]],//名称 }); console.log(this.validateCategoryForm.controls) } // 编辑 // editCategory(data) { // console.log(data); // this.modelName = "编辑"; // this.add = false; // this.modalCategory = true; // this.initCategoryForm(); // this.coopData = data; // this.validateCategoryForm.controls.name.setValue(data.name); // } // 新增/编辑表单提交 btnLoading: boolean = false; //提交按钮loading状态 submitCategoryForm(): void { for (const i in this.validateCategoryForm.controls) { this.validateCategoryForm.controls[i].markAsDirty(); this.validateCategoryForm.controls[i].updateValueAndValidity(); } if (this.validateCategoryForm.invalid) { return; } console.log(this.validateCategoryForm.value); this.btnLoading = true; // ----------------------------------- let postData:any = { category: { hosId: this.currentHospital.id, parent: this.coopType === 1 ? undefined : this['activeCategory' + (this.coopType - 1)], category: this.validateCategoryForm.value.name, hierarchy: this.coopType, dutyIds: this.hospitalConfig === 1 ? this.currentHospital.id.toString() : undefined, }, }; this.mainService .incidentPost("checkIncidentCategory", postData) .subscribe((result) => { let msg = ""; if (this.add) { msg = "新增"; } else { msg = "修改"; } if (result.status == 200) { this.submitCategoryAddForm(); } else if(result.status == 502) { this.btnLoading = false; this.showDelModal(null, result.msg, '', 'relevance'); } else { this.btnLoading = false; this.showPromptModal(msg, false, result.msg); } }); // ----------------------------------- } delModal: boolean = false; //删除模态框 tipsMsg1: string; //提示框信息 tipsMsg2: string; //操作后信息 confirmDelType: string; //确认的类型(启用/停用,删除) showDelModal( data, tipsMsg1: string, tipsMsg2: string, type: string, ) { this.confirmDelType = type; this.delModal = true; this.coopData = data; this.tipsMsg1 = tipsMsg1; this.tipsMsg2 = tipsMsg2; } // 隐藏删除框 hideDelModal() { this.delModal = false; } // 确认删除 confirmDel() { this.btnLoading = true; if (this.confirmDelType === "relevance") { //新增故障现象-关联 this.btnLoading = false; this.delModal = false; this.submitCategoryAddForm(); } else if (this.confirmDelType === "delConfig") { //删除-关联 this.mainService .simplePost("rmvData", "incidentCategoryConfig", [this.coopData.id]) .subscribe((data) => { this.btnLoading = false; this.delModal = false; if (data.status == 200) { this.showPromptModal(this.tipsMsg2, true, ""); } else { this.showPromptModal(this.tipsMsg2, false, data.msg); } }); } else if (this.confirmDelType === "copy") { //向下复制-关联 let postData:any = { type: this.hospitalConfig === 1 ? 'duty': 'hospital', category: this.currentCategory, }; postData.category.dutyIds = this.hospitalConfig === 1 ? this.currentHospital.id.toString() : undefined; this.mainService .incidentPost("copyIncidentCategoryConfig", postData) .subscribe((data) => { this.btnLoading = false; this.delModal = false; if (data.status == 200) { this.showPromptModal(this.tipsMsg2, true, ""); } else { this.showPromptModal(this.tipsMsg2, false, data.msg); } }); } } submitCategoryAddForm(): void { let postData:any = {}; if (this.add) { //增加 console.log(this['activeCategory' + this.coopType]) postData = { category: { hosId: this.currentHospital.id, parent: this.coopType === 1 ? undefined : this['activeCategory' + (this.coopType - 1)], category: this.validateCategoryForm.value.name, hierarchy: this.coopType, dutyIds: this.hospitalConfig === 1 ? this.currentHospital.id.toString() : undefined, }, }; } else { //编辑 // postData = { // category: { // hosId: this.currentHospital.id, // parent: this.coopType === 1 ? undefined : { id: this.coopData.id }, // category: this.validateCategoryForm.value.name, // hierarchy: this.coopType, // }, // }; } this.mainService .incidentPost("addIncidentCategory", postData) .subscribe((result) => { this.btnLoading = false; this.hideCategoryModal(); let msg = ""; if (this.add) { msg = "新增"; } else { msg = "修改"; } if (result.status == 200) { this.showPromptModal(msg, true, ''); } else { this.showPromptModal(msg, false, result.msg); } }); } // ------------------------------ // 新增故障现象-关联弹框 modalConfig: boolean = false; //新增/编辑模态框 addConfigModal() { this.modelName = "新增"; this.add = true; //新增 this.modalConfig = true; this.initConfigForm(); this.requiredConfigChange('userId', true); } //关闭新增/编辑弹框 hideConfigModal() { this.modalConfig = false; } // 初始化新增form表单 validateConfigForm: FormGroup; //新增/编辑表单 initConfigForm() { this.validateConfigForm = this.fb.group({ hosId: [null, [Validators.required]],//院区 dutyId: [null, [Validators.required]],//责任部门 priority: [null, [Validators.required]],//优先级 score: [null, [Validators.required]],//积分 userGroup: [1, [Validators.required]],//分配方式 userId: [null],//维修人 groupId: [null, [Validators.required]],//维修组 }); console.log(this.validateConfigForm.controls) } // 选择人|组 changeUserGroup(id){ this.validateConfigForm.controls.userId.setValue(null); this.validateConfigForm.controls.groupId.setValue(null); this.userList = []; if(id === 1){ // 人 this.requiredConfigChange('userId', true); }else if(id === 2){ // 组 this.requiredConfigChange('userId', false); } } // 编辑 editConfig(data) { console.log(data); this.modelName = "编辑"; this.add = false; this.modalConfig = true; this.initConfigForm(); this.coopData = data; this.validateConfigForm.controls.hosId.setValue(data.hosId); this.validateConfigForm.controls.dutyId.setValue(data.dutyId); this.validateConfigForm.controls.priority.setValue(data.priority); this.validateConfigForm.controls.score.setValue(data.score ? data.score.id : null); this.validateConfigForm.controls.userGroup.setValue(data.userGroup); this.validateConfigForm.controls.userId.setValue(data.userId); this.validateConfigForm.controls.groupId.setValue(data.groupId); if(data.userGroup === 1){ this.requiredConfigChange('userId', true); }else if(data.userGroup === 2){ this.requiredConfigChange('userId', false); } // data.hosId && this.getHospitals(2, data.hosId); data.dutyId && this.getUsers('', true); data.dutyId && this.getGroups('', true); } // 修改组 changeGroup(id){ this.validateConfigForm.controls.userId.setValue(null); this.getUsers(); } // 新增/编辑表单提交 submitConfigForm(): void { for (const i in this.validateConfigForm.controls) { this.validateConfigForm.controls[i].markAsDirty(); this.validateConfigForm.controls[i].updateValueAndValidity(); } if (this.validateConfigForm.invalid) { return; } console.log(this.validateConfigForm.value); this.btnLoading = true; let postData:any = {}; let categoryId = this.activeCategory3.id || this.activeCategory2.id || this.activeCategory1.id; if (this.add) { //增加 postData = { incidentCategoryConfig: { categoryId, priority: this.validateConfigForm.value.priority, score: { id: this.validateConfigForm.value.score }, dutyId: this.validateConfigForm.value.dutyId, userGroup: this.validateConfigForm.value.userGroup, groupId: this.validateConfigForm.value.groupId || undefined, userId: this.validateConfigForm.value.userGroup === 1 ? this.validateConfigForm.value.userId : undefined, hosId: this.hospitalConfig === 1 ? this.currentHospital.id : this.validateConfigForm.value.hosId, } }; } else { //编辑 postData = { incidentCategoryConfig: { ...this.coopData, ...{ categoryId, priority: this.validateConfigForm.value.priority, score: { id: this.validateConfigForm.value.score }, userGroup: this.validateConfigForm.value.userGroup, groupId: this.validateConfigForm.value.groupId || undefined, userId: this.validateConfigForm.value.userGroup === 1 ? this.validateConfigForm.value.userId : undefined, } } }; } console.log(postData); this.mainService .coopData("addData", "incidentCategoryConfig", postData) .subscribe((result) => { this.btnLoading = false; this.hideConfigModal(); let msg = ""; if (this.add) { msg = "新增"; } else { msg = "修改"; } if (result.status == 200) { this.showPromptModal(msg, true, ''); } else { this.showPromptModal(msg, false, result.msg); } }); } requiredConfigChange(name: string, required: boolean): void { if (!required) { this.validateConfigForm.get(name)!.clearValidators(); this.validateConfigForm.get(name)!.markAsPristine(); } else { this.validateConfigForm.get(name)!.setValidators(Validators.required); this.validateConfigForm.get(name)!.markAsDirty(); } this.validateConfigForm.get(name)!.updateValueAndValidity(); } // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息) promptContent: string; //操作提示框提示信息 ifSuccess: boolean; //操作成功/失败 promptInfo: string; //操作结果提示信息 promptModalShow: boolean; //操作提示框是否展示 showPromptModal(con, success, promptInfo?) { this.promptModalShow = false; this.promptContent = con; this.ifSuccess = success; this.promptInfo = promptInfo; setTimeout(() => { this.promptModalShow = true; }, 100); if(this.coopType !== 0){ this.getCategoryList(this.coopType, this.coopType === 1 ? undefined : this['activeCategory' + (this.coopType - 1)].id); }else{ this.getCategoryList(this.currentCategoryIndex, this.currentCategoryIndex === 1 ? undefined : this['activeCategory' + (this.currentCategoryIndex - 1)].id); } if(this.activeCategory3.id || this.activeCategory2.id || this.activeCategory1.id){ this.getCategoryConfigList(this.activeCategory3.id || this.activeCategory2.id || this.activeCategory1.id); } } }