|
@@ -5,6 +5,8 @@ import { Router } from '@angular/router';
|
|
|
import { catchError } from 'rxjs/operators';
|
|
|
import { NzUploadChangeParam } from 'ng-zorro-antd/upload';
|
|
|
import { NzUploadModule } from 'ng-zorro-antd/upload';
|
|
|
+import { NzModalModule } from 'ng-zorro-antd/modal';
|
|
|
+import { NzModalService } from 'ng-zorro-antd/modal';
|
|
|
import {
|
|
|
FormControl,
|
|
|
FormGroup,
|
|
@@ -17,7 +19,6 @@ import { AuthServr } from '../../../services/auth.service';
|
|
|
import { CaptchaComponent } from '../../../app/captcha/captcha.component';
|
|
|
import { NzMessageService } from 'ng-zorro-antd/message';
|
|
|
import { provinces } from '../../../services/provinces';
|
|
|
-
|
|
|
import Parse from 'parse';
|
|
|
@Component({
|
|
|
selector: 'app-account-info',
|
|
@@ -26,142 +27,110 @@ import Parse from 'parse';
|
|
|
ReactiveFormsModule,
|
|
|
CommonCompModule,
|
|
|
CaptchaComponent,
|
|
|
- NzUploadModule,
|
|
|
+ NzUploadModule,NzModalModule
|
|
|
],
|
|
|
templateUrl: './account-info.component.html',
|
|
|
styleUrls: ['./account-info.component.scss'],
|
|
|
})
|
|
|
export class AccountInfoComponent implements OnInit {
|
|
|
- user: Parse.Object = Parse.User.current()!;
|
|
|
+ user: Parse.Object|undefined
|
|
|
validateForm: FormGroup<{
|
|
|
name: FormControl<string>; //姓名
|
|
|
- // mobile: FormControl<string>; //手机号
|
|
|
+ phone: FormControl<string>; //手机号
|
|
|
email: FormControl<string>; //电子邮箱
|
|
|
+ telephone: FormControl<string>; //办公电话
|
|
|
province: FormControl<string>; //省份
|
|
|
- unitType: FormControl<string>; //单位类型
|
|
|
- unit: FormControl<string>; //单位名称
|
|
|
- idcard: FormControl<string>; //身份证号
|
|
|
- identity: FormControl<string>; //用户类型
|
|
|
- file: FormControl<string>; //单位联系人认证文件
|
|
|
+ companyType: FormControl<string>; //单位类型
|
|
|
+ companyName: FormControl<string>; //单位名称
|
|
|
+ // idcard: FormControl<string>; //身份证号
|
|
|
+ departmentName:FormControl<string>; //所在部门
|
|
|
+ postName:FormControl<string>; //职务
|
|
|
+ identityFile: FormControl<string>; //单位联系人认证文件
|
|
|
}> = this.fb.group({
|
|
|
name: ['', [Validators.required]],
|
|
|
- // mobile: ['', [Validators.required]],
|
|
|
+ phone: [''],
|
|
|
email: ['', [Validators.required]],
|
|
|
- province: ['', [Validators.required]],
|
|
|
- unitType: ['', [Validators.required]],
|
|
|
- unit: ['', [Validators.required]],
|
|
|
- idcard: ['', [Validators.required]],
|
|
|
- identity: ['', [Validators.required]],
|
|
|
- file: ['暂无', [Validators.required]],
|
|
|
+ telephone: [''],
|
|
|
+ province: [''],
|
|
|
+ companyType: ['', [Validators.required]],
|
|
|
+ companyName: ['', [Validators.required]],
|
|
|
+ // idcard: ['', [Validators.required]],
|
|
|
+ departmentName: [''],
|
|
|
+ postName: [''],
|
|
|
+ identityFile: [''],
|
|
|
});
|
|
|
nonRequired: any = {
|
|
|
- workPhone: '',
|
|
|
- branch: '',
|
|
|
job: '',
|
|
|
};
|
|
|
- mobile: string = '';
|
|
|
|
|
|
//省份
|
|
|
provinces: Array<string> = provinces.options
|
|
|
unitTypes: Array<string> = [
|
|
|
- '个体工商户',
|
|
|
- '企业公司',
|
|
|
- '国有机构或事业单位',
|
|
|
- '非营利组织或公益机构',
|
|
|
- '教育机构',
|
|
|
- '自由职业者或个人',
|
|
|
- '其他特定单位类型',
|
|
|
- ];
|
|
|
- identitys: Array<string> = [
|
|
|
- '国家级管理员',
|
|
|
+ '教育部直属高校',
|
|
|
+ '中央有关部门(单位)',
|
|
|
+ '教育司(局)',
|
|
|
'省级教育行政部门',
|
|
|
- '合集管理员',
|
|
|
- '省属高校联系人',
|
|
|
- '教材评审组成员',
|
|
|
- '作者/教师/主编',
|
|
|
+ '出版单位',
|
|
|
];
|
|
|
+ companys: Array<string> = [];
|
|
|
constructor(
|
|
|
public tbookSer: textbookServer,
|
|
|
private fb: NonNullableFormBuilder,
|
|
|
public router: Router,
|
|
|
private authServr: AuthServr,
|
|
|
private message: NzMessageService,
|
|
|
+ private modal: NzModalService,
|
|
|
private http: HttpClient
|
|
|
) {}
|
|
|
|
|
|
ngOnInit() {
|
|
|
- if (Parse.User.current()?.id) {
|
|
|
- // this.validateForm.value.mobile = Parse.User.current()?.get('mobile');
|
|
|
- this.mobile = this.user.get('mobile');
|
|
|
- this.authProfile();
|
|
|
- } else {
|
|
|
- this.router.navigate(['user/login']);
|
|
|
+ let user = Parse.User.current()
|
|
|
+ if(user?.id) history.back()
|
|
|
+ this.user = user
|
|
|
+ this.validateForm.value.phone = user?.get('phone')
|
|
|
+ this.validateForm.value.email = user?.get('email')
|
|
|
+ if(user?.get('accountState') == '已认证'){
|
|
|
+ this.message.success('账号已认证,无需重复认证')
|
|
|
+ this.authServr.profileVerify()
|
|
|
+ return
|
|
|
+ }else if(user?.get('accountState') == '已禁用'){
|
|
|
+ this.message.success('账号已禁用')
|
|
|
+ this.router.navigate(['/user/register'],{ replaceUrl: true })
|
|
|
+ return
|
|
|
}
|
|
|
}
|
|
|
- async authProfile() {
|
|
|
- let query = new Parse.Query('Profile');
|
|
|
- query.equalTo('user', Parse.User.current()?.id);
|
|
|
- query.notEqualTo('isDeleted', true);
|
|
|
- let r = await query.first();
|
|
|
- if (r?.id) {
|
|
|
- if (!r.get('verify')) {
|
|
|
- this.message.info('您已完成身份认证,即将跳转到管理后台');
|
|
|
- return;
|
|
|
- }
|
|
|
- this.validateForm = this.fb.group({
|
|
|
- name: [r.get('name'), [Validators.required]],
|
|
|
- // mobile: [Parse.User.current()?.get('mobile') || r.get('mobile'), [Validators.required]],
|
|
|
- email: [r.get('email'), [Validators.required]],
|
|
|
- province: [r.get('province'), [Validators.required]],
|
|
|
- unitType: [r.get('unitType'), [Validators.required]],
|
|
|
- unit: [r.get('unit'), [Validators.required]],
|
|
|
- idcard: [r.get('idcard'), [Validators.required]],
|
|
|
- identity: [r.get('identity'), [Validators.required]],
|
|
|
- file: [r.get('file'), [Validators.required]],
|
|
|
- });
|
|
|
- this.nonRequired = {
|
|
|
- workPhone: r.get('workPhone'),
|
|
|
- branch: r.get('branch'),
|
|
|
- job: r.get('job'),
|
|
|
- };
|
|
|
+ //根据所选单位类型获取对应单位
|
|
|
+ async provinceChange(val?:string){
|
|
|
+ this.companys = []
|
|
|
+ console.log(this.validateForm.value.companyType);
|
|
|
+ let query = new Parse.Query('Department')
|
|
|
+ query.equalTo('branch',this.validateForm.value.companyType)
|
|
|
+ val && query.contains('name',val)
|
|
|
+ let r = await query.find()
|
|
|
+ if(r.length > 0){
|
|
|
+ this.companys = r.map((item:Parse.Object)=> item.get('name'))
|
|
|
}
|
|
|
}
|
|
|
submitForm(): void {
|
|
|
console.log(this.validateForm.value);
|
|
|
if (this.validateForm.valid) {
|
|
|
- let {
|
|
|
- name,
|
|
|
- // mobile,
|
|
|
- email,
|
|
|
- province,
|
|
|
- unitType,
|
|
|
- unit,
|
|
|
- idcard,
|
|
|
- identity,
|
|
|
- file,
|
|
|
- } = this.validateForm.value;
|
|
|
-
|
|
|
- let a =
|
|
|
- /^\d{6}((((((19|20)\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|(((19|20)\d{2})(0[13578]|1[02])31)|((19|20)\d{2})02(0[1-9]|1\d|2[0-8])|((((19|20)([13579][26]|[2468][048]|0[48]))|(2000))0229))\d{3})|((((\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|((\d{2})(0[13578]|1[02])31)|((\d{2})02(0[1-9]|1\d|2[0-8]))|(([13579][26]|[2468][048]|0[048])0229))\d{2}))(\d|X|x)$/;
|
|
|
- if (!String(idcard).match(a)) {
|
|
|
- this.message.error('身份证格式错误');
|
|
|
+ // let {
|
|
|
+ // idcard,
|
|
|
+ // } = this.validateForm.value;
|
|
|
+ // let a =
|
|
|
+ // /^\d{6}((((((19|20)\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|(((19|20)\d{2})(0[13578]|1[02])31)|((19|20)\d{2})02(0[1-9]|1\d|2[0-8])|((((19|20)([13579][26]|[2468][048]|0[48]))|(2000))0229))\d{3})|((((\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|((\d{2})(0[13578]|1[02])31)|((\d{2})02(0[1-9]|1\d|2[0-8]))|(([13579][26]|[2468][048]|0[048])0229))\d{2}))(\d|X|x)$/;
|
|
|
+ // if (!String(idcard).match(a)) {
|
|
|
+ // this.message.error('身份证格式错误');
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ let a = /^(([^<>()[\]\\.,;:\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.validateForm.value.email).match(a)) {
|
|
|
+ this.message.error('邮箱格式不正确');
|
|
|
return;
|
|
|
}
|
|
|
- let params = {
|
|
|
- name,
|
|
|
- mobile: this.mobile,
|
|
|
- email,
|
|
|
- province,
|
|
|
- unitType,
|
|
|
- unit,
|
|
|
- idcard,
|
|
|
- identity,
|
|
|
- file,
|
|
|
- workPhone: this.nonRequired.workPhone,
|
|
|
- branch: this.nonRequired.branch,
|
|
|
- job: this.nonRequired.job,
|
|
|
- };
|
|
|
+ let params = this.validateForm.value
|
|
|
this.profileSave(params);
|
|
|
+
|
|
|
} else {
|
|
|
this.message.warning('请填写完整的信息');
|
|
|
Object.values(this.validateForm.controls).forEach((control) => {
|
|
@@ -174,6 +143,18 @@ export class AccountInfoComponent implements OnInit {
|
|
|
}
|
|
|
|
|
|
async profileSave(params: any) {
|
|
|
+ if(!await this.authUser()){
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ this.user?.set('name', params.name);
|
|
|
+ this.user?.set('email', params.email);
|
|
|
+ this.user?.set('phone', params.email);
|
|
|
+ this.user?.set('province', params.province);
|
|
|
+ this.user?.set('companyName', params.companyName);
|
|
|
+ this.user?.set('departmentName', params.departmentName);
|
|
|
+ await this.user?.save()
|
|
|
+
|
|
|
console.log(params);
|
|
|
let query = new Parse.Query('Profile');
|
|
|
query.equalTo('user', Parse.User.current()?.id);
|
|
@@ -189,22 +170,40 @@ export class AccountInfoComponent implements OnInit {
|
|
|
className: 'Company',
|
|
|
objectId: this.tbookSer.company,
|
|
|
});
|
|
|
- profile?.set('name', params.name);
|
|
|
- profile?.set('email', params.email);
|
|
|
- profile?.set('mobile', params.email);
|
|
|
- profile?.set('province', params.province);
|
|
|
- profile?.set('unitType', params.unitType);
|
|
|
- profile?.set('unit', params.unit);
|
|
|
- profile?.set('idcard', params.idcard);
|
|
|
- profile?.set('identity', params.identity);
|
|
|
- profile?.set('file', params.file);
|
|
|
- profile?.set('workPhone', params.workPhone);
|
|
|
- profile?.set('branch', params.branch);
|
|
|
- profile?.set('job', params.job);
|
|
|
- profile?.set('verify', true);
|
|
|
+ profile?.set('telephone', params.telephone);
|
|
|
+ profile?.set('companyType', params.companyType);
|
|
|
+ // profile?.set('idcard', params.idcard);
|
|
|
+ profile?.set('identity', '报送联系人');
|
|
|
+ profile?.set('identityFile', params.identityFile);
|
|
|
+ profile?.set('postName', params.postName);
|
|
|
let res = await profile?.save();
|
|
|
- this.authServr.profileVerify()
|
|
|
+ this.modal.success({
|
|
|
+ nzTitle: '提交成功',
|
|
|
+ nzContent: '',
|
|
|
+ nzOnOk: () => this.router.navigate(['/user/register'],{replaceUrl:true}),
|
|
|
+ });
|
|
|
}
|
|
|
+ //验证手机号或邮箱是否注册
|
|
|
+ async authUser():Promise<boolean>{
|
|
|
+ let query = new Parse.Query('_User')
|
|
|
+ if(this.validateForm.value.phone){
|
|
|
+ query.equalTo('phone',this.validateForm.value.phone)
|
|
|
+ let r = await query.first()
|
|
|
+ if(r?.id){
|
|
|
+ this.message.warning('手机号已被注册')
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }else if(this.validateForm.value.email){
|
|
|
+ query.equalTo('email',this.validateForm.value.email)
|
|
|
+ let r = await query.first()
|
|
|
+ if(r?.id){
|
|
|
+ this.message.warning('邮箱已被注册')
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
handleChange(info: NzUploadChangeParam): void {
|
|
|
if (info.file.status !== 'uploading') {
|
|
|
console.log(info.file, info.fileList);
|