中化加油站项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

198 lines
5.9 KiB

import { Component, OnInit, TemplateRef, ViewContainerRef } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
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';
@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) { }
ngOnInit(): void {
this.validateForm = this.fb.group({
search: [null]
});
this.getAllUsers()
}
//获取所有用户
usersLIst: any = []
usersNum: string
getAllUsers() {
let params = {
Keyword: this.validateForm.value.search ? this.validateForm.value.search : '',
SkipCount: String(this.SkipCount),
MaxResultCount: String(this.MaxResultCount)
}
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()
}
//搜索框提交
submitForm(): void {
for (const i in this.validateForm.controls) {
this.validateForm.controls[i].markAsDirty();
this.validateForm.controls[i].updateValueAndValidity();
}
this.getAllUsers()
}
//新增用户
addUser(): void {
const modal = this.modal.create({
nzTitle: '新增用户',
nzContent: AdduserComponent,
nzViewContainerRef: this.viewContainerRef,
nzWidth: 288,
nzComponentParams: {
title: '',
subtitle: ''
},
nzOnOk: async () => {
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: 288,
nzComponentParams: {
data: data,
},
nzOnOk: async () => {
console.log('hhhhhhh', instance.validateForm)
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: () => {
}
});
}
}