|
|
|
import { Component, OnInit, Inject } from '@angular/core';
|
|
|
|
import { HttpClient } from '@angular/common/http';
|
|
|
|
import {MatDialogRef, MAT_DIALOG_DATA} from '@angular/material/dialog';
|
|
|
|
import {FormControl} from '@angular/forms';
|
|
|
|
import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar';
|
|
|
|
import { MatTreeFlatDataSource, MatTreeFlattener } from '@angular/material/tree';
|
|
|
|
import { FlatTreeControl } from '@angular/cdk/tree';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'addenterpriseuser',
|
|
|
|
templateUrl: './addenterpriseuser.component.html',
|
|
|
|
styleUrls: ['./enterpriseuser.component.scss']
|
|
|
|
})
|
|
|
|
export class AddTeacher {
|
|
|
|
|
|
|
|
constructor(private http: HttpClient,public dialogRef: MatDialogRef<AddTeacher>,public snackBar: MatSnackBar,@Inject(MAT_DIALOG_DATA) public data) {}
|
|
|
|
|
|
|
|
ngOnInit(): void { this.dataSource.data = this.data }
|
|
|
|
|
|
|
|
errmsg:string = null;
|
|
|
|
|
|
|
|
organizationId:string = null;
|
|
|
|
organizationName:string = null;
|
|
|
|
|
|
|
|
private _transformer = (node, level: number) => { //初始化tree
|
|
|
|
return {
|
|
|
|
expandable: !!node.children && node.children.length > 0,
|
|
|
|
name: node.name,
|
|
|
|
level: level,
|
|
|
|
id: node.id,
|
|
|
|
parentId: node.parentId,
|
|
|
|
children: 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);
|
|
|
|
hasChild = (_: number, node: any) => node.expandable;
|
|
|
|
|
|
|
|
//选择tree节点
|
|
|
|
selectTree (e) {
|
|
|
|
this.organizationId = e.id
|
|
|
|
this.organizationName = e.name
|
|
|
|
}
|
|
|
|
|
|
|
|
//提交创建表单
|
|
|
|
onSubmit (e) {
|
|
|
|
if (this.organizationId && this.organizationName) {
|
|
|
|
e.phone = null
|
|
|
|
e.identityCard = null
|
|
|
|
e.roleType = 1
|
|
|
|
e.enabled = true
|
|
|
|
e.creationTime = new Date()
|
|
|
|
e.organizationId = this.organizationId
|
|
|
|
e.organizationName = this.organizationName
|
|
|
|
this.http.post("/api/ExamUsers",e).subscribe(data => {
|
|
|
|
this.dialogRef.close(data);
|
|
|
|
},err => {
|
|
|
|
const config = new MatSnackBarConfig();
|
|
|
|
config.verticalPosition = 'top';
|
|
|
|
config.duration = 3000
|
|
|
|
this.snackBar.open(err,'确定',config);
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
const config = new MatSnackBarConfig();
|
|
|
|
config.verticalPosition = 'top';
|
|
|
|
config.duration = 3000
|
|
|
|
this.snackBar.open('请选择消防救援站','确定',config);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|