|
|
|
import { Component, OnInit, Input } from '@angular/core';
|
|
|
|
import { NzModalRef } from 'ng-zorro-antd/modal';
|
|
|
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
|
|
|
import { HttpClient } from '@angular/common/http';
|
|
|
|
import { TreeService } from 'src/app/service/tree.service';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-edituser',
|
|
|
|
templateUrl: './edituser.component.html',
|
|
|
|
styleUrls: ['./edituser.component.scss']
|
|
|
|
})
|
|
|
|
export class EdituserComponent implements OnInit {
|
|
|
|
|
|
|
|
@Input() data?: any;
|
|
|
|
@Input() listOfData?: any;
|
|
|
|
@Input() nodes?: any;
|
|
|
|
validateForm!: FormGroup;
|
|
|
|
constructor(private modal: NzModalRef, private fb: FormBuilder, private http: HttpClient, private toTree: TreeService) { }
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
this.validateForm = this.fb.group({
|
|
|
|
account: [null, [Validators.required]],
|
|
|
|
name: [null, [Validators.required]],
|
|
|
|
organization: [null, [Validators.required]],
|
|
|
|
role: [null, [Validators.required]],
|
|
|
|
phonenum: [null, [Validators.required]]
|
|
|
|
});
|
|
|
|
if (this.listOfData.length == 0) {
|
|
|
|
this.getAllRoles()
|
|
|
|
}
|
|
|
|
if (this.nodes.length == 0) {
|
|
|
|
this.getAllOrganization()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
destroyModal(): void {
|
|
|
|
this.modal.destroy({ data: 'this the result data' });
|
|
|
|
}
|
|
|
|
|
|
|
|
//获取角色列表
|
|
|
|
async getAllRoles() {
|
|
|
|
let params = {
|
|
|
|
SkipCount: '0',
|
|
|
|
MaxResultCount: '999',
|
|
|
|
ContainsBuiltins: 'true'
|
|
|
|
}
|
|
|
|
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
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
//获取所有组织机构
|
|
|
|
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 => {
|
|
|
|
if (element.id == OrganizationUnitId) {
|
|
|
|
element.parentId = null
|
|
|
|
}
|
|
|
|
element.key = element.id
|
|
|
|
element.title = element.displayName
|
|
|
|
});
|
|
|
|
this.nodes = [...this.toTree.toTree(data.result.items)]
|
|
|
|
resolve(data)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|