You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
219 lines
6.7 KiB
219 lines
6.7 KiB
|
|
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' |
|
@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, |
|
UseNature: 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 / 56 |
|
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: '取消' |
|
}); |
|
} |
|
}
|
|
|