import { Component, OnInit, ViewChild } from '@angular/core'; import { NzFormatEmitEvent, NzTreeComponent, NzTreeNodeOptions } from 'ng-zorro-antd/tree'; import { FacilityInfoInSceneWindow } from 'src/app/babylon/view/facilityinfoinscene-window/facilityinfoinscene-window'; import { PlanComponent } from '../plan/plan.component'; import { FacilityInfoUIItem } from "../../babylon/view/facilityinfoinscene-window/facilityinfo-ui-item"; import { ConfigManager } from 'src/app/babylon/controller/config-manager'; import { FacilityType } from 'src/app/babylon/model/data/model-data/model-data-facility'; import { EventManager } from 'src/app/babylon/controller/event-manager/event-manager'; import { Event_GetAllMarkPlanData } from 'src/app/babylon/controller/event-manager/events/event-get-markplandata-success'; import { AllMarkPlanData, MarkNodeData, MarkPlanData } from 'src/app/babylon/model/data/mark/mark-plan-data'; import { MarkWindow } from 'src/app/babylon/view/mark-window/mark-window'; import { NzMessageService } from 'ng-zorro-antd/message'; import { ModeManager, ModeType } from 'src/app/babylon/controller/mode-manager'; @Component({ selector: 'app-left-domain', templateUrl: './left-domain.component.html', styleUrls: ['./left-domain.component.scss', '../plan/publicPop.scss'] }) export class LeftDomainComponent implements OnInit { constructor(private message: NzMessageService) { } ngOnInit(): void { let editMode = sessionStorage.getItem('isGasStation') if (editMode == 'false') { this.editMode = true } else { this.editMode = false } this.initComponent() } editMode: boolean = true; //编辑/查看模式 beforeFence: number; //当前选中功能栏 FacilityList: FacilityInfoUIItem[] = []; //统计设备 list selectFacilityId: string = null; //选中设备 ID //初始化组件 initComponent(type?: number) { if (type != undefined && type != null) { this.beforeFence = type this.handleFacility() } else { this.beforeFence = PlanComponent.instance.selectFence this.handleFacility() } } //处理 设备data handleFacility() { if (this.beforeFence === 7) { //应急预案 MarkWindow.instance ? this.allMarkPlanData = MarkWindow.instance.allMarkPlanData : null EventManager.addListener(Event_GetAllMarkPlanData, (data: Event_GetAllMarkPlanData) => { this.allMarkPlanData = data.data PlanComponent.instance.allMarkPlanData = this.allMarkPlanData }) PlanComponent.instance.allMarkPlanData = this.allMarkPlanData return } let list: FacilityInfoUIItem[] = [] FacilityInfoInSceneWindow.instance.facilityInfoUIItemes.forEach(item => { if (this.beforeFence === 1) { //加油机 item.getType() === "JY_JYJ" ? list.push(item) : null } else if (this.beforeFence === 2) { //油罐设备 item.getType() === "JY_YG" ? list.push(item) : null } else if (this.beforeFence === 3) { //消防设施 (item.getType()).slice(0, 3) === "XF_" ? list.push(item) : null } else if (this.beforeFence === 5) { //输油管线 item.getType() === "JY_SYGX" ? list.push(item) : null } else if (this.beforeFence === 6) { //油气回收 item.getType() === "JY_YQHSGX" ? list.push(item) : null } }) this.FacilityList = list this.selectFacilityId = null if (this.beforeFence === 3) { //消防设施 this.handleTreeData(this.FacilityList) } } //选中 设备 selectFacility(item: FacilityInfoUIItem) { if (this.selectFacilityId != item.getID()) { this.selectFacilityId = item.getID() FacilityInfoInSceneWindow.instance.selectFacilityItem(item); } else { this.selectFacilityId = null item.onSelect(false) } } @ViewChild('nzTreeComponent', { static: false }) nzTreeComponent!: NzTreeComponent; treeData: NzTreeNodeOptions[] = []; //tree data //处理 treeData handleTreeData(list: FacilityInfoUIItem[]) { this.treeData = [] list.forEach(item => { let isFind = this.treeData.find(element => { return (item.getType()).includes(element.key) }) if (!isFind) { //不存在 if (item.getType().includes('XF_MHQ')) { //灭火器 let primaryNode = { title: '灭火器', key: 'XF_MHQ', selectable: false, expanded: true, children: [], } let treeNode = { title: ConfigManager.getFacilityTypeName(item.getType()), key: item.getType(), selectable: false, } primaryNode.children.push(treeNode) this.treeData.push(primaryNode) } else { let primaryNode = { title: ConfigManager.getFacilityTypeName(item.getType()), key: item.getType(), selectable: false, } this.treeData.push(primaryNode) } } else { //存在 if (item.getType().includes('XF_MHQ') && !isFind.children.find(elements => { return elements.key === item.getType() })) { //灭火器 let treeNode = { title: ConfigManager.getFacilityTypeName(item.getType()), key: item.getType(), selectable: false, } isFind.children.push(treeNode) } } }) //编辑模式 if (this.editMode) { let isFind = this.treeData.find(item=>{ return item.key === 'XF_MHQ' }) if (!isFind) { let primaryNode = { title: '灭火器', key: 'XF_MHQ', selectable: false, } this.treeData.push(primaryNode) } for (let facility in FacilityType) { if (facility.slice(0, 3) === "XF_" && !facility.includes('XF_MHQ')) { let isFind = this.treeData.find(item => { return item.key === facility }) if (!isFind) { let primaryNode = { title: ConfigManager.getFacilityTypeName(FacilityType[facility]), key: facility, selectable: false, } this.treeData.push(primaryNode) } } } } //编辑模式 } //获取设备 数量 getFacilityNum(type: string): number { let num = 0 this.FacilityList.forEach(item => { item.getType().includes(type) ? num = num + 1 : null }) return num } //点击tree节点 nzClick(event: NzFormatEmitEvent) { if (event.node.key != 'XF_MHQ') { event.node.isSelected = !event.node.isSelected if (event.node.isSelected) { //显示当前, 隐藏所有 FacilityInfoInSceneWindow.instance.showFacilityByType(null, false) FacilityInfoInSceneWindow.instance.showFacilityByType(FacilityType[event.node.key], event.node.isSelected) } else { //显示所有 this.treeData.forEach(item => { if (item.key != 'XF_MHQ') { FacilityInfoInSceneWindow.instance.showFacilityByType(FacilityType[item.key], true) } else { item.children.forEach(element => { FacilityInfoInSceneWindow.instance.showFacilityByType(FacilityType[element.key], true) }) } }) } } } allMarkPlanData: AllMarkPlanData; //处置预案节点数据 selectPlanId: number; selectNodeId: number; addDisposalPop: boolean = false; //显示/隐藏 创建预案 弹窗 addNodePop: number = null; //显示/隐藏 创建节点 父节点ID //创建预案/节点 addDisposal(e) { if (this.addDisposalPop) { //创建预案 MarkWindow.instance.createMarkPlaneData(e.name) this.addDisposalPop = false } else { //创建节点 MarkWindow.instance.createMarkNodeData(this.addNodePop, e.name) this.addNodePop = null } } editSelectDisposal: MarkPlanData = null; //编辑预案名称 选中预案 editDisposalName: string = null; //显示/隐藏 编辑预案名称 弹窗 //打开 编辑预案名称弹窗 openEditDisposal(item: MarkPlanData) { this.editSelectDisposal = item; this.editDisposalName = JSON.parse(JSON.stringify(item.name)) } //编辑预案名称 editDisposal(e) { this.editSelectDisposal.name = e.name this.editSelectDisposal = null } //删除预案/节点 deleteDisposal(item: MarkPlanData, e?: MarkNodeData) { let isTrue = confirm('您确定要删除吗') if (isTrue) { if (!e) { MarkWindow.instance.deleteMarkPlaneData(item.id) } else { MarkWindow.instance.deleteMarkNodeData(item.id, e.id) } } } //选中 数据节点 selectNode(item: MarkPlanData, e: MarkNodeData) { if (this.selectPlanId != item.id || this.selectNodeId != e.id) { //选中 if (!MarkWindow.instance.currentMarkNodeInfo) { //未选中节点 this.updateFatherData() //更新/初始化父组件 数据 this.selectPlanId = item.id this.selectNodeId = e.id MarkWindow.instance.selectMarkNode(item.id, e.id) PlanComponent.instance.beforeEmergencyPlan = item PlanComponent.instance.beforePlanNode = MarkWindow.instance.currentMarkNodeInfo.nodeData } else { //已选中节点 let isTrue = true; if (ModeManager.currentMode == ModeType.Edit) { isTrue = confirm('切换节点后,没保存的信息将会丢失!') } if (isTrue) { this.updateFatherData() //更新/初始化父组件 数据 this.selectPlanId = item.id this.selectNodeId = e.id MarkWindow.instance.selectMarkNode(item.id, e.id) PlanComponent.instance.beforeEmergencyPlan = item PlanComponent.instance.beforePlanNode = MarkWindow.instance.currentMarkNodeInfo.nodeData } } } else if (this.selectPlanId === item.id && this.selectNodeId === e.id) { //取消选中 let isTrue = true; if (ModeManager.currentMode == ModeType.Edit) { isTrue = confirm('切换节点后,没保存的信息将会丢失!') } if (isTrue) { PlanComponent.instance.beforeEmergencyPlan = new MarkPlanData(-99, "请选择节点") PlanComponent.instance.beforePlanNode = new MarkNodeData(-99, "请选择节点") this.updateFatherData() //更新/初始化父组件 数据 this.selectPlanId = null this.selectNodeId = null MarkWindow.instance.selectMarkNode(null, null) } } } //更新/初始化父组件 数据 updateFatherData() { PlanComponent.instance.nzCurrent = -1 PlanComponent.instance.isSuspend = true //暂停 PlanComponent.instance.timer? window.clearTimeout(PlanComponent.instance.timer) : null //清除定时器 PlanComponent.instance.updateTimer? window.clearTimeout(PlanComponent.instance.updateTimer) : null //清除定时器 } saveDisposalDialog: boolean = false; //整体保存预案 弹窗 saveType: number = null; //新建保存/保存到已有 弹窗 allNodeList: any[] = []; //所有根节点/节点 //保存-1 saveDisposal(markPlanId: number = null, nodeId: number = null) { if (!MarkWindow.instance.currentMarkNodeInfo) { //未选中节点 this.message.info('还没有进行标绘,无法保存'); return } if (markPlanId === null && nodeId === null) { // 整体弹窗保存 this.saveDisposalDialog = true } else { if (this.selectPlanId === markPlanId && this.selectNodeId === nodeId) { MarkWindow.instance.saveToOldNode(markPlanId, nodeId) } else { let isTrue = confirm('是否覆盖要保存的节点?') isTrue ? MarkWindow.instance.saveToOldNode(markPlanId, nodeId) : null } } } //保存-2 saveNode(isNew: boolean) { this.saveDisposalDialog = false if (isNew) { //新建节点并保存 this.saveType = 1 this.allNodeList = MarkWindow.instance.allMarkPlanData.datas } else { //保存到已有节点 this.saveType = 2 this.allNodeList = [] MarkWindow.instance.allMarkPlanData.datas.forEach(item => { item.nodes.forEach(element => { let node = { id: element.id, parrentId: item.id, name: element.name, } this.allNodeList.push(node) }) }); } } //保存-3 saveDisposalNode(e) { if (this.saveType === 1) { //新建节点并保存 if (!e.name || !e.root) { this.message.info('请完善表单') return } MarkWindow.instance.createNewNodeAndSave(e.root.id, e.name) this.saveType = null } else { //保存到已有节点 if (!e.node) { this.message.info('请完善表单') return } MarkWindow.instance.saveToOldNode(e.node.parrentId, e.node.id) this.saveType = null } } //编辑信息 editInfo() { } //导出Excel deriveExcel() { } } export class treeData { static nodes: NzTreeNodeOptions[] = [] }