import { Router } from '@angular/router'; import { HttpClient } from '@angular/common/http'; import { Component, OnInit, AfterViewInit, ViewChild, ViewContainerRef } from '@angular/core'; import { TreeService } from 'src/app/service/tree.service'; import { NzFormatEmitEvent, NzTreeComponent, NzTreeNodeOptions } from 'ng-zorro-antd/tree'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { NzModalService } from 'ng-zorro-antd/modal'; import { NzMessageService } from 'ng-zorro-antd/message'; import { AddUnitComponent } from '../add-unit/add-unit.component'; import { UnitEditComponent } from '../unit-edit/unit-edit.component' import { asBlob } from 'html-docx-js-typescript' // 要保存这个docx文件推荐引入file-saver哦,你可以用npm i -D file-saver来安装 import { saveAs } from 'file-saver' @Component({ selector: 'app-unit', templateUrl: './unit.component.html', styleUrls: ['./unit.component.scss'] }) export class UnitComponent implements OnInit { listOfData: any = []; validateForm!: FormGroup; constructor(private router: Router, private fb: FormBuilder, private http: HttpClient, private toTree: TreeService, private modal: NzModalService, private message: NzMessageService, private viewContainerRef: ViewContainerRef) { } PageNumber = 1 PageSize = 10 ngOnInit(): void { this.getBuildingTypes() this.getAllOrganization() } expandKeys defaultOrId: string //获取所有组织机构 nodes: any = [] getAllOrganization() { let organizationId = JSON.parse(sessionStorage.getItem('userData')).organizationId let params = { OrganizationId: organizationId || '', ContainsChildren: "true", PageNumber: 1, PageSize: 9999 } this.http.get('/api/Organizations', { params: params }).subscribe((data: any) => { data.items.forEach(element => { if (element.id == organizationId) { element.parentId = null } element.key = element.id element.title = element.name }); this.nodes = [...this.toTree.toTree(data.items)] this.searchValue.or = JSON.parse(sessionStorage.getItem('userData')).organizationId //回显 let unitPagesData = JSON.parse(sessionStorage.getItem('unitPagesData')) || null if (unitPagesData) { this.searchValue = unitPagesData.searchValue this.PageNumber = unitPagesData.PageNumber } this.getCompanies() }) } BuildingTypes getBuildingTypes() { this.http.get('/api/BuildingTypes').subscribe((data: any) => { this.BuildingTypes = data }) } searchValue = { unit: '', uniytype: '', or: JSON.parse(sessionStorage.getItem('userData')).organizationId, property: '' }; nzLoading = false totalCount getCompanies() { this.nzLoading = true let params = { CompanyName: this.searchValue.unit, BuildingTypeId: this.searchValue.uniytype, OrganizationId: this.searchValue.or, CompanyLevel: this.searchValue.property, PageNumber: this.PageNumber, PageSize: this.PageSize } this.http.get('/api/Companies', { params: params }).subscribe((data: any) => { this.nzLoading = false console.log(data); this.totalCount = data.totalCount this.listOfData = data.items this.listOfData = [...this.listOfData] }) } pageChange($event) { this.PageNumber = $event this.getCompanies() } search() { this.PageNumber = 1 this.getCompanies() } reset() { this.PageNumber = 1 this.searchValue = { unit: '', uniytype: '', or: JSON.parse(sessionStorage.getItem('userData')).organizationId, property: '' }; this.getCompanies() } ngOnDestroy(): void { // CustomReuseStrategy.deleteRouteSnapshot('/basicInfo/unit'); } addUnit() { const modal = this.modal.create({ nzTitle: "新增单位", nzContent: AddUnitComponent, nzViewContainerRef: this.viewContainerRef, nzWidth: 450, nzComponentParams: { nodes: this.nodes, BuildingTypes: this.BuildingTypes }, nzOnOk: async () => { if (instance.validateForm.valid) { await new Promise((resolve, reject) => { let num = 0 for (const key in instance.validateForm.value) { if (Object.prototype.hasOwnProperty.call(instance.validateForm.value, key)) { const element = instance.validateForm.value[key]; if (element) { num += 1 } } } let integrity: number = num / 63 let body = { companyName: instance.validateForm.value.unitname, directorName: instance.validateForm.value.person, directorPhone: instance.validateForm.value.phone, address: instance.validateForm.value.addr, organizationId: instance.validateForm.value.orStation || null, relatedOrganizationId: instance.validateForm.value.orDa || null, buildingTypeId: instance.validateForm.value.unittype || null, useNature: instance.validateForm.value.nature, data: null, integrity: integrity.toFixed(2) } this.http.post('/api/Companies', body).subscribe({ next: async (data) => { this.message.create('success', '创建成功'); resolve(data) await this.getCompanies() return true }, error: (err) => { this.message.create('warning', '创建失败'); reject(err) return false } }) }) } else { this.message.create('warning', '请填写完整!'); return false } } }); const instance = modal.getContentComponent(); } look(data) { let unitPagesData = { searchValue: this.searchValue, PageNumber: this.PageNumber } sessionStorage.setItem('unitPagesData', JSON.stringify(unitPagesData)) this.router.navigate(['/basicInfo/unit/details'], { queryParams: { id: data.id, pattern: 'look' } }) } edit(data) { let unitPagesData = { searchValue: this.searchValue, PageNumber: this.PageNumber } sessionStorage.setItem('unitPagesData', JSON.stringify(unitPagesData)) this.router.navigate(['/basicInfo/unit/details'], { queryParams: { id: data.id, pattern: 'edit' } }) } delete(item) { this.modal.confirm({ nzTitle: `确定要删除${item.companyName}这个单位吗?`, nzOkText: '确定', nzOkType: 'default', nzOnOk: () => { this.http.delete(`/api/Companies/${item.id}`).subscribe(data => { this.message.create('success', '删除成功!'); this.getCompanies() }) }, nzCancelText: '取消' }); } //下载 datas download(data) { // console.log(data) if(data.data){ this.datas = JSON.parse(data.data) }else{ this.message.create('warning', '该单位未保存过数据'); return } let alarm = "" let spray = "" let broadcast = "" let smoke = "" if (this.datas.facilities.system.alarm) { alarm = "有" } else { alarm = "无" } if (this.datas.facilities.system.spray) { spray = "有" } else { spray = "无" } if (this.datas.facilities.system.broadcast) { broadcast = "有" } else { broadcast = "无" } if (this.datas.facilities.system.smoke) { smoke = "有" } else { smoke = "无" } let box = `
单位基本情况 |
单位名称 |
`+ this.datas.basicInfo.name + ` |
单位地址 |
`+ this.datas.basicInfo.addr + ` |
联系电话 |
`+ this.datas.basicInfo.phone + ` |
|||||||||||||
人员总数 |
`+ this.datas.basicInfo.total + ` |
建筑高度 |
`+ this.datas.basicInfo.height + ` |
层数 |
`+ this.datas.basicInfo.layer + ` |
||||||||||||||
建筑结构 |
`+ this.datas.basicInfo.structure + ` |
占地面积 |
`+ this.datas.basicInfo.coveredArea + ` |
总建筑面积 |
`+ this.datas.basicInfo.builtUpArea + ` |
主要使用性质 |
`+ this.datas.basicInfo.nature + ` |
||||||||||||
毗邻建筑 |
东:`+ this.datas.basicInfo.east + ` |
南:`+ this.datas.basicInfo.south + ` |
西:`+ this.datas.basicInfo.west + ` |
北:`+ this.datas.basicInfo.north + ` |
|||||||||||||||
辖区中队行驶路线及时间 |
`+ this.datas.basicInfo.routeAndTime + ` |
||||||||||||||||||
单位内部主要消防设施 |
消防控制室 |
位置 |
`+ this.datas.facilities.controlPosition + ` |
||||||||||||||||
消防水源 |
消防水池数量 |
`+ this.datas.facilities.poolNumbe + ` |
位置 |
`+ this.datas.facilities.poolPosition + ` |
总容量 |
`+ this.datas.facilities.poolCapacity + ` |
补给方式 |
|
|||||||||||
室外其他水源 |
`+ this.datas.facilities.waterSources + ` |
位置 |
`+ this.datas.facilities.waterSourcesPosition + ` |
||||||||||||||||
自动报警系统 |
`+ alarm + ` |
自动喷水系统 |
`+ spray + ` |
应急广播系统 |
`+ broadcast + ` |
防排烟系统 |
`+ smoke + ` |
||||||||||||
室外消火栓数量 |
`+ this.datas.facilities.hydrantsNumber + `个 |
室外消火栓位置分布 |
`+ this.datas.facilities.hydrantsPosition + ` |
||||||||||||||||
消防泵 |
消火栓泵 |
数量:`+ this.datas.facilities.pumpNumber + ` |
扬程:`+ this.datas.facilities.pumpRange + `m |
流量:`+ this.datas.facilities.pumpFlow + `L/S |
水泵接合器 |
数量: |
`+ this.datas.facilities.pumpAdapter + ` |
||||||||||||
喷淋泵 |
数量:`+ this.datas.facilities.SprayPumpNumber + ` |
扬程:`+ this.datas.facilities.SprayPumpRange + `m |
流量:`+ this.datas.facilities.SprayPumpFlow + `L/S |
水泵接合器 |
数量: |
`+ this.datas.facilities.SprayPumpAdapter + ` |
|||||||||||||
消防电梯 数量及位置 |
`+ this.datas.facilities.elevator + ` |
疏散楼梯 数量及位置 |
`+ this.datas.facilities.stairs + ` |
安全出口 数量及位置 |
`+ this.datas.facilities.Export + ` |
||||||||||||||
室内消火栓数量 |
`+ this.datas.facilities.indoorHydrant + `个 |
标准层室内消火栓数量及位置 |
`+ this.datas.facilities.standardIndoorHydrant + ` |
||||||||||||||||
重点部位情况(一) |
重点部位名称 |
`+ this.datas.KeyParts[0].keyparts + ` |
重点部位所在位置 |
`+ this.datas.KeyParts[0].keypartsposition + ` |
建筑结构 |
`+ this.datas.KeyParts[0].buildingstructure + ` |
使用性质 |
`+ this.datas.KeyParts[0].useNature + ` |
|||||||||||
主要危险性 |
`+ this.datas.KeyParts[0].danger + ` |
||||||||||||||||||
重点部位情况(二) |
重点部位名称 |
`+ this.datas.KeyParts[1].keyparts + ` |
重点部位所在位置 |
`+ this.datas.KeyParts[1].keypartsposition + ` |
建筑结构 |
`+ this.datas.KeyParts[1].buildingstructure + ` |
使用性质 |
`+ this.datas.KeyParts[1].useNature + ` |
|||||||||||
主要危险性 |
`+ this.datas.KeyParts[1].danger + ` |
||||||||||||||||||
重点 提示 |
`+ this.datas.tips + ` |
||||||||||||||||||
` const htmlString = `