|
|
|
@ -1,7 +1,17 @@
|
|
|
|
|
import { HttpClient } from '@angular/common/http'; |
|
|
|
|
import { Component, OnInit, AfterViewInit, ViewChild, ViewContainerRef } from '@angular/core'; |
|
|
|
|
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 { |
|
|
|
|
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'; |
|
|
|
@ -15,20 +25,38 @@ import { CustomReuseStrategy } from 'src/app/CustomReuseStrategy';
|
|
|
|
|
@Component({ |
|
|
|
|
selector: 'app-organization', |
|
|
|
|
templateUrl: './organization.component.html', |
|
|
|
|
styleUrls: ['./organization.component.scss'] |
|
|
|
|
styleUrls: ['./organization.component.scss'], |
|
|
|
|
}) |
|
|
|
|
export class OrganizationComponent implements OnInit { |
|
|
|
|
validateForm!: FormGroup; |
|
|
|
|
constructor(private fb: FormBuilder, private http: HttpClient, private toTree: TreeService, private modal: NzModalService, private message: NzMessageService, private viewContainerRef: ViewContainerRef) { } |
|
|
|
|
constructor( |
|
|
|
|
private fb: FormBuilder, |
|
|
|
|
private http: HttpClient, |
|
|
|
|
private toTree: TreeService, |
|
|
|
|
private modal: NzModalService, |
|
|
|
|
private message: NzMessageService, |
|
|
|
|
private viewContainerRef: ViewContainerRef |
|
|
|
|
) {} |
|
|
|
|
|
|
|
|
|
ngOnInit(): void { |
|
|
|
|
this.validateForm = this.fb.group({ |
|
|
|
|
search: [null] |
|
|
|
|
search: [null], |
|
|
|
|
}); |
|
|
|
|
this.getAllOrganization() |
|
|
|
|
this.getAllOrganization(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// this.deleteRouteSnapshot();
|
|
|
|
|
refresh() { |
|
|
|
|
this.http.put('/api/Organizations/SyncAllOrganizations', null).subscribe({ |
|
|
|
|
next: (data) => { |
|
|
|
|
this.message.success('同步成功'); |
|
|
|
|
this.getAllOrganization(); |
|
|
|
|
}, |
|
|
|
|
error: (err) => { |
|
|
|
|
this.message.error('同步失败'); |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
deleteRouteSnapshot() { |
|
|
|
|
CustomReuseStrategy.deleteRouteSnapshot('/system/host'); |
|
|
|
|
} |
|
|
|
@ -43,44 +71,46 @@ export class OrganizationComponent implements OnInit {
|
|
|
|
|
//获取所有组织机构
|
|
|
|
|
searchValue = ''; |
|
|
|
|
nzExpandAll = false; |
|
|
|
|
totalCount: string |
|
|
|
|
totalCount: string; |
|
|
|
|
|
|
|
|
|
allOrList: any |
|
|
|
|
allOrList: any; |
|
|
|
|
getAllOrganization() { |
|
|
|
|
let OrganizationUnitId = '' |
|
|
|
|
let OrganizationUnitId = ''; |
|
|
|
|
let params = { |
|
|
|
|
// OrganizationUnitId: OrganizationUnitId,
|
|
|
|
|
// IsContainsChildren: "true"
|
|
|
|
|
ContainsChildren: true, |
|
|
|
|
pageSize: 9999 |
|
|
|
|
} |
|
|
|
|
this.http.get('/api/Organizations', { |
|
|
|
|
params: params |
|
|
|
|
}).subscribe((data: any) => { |
|
|
|
|
console.log('组织机构列表', data) |
|
|
|
|
this.totalCount = data.totalCount |
|
|
|
|
data.items.forEach(element => { |
|
|
|
|
element.key = element.id |
|
|
|
|
element.title = element.name |
|
|
|
|
element.selectable = false |
|
|
|
|
if (element.isGasStation) { |
|
|
|
|
element.isLeaf = true |
|
|
|
|
} |
|
|
|
|
pageSize: 9999, |
|
|
|
|
}; |
|
|
|
|
this.http |
|
|
|
|
.get('/api/Organizations', { |
|
|
|
|
params: params, |
|
|
|
|
}) |
|
|
|
|
.subscribe((data: any) => { |
|
|
|
|
console.log('组织机构列表', data); |
|
|
|
|
this.totalCount = data.totalCount; |
|
|
|
|
data.items.forEach((element) => { |
|
|
|
|
element.key = element.id; |
|
|
|
|
element.title = element.name; |
|
|
|
|
element.selectable = false; |
|
|
|
|
if (element.isGasStation) { |
|
|
|
|
element.isLeaf = true; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
this.allOrList = data.items; |
|
|
|
|
this.nodes = [...this.toTree.toTree(data.items)]; |
|
|
|
|
this.defaultExpandedKeys.length == 0 |
|
|
|
|
? (this.defaultExpandedKeys = [this.nodes[0].id]) |
|
|
|
|
: (this.defaultExpandedKeys = [...this.defaultExpandedKeys]); |
|
|
|
|
}); |
|
|
|
|
this.allOrList = data.items |
|
|
|
|
this.nodes = [...this.toTree.toTree(data.items)] |
|
|
|
|
this.defaultExpandedKeys.length == 0 ? this.defaultExpandedKeys = [this.nodes[0].id] : this.defaultExpandedKeys = [...this.defaultExpandedKeys] |
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ViewChild('nzTreeComponent', { static: false }) nzTreeComponent!: NzTreeComponent; |
|
|
|
|
@ViewChild('nzTreeComponent', { static: false }) |
|
|
|
|
nzTreeComponent!: NzTreeComponent; |
|
|
|
|
|
|
|
|
|
defaultExpandedKeys = []; |
|
|
|
|
|
|
|
|
|
nodes: any[] = [] |
|
|
|
|
|
|
|
|
|
nodes: any[] = []; |
|
|
|
|
|
|
|
|
|
addOr(node?: any) { |
|
|
|
|
// console.log(node.key)
|
|
|
|
@ -92,37 +122,32 @@ export class OrganizationComponent implements OnInit {
|
|
|
|
|
nzComponentParams: {}, |
|
|
|
|
nzOnOk: async () => { |
|
|
|
|
if (instance.validateForm.valid) { |
|
|
|
|
await new Promise(resolve => { |
|
|
|
|
await new Promise((resolve) => { |
|
|
|
|
let body = { |
|
|
|
|
name: instance.validateForm.value.name, |
|
|
|
|
parentId: node ? node.key : null, |
|
|
|
|
isGasStation: instance.validateForm.value.isGasStation |
|
|
|
|
} |
|
|
|
|
this.http.post('/api/Organizations', body).subscribe(data => { |
|
|
|
|
resolve(data) |
|
|
|
|
isGasStation: instance.validateForm.value.isGasStation, |
|
|
|
|
}; |
|
|
|
|
this.http.post('/api/Organizations', body).subscribe((data) => { |
|
|
|
|
resolve(data); |
|
|
|
|
this.message.create('success', '创建成功!'); |
|
|
|
|
this.nzTreeComponent.getExpandedNodeList().forEach((item) => { |
|
|
|
|
this.defaultExpandedKeys.push(item.key) |
|
|
|
|
}) |
|
|
|
|
this.getAllOrganization() |
|
|
|
|
return true |
|
|
|
|
}, err => { |
|
|
|
|
resolve(err) |
|
|
|
|
this.message.create('warning', '创建失败'); |
|
|
|
|
return false |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
this.defaultExpandedKeys.push(item.key); |
|
|
|
|
}); |
|
|
|
|
this.getAllOrganization(); |
|
|
|
|
return true; |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
this.message.create('warning', '请填写完整!'); |
|
|
|
|
return false |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
const instance = modal.getContentComponent(); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
editOr(node) { |
|
|
|
|
console.log(node) |
|
|
|
|
console.log(node); |
|
|
|
|
const modal = this.modal.create({ |
|
|
|
|
nzTitle: '编辑组织机构', |
|
|
|
|
nzContent: EditorComponent, |
|
|
|
@ -133,36 +158,34 @@ export class OrganizationComponent implements OnInit {
|
|
|
|
|
}, |
|
|
|
|
nzOnOk: async () => { |
|
|
|
|
if (instance.validateForm.valid) { |
|
|
|
|
await new Promise(resolve => { |
|
|
|
|
await new Promise((resolve) => { |
|
|
|
|
let body = { |
|
|
|
|
name: instance.validateForm.value.name, |
|
|
|
|
isGasStation: instance.validateForm.value.isGasStation, |
|
|
|
|
parentId: node.origin.parentId |
|
|
|
|
} |
|
|
|
|
this.http.put(`/api/Organizations/${node.origin.id}`, body).subscribe(data => { |
|
|
|
|
resolve(data) |
|
|
|
|
this.message.create('success', '编辑成功!'); |
|
|
|
|
this.nzTreeComponent.getExpandedNodeList().forEach((item) => { |
|
|
|
|
this.defaultExpandedKeys.push(item.key) |
|
|
|
|
}) |
|
|
|
|
this.getAllOrganization() |
|
|
|
|
return true |
|
|
|
|
}, err => { |
|
|
|
|
resolve(err) |
|
|
|
|
this.message.create('warning', '编辑失败'); |
|
|
|
|
return false |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
parentId: node.origin.parentId, |
|
|
|
|
}; |
|
|
|
|
this.http |
|
|
|
|
.put(`/api/Organizations/${node.origin.id}`, body) |
|
|
|
|
.subscribe((data) => { |
|
|
|
|
resolve(data); |
|
|
|
|
this.message.create('success', '编辑成功!'); |
|
|
|
|
this.nzTreeComponent.getExpandedNodeList().forEach((item) => { |
|
|
|
|
this.defaultExpandedKeys.push(item.key); |
|
|
|
|
}); |
|
|
|
|
this.getAllOrganization(); |
|
|
|
|
return true; |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
this.message.create('warning', '请填写完整!'); |
|
|
|
|
return false |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
const instance = modal.getContentComponent(); |
|
|
|
|
} |
|
|
|
|
deleteOr(item) { |
|
|
|
|
console.log(item) |
|
|
|
|
console.log(item); |
|
|
|
|
if (item.origin.children && item.origin.children.length != 0) { |
|
|
|
|
this.message.create('warning', '请先删除所有子节点'); |
|
|
|
|
} else { |
|
|
|
@ -171,66 +194,64 @@ export class OrganizationComponent implements OnInit {
|
|
|
|
|
nzOkText: '确定', |
|
|
|
|
nzOkType: 'primary', |
|
|
|
|
nzOnOk: () => { |
|
|
|
|
this.http.delete(`/api/Organizations/${item.origin.id}`).subscribe(data => { |
|
|
|
|
this.nzTreeComponent.getExpandedNodeList().forEach((item) => { |
|
|
|
|
this.defaultExpandedKeys.push(item.key) |
|
|
|
|
}) |
|
|
|
|
this.getAllOrganization() |
|
|
|
|
this.message.create('success', '删除成功!'); |
|
|
|
|
}) |
|
|
|
|
this.http |
|
|
|
|
.delete(`/api/Organizations/${item.origin.id}`) |
|
|
|
|
.subscribe((data) => { |
|
|
|
|
this.nzTreeComponent.getExpandedNodeList().forEach((item) => { |
|
|
|
|
this.defaultExpandedKeys.push(item.key); |
|
|
|
|
}); |
|
|
|
|
this.getAllOrganization(); |
|
|
|
|
this.message.create('success', '删除成功!'); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
nzCancelText: '取消', |
|
|
|
|
nzOnCancel: () => { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
nzOnCancel: () => {}, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nzEvent(event: NzFormatEmitEvent): void { |
|
|
|
|
console.log('event', event) |
|
|
|
|
console.log('event', event); |
|
|
|
|
if (this.isDrag) { |
|
|
|
|
let parentId |
|
|
|
|
if (this.pos == 0) {//目标节点内部
|
|
|
|
|
parentId = event.node.key |
|
|
|
|
let parentId; |
|
|
|
|
if (this.pos == 0) { |
|
|
|
|
//目标节点内部
|
|
|
|
|
parentId = event.node.key; |
|
|
|
|
} else { |
|
|
|
|
if (event.node.level == 0) { |
|
|
|
|
parentId = null |
|
|
|
|
parentId = null; |
|
|
|
|
} else { |
|
|
|
|
parentId = event.node.origin.parentId |
|
|
|
|
parentId = event.node.origin.parentId; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
let body = { |
|
|
|
|
parentId: parentId, |
|
|
|
|
name: event.dragNode.origin.name, |
|
|
|
|
isGasStation: event.dragNode.origin.isGasStation |
|
|
|
|
} |
|
|
|
|
this.http.put(`/api/Organizations/${event.dragNode.origin.id}`, body).subscribe(data => { |
|
|
|
|
this.message.create('success', '拖拽成功!'); |
|
|
|
|
this.nzTreeComponent.getExpandedNodeList().forEach((item) => { |
|
|
|
|
this.defaultExpandedKeys.push(item.key) |
|
|
|
|
}) |
|
|
|
|
this.getAllOrganization() |
|
|
|
|
return true |
|
|
|
|
}, err => { |
|
|
|
|
this.message.create('warning', '拖拽失败'); |
|
|
|
|
return false |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
isGasStation: event.dragNode.origin.isGasStation, |
|
|
|
|
}; |
|
|
|
|
this.http |
|
|
|
|
.put(`/api/Organizations/${event.dragNode.origin.id}`, body) |
|
|
|
|
.subscribe((data) => { |
|
|
|
|
this.message.create('success', '拖拽成功!'); |
|
|
|
|
this.nzTreeComponent.getExpandedNodeList().forEach((item) => { |
|
|
|
|
this.defaultExpandedKeys.push(item.key); |
|
|
|
|
}); |
|
|
|
|
this.getAllOrganization(); |
|
|
|
|
return true; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
isDrag //是否可以拖动
|
|
|
|
|
pos//放置位置
|
|
|
|
|
isDrag; //是否可以拖动
|
|
|
|
|
pos; //放置位置
|
|
|
|
|
beforeDrop = (arg: NzFormatBeforeDropEvent) => { |
|
|
|
|
console.log('arg', arg) |
|
|
|
|
if (arg.pos != 0 && arg.node.level === 0) {//如果为数据节点则不允许拖到一级节点
|
|
|
|
|
console.log('arg', arg); |
|
|
|
|
if (arg.pos != 0 && arg.node.level === 0) { |
|
|
|
|
//如果为数据节点则不允许拖到一级节点
|
|
|
|
|
this.message.create('warning', '不允许拖拽到一级节点'); |
|
|
|
|
this.isDrag = false |
|
|
|
|
this.isDrag = false; |
|
|
|
|
return of(false); |
|
|
|
|
} else { |
|
|
|
|
return of(true) |
|
|
|
|
return of(true); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|