|
|
|
@ -1,21 +1,29 @@
|
|
|
|
|
import { Component, OnInit, Inject } from '@angular/core'; |
|
|
|
|
import {MatTreeFlatDataSource, MatTreeFlattener} from '@angular/material/tree'; |
|
|
|
|
import {FlatTreeControl} from '@angular/cdk/tree'; |
|
|
|
|
import { HttpClient } from '@angular/common/http'; |
|
|
|
|
import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material/dialog'; |
|
|
|
|
import {FormControl} from '@angular/forms'; |
|
|
|
|
import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar'; |
|
|
|
|
import { TreeService } from '../../http-interceptors/tree.service' |
|
|
|
|
import { Component, OnInit, Inject } from "@angular/core"; |
|
|
|
|
import { |
|
|
|
|
MatTreeFlatDataSource, |
|
|
|
|
MatTreeFlattener, |
|
|
|
|
} from "@angular/material/tree"; |
|
|
|
|
import { FlatTreeControl } from "@angular/cdk/tree"; |
|
|
|
|
import { HttpClient } from "@angular/common/http"; |
|
|
|
|
import { |
|
|
|
|
MatDialog, |
|
|
|
|
MatDialogRef, |
|
|
|
|
MAT_DIALOG_DATA, |
|
|
|
|
} from "@angular/material/dialog"; |
|
|
|
|
import { FormControl } from "@angular/forms"; |
|
|
|
|
import { MatSnackBar, MatSnackBarConfig } from "@angular/material/snack-bar"; |
|
|
|
|
import { TreeService } from "../../http-interceptors/tree.service"; |
|
|
|
|
@Component({ |
|
|
|
|
selector: 'app-organization', |
|
|
|
|
templateUrl: './organization.component.html', |
|
|
|
|
styleUrls: ['./organization.component.scss'] |
|
|
|
|
selector: "app-organization", |
|
|
|
|
templateUrl: "./organization.component.html", |
|
|
|
|
styleUrls: ["./organization.component.scss"], |
|
|
|
|
}) |
|
|
|
|
export class OrganizationComponent implements OnInit { |
|
|
|
|
data:any =[] //存储所有组织机构
|
|
|
|
|
data: any = []; //存储所有组织机构
|
|
|
|
|
newdata = []; |
|
|
|
|
|
|
|
|
|
private _transformer = (node, level: number) => {//要给渲染节点传那些属性参数
|
|
|
|
|
private _transformer = (node, level: number) => { |
|
|
|
|
//要给渲染节点传那些属性参数
|
|
|
|
|
return { |
|
|
|
|
expandable: !!node.children && node.children.length > 0, |
|
|
|
|
name: node.name, |
|
|
|
@ -28,22 +36,33 @@ export class OrganizationComponent implements OnInit {
|
|
|
|
|
isTop: node.isTop, |
|
|
|
|
isBottom: node.isBottom, |
|
|
|
|
code: node.code, |
|
|
|
|
division:node.division |
|
|
|
|
division: node.division, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
treeControl = new FlatTreeControl<any>(node => node.level, node => node.expandable); |
|
|
|
|
treeFlattener = new MatTreeFlattener(this._transformer, node => node.level, node => node.expandable, node => node.children); |
|
|
|
|
}; |
|
|
|
|
treeControl = new FlatTreeControl<any>( |
|
|
|
|
(node) => node.level, |
|
|
|
|
(node) => node.expandable |
|
|
|
|
); |
|
|
|
|
treeFlattener = new MatTreeFlattener( |
|
|
|
|
this._transformer, |
|
|
|
|
(node) => node.level, |
|
|
|
|
(node) => node.expandable, |
|
|
|
|
(node) => node.children |
|
|
|
|
); |
|
|
|
|
dataSource = new MatTreeFlatDataSource(this.treeControl, this.treeFlattener); |
|
|
|
|
|
|
|
|
|
constructor(private http: HttpClient,public dialog: MatDialog,public snackBar: MatSnackBar,private tree: TreeService) { |
|
|
|
|
} |
|
|
|
|
isloading:any = false //loading效果
|
|
|
|
|
constructor( |
|
|
|
|
private http: HttpClient, |
|
|
|
|
public dialog: MatDialog, |
|
|
|
|
public snackBar: MatSnackBar, |
|
|
|
|
private tree: TreeService |
|
|
|
|
) {} |
|
|
|
|
isloading: any = false; //loading效果
|
|
|
|
|
//重新获取列表并且展开到上次位置的方法
|
|
|
|
|
getlist = (): void => { |
|
|
|
|
this.http.get('/api/Organizations').subscribe( |
|
|
|
|
(data:any)=>{ |
|
|
|
|
this.http.get("/api/Organizations").subscribe((data: any) => { |
|
|
|
|
this.data = data; |
|
|
|
|
this.newdata = this.tree.toTree(data) |
|
|
|
|
this.newdata = this.tree.toTree(data); |
|
|
|
|
|
|
|
|
|
const nodes = this.treeControl.dataNodes; |
|
|
|
|
const expandNodes = []; |
|
|
|
@ -53,76 +72,79 @@ export class OrganizationComponent implements OnInit {
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.dataSource.data = this.newdata; |
|
|
|
|
let newNodes = this.treeControl.dataNodes; |
|
|
|
|
newNodes = newNodes.filter(n => { |
|
|
|
|
newNodes = newNodes.filter((n) => { |
|
|
|
|
return expandNodes.indexOf(n.id) >= 0; |
|
|
|
|
}); |
|
|
|
|
newNodes.forEach(item => { |
|
|
|
|
newNodes.forEach((item) => { |
|
|
|
|
this.treeControl.expand(item); |
|
|
|
|
}); |
|
|
|
|
this.isloading = false |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
this.isloading = false; |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
//初始化视图
|
|
|
|
|
ngOnInit() { |
|
|
|
|
this.http.get('/api/Organizations').subscribe( |
|
|
|
|
(data:any)=>{ |
|
|
|
|
this.http.get("/api/Organizations").subscribe((data: any) => { |
|
|
|
|
this.data = data; |
|
|
|
|
this.dataSource.data = this.tree.toTree(data); |
|
|
|
|
this.treeControl.expand(this.treeControl.dataNodes[0]); |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
hasChild = (_: number, node: any) => node.expandable; |
|
|
|
|
|
|
|
|
|
//创建组织按钮
|
|
|
|
|
create(value) { |
|
|
|
|
const dialogRef = this.dialog.open(CreateOrganization, {//调用open方法打开对话框并且携带参数过去
|
|
|
|
|
width: '260px', |
|
|
|
|
data: {id:value.id,childlength:value.children,level:value.level} |
|
|
|
|
const dialogRef = this.dialog.open(CreateOrganization, { |
|
|
|
|
//调用open方法打开对话框并且携带参数过去
|
|
|
|
|
width: "260px", |
|
|
|
|
data: { id: value.id, childlength: value.children, level: value.level }, |
|
|
|
|
}); |
|
|
|
|
dialogRef.afterClosed().subscribe( |
|
|
|
|
data=>{ |
|
|
|
|
dialogRef.afterClosed().subscribe((data) => { |
|
|
|
|
if (data) { |
|
|
|
|
this.getlist() |
|
|
|
|
this.getlist(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
createOne() { |
|
|
|
|
const dialogRef = this.dialog.open(CreateOrganization, { |
|
|
|
|
//调用open方法打开对话框并且携带参数过去
|
|
|
|
|
width: "260px", |
|
|
|
|
data: { id: "", childlength: "", level: "" }, |
|
|
|
|
}); |
|
|
|
|
dialogRef.afterClosed().subscribe((data) => { |
|
|
|
|
if (data) { |
|
|
|
|
this.getlist(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
//编辑组织按钮
|
|
|
|
|
edit(node) { |
|
|
|
|
const dialogRef = this.dialog.open(EditOrganization, {//调用open方法打开对话框并且携带参数过去
|
|
|
|
|
data: node |
|
|
|
|
const dialogRef = this.dialog.open(EditOrganization, { |
|
|
|
|
//调用open方法打开对话框并且携带参数过去
|
|
|
|
|
data: node, |
|
|
|
|
}); |
|
|
|
|
dialogRef.afterClosed().subscribe((data) => { |
|
|
|
|
this.getlist(); |
|
|
|
|
}); |
|
|
|
|
dialogRef.afterClosed().subscribe( |
|
|
|
|
data=>{ |
|
|
|
|
this.getlist() |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
//删除组织按钮
|
|
|
|
|
delete(value) { |
|
|
|
|
var isdeleted = confirm("确定要删除此组织?") |
|
|
|
|
var isdeleted = confirm("确定要删除此组织?"); |
|
|
|
|
if (isdeleted) { |
|
|
|
|
//请求删除接口
|
|
|
|
|
this.isloading = true |
|
|
|
|
this.http.delete(`/api/Organizations/${value.id}`).subscribe( data=>{
|
|
|
|
|
this.getlist() |
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|
this.isloading = true; |
|
|
|
|
this.http.delete(`/api/Organizations/${value.id}`).subscribe((data) => { |
|
|
|
|
this.getlist(); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//禁用按钮
|
|
|
|
|
disable(value) { |
|
|
|
|
this.isloading = true |
|
|
|
|
this.isloading = true; |
|
|
|
|
if (!value.enabled) { |
|
|
|
|
this.http.put( |
|
|
|
|
`/api/Organizations/${value.id}`,
|
|
|
|
|
{ |
|
|
|
|
this.http |
|
|
|
|
.put(`/api/Organizations/${value.id}`, { |
|
|
|
|
id: value.id, |
|
|
|
|
code: value.code, |
|
|
|
|
name: value.name, |
|
|
|
@ -130,32 +152,29 @@ export class OrganizationComponent implements OnInit {
|
|
|
|
|
order: value.order, |
|
|
|
|
location: null, |
|
|
|
|
enabled: true, |
|
|
|
|
parentId: value.parentId |
|
|
|
|
} |
|
|
|
|
).subscribe( |
|
|
|
|
data=>{ |
|
|
|
|
parentId: value.parentId, |
|
|
|
|
}) |
|
|
|
|
.subscribe( |
|
|
|
|
(data) => { |
|
|
|
|
const config = new MatSnackBarConfig(); |
|
|
|
|
config.verticalPosition = 'top'; |
|
|
|
|
config.duration = 3000 |
|
|
|
|
this.snackBar.open('启用成功','确定',config); |
|
|
|
|
this.getlist() |
|
|
|
|
|
|
|
|
|
config.verticalPosition = "top"; |
|
|
|
|
config.duration = 3000; |
|
|
|
|
this.snackBar.open("启用成功", "确定", config); |
|
|
|
|
this.getlist(); |
|
|
|
|
}, |
|
|
|
|
err=>{ |
|
|
|
|
(err) => { |
|
|
|
|
const config = new MatSnackBarConfig(); |
|
|
|
|
config.verticalPosition = 'top'; |
|
|
|
|
config.duration = 3000 |
|
|
|
|
this.snackBar.open('操作无效','确定',config); |
|
|
|
|
this.isloading = false |
|
|
|
|
config.verticalPosition = "top"; |
|
|
|
|
config.duration = 3000; |
|
|
|
|
this.snackBar.open("操作无效", "确定", config); |
|
|
|
|
this.isloading = false; |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
); |
|
|
|
|
} else { |
|
|
|
|
// var isdeleted = confirm("确定要禁用此组织?")
|
|
|
|
|
// if(isdeleted){
|
|
|
|
|
this.http.put( |
|
|
|
|
`/api/Organizations/${value.id}`,
|
|
|
|
|
{ |
|
|
|
|
this.http |
|
|
|
|
.put(`/api/Organizations/${value.id}`, { |
|
|
|
|
id: value.id, |
|
|
|
|
code: value.code, |
|
|
|
|
name: value.name, |
|
|
|
@ -163,49 +182,47 @@ export class OrganizationComponent implements OnInit {
|
|
|
|
|
order: value.order, |
|
|
|
|
location: null, |
|
|
|
|
enabled: false, |
|
|
|
|
parentId: value.parentId |
|
|
|
|
} |
|
|
|
|
).subscribe( |
|
|
|
|
data=>{ |
|
|
|
|
parentId: value.parentId, |
|
|
|
|
}) |
|
|
|
|
.subscribe( |
|
|
|
|
(data) => { |
|
|
|
|
const config = new MatSnackBarConfig(); |
|
|
|
|
config.verticalPosition = 'top'; |
|
|
|
|
config.duration = 3000 |
|
|
|
|
this.snackBar.open('禁用成功','确定',config); |
|
|
|
|
this.getlist() |
|
|
|
|
|
|
|
|
|
config.verticalPosition = "top"; |
|
|
|
|
config.duration = 3000; |
|
|
|
|
this.snackBar.open("禁用成功", "确定", config); |
|
|
|
|
this.getlist(); |
|
|
|
|
}, |
|
|
|
|
err=>{ |
|
|
|
|
(err) => { |
|
|
|
|
const config = new MatSnackBarConfig(); |
|
|
|
|
config.verticalPosition = 'top'; |
|
|
|
|
config.duration = 3000 |
|
|
|
|
this.snackBar.open('操作无效','确定',config); |
|
|
|
|
this.isloading = false |
|
|
|
|
config.verticalPosition = "top"; |
|
|
|
|
config.duration = 3000; |
|
|
|
|
this.snackBar.open("操作无效", "确定", config); |
|
|
|
|
this.isloading = false; |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
); |
|
|
|
|
// }
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//向上箭头
|
|
|
|
|
updata = [] |
|
|
|
|
updata = []; |
|
|
|
|
up(node) { |
|
|
|
|
this.isloading = true |
|
|
|
|
this.isloading = true; |
|
|
|
|
var olddata = this.data; |
|
|
|
|
// console.log(1,olddata)
|
|
|
|
|
// console.log(2,node)
|
|
|
|
|
this.updata = [] |
|
|
|
|
olddata.forEach(item => { |
|
|
|
|
this.updata = []; |
|
|
|
|
olddata.forEach((item) => { |
|
|
|
|
if (item.id == node.parentId) { |
|
|
|
|
this.updata = item.children |
|
|
|
|
this.updata = item.children; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
// console.log(this.updata)
|
|
|
|
|
this.updata.forEach((item, index) => { |
|
|
|
|
if (item.name == node.name) { |
|
|
|
|
this.http.put(//更改点击的节点为上一节点的order
|
|
|
|
|
this.http |
|
|
|
|
.put( |
|
|
|
|
//更改点击的节点为上一节点的order
|
|
|
|
|
`/api/Organizations/${this.updata[index].id}`, |
|
|
|
|
{ |
|
|
|
|
id: this.updata[index].id, |
|
|
|
@ -217,10 +234,13 @@ export class OrganizationComponent implements OnInit {
|
|
|
|
|
enabled: true, |
|
|
|
|
parentId: this.updata[index].parentId, |
|
|
|
|
} |
|
|
|
|
).subscribe( |
|
|
|
|
data=>{
|
|
|
|
|
) |
|
|
|
|
.subscribe( |
|
|
|
|
(data) => { |
|
|
|
|
// this.getlist()
|
|
|
|
|
this.http.put(//更改上一节点为点击节点的order
|
|
|
|
|
this.http |
|
|
|
|
.put( |
|
|
|
|
//更改上一节点为点击节点的order
|
|
|
|
|
`/api/Organizations/${this.updata[index - 1].id}`, |
|
|
|
|
{ |
|
|
|
|
id: this.updata[index - 1].id, |
|
|
|
@ -232,55 +252,49 @@ export class OrganizationComponent implements OnInit {
|
|
|
|
|
enabled: true, |
|
|
|
|
parentId: this.updata[index].parentId, |
|
|
|
|
} |
|
|
|
|
).subscribe( |
|
|
|
|
data=>{ |
|
|
|
|
this.getlist() |
|
|
|
|
|
|
|
|
|
) |
|
|
|
|
.subscribe( |
|
|
|
|
(data) => { |
|
|
|
|
this.getlist(); |
|
|
|
|
}, |
|
|
|
|
err=>{ |
|
|
|
|
(err) => { |
|
|
|
|
const config = new MatSnackBarConfig(); |
|
|
|
|
config.verticalPosition = 'top'; |
|
|
|
|
config.duration = 3000 |
|
|
|
|
this.snackBar.open('更改order失败','确定',config); |
|
|
|
|
this.isloading = false |
|
|
|
|
config.verticalPosition = "top"; |
|
|
|
|
config.duration = 3000; |
|
|
|
|
this.snackBar.open("更改order失败", "确定", config); |
|
|
|
|
this.isloading = false; |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
); |
|
|
|
|
}, |
|
|
|
|
err=>{ |
|
|
|
|
(err) => { |
|
|
|
|
const config = new MatSnackBarConfig(); |
|
|
|
|
config.verticalPosition = 'top'; |
|
|
|
|
config.duration = 3000 |
|
|
|
|
this.snackBar.open('更改order失败','确定',config); |
|
|
|
|
this.isloading = false |
|
|
|
|
config.verticalPosition = "top"; |
|
|
|
|
config.duration = 3000; |
|
|
|
|
this.snackBar.open("更改order失败", "确定", config); |
|
|
|
|
this.isloading = false; |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//向下箭头
|
|
|
|
|
downdata = [] |
|
|
|
|
downdata = []; |
|
|
|
|
down(node) { |
|
|
|
|
this.isloading = true |
|
|
|
|
this.isloading = true; |
|
|
|
|
var olddata = this.data; |
|
|
|
|
this.downdata = [] |
|
|
|
|
olddata.forEach(item => { |
|
|
|
|
this.downdata = []; |
|
|
|
|
olddata.forEach((item) => { |
|
|
|
|
if (item.id == node.parentId) { |
|
|
|
|
this.downdata = item.children |
|
|
|
|
this.downdata = item.children; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
// console.log(this.downdata)
|
|
|
|
|
this.downdata.forEach((item, index) => { |
|
|
|
|
if (item.name == node.name) { |
|
|
|
|
this.http.put(//更改点击的节点为下一节点的order
|
|
|
|
|
this.http |
|
|
|
|
.put( |
|
|
|
|
//更改点击的节点为下一节点的order
|
|
|
|
|
`/api/Organizations/${this.downdata[index].id}`, |
|
|
|
|
{ |
|
|
|
|
id: this.downdata[index].id, |
|
|
|
@ -292,10 +306,13 @@ export class OrganizationComponent implements OnInit {
|
|
|
|
|
enabled: true, |
|
|
|
|
parentId: this.downdata[index].parentId, |
|
|
|
|
} |
|
|
|
|
).subscribe( |
|
|
|
|
data=>{
|
|
|
|
|
) |
|
|
|
|
.subscribe( |
|
|
|
|
(data) => { |
|
|
|
|
// this.getlist()
|
|
|
|
|
this.http.put(//更改上一节点为点击节点的order
|
|
|
|
|
this.http |
|
|
|
|
.put( |
|
|
|
|
//更改上一节点为点击节点的order
|
|
|
|
|
`/api/Organizations/${this.downdata[index + 1].id}`, |
|
|
|
|
{ |
|
|
|
|
id: this.downdata[index + 1].id, |
|
|
|
@ -307,179 +324,154 @@ export class OrganizationComponent implements OnInit {
|
|
|
|
|
enabled: true, |
|
|
|
|
parentId: this.downdata[index].parentId, |
|
|
|
|
} |
|
|
|
|
).subscribe( |
|
|
|
|
data=>{ |
|
|
|
|
this.getlist() |
|
|
|
|
|
|
|
|
|
) |
|
|
|
|
.subscribe( |
|
|
|
|
(data) => { |
|
|
|
|
this.getlist(); |
|
|
|
|
}, |
|
|
|
|
err=>{ |
|
|
|
|
(err) => { |
|
|
|
|
const config = new MatSnackBarConfig(); |
|
|
|
|
config.verticalPosition = 'top'; |
|
|
|
|
config.duration = 3000 |
|
|
|
|
this.snackBar.open('更改order失败','确定',config); |
|
|
|
|
this.isloading = false |
|
|
|
|
config.verticalPosition = "top"; |
|
|
|
|
config.duration = 3000; |
|
|
|
|
this.snackBar.open("更改order失败", "确定", config); |
|
|
|
|
this.isloading = false; |
|
|
|
|
} |
|
|
|
|
)
|
|
|
|
|
); |
|
|
|
|
}, |
|
|
|
|
err=>{ |
|
|
|
|
(err) => { |
|
|
|
|
const config = new MatSnackBarConfig(); |
|
|
|
|
config.verticalPosition = 'top'; |
|
|
|
|
config.duration = 3000 |
|
|
|
|
this.snackBar.open('更改order失败','确定',config); |
|
|
|
|
this.isloading = false |
|
|
|
|
config.verticalPosition = "top"; |
|
|
|
|
config.duration = 3000; |
|
|
|
|
this.snackBar.open("更改order失败", "确定", config); |
|
|
|
|
this.isloading = false; |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
selectedOrg:any//当前选择的组织机构
|
|
|
|
|
OfficesList:any //获得的下级列表
|
|
|
|
|
selectedOrg: any; //当前选择的组织机构
|
|
|
|
|
OfficesList: any; //获得的下级列表
|
|
|
|
|
//获得点击组织机构的下级机关单位
|
|
|
|
|
getOffices(node) { |
|
|
|
|
// console.log(node)
|
|
|
|
|
this.selectedOrg = node |
|
|
|
|
this.http.get(`/api/OrganizationsOffices/${node.id}`).subscribe(data => { |
|
|
|
|
this.selectedOrg = node; |
|
|
|
|
this.http.get(`/api/OrganizationsOffices/${node.id}`).subscribe((data) => { |
|
|
|
|
// console.log("获取成功",data)
|
|
|
|
|
this.OfficesList = data |
|
|
|
|
}) |
|
|
|
|
this.OfficesList = data; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
//新增下属机关
|
|
|
|
|
addOffices() { |
|
|
|
|
const dialogRef = this.dialog.open(addOffices, {//调用open方法打开对话框并且携带参数过去
|
|
|
|
|
data: {selectedOrg:this.selectedOrg,OfficesList:this.OfficesList} |
|
|
|
|
const dialogRef = this.dialog.open(addOffices, { |
|
|
|
|
//调用open方法打开对话框并且携带参数过去
|
|
|
|
|
data: { selectedOrg: this.selectedOrg, OfficesList: this.OfficesList }, |
|
|
|
|
}); |
|
|
|
|
dialogRef.afterClosed().subscribe( |
|
|
|
|
data=>{ |
|
|
|
|
if(data == '创建成功'){ |
|
|
|
|
this.getOffices(this.selectedOrg) |
|
|
|
|
dialogRef.afterClosed().subscribe((data) => { |
|
|
|
|
if (data == "创建成功") { |
|
|
|
|
this.getOffices(this.selectedOrg); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
//编辑机关
|
|
|
|
|
editOffice(item) { |
|
|
|
|
const dialogRef = this.dialog.open(editOffices, {//调用open方法打开对话框并且携带参数过去
|
|
|
|
|
data: {item:item} |
|
|
|
|
const dialogRef = this.dialog.open(editOffices, { |
|
|
|
|
//调用open方法打开对话框并且携带参数过去
|
|
|
|
|
data: { item: item }, |
|
|
|
|
}); |
|
|
|
|
dialogRef.afterClosed().subscribe( |
|
|
|
|
data=>{ |
|
|
|
|
if(data == '修改成功'){ |
|
|
|
|
this.getOffices(this.selectedOrg) |
|
|
|
|
}
|
|
|
|
|
dialogRef.afterClosed().subscribe((data) => { |
|
|
|
|
if (data == "修改成功") { |
|
|
|
|
this.getOffices(this.selectedOrg); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
//删除机关
|
|
|
|
|
deleteOffice(item) { |
|
|
|
|
let isDelete = window.confirm('确定要删除此机关吗?') |
|
|
|
|
let isDelete = window.confirm("确定要删除此机关吗?"); |
|
|
|
|
if (isDelete) { |
|
|
|
|
this.http.delete(`/api/OrganizationsOffices/${item.id}`).subscribe(data => { |
|
|
|
|
this.http |
|
|
|
|
.delete(`/api/OrganizationsOffices/${item.id}`) |
|
|
|
|
.subscribe((data) => { |
|
|
|
|
const config = new MatSnackBarConfig(); |
|
|
|
|
config.verticalPosition = 'top'; |
|
|
|
|
config.duration = 3000 |
|
|
|
|
this.snackBar.open('删除成功','确定',config); |
|
|
|
|
this.getOffices(this.selectedOrg) |
|
|
|
|
}) |
|
|
|
|
config.verticalPosition = "top"; |
|
|
|
|
config.duration = 3000; |
|
|
|
|
this.snackBar.open("删除成功", "确定", config); |
|
|
|
|
this.getOffices(this.selectedOrg); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//创建组织
|
|
|
|
|
@Component({ |
|
|
|
|
selector: 'createorganization', |
|
|
|
|
templateUrl: './createorganization.component.html', |
|
|
|
|
styleUrls: ['./organization.component.scss'] |
|
|
|
|
selector: "createorganization", |
|
|
|
|
templateUrl: "./createorganization.component.html", |
|
|
|
|
styleUrls: ["./organization.component.scss"], |
|
|
|
|
}) |
|
|
|
|
export class CreateOrganization { |
|
|
|
|
myControl = new FormControl(); |
|
|
|
|
ishttp: boolean =false |
|
|
|
|
constructor(private http: HttpClient,public dialogRef: MatDialogRef<CreateOrganization>,@Inject(MAT_DIALOG_DATA) public data, |
|
|
|
|
public snackBar: MatSnackBar) {} |
|
|
|
|
ishttp: boolean = false; |
|
|
|
|
constructor( |
|
|
|
|
private http: HttpClient, |
|
|
|
|
public dialogRef: MatDialogRef<CreateOrganization>, |
|
|
|
|
@Inject(MAT_DIALOG_DATA) public data, |
|
|
|
|
public snackBar: MatSnackBar |
|
|
|
|
) {} |
|
|
|
|
|
|
|
|
|
onNoClick(): void { |
|
|
|
|
this.dialogRef.close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onSubmit(value) { |
|
|
|
|
if(this.data.childlength){//如果点击节点存在children
|
|
|
|
|
this.http.post( |
|
|
|
|
'/api/Organizations',
|
|
|
|
|
{ |
|
|
|
|
let obj = { |
|
|
|
|
id: "", |
|
|
|
|
code:value.number, |
|
|
|
|
division:value.division, |
|
|
|
|
name: value.name, |
|
|
|
|
level:this.data.level + 1, |
|
|
|
|
order: this.data.childlength[this.data.childlength.length -1].order + 1, |
|
|
|
|
code: "12000000", |
|
|
|
|
division: "12000000", |
|
|
|
|
name: "天津总队", |
|
|
|
|
level: 0, |
|
|
|
|
order: null, |
|
|
|
|
location: null, |
|
|
|
|
enabled: true, |
|
|
|
|
parentId: this.data.id, |
|
|
|
|
} |
|
|
|
|
).subscribe( |
|
|
|
|
data=>{ |
|
|
|
|
this.dialogRef.close(data);
|
|
|
|
|
const config = new MatSnackBarConfig(); |
|
|
|
|
config.verticalPosition = 'top'; |
|
|
|
|
config.duration = 3000 |
|
|
|
|
this.snackBar.open('创建组织成功','确定',config); |
|
|
|
|
}, |
|
|
|
|
err=>{ |
|
|
|
|
const config = new MatSnackBarConfig(); |
|
|
|
|
config.verticalPosition = 'top'; |
|
|
|
|
config.duration = 3000 |
|
|
|
|
this.snackBar.open('请填写正确格式','确定',config); |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
}else{ |
|
|
|
|
this.http.post( |
|
|
|
|
'/api/Organizations',
|
|
|
|
|
{ |
|
|
|
|
parentId: null, |
|
|
|
|
}; |
|
|
|
|
//如果点击节点存在children
|
|
|
|
|
this.http |
|
|
|
|
.post("/api/Organizations", { |
|
|
|
|
id: "", |
|
|
|
|
code: value.number, |
|
|
|
|
division: value.division, |
|
|
|
|
name: value.name, |
|
|
|
|
level: this.data.level + 1, |
|
|
|
|
order:0, |
|
|
|
|
order: this.data.childlength |
|
|
|
|
? this.data.childlength[this.data.childlength.length - 1].order + 1 |
|
|
|
|
: 0, |
|
|
|
|
location: null, |
|
|
|
|
enabled: true, |
|
|
|
|
parentId: this.data.id, |
|
|
|
|
} |
|
|
|
|
).subscribe( |
|
|
|
|
data=>{ |
|
|
|
|
}) |
|
|
|
|
.subscribe( |
|
|
|
|
(data) => { |
|
|
|
|
this.dialogRef.close(data); |
|
|
|
|
const config = new MatSnackBarConfig(); |
|
|
|
|
config.verticalPosition = 'top'; |
|
|
|
|
config.duration = 3000 |
|
|
|
|
this.snackBar.open('创建组织成功','确定',config); |
|
|
|
|
config.verticalPosition = "top"; |
|
|
|
|
config.duration = 3000; |
|
|
|
|
this.snackBar.open("创建组织成功", "确定", config); |
|
|
|
|
}, |
|
|
|
|
err=>{ |
|
|
|
|
(err) => { |
|
|
|
|
const config = new MatSnackBarConfig(); |
|
|
|
|
config.verticalPosition = 'top'; |
|
|
|
|
config.duration = 3000 |
|
|
|
|
this.snackBar.open('请填写正确格式','确定',config); |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
config.verticalPosition = "top"; |
|
|
|
|
config.duration = 3000; |
|
|
|
|
this.snackBar.open("请填写正确格式", "确定", config); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//编辑组件
|
|
|
|
|
@Component({ |
|
|
|
|
selector: 'editorganization', |
|
|
|
|
templateUrl: './editorganization.component.html', |
|
|
|
|
styleUrls: ['./organization.component.scss'] |
|
|
|
|
selector: "editorganization", |
|
|
|
|
templateUrl: "./editorganization.component.html", |
|
|
|
|
styleUrls: ["./organization.component.scss"], |
|
|
|
|
}) |
|
|
|
|
export class EditOrganization { |
|
|
|
|
newdata = []; |
|
|
|
@ -491,65 +483,77 @@ export class EditOrganization {
|
|
|
|
|
id: node.id, |
|
|
|
|
parentId: node.parentId, |
|
|
|
|
children: node.children, |
|
|
|
|
division:node.division |
|
|
|
|
division: node.division, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
treeControl = new FlatTreeControl<any>(node => node.level, node => node.expandable); |
|
|
|
|
treeFlattener = new MatTreeFlattener(this._transformer, node => node.level, node => node.expandable, node => node.children); |
|
|
|
|
}; |
|
|
|
|
treeControl = new FlatTreeControl<any>( |
|
|
|
|
(node) => node.level, |
|
|
|
|
(node) => node.expandable |
|
|
|
|
); |
|
|
|
|
treeFlattener = new MatTreeFlattener( |
|
|
|
|
this._transformer, |
|
|
|
|
(node) => node.level, |
|
|
|
|
(node) => node.expandable, |
|
|
|
|
(node) => node.children |
|
|
|
|
); |
|
|
|
|
dataSource = new MatTreeFlatDataSource(this.treeControl, this.treeFlattener); |
|
|
|
|
myControl = new FormControl(); |
|
|
|
|
organizationname:string=""//自己组织的名字
|
|
|
|
|
organizationcode:any//自己组织的编号
|
|
|
|
|
organizationName:any =''//上级组织的名字
|
|
|
|
|
organizationId:any =''//上级组织的id
|
|
|
|
|
organizationLevel:number =null//上级组织的层级
|
|
|
|
|
organizationchildlength:number = null |
|
|
|
|
allOrganizations:any //所有组织机构
|
|
|
|
|
division:any //区划
|
|
|
|
|
constructor(private http: HttpClient,public dialogRef: MatDialogRef<EditOrganization>,@Inject(MAT_DIALOG_DATA) public data, |
|
|
|
|
private tree:TreeService,public snackBar: MatSnackBar) {} |
|
|
|
|
organizationname: string = ""; //自己组织的名字
|
|
|
|
|
organizationcode: any; //自己组织的编号
|
|
|
|
|
organizationName: any = ""; //上级组织的名字
|
|
|
|
|
organizationId: any = ""; //上级组织的id
|
|
|
|
|
organizationLevel: number = null; //上级组织的层级
|
|
|
|
|
organizationchildlength: number = null; |
|
|
|
|
allOrganizations: any; //所有组织机构
|
|
|
|
|
division: any; //区划
|
|
|
|
|
constructor( |
|
|
|
|
private http: HttpClient, |
|
|
|
|
public dialogRef: MatDialogRef<EditOrganization>, |
|
|
|
|
@Inject(MAT_DIALOG_DATA) public data, |
|
|
|
|
private tree: TreeService, |
|
|
|
|
public snackBar: MatSnackBar |
|
|
|
|
) {} |
|
|
|
|
|
|
|
|
|
//获取所有组织机构
|
|
|
|
|
getMechanism() { |
|
|
|
|
this.http.get('/api/Organizations').subscribe( |
|
|
|
|
(data:any)=>{ |
|
|
|
|
this.allOrganizations = data |
|
|
|
|
this.http.get("/api/Organizations").subscribe((data: any) => { |
|
|
|
|
this.allOrganizations = data; |
|
|
|
|
this.dataSource.data = this.tree.toTree(data); |
|
|
|
|
data.forEach(item=>{ |
|
|
|
|
data.forEach((item) => { |
|
|
|
|
if (item.id == this.data.parentId) { |
|
|
|
|
this.organizationName = item.name |
|
|
|
|
this.organizationName = item.name; |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ngOnInit() { |
|
|
|
|
// console.log(this.data)
|
|
|
|
|
this.getMechanism() |
|
|
|
|
this.organizationname = this.data.name |
|
|
|
|
this.organizationcode = this.data.code |
|
|
|
|
this.division = this.data.division |
|
|
|
|
this.getMechanism(); |
|
|
|
|
this.organizationname = this.data.name; |
|
|
|
|
this.organizationcode = this.data.code; |
|
|
|
|
this.division = this.data.division; |
|
|
|
|
} |
|
|
|
|
hasChild = (_: number, node: any) => node.expandable; |
|
|
|
|
onNoClick(): void { |
|
|
|
|
this.dialogRef.close(); |
|
|
|
|
} |
|
|
|
|
add(e) { |
|
|
|
|
this.organizationName=e.name |
|
|
|
|
this.organizationId=e.id |
|
|
|
|
this.organizationLevel=e.level |
|
|
|
|
if(e.children){//如果点击的父组织有子节点
|
|
|
|
|
this.organizationchildlength = e.children.length |
|
|
|
|
this.organizationName = e.name; |
|
|
|
|
this.organizationId = e.id; |
|
|
|
|
this.organizationLevel = e.level; |
|
|
|
|
if (e.children) { |
|
|
|
|
//如果点击的父组织有子节点
|
|
|
|
|
this.organizationchildlength = e.children.length; |
|
|
|
|
} else { |
|
|
|
|
this.organizationchildlength = 0 |
|
|
|
|
this.organizationchildlength = 0; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
onSubmit(value) { |
|
|
|
|
if(this.organizationLevel){//如果点击了右边的树
|
|
|
|
|
this.http.put( |
|
|
|
|
`/api/Organizations/${this.data.id}`,
|
|
|
|
|
{ |
|
|
|
|
if (this.organizationLevel) { |
|
|
|
|
//如果点击了右边的树
|
|
|
|
|
this.http |
|
|
|
|
.put(`/api/Organizations/${this.data.id}`, { |
|
|
|
|
id: this.data.id, |
|
|
|
|
code: value.number, |
|
|
|
|
division: value.division, |
|
|
|
@ -559,26 +563,26 @@ export class EditOrganization {
|
|
|
|
|
location: null, |
|
|
|
|
enabled: true, |
|
|
|
|
parentId: this.organizationId, |
|
|
|
|
} |
|
|
|
|
).subscribe( |
|
|
|
|
data=>{ |
|
|
|
|
}) |
|
|
|
|
.subscribe( |
|
|
|
|
(data) => { |
|
|
|
|
this.dialogRef.close(); |
|
|
|
|
const config = new MatSnackBarConfig(); |
|
|
|
|
config.verticalPosition = 'top'; |
|
|
|
|
config.duration = 3000 |
|
|
|
|
this.snackBar.open('修改成功','确定',config); |
|
|
|
|
config.verticalPosition = "top"; |
|
|
|
|
config.duration = 3000; |
|
|
|
|
this.snackBar.open("修改成功", "确定", config); |
|
|
|
|
}, |
|
|
|
|
err=>{ |
|
|
|
|
(err) => { |
|
|
|
|
const config = new MatSnackBarConfig(); |
|
|
|
|
config.verticalPosition = 'top'; |
|
|
|
|
config.duration = 3000 |
|
|
|
|
this.snackBar.open('请填写正确格式','确定',config); |
|
|
|
|
config.verticalPosition = "top"; |
|
|
|
|
config.duration = 3000; |
|
|
|
|
this.snackBar.open("请填写正确格式", "确定", config); |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
}else{ //如果只改了姓名
|
|
|
|
|
this.http.put( |
|
|
|
|
`/api/Organizations/${this.data.id}`,
|
|
|
|
|
{ |
|
|
|
|
); |
|
|
|
|
} else { |
|
|
|
|
//如果只改了姓名
|
|
|
|
|
this.http |
|
|
|
|
.put(`/api/Organizations/${this.data.id}`, { |
|
|
|
|
id: this.data.id, |
|
|
|
|
code: value.number, |
|
|
|
|
division: value.division, |
|
|
|
@ -588,37 +592,39 @@ export class EditOrganization {
|
|
|
|
|
location: null, |
|
|
|
|
enabled: true, |
|
|
|
|
parentId: this.data.parentId, |
|
|
|
|
} |
|
|
|
|
).subscribe( |
|
|
|
|
data=>{ |
|
|
|
|
}) |
|
|
|
|
.subscribe( |
|
|
|
|
(data) => { |
|
|
|
|
this.dialogRef.close(); |
|
|
|
|
const config = new MatSnackBarConfig(); |
|
|
|
|
config.verticalPosition = 'top'; |
|
|
|
|
config.duration = 3000 |
|
|
|
|
this.snackBar.open('修改成功','确定',config); |
|
|
|
|
config.verticalPosition = "top"; |
|
|
|
|
config.duration = 3000; |
|
|
|
|
this.snackBar.open("修改成功", "确定", config); |
|
|
|
|
}, |
|
|
|
|
err=>{ |
|
|
|
|
(err) => { |
|
|
|
|
const config = new MatSnackBarConfig(); |
|
|
|
|
config.verticalPosition = 'top'; |
|
|
|
|
config.duration = 3000 |
|
|
|
|
this.snackBar.open('请填写正确格式','确定',config); |
|
|
|
|
config.verticalPosition = "top"; |
|
|
|
|
config.duration = 3000; |
|
|
|
|
this.snackBar.open("请填写正确格式", "确定", config); |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//增加下属机关
|
|
|
|
|
@Component({ |
|
|
|
|
selector: 'addOffices', |
|
|
|
|
templateUrl: './addOffices.html', |
|
|
|
|
styleUrls: ['./organization.component.scss'] |
|
|
|
|
selector: "addOffices", |
|
|
|
|
templateUrl: "./addOffices.html", |
|
|
|
|
styleUrls: ["./organization.component.scss"], |
|
|
|
|
}) |
|
|
|
|
export class addOffices { |
|
|
|
|
|
|
|
|
|
constructor(private http: HttpClient,public dialogRef: MatDialogRef<addOffices>,@Inject(MAT_DIALOG_DATA) public data,public snackBar: MatSnackBar) {} |
|
|
|
|
constructor( |
|
|
|
|
private http: HttpClient, |
|
|
|
|
public dialogRef: MatDialogRef<addOffices>, |
|
|
|
|
@Inject(MAT_DIALOG_DATA) public data, |
|
|
|
|
public snackBar: MatSnackBar |
|
|
|
|
) {} |
|
|
|
|
|
|
|
|
|
onNoClick(): void { |
|
|
|
|
this.dialogRef.close(); |
|
|
|
@ -630,30 +636,35 @@ export class addOffices {
|
|
|
|
|
id: null, |
|
|
|
|
organizationId: this.data.selectedOrg.id, |
|
|
|
|
officeName: value.name, |
|
|
|
|
order: this.data.OfficesList.length == 0 ? 0 : this.data.OfficesList[this.data.OfficesList.length - 1].order, |
|
|
|
|
enabled: true |
|
|
|
|
} |
|
|
|
|
this.http.post('/api/OrganizationsOffices',body).subscribe(data => { |
|
|
|
|
order: |
|
|
|
|
this.data.OfficesList.length == 0 |
|
|
|
|
? 0 |
|
|
|
|
: this.data.OfficesList[this.data.OfficesList.length - 1].order, |
|
|
|
|
enabled: true, |
|
|
|
|
}; |
|
|
|
|
this.http.post("/api/OrganizationsOffices", body).subscribe((data) => { |
|
|
|
|
const config = new MatSnackBarConfig(); |
|
|
|
|
config.verticalPosition = 'top'; |
|
|
|
|
config.duration = 3000 |
|
|
|
|
this.snackBar.open('创建成功','确定',config); |
|
|
|
|
this.dialogRef.close('创建成功'); |
|
|
|
|
}) |
|
|
|
|
config.verticalPosition = "top"; |
|
|
|
|
config.duration = 3000; |
|
|
|
|
this.snackBar.open("创建成功", "确定", config); |
|
|
|
|
this.dialogRef.close("创建成功"); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//编辑下属机关
|
|
|
|
|
@Component({ |
|
|
|
|
selector: 'editOffices', |
|
|
|
|
templateUrl: './editOffices.html', |
|
|
|
|
styleUrls: ['./organization.component.scss'] |
|
|
|
|
selector: "editOffices", |
|
|
|
|
templateUrl: "./editOffices.html", |
|
|
|
|
styleUrls: ["./organization.component.scss"], |
|
|
|
|
}) |
|
|
|
|
export class editOffices { |
|
|
|
|
|
|
|
|
|
constructor(private http: HttpClient,public dialogRef: MatDialogRef<editOffices>,@Inject(MAT_DIALOG_DATA) public data,public snackBar: MatSnackBar) {} |
|
|
|
|
|
|
|
|
|
constructor( |
|
|
|
|
private http: HttpClient, |
|
|
|
|
public dialogRef: MatDialogRef<editOffices>, |
|
|
|
|
@Inject(MAT_DIALOG_DATA) public data, |
|
|
|
|
public snackBar: MatSnackBar |
|
|
|
|
) {} |
|
|
|
|
|
|
|
|
|
ngOnInit(): void { |
|
|
|
|
// console.log(this.data)
|
|
|
|
@ -661,7 +672,7 @@ export class editOffices {
|
|
|
|
|
onNoClick(): void { |
|
|
|
|
this.dialogRef.close(); |
|
|
|
|
} |
|
|
|
|
officeName:any = this.data.item.officeName |
|
|
|
|
officeName: any = this.data.item.officeName; |
|
|
|
|
onSubmit(value) { |
|
|
|
|
// console.log(value)
|
|
|
|
|
let body = { |
|
|
|
@ -669,14 +680,16 @@ export class editOffices {
|
|
|
|
|
organizationId: this.data.item.organizationId, |
|
|
|
|
officeName: value.name, |
|
|
|
|
order: this.data.item.order, |
|
|
|
|
enabled: true |
|
|
|
|
} |
|
|
|
|
this.http.put(`/api/OrganizationsOffices/${this.data.item.id}`,body).subscribe(data => { |
|
|
|
|
enabled: true, |
|
|
|
|
}; |
|
|
|
|
this.http |
|
|
|
|
.put(`/api/OrganizationsOffices/${this.data.item.id}`, body) |
|
|
|
|
.subscribe((data) => { |
|
|
|
|
const config = new MatSnackBarConfig(); |
|
|
|
|
config.verticalPosition = 'top'; |
|
|
|
|
config.duration = 3000 |
|
|
|
|
this.snackBar.open('修改成功','确定',config); |
|
|
|
|
this.dialogRef.close('修改成功'); |
|
|
|
|
}) |
|
|
|
|
config.verticalPosition = "top"; |
|
|
|
|
config.duration = 3000; |
|
|
|
|
this.snackBar.open("修改成功", "确定", config); |
|
|
|
|
this.dialogRef.close("修改成功"); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |