|
|
|
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';
|
|
|
|
import { NzMessageService } from 'ng-zorro-antd/message';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-edituser',
|
|
|
|
templateUrl: './edituser.component.html',
|
|
|
|
styleUrls: ['./edituser.component.scss']
|
|
|
|
})
|
|
|
|
export class EdituserComponent implements OnInit {
|
|
|
|
|
|
|
|
@Input() data?: any;
|
|
|
|
@Input() listOfData?: any;
|
|
|
|
@Input() listOfData2?: any;
|
|
|
|
@Input() nodes?: any;
|
|
|
|
@Input() editUrl?: any;
|
|
|
|
validateForm!: FormGroup;
|
|
|
|
constructor(private modal: NzModalRef, private fb: FormBuilder, private http: HttpClient, private toTree: TreeService, private message: NzMessageService) { }
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
console.log(this.data)
|
|
|
|
let roleData1 = []
|
|
|
|
let roleData2 = []
|
|
|
|
this.data.roleNames.forEach(element => {
|
|
|
|
if (element.indexOf('LEVEL') != -1) {
|
|
|
|
roleData2.push(element)
|
|
|
|
} else {
|
|
|
|
roleData1.push(element)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.validateForm = this.fb.group({
|
|
|
|
account: [null, [Validators.required]],
|
|
|
|
name: [null, [Validators.required]],
|
|
|
|
organization: [null, [Validators.required]],
|
|
|
|
role: [roleData1, [Validators.required]],
|
|
|
|
role2: [roleData2],
|
|
|
|
phonenum: [null, [Validators.required]],
|
|
|
|
remarks: [null]
|
|
|
|
});
|
|
|
|
if (this.listOfData.length == 0) {
|
|
|
|
this.getAllRoles()
|
|
|
|
}
|
|
|
|
if (this.listOfData2.length == 0) {
|
|
|
|
this.getAllRoles2()
|
|
|
|
}
|
|
|
|
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'
|
|
|
|
}
|
|
|
|
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 getAllRoles2() {
|
|
|
|
let params = {
|
|
|
|
SkipCount: '0',
|
|
|
|
MaxResultCount: '999',
|
|
|
|
IsViolationRoles: 'true'
|
|
|
|
}
|
|
|
|
await new Promise<void>((resolve, reject) => {
|
|
|
|
this.http.get('/api/services/app/Role/GetAll', {
|
|
|
|
params: params
|
|
|
|
}).subscribe((data: any) => {
|
|
|
|
resolve(data)
|
|
|
|
this.listOfData2 = 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)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
isLoading = false
|
|
|
|
//确定
|
|
|
|
async ok() {
|
|
|
|
this.isLoading = true
|
|
|
|
if (this.validateForm.valid) {
|
|
|
|
return await new Promise(resolve => {
|
|
|
|
for (let index = 0; index < this.validateForm.value.role2.length; index++) {
|
|
|
|
const element = this.validateForm.value.role2[index];
|
|
|
|
if (element.indexOf('HANDLE') != -1) {
|
|
|
|
this.validateForm.value.role2.splice(index, 1)
|
|
|
|
index--
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let roleNames = [...this.validateForm.value.role, ...this.validateForm.value.role2]
|
|
|
|
let body = {
|
|
|
|
id: this.data.id,
|
|
|
|
userName: this.validateForm.value.account,
|
|
|
|
name: this.validateForm.value.name,
|
|
|
|
organizationUnitId: this.validateForm.value.organization,
|
|
|
|
roleNames: roleNames,
|
|
|
|
phoneNumber: this.validateForm.value.phonenum,
|
|
|
|
isActive: true
|
|
|
|
}
|
|
|
|
this.http.put(this.editUrl, body).subscribe((data:any) => {
|
|
|
|
resolve(data)
|
|
|
|
this.data.auditStatus = data.result.auditStatus
|
|
|
|
this.isLoading = false
|
|
|
|
this.message.create('success', '保存成功!');
|
|
|
|
}, err => {
|
|
|
|
resolve(err)
|
|
|
|
this.isLoading = false
|
|
|
|
this.message.create('warning', '保存失败');
|
|
|
|
})
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
this.message.create('warning', '请填写完整!');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//取消
|
|
|
|
cancel() {
|
|
|
|
this.modal.destroy();
|
|
|
|
}
|
|
|
|
//提交审核
|
|
|
|
async audit(type) {
|
|
|
|
if (type && this.data.auditStatus == 5) {//提交审核
|
|
|
|
this.message.create('warning', '审核完成的不能重复提交,请编辑后提交');
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if(type){
|
|
|
|
await this.ok()
|
|
|
|
}
|
|
|
|
this.isLoading = true
|
|
|
|
let url
|
|
|
|
type ? url = '/api/services/app/EdittingUser/Commit' : url = '/api/services/app/EdittingUser/Uncommit'
|
|
|
|
this.http.post(url, '', {
|
|
|
|
params: {
|
|
|
|
id: this.data.id
|
|
|
|
}
|
|
|
|
}).subscribe((data: any) => {
|
|
|
|
this.data.auditStatus = data.result.auditStatus
|
|
|
|
this.isLoading = false
|
|
|
|
this.message.create('success', type ? '提交审核成功' : '撤销审核成功');
|
|
|
|
}, err => {
|
|
|
|
this.isLoading = false
|
|
|
|
this.message.create('error', type ? '提交审核失败' : '撤销审核失败');
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|