|
@@ -18,7 +18,7 @@ import { NzImageModule } from 'ng-zorro-antd/image';
|
|
|
import { NzSelectModule } from 'ng-zorro-antd/select';
|
|
|
import { MatButtonModule } from '@angular/material/button';
|
|
|
import { provinces } from '../../../services/provinces';
|
|
|
-
|
|
|
+import { NzModalService } from 'ng-zorro-antd/modal';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-user-edit',
|
|
@@ -36,7 +36,8 @@ import { provinces } from '../../../services/provinces';
|
|
|
NzModalModule,
|
|
|
NzRadioModule,
|
|
|
NzImageModule,
|
|
|
- NzSelectModule,MatButtonModule
|
|
|
+ NzSelectModule,
|
|
|
+ MatButtonModule,
|
|
|
],
|
|
|
standalone: true,
|
|
|
})
|
|
@@ -64,20 +65,22 @@ export class UserEditComponent implements OnInit {
|
|
|
isShowModal: boolean = false;
|
|
|
searchValue: string = ''; //搜索部门内容
|
|
|
unitTypes: Array<any> = [];
|
|
|
- userJson: any = { //user编辑数据
|
|
|
- email:'',
|
|
|
- phone:'',
|
|
|
- name:'',
|
|
|
- username:'',
|
|
|
- }
|
|
|
- profileJson: any = { //身份编辑数据
|
|
|
- identity:'',
|
|
|
- telephone:'',
|
|
|
- province:'',
|
|
|
- departmentName:'',
|
|
|
- postName:'',
|
|
|
- majorSubject:''
|
|
|
- }
|
|
|
+ userJson: any = {
|
|
|
+ //user编辑数据
|
|
|
+ email: '',
|
|
|
+ phone: '',
|
|
|
+ name: '',
|
|
|
+ username: '',
|
|
|
+ };
|
|
|
+ profileJson: any = {
|
|
|
+ //身份编辑数据
|
|
|
+ identity: '',
|
|
|
+ telephone: '',
|
|
|
+ province: '',
|
|
|
+ departmentName: '',
|
|
|
+ postName: '',
|
|
|
+ majorSubject: '',
|
|
|
+ };
|
|
|
userType: Array<string> = ['教师', '评审专家', '高校联系人', '工作联系人'];
|
|
|
provinces: Array<string> = provinces.options; //省份
|
|
|
|
|
@@ -86,7 +89,8 @@ export class UserEditComponent implements OnInit {
|
|
|
private activeRoute: ActivatedRoute,
|
|
|
private router: Router,
|
|
|
private message: NzMessageService,
|
|
|
- private nzImageService: NzImageService
|
|
|
+ private nzImageService: NzImageService,
|
|
|
+ private modal: NzModalService
|
|
|
) {}
|
|
|
|
|
|
ngOnInit() {
|
|
@@ -112,7 +116,9 @@ export class UserEditComponent implements OnInit {
|
|
|
let arr = ['教师', '评审专家', '高校联系人'];
|
|
|
if (this.tbookSer.profile.identity == '国家级管理员') {
|
|
|
this.edit = true;
|
|
|
- } else if (this.tbookSer.profile.identity == '工作联系人' && arr.includes(this.profile.get('identity'))
|
|
|
+ } else if (
|
|
|
+ this.tbookSer.profile.identity == '工作联系人' &&
|
|
|
+ arr.includes(this.profile.get('identity'))
|
|
|
) {
|
|
|
this.userType = ['教师', '评审专家', '工作联系人'];
|
|
|
this.edit = true;
|
|
@@ -156,7 +162,7 @@ export class UserEditComponent implements OnInit {
|
|
|
this.message.warning('同级身份暂无权限操作');
|
|
|
return;
|
|
|
}
|
|
|
- this.password = this.password.trim();
|
|
|
+ this.password = this.password?.trim();
|
|
|
if (!this.password) {
|
|
|
this.message.warning('密码格式错误');
|
|
|
return;
|
|
@@ -171,8 +177,8 @@ export class UserEditComponent implements OnInit {
|
|
|
this.isVisible = false;
|
|
|
}
|
|
|
//切换单位类型
|
|
|
- onChangeType(){
|
|
|
- this.userDataJson.department = null
|
|
|
+ onChangeType() {
|
|
|
+ this.userDataJson.department = null;
|
|
|
}
|
|
|
//选择部门
|
|
|
async showModalDepart() {
|
|
@@ -295,8 +301,97 @@ export class UserEditComponent implements OnInit {
|
|
|
this.nzImageService.preview(images, { nzZoom: 1.5, nzRotate: 0 });
|
|
|
}
|
|
|
}
|
|
|
+ /* 修改账号 */
|
|
|
+ loading: boolean = false;
|
|
|
+ submitForm(type: string) {
|
|
|
+ if (this.loading) return;
|
|
|
+ this.loading = true;
|
|
|
+ if (type == 'save') {
|
|
|
+ this.updateUserJson();
|
|
|
+ } else {
|
|
|
+ this.userJson = this.user.toJSON();
|
|
|
+ this.profileJson = this.profile.toJSON();
|
|
|
+ this.userDataJson = {
|
|
|
+ companyType: this.profile?.get('companyType'),
|
|
|
+ department: this.user.get('department'),
|
|
|
+ };
|
|
|
+ this.loading = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ async updateUserJson() {
|
|
|
+ //修改用户数据
|
|
|
+ console.log(this.userJson);
|
|
|
+ console.log(this.profileJson);
|
|
|
+ this.userJson.username = this.userJson?.username?.trim();
|
|
|
+ this.userJson.email = this.userJson?.email?.trim();
|
|
|
+ this.userJson.phone = this.userJson?.phone?.trim();
|
|
|
+ this.userJson.name = this.userJson?.name?.trim();
|
|
|
+ if (!(await this.authVrifly())) {
|
|
|
+ this.loading = false;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ this.user?.set('username', this.userJson?.username);
|
|
|
+ this.user?.set('name', this.userJson?.name);
|
|
|
+ this.user?.set('phone', this.userJson?.phone);
|
|
|
+ this.userJson?.email && this.user?.set('email', this.userJson?.email);
|
|
|
+ await this.user.save();
|
|
|
+
|
|
|
+ this.profile?.set('companyType', this.userDataJson.companyType);
|
|
|
+ this.profile?.set('email', this.userJson.email);
|
|
|
+ this.profile?.set('identity', this.profileJson.identity);
|
|
|
+
|
|
|
+ this.profile?.set('telephone', this.profileJson.telephone);
|
|
|
+ this.profile?.set('province', this.profileJson.province);
|
|
|
+ this.profile?.set('departmentName', this.profileJson.departmentName);
|
|
|
+ this.profile?.set('postName', this.profileJson.postName);
|
|
|
+ this.profile?.set('majorSubject', this.profileJson.majorSubject);
|
|
|
+
|
|
|
+ await this.profile?.save();
|
|
|
+ this.loading = false;
|
|
|
+ this.modal.success({
|
|
|
+ nzTitle: '修改成功',
|
|
|
+ nzContent: '',
|
|
|
+ nzOnOk: () => {},
|
|
|
+ });
|
|
|
+ } catch (err: any) {
|
|
|
+ console.warn('添加用户错误', err);
|
|
|
+ this.loading = false;
|
|
|
+ this.message.error(
|
|
|
+ err?.Error || '错误:请检查用户或邮箱及手机号是否已存在'
|
|
|
+ );
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- submitForm(type:string){
|
|
|
- this.message.warning('权限暂未开放')
|
|
|
+ async authVrifly(): Promise<boolean | undefined> {
|
|
|
+ this.userJson.username = this.userJson?.username?.trim();
|
|
|
+ this.userJson.email = this.userJson?.email?.trim();
|
|
|
+ this.userJson.phone = this.userJson?.phone?.trim();
|
|
|
+ this.userJson.name = this.userJson?.name?.trim();
|
|
|
+ if (!this.userJson?.username || !this.userJson?.name || !this.userJson.phone || !this.userJson?.email) {
|
|
|
+ this.message.warning('请填写必填项');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!this.profileJson.identity) {
|
|
|
+ this.message.error('请选择人员类型');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let a = /^(?:(?:\+|00)86)?1[3-9]\d{9}$/;
|
|
|
+ if (this.userJson.phone && !String(this.userJson.phone).match(a)) {
|
|
|
+ this.message.error('请填写正确手机号');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let m =
|
|
|
+ /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
|
+ if (!String(this.userJson.email).match(m)) {
|
|
|
+ this.message.error('邮箱格式有误');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (this.userJson.phone != this.user.get('phone') && !(await this.tbookSer.userFind(this.userJson.phone))) {
|
|
|
+ this.message.error('手机号已存在');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
}
|
|
|
}
|