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-adduser', templateUrl: './adduser.component.html', styleUrls: ['./adduser.component.scss'] }) export class AdduserComponent implements OnInit { @Input() title?: string; @Input() subtitle?: string; 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: [[], [Validators.required]], role2: [[]], phonenum: [null, [Validators.required]] }); this.getAllRoles() this.getAllRoles2() this.getAllOrganization() } destroyModal(): void { this.modal.destroy({ data: 'this the result data' }); } listOfData: any[] = []; listOfData2: any[] = []; //获取角色列表 getAllRoles() { let params = { SkipCount: '0', MaxResultCount: '999' } this.http.get('/api/services/app/Role/GetAll', { params: params }).subscribe((data: any) => { // console.log('角色列表', data.result.items) this.listOfData = data.result.items }) } //获取角色列表 getAllRoles2() { let params = { SkipCount: '0', MaxResultCount: '999', IsViolationRoles:'true' } this.http.get('/api/services/app/Role/GetAll', { params: params }).subscribe((data: any) => { // console.log('角色列表', data.result.items) this.listOfData2 = data.result.items }) } //获取所有组织机构 nodes: any = [] 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" } 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)] }) } }