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.
248 lines
8.3 KiB
248 lines
8.3 KiB
5 years ago
|
import { Component, OnInit, Inject } from '@angular/core';
|
||
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||
|
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
||
|
import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar';
|
||
|
import { Router,ActivatedRoute } from '@angular/router'
|
||
|
|
||
|
|
||
|
@Component({
|
||
|
selector: 'app-function-division-look',
|
||
|
templateUrl: './function-division.component.html',
|
||
|
styleUrls: ['./function-division.component.scss']
|
||
|
})
|
||
|
export class FunctionDivisionLookComponent implements OnInit {
|
||
|
|
||
|
constructor(private router:Router,private route:ActivatedRoute,private http:HttpClient,public dialog: MatDialog,public snackBar: MatSnackBar) { }
|
||
|
|
||
|
ngOnInit(): void {
|
||
|
this.companyId = this.route.snapshot.queryParams.id
|
||
|
this.getAllCompany()
|
||
|
this.getAllBuilding()
|
||
|
}
|
||
|
|
||
|
displayedColumns: string[] = ['checked', 'region', 'measure', 'situation'];
|
||
|
|
||
|
companyId:any; //单位编号
|
||
|
companyFunctionalZoning:any=[]; //所有单位功能分区属性
|
||
|
selectFunctionalZoning:any=[]; //选中的单位功能分区属性
|
||
|
|
||
|
//获得所有单位功能分区属性
|
||
|
getAllCompany () {
|
||
|
let companyId = this.route.snapshot.queryParams.id
|
||
|
this.http.get('/api/CompanyFunctionalDivisions',{params:{
|
||
|
companyId:companyId
|
||
|
}}).subscribe((data:any)=>{
|
||
|
this.companyFunctionalZoning = data
|
||
|
this.selectFunctionalZoning = []
|
||
|
})
|
||
|
}
|
||
|
|
||
|
//新建单位功能分区属性
|
||
|
addCompany () {
|
||
|
let companyId = this.route.snapshot.queryParams.id
|
||
|
let data = {companyId:companyId, region:'', area:0, details:''}
|
||
|
this.companyFunctionalZoning.push(data)
|
||
|
this.preservation()
|
||
|
}
|
||
|
|
||
|
//保存单位功能分区属性
|
||
|
preservation () {
|
||
|
let companyId = this.route.snapshot.queryParams.id
|
||
|
// console.log(123,companyId)
|
||
|
if (this.companyFunctionalZoning.length) {
|
||
|
this.http.post('/api/CompanyFunctionalDivisions/Batch',this.companyFunctionalZoning,{params:{
|
||
|
companyId:companyId
|
||
|
}}).subscribe(data=>{
|
||
|
this.getAllCompany()
|
||
|
const config = new MatSnackBarConfig();
|
||
|
config.verticalPosition = 'top';
|
||
|
config.duration = 3000
|
||
|
this.snackBar.open('数据更新成功','确定',config);
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//单位功能分区checked选择
|
||
|
changeCompany (ele,e) {
|
||
|
if (e.checked) {
|
||
|
this.selectFunctionalZoning.push(ele.id)
|
||
|
} else {
|
||
|
this.selectFunctionalZoning.splice(this.selectFunctionalZoning.findIndex(item => item === ele.id), 1)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//删除单位功能分区属性
|
||
|
delete () {
|
||
|
let companyId = this.route.snapshot.queryParams.id
|
||
|
if (this.selectFunctionalZoning.length) {
|
||
|
let isDelete = confirm('您确定要删除吗')
|
||
|
if (isDelete) {
|
||
|
this.http.post('/api/CompanyFunctionalDivisions/Batch',this.companyFunctionalZoning,{params:{
|
||
|
companyId:companyId
|
||
|
}}).subscribe(data=>{
|
||
|
const options = {
|
||
|
headers: new HttpHeaders({'Content-Type': 'application/json',}),
|
||
|
body:this.selectFunctionalZoning}
|
||
|
this.http.delete(`/api/CompanyFunctionalDivisions/Batch`,options).subscribe(data=>{
|
||
|
this.getAllCompany()
|
||
|
const config = new MatSnackBarConfig();
|
||
|
config.verticalPosition = 'top';
|
||
|
config.duration = 3000
|
||
|
this.snackBar.open('数据更新成功','确定',config);
|
||
|
})
|
||
|
})
|
||
|
}
|
||
|
} else if (!this.selectFunctionalZoning.length) {
|
||
|
const config = new MatSnackBarConfig();
|
||
|
config.verticalPosition = 'top';
|
||
|
config.duration = 3000
|
||
|
this.snackBar.open('请选择单位功能分区','确定',config);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//建筑功能分区↓
|
||
|
allBuilding:any = []; //所有建筑
|
||
|
allBuildingFunctionalZoning:any = []; //所有建筑的功能分区
|
||
|
selectBuildingFunctionalZoning:any = []; //选中的建筑的功能分区
|
||
|
|
||
|
//获得所有建筑
|
||
|
getAllBuilding () {
|
||
|
let companyId = this.route.snapshot.queryParams.id
|
||
|
this.http.get(`/api/Buildings`,{params:{
|
||
|
companyId:companyId
|
||
|
}}).subscribe((data:any)=>{
|
||
|
if (data.length) {
|
||
|
this.allBuilding = data
|
||
|
this.allBuilding.forEach(element => { //为每个建筑添加一个 功能分区对象
|
||
|
element.functionalZoning = null
|
||
|
});
|
||
|
this.getAllBuildingFunctionalZoning()
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
|
||
|
//获得所有建筑的功能分区
|
||
|
getAllBuildingFunctionalZoning () {
|
||
|
this.selectBuildingFunctionalZoning = []
|
||
|
this.allBuildingFunctionalZoning = []
|
||
|
this.allBuilding.forEach(element => {
|
||
|
let data={buildingId: element.id}
|
||
|
this.http.get(`/api/BuildingFunctionalDivisions`,{params:data}).subscribe((data:any)=>{
|
||
|
if (data.length) {
|
||
|
element.functionalZoning = data
|
||
|
this.selectBuildingFunctionalZoning.push([]) //拥有建筑功能分区的提前push空数组
|
||
|
this.allBuildingFunctionalZoning.push(element) }
|
||
|
})
|
||
|
});
|
||
|
}
|
||
|
|
||
|
//封装函数刷新当前建筑功能分区
|
||
|
updateCurrent (e,index) {
|
||
|
let data= {buildingId: e.id}
|
||
|
this.http.get(`/api/BuildingFunctionalDivisions`,{params:data}).subscribe((data:any)=>{
|
||
|
this.selectBuildingFunctionalZoning[index] = []
|
||
|
this.allBuildingFunctionalZoning[index].functionalZoning = data
|
||
|
const config = new MatSnackBarConfig();
|
||
|
config.verticalPosition = 'top';
|
||
|
config.duration = 3000
|
||
|
this.snackBar.open('数据更新成功','确定',config);
|
||
|
})
|
||
|
}
|
||
|
|
||
|
//创建建筑功能分区
|
||
|
addPartition () {
|
||
|
}
|
||
|
|
||
|
//创建建筑功能分区属性
|
||
|
addBuilding (e,index) {
|
||
|
let data = {buildingId:e.id, region:'', area:0, details:''}
|
||
|
this.http.post('/api/BuildingFunctionalDivisions',data).subscribe(data=>{
|
||
|
this.preservationBuilding(e,index)
|
||
|
})
|
||
|
}
|
||
|
|
||
|
//保存建筑功能分区属性
|
||
|
preservationBuilding (e,index) {
|
||
|
let data ={buildingId:e.id}
|
||
|
this.http.post(`/api/BuildingFunctionalDivisions/Batch`,this.allBuildingFunctionalZoning[index].functionalZoning,{params:data}).subscribe(data=>{
|
||
|
this.updateCurrent(e,index)
|
||
|
})
|
||
|
}
|
||
|
|
||
|
//建筑功能分区checked选择
|
||
|
changeBuilding (ele,e,index) {
|
||
|
if (e.checked) {
|
||
|
this.selectBuildingFunctionalZoning[index].push(ele.id)
|
||
|
} else {
|
||
|
this.selectBuildingFunctionalZoning[index].splice(this.selectBuildingFunctionalZoning[index].findIndex(item => item === ele.id), 1)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//删除建筑功能分区
|
||
|
deleteBuilding (e,index) {
|
||
|
if (this.selectBuildingFunctionalZoning[index].length) {
|
||
|
let isDelete = confirm('您确定要删除吗')
|
||
|
if (isDelete) {
|
||
|
let data ={buildingId:e.id}
|
||
|
this.http.post(`/api/BuildingFunctionalDivisions/Batch`,this.allBuildingFunctionalZoning[index].functionalZoning,{params:data}).subscribe(data=>{
|
||
|
const options = {
|
||
|
headers: new HttpHeaders({'Content-Type': 'application/json',}),
|
||
|
body:this.selectBuildingFunctionalZoning[index],
|
||
|
params:{buildingId:e.id}}
|
||
|
this.http.delete(`/api/BuildingFunctionalDivisions/Batch`,options).subscribe(data=>{
|
||
|
this.selectBuildingFunctionalZoning[index].forEach((element,newIndex) => {
|
||
|
this.allBuildingFunctionalZoning[index].functionalZoning.splice(this.allBuildingFunctionalZoning[index].functionalZoning.findIndex(item=>item.id==element),1)
|
||
|
if (newIndex==this.selectBuildingFunctionalZoning[index].length-1) {
|
||
|
if (this.allBuildingFunctionalZoning[index].functionalZoning.length) {
|
||
|
this.updateCurrent(e,index)
|
||
|
} else {
|
||
|
this.selectBuildingFunctionalZoning.splice(index,1)
|
||
|
this.allBuildingFunctionalZoning.splice(index,1)}
|
||
|
}
|
||
|
});
|
||
|
|
||
|
|
||
|
})
|
||
|
})
|
||
|
}
|
||
|
} else if (!this.selectBuildingFunctionalZoning[index].length) {
|
||
|
const config = new MatSnackBarConfig();
|
||
|
config.verticalPosition = 'top';
|
||
|
config.duration = 3000
|
||
|
this.snackBar.open('请选择建筑功能分区','确定',config);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//暂时无用
|
||
|
@Component({
|
||
|
selector: 'app-addPartitionAttribute',
|
||
|
templateUrl: './addPartitionAttribute.html',
|
||
|
styleUrls: ['./function-division.component.scss']
|
||
|
})
|
||
|
export class addPartitionAttribute2 {
|
||
|
|
||
|
constructor(private http:HttpClient,public dialog: MatDialog,public dialogRef: MatDialogRef<addPartitionAttribute2>,
|
||
|
@Inject(MAT_DIALOG_DATA) public data) { }
|
||
|
|
||
|
ngOnInit(): void {
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
}
|