account-info.component.ts 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. import { Component, OnInit, ViewChild } from '@angular/core';
  2. import { ReactiveFormsModule } from '@angular/forms';
  3. import { HttpClient } from '@angular/common/http';
  4. import { Router } from '@angular/router';
  5. import { catchError } from 'rxjs/operators';
  6. import { NzUploadChangeParam } from 'ng-zorro-antd/upload';
  7. import { NzUploadModule } from 'ng-zorro-antd/upload';
  8. import {
  9. FormControl,
  10. FormGroup,
  11. NonNullableFormBuilder,
  12. Validators,
  13. } from '@angular/forms';
  14. import { CommonCompModule } from '../common.modules';
  15. import { textbookServer } from '../../../services/textbook';
  16. import { AuthServr } from '../../../services/auth.service';
  17. import { CaptchaComponent } from '../../../app/captcha/captcha.component';
  18. import { NzMessageService } from 'ng-zorro-antd/message';
  19. import { provinces } from '../../../services/provinces';
  20. import Parse from 'parse';
  21. @Component({
  22. selector: 'app-account-info',
  23. standalone: true,
  24. imports: [
  25. ReactiveFormsModule,
  26. CommonCompModule,
  27. CaptchaComponent,
  28. NzUploadModule,
  29. ],
  30. templateUrl: './account-info.component.html',
  31. styleUrls: ['./account-info.component.scss'],
  32. })
  33. export class AccountInfoComponent implements OnInit {
  34. user: Parse.Object = Parse.User.current()!;
  35. validateForm: FormGroup<{
  36. name: FormControl<string>; //姓名
  37. // mobile: FormControl<string>; //手机号
  38. email: FormControl<string>; //电子邮箱
  39. province: FormControl<string>; //省份
  40. unitType: FormControl<string>; //单位类型
  41. unit: FormControl<string>; //单位名称
  42. idcard: FormControl<string>; //身份证号
  43. identity: FormControl<string>; //用户类型
  44. file: FormControl<string>; //单位联系人认证文件
  45. }> = this.fb.group({
  46. name: ['', [Validators.required]],
  47. // mobile: ['', [Validators.required]],
  48. email: ['', [Validators.required]],
  49. province: ['', [Validators.required]],
  50. unitType: ['', [Validators.required]],
  51. unit: ['', [Validators.required]],
  52. idcard: ['', [Validators.required]],
  53. identity: ['', [Validators.required]],
  54. file: ['暂无', [Validators.required]],
  55. });
  56. nonRequired: any = {
  57. workPhone: '',
  58. branch: '',
  59. job: '',
  60. };
  61. mobile: string = '';
  62. //省份
  63. provinces: Array<string> = provinces.options
  64. unitTypes: Array<string> = [
  65. '个体工商户',
  66. '企业公司',
  67. '国有机构或事业单位',
  68. '非营利组织或公益机构',
  69. '教育机构',
  70. '自由职业者或个人',
  71. '其他特定单位类型',
  72. ];
  73. identitys: Array<string> = [
  74. '国家级管理员',
  75. '省级教育行政部门',
  76. '合集管理员',
  77. '省属高校联系人',
  78. '教材评审组成员',
  79. '作者/教师/主编',
  80. ];
  81. constructor(
  82. public tbookSer: textbookServer,
  83. private fb: NonNullableFormBuilder,
  84. public router: Router,
  85. private authServr: AuthServr,
  86. private message: NzMessageService,
  87. private http: HttpClient
  88. ) {}
  89. ngOnInit() {
  90. if (Parse.User.current()?.id) {
  91. // this.validateForm.value.mobile = Parse.User.current()?.get('mobile');
  92. this.mobile = this.user.get('mobile');
  93. this.authProfile();
  94. } else {
  95. this.router.navigate(['user/login']);
  96. }
  97. }
  98. async authProfile() {
  99. let query = new Parse.Query('Profile');
  100. query.equalTo('user', Parse.User.current()?.id);
  101. query.notEqualTo('isDeleted', true);
  102. let r = await query.first();
  103. if (r?.id) {
  104. if (!r.get('verify')) {
  105. this.message.info('您已完成身份认证,即将跳转到管理后台');
  106. return;
  107. }
  108. this.validateForm = this.fb.group({
  109. name: [r.get('name'), [Validators.required]],
  110. // mobile: [Parse.User.current()?.get('mobile') || r.get('mobile'), [Validators.required]],
  111. email: [r.get('email'), [Validators.required]],
  112. province: [r.get('province'), [Validators.required]],
  113. unitType: [r.get('unitType'), [Validators.required]],
  114. unit: [r.get('unit'), [Validators.required]],
  115. idcard: [r.get('idcard'), [Validators.required]],
  116. identity: [r.get('identity'), [Validators.required]],
  117. file: [r.get('file'), [Validators.required]],
  118. });
  119. this.nonRequired = {
  120. workPhone: r.get('workPhone'),
  121. branch: r.get('branch'),
  122. job: r.get('job'),
  123. };
  124. }
  125. }
  126. submitForm(): void {
  127. console.log(this.validateForm.value);
  128. if (this.validateForm.valid) {
  129. let {
  130. name,
  131. // mobile,
  132. email,
  133. province,
  134. unitType,
  135. unit,
  136. idcard,
  137. identity,
  138. file,
  139. } = this.validateForm.value;
  140. let a =
  141. /^\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)$/;
  142. if (!String(idcard).match(a)) {
  143. this.message.error('身份证格式错误');
  144. return;
  145. }
  146. let params = {
  147. name,
  148. mobile: this.mobile,
  149. email,
  150. province,
  151. unitType,
  152. unit,
  153. idcard,
  154. identity,
  155. file,
  156. workPhone: this.nonRequired.workPhone,
  157. branch: this.nonRequired.branch,
  158. job: this.nonRequired.job,
  159. };
  160. this.profileSave(params);
  161. } else {
  162. this.message.warning('请填写完整的信息');
  163. Object.values(this.validateForm.controls).forEach((control) => {
  164. if (control.invalid) {
  165. control.markAsDirty();
  166. control.updateValueAndValidity({ onlySelf: true });
  167. }
  168. });
  169. }
  170. }
  171. async profileSave(params: any) {
  172. console.log(params);
  173. let query = new Parse.Query('Profile');
  174. query.equalTo('user', Parse.User.current()?.id);
  175. query.notEqualTo('isDeleted', true);
  176. let profile = await query.first();
  177. if (!profile?.id) {
  178. let obj = Parse.Object.extend('Profile');
  179. profile = new obj();
  180. }
  181. profile?.set('user', Parse.User.current()?.toPointer());
  182. profile?.set('company', {
  183. __type: 'Pointer',
  184. className: 'Company',
  185. objectId: this.tbookSer.company,
  186. });
  187. profile?.set('name', params.name);
  188. profile?.set('email', params.email);
  189. profile?.set('mobile', params.email);
  190. profile?.set('province', params.province);
  191. profile?.set('unitType', params.unitType);
  192. profile?.set('unit', params.unit);
  193. profile?.set('idcard', params.idcard);
  194. profile?.set('identity', params.identity);
  195. profile?.set('file', params.file);
  196. profile?.set('workPhone', params.workPhone);
  197. profile?.set('branch', params.branch);
  198. profile?.set('job', params.job);
  199. profile?.set('verify', true);
  200. let res = await profile?.save();
  201. this.authServr.profileVerify()
  202. }
  203. handleChange(info: NzUploadChangeParam): void {
  204. if (info.file.status !== 'uploading') {
  205. console.log(info.file, info.fileList);
  206. }
  207. if (info.file.status === 'done') {
  208. this.message.success(`${info.file.name} file uploaded successfully`);
  209. } else if (info.file.status === 'error') {
  210. this.message.error(`${info.file.name} file upload failed.`);
  211. }
  212. }
  213. }