|
|
|
import { Component, OnInit, TemplateRef, ViewContainerRef } from '@angular/core';
|
|
|
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
|
|
|
import { NzFormatEmitEvent, NzTreeComponent, NzTreeNodeOptions } from 'ng-zorro-antd/tree';
|
|
|
|
import { NzModalService } from 'ng-zorro-antd/modal';
|
|
|
|
import { AdduserComponent } from './adduser/adduser.component';
|
|
|
|
import { NzMessageService } from 'ng-zorro-antd/message';
|
|
|
|
import { HttpClient } from '@angular/common/http';
|
|
|
|
import { EdituserComponent } from './edituser/edituser.component';
|
|
|
|
import { TreeService } from 'src/app/service/tree.service';
|
|
|
|
@Component({
|
|
|
|
selector: 'app-user',
|
|
|
|
templateUrl: './user.component.html',
|
|
|
|
styleUrls: ['./user.component.scss']
|
|
|
|
})
|
|
|
|
export class UserComponent implements OnInit {
|
|
|
|
validateForm!: FormGroup;
|
|
|
|
constructor(private fb: FormBuilder, private modal: NzModalService, private viewContainerRef: ViewContainerRef, private message: NzMessageService, private http: HttpClient, private toTree: TreeService) { }
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
this.validateForm = this.fb.group({
|
|
|
|
search: [null]
|
|
|
|
});
|
|
|
|
this.getAllUsers()
|
|
|
|
|
|
|
|
this.getAllRoles()
|
|
|
|
this.getAllOrganization()
|
|
|
|
}
|
|
|
|
nzSelectedKeys: any[] = []
|
|
|
|
defaultExpandedKeys = [];
|
|
|
|
searchValue = '';
|
|
|
|
nzExpandAll = false;
|
|
|
|
totalCount: string
|
|
|
|
//获取所有用户
|
|
|
|
usersLIst: any = []
|
|
|
|
usersNum: string
|
|
|
|
OrganizaiotnId
|
|
|
|
|
|
|
|
getAllUsers() {
|
|
|
|
let params = {
|
|
|
|
Keyword: this.validateForm.value.search ? this.validateForm.value.search : '',
|
|
|
|
SkipCount: String(this.SkipCount),
|
|
|
|
MaxResultCount: String(this.MaxResultCount),
|
|
|
|
OrganizaiotnId:this.OrganizaiotnId
|
|
|
|
}
|
|
|
|
console.log(this.OrganizaiotnId);
|
|
|
|
|
|
|
|
this.http.get('/api/services/app/User/GetAll', {
|
|
|
|
params: params
|
|
|
|
}).subscribe((data: any) => {
|
|
|
|
this.usersLIst = data.result.items
|
|
|
|
this.usersNum = data.result.totalCount
|
|
|
|
console.log('所有用户', this.usersLIst)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
SkipCount: number = 0 //0 16 32 48
|
|
|
|
MaxResultCount: number = 16
|
|
|
|
pageChange($event) {
|
|
|
|
this.SkipCount = ($event - 1) * this.MaxResultCount
|
|
|
|
this.getAllUsers()
|
|
|
|
}
|
|
|
|
|
|
|
|
listOfData: any = []
|
|
|
|
//获取角色列表
|
|
|
|
async getAllRoles() {
|
|
|
|
let params = {
|
|
|
|
SkipCount: '0',
|
|
|
|
MaxResultCount: '999'
|
|
|
|
}
|
|
|
|
await new Promise<void>((resolve, reject) => {
|
|
|
|
this.http.get('/api/services/app/Role/GetAll', {
|
|
|
|
params: params
|
|
|
|
}).subscribe((data: any) => {
|
|
|
|
resolve(data)
|
|
|
|
this.listOfData = data.result.items
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
//获取所有组织机构
|
|
|
|
nodes: any = []
|
|
|
|
async getAllOrganization() {
|
|
|
|
let OrganizationUnitId = sessionStorage.getItem('isGasStation') == 'true' ? JSON.parse(sessionStorage.getItem('userdataOfgasstation')).organization.id : JSON.parse(sessionStorage.getItem('userdata')).organization.id
|
|
|
|
let params = {
|
|
|
|
OrganizationUnitId: OrganizationUnitId,
|
|
|
|
IsContainsChildren: "true"
|
|
|
|
}
|
|
|
|
await new Promise<void>((resolve, reject) => {
|
|
|
|
this.http.get('/api/services/app/Organization/GetAll', {
|
|
|
|
params: params
|
|
|
|
}).subscribe((data: any) => {
|
|
|
|
data.result.items.forEach(element => {
|
|
|
|
element.key = element.id
|
|
|
|
element.title = element.displayName
|
|
|
|
});
|
|
|
|
this.nodes = [...this.toTree.toTree(data.result.items)]
|
|
|
|
resolve(data)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//搜索框提交
|
|
|
|
submitForm(): void {
|
|
|
|
for (const i in this.validateForm.controls) {
|
|
|
|
this.validateForm.controls[i].markAsDirty();
|
|
|
|
this.validateForm.controls[i].updateValueAndValidity();
|
|
|
|
}
|
|
|
|
this.getAllUsers()
|
|
|
|
}
|
|
|
|
nzClick(event: NzFormatEmitEvent){
|
|
|
|
console.log(event);
|
|
|
|
this.OrganizaiotnId=event.node.origin.id
|
|
|
|
this.getAllUsers()
|
|
|
|
}
|
|
|
|
//新增用户
|
|
|
|
addUser(): void {
|
|
|
|
const modal = this.modal.create({
|
|
|
|
nzTitle: '新增用户',
|
|
|
|
nzContent: AdduserComponent,
|
|
|
|
nzViewContainerRef: this.viewContainerRef,
|
|
|
|
nzWidth: 450,
|
|
|
|
nzMaskClosable: false,
|
|
|
|
nzComponentParams: {
|
|
|
|
title: '',
|
|
|
|
subtitle: ''
|
|
|
|
},
|
|
|
|
nzOnOk: async () => {
|
|
|
|
// console.log(instance.validateForm.value)
|
|
|
|
if (instance.validateForm.valid) {
|
|
|
|
await new Promise(resolve => {
|
|
|
|
let body = {
|
|
|
|
userName: instance.validateForm.value.account,
|
|
|
|
name: instance.validateForm.value.name,
|
|
|
|
organizationUnitId: Number(instance.validateForm.value.organization),
|
|
|
|
roleNames: instance.validateForm.value.role,
|
|
|
|
phoneNumber: instance.validateForm.value.phonenum,
|
|
|
|
isActive: true
|
|
|
|
}
|
|
|
|
this.http.post('/api/services/app/User/Create', body).subscribe(data => {
|
|
|
|
resolve(data)
|
|
|
|
this.message.create('success', '创建成功!');
|
|
|
|
this.SkipCount = 0
|
|
|
|
this.getAllUsers()
|
|
|
|
return true
|
|
|
|
}, err => {
|
|
|
|
resolve(err)
|
|
|
|
console.log(4444, err)
|
|
|
|
this.message.create('warning', err.error.error.message);
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
this.message.create('warning', '请填写完整!');
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const instance = modal.getContentComponent();
|
|
|
|
modal.afterOpen.subscribe(() => console.log('[afterOpen] emitted!'));
|
|
|
|
// Return a result when closed
|
|
|
|
modal.afterClose.subscribe(result => console.log('[afterClose] The result is:', result));
|
|
|
|
}
|
|
|
|
|
|
|
|
//编辑用户
|
|
|
|
editUser(data): void {
|
|
|
|
console.log(data)
|
|
|
|
const modal = this.modal.create({
|
|
|
|
nzTitle: '编辑用户',
|
|
|
|
nzContent: EdituserComponent,
|
|
|
|
nzViewContainerRef: this.viewContainerRef,
|
|
|
|
nzWidth: 450,
|
|
|
|
nzMaskClosable: false,
|
|
|
|
// nzOkLoading: true,
|
|
|
|
nzComponentParams: {
|
|
|
|
data: data,
|
|
|
|
listOfData: this.listOfData,
|
|
|
|
nodes: this.nodes
|
|
|
|
},
|
|
|
|
nzOnOk: async () => {
|
|
|
|
if (instance.validateForm.valid) {
|
|
|
|
await new Promise(resolve => {
|
|
|
|
let body = {
|
|
|
|
id: data.id,
|
|
|
|
userName: instance.validateForm.value.account,
|
|
|
|
name: instance.validateForm.value.name,
|
|
|
|
organizationUnitId: instance.validateForm.value.organization,
|
|
|
|
roleNames: instance.validateForm.value.role,
|
|
|
|
phoneNumber: instance.validateForm.value.phonenum,
|
|
|
|
isActive: true
|
|
|
|
}
|
|
|
|
this.http.put('/api/services/app/User/Update', body).subscribe(data => {
|
|
|
|
resolve(data)
|
|
|
|
this.message.create('success', '编辑成功!');
|
|
|
|
this.getAllUsers()
|
|
|
|
return true
|
|
|
|
}, err => {
|
|
|
|
resolve(err)
|
|
|
|
this.message.create('warning', '编辑失败');
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
this.message.create('warning', '请填写完整!');
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const instance = modal.getContentComponent();
|
|
|
|
}
|
|
|
|
|
|
|
|
//重置密码
|
|
|
|
resetPassword(item) {
|
|
|
|
console.log(item)
|
|
|
|
this.modal.confirm({
|
|
|
|
nzTitle: `确定要重置${item.userName}这个账户的密码吗?`,
|
|
|
|
nzOkText: '确定',
|
|
|
|
nzOkType: 'primary',
|
|
|
|
nzOnOk: () => {
|
|
|
|
let body = {
|
|
|
|
userId: item.id
|
|
|
|
}
|
|
|
|
this.http.post('/api/services/app/User/ResetPassword', body).subscribe(data => {
|
|
|
|
this.message.create('success', '重置成功!');
|
|
|
|
})
|
|
|
|
},
|
|
|
|
nzCancelText: '取消',
|
|
|
|
nzOnCancel: () => {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//删除
|
|
|
|
delete(item) {
|
|
|
|
this.modal.confirm({
|
|
|
|
nzTitle: `确定要删除${item.userName}这个账户吗?`,
|
|
|
|
nzOkText: '确定',
|
|
|
|
nzOkType: 'danger',
|
|
|
|
nzOnOk: () => {
|
|
|
|
this.http.delete('/api/services/app/User/Delete', {
|
|
|
|
params: {
|
|
|
|
Id: item.id
|
|
|
|
}
|
|
|
|
}).subscribe(data => {
|
|
|
|
this.message.create('success', '删除成功!');
|
|
|
|
this.getAllUsers()
|
|
|
|
})
|
|
|
|
},
|
|
|
|
nzCancelText: '取消',
|
|
|
|
nzOnCancel: () => {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|