certification.component.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import { Component, OnInit } from '@angular/core';
  2. import { FormsModule } from '@angular/forms';
  3. import {
  4. IonicModule,
  5. LoadingController,
  6. ModalController,
  7. ToastController,
  8. } from '@ionic/angular';
  9. import { HttpService } from '../../../services/http.service';
  10. import * as utils from '../../../services/utils';
  11. import { AgreementComponent } from '../../login/agreement/agreement.component';
  12. import * as Parse from 'parse';
  13. import { NavComponent } from '../../../app/components/nav/nav.component';
  14. @Component({
  15. selector: 'app-certification',
  16. templateUrl: './certification.component.html',
  17. styleUrls: ['./certification.component.scss'],
  18. standalone: true,
  19. imports: [IonicModule, FormsModule, NavComponent],
  20. })
  21. export class CertificationComponent implements OnInit {
  22. name: string = '';
  23. idCard: string = '';
  24. title: string =
  25. '根据相关法律法规要求,用户需先进行实名认证,方可使用本平台。请尽快完成下方实名认证,本平台将对您的信息严格保密。';
  26. company: any = window.localStorage.getItem('company');
  27. isReal: boolean = false;
  28. loading: any;
  29. time: any; //节流
  30. secretName: any;
  31. secretIdCard: any;
  32. agreement: boolean = false;
  33. registerAgreement: any;
  34. profile?: Parse.Object;
  35. constructor(
  36. private service: HttpService,
  37. public loadCtrl: LoadingController,
  38. private modalController: ModalController,
  39. public toastController: ToastController
  40. ) {}
  41. ngOnInit() {
  42. this.getAgreement();
  43. this.getProfile();
  44. }
  45. getAgreement() {
  46. let Agreement = new Parse.Query('ContractAgreement');
  47. Agreement.equalTo('company', this.company);
  48. Agreement.equalTo('type', 'register');
  49. Agreement.first().then((res) => {
  50. console.log(res);
  51. this.registerAgreement = res;
  52. });
  53. }
  54. async getProfile() {
  55. let uid = Parse.User.current()?.id;
  56. let query = new Parse.Query('Profile');
  57. query.equalTo('user', uid);
  58. query.notEqualTo('isDeleted', true);
  59. this.profile = await query.first();
  60. if (this.profile?.id) {
  61. this.isReal = this.profile.get('isCross');
  62. this.secretIdCard = this.profile.get('idcard')?.slice(0, 6);
  63. this.secretName = this.profile.get('name')?.slice(0, 1);
  64. }
  65. }
  66. async showAgreement() {
  67. const modal = await this.modalController.create({
  68. component: AgreementComponent,
  69. cssClass: 'my-custom-class',
  70. componentProps: {
  71. agreement: this.registerAgreement,
  72. },
  73. });
  74. return await modal.present();
  75. }
  76. async presentToast(title: string, time: number, color: string) {
  77. const toast = await this.toastController.create({
  78. message: title,
  79. duration: time,
  80. color: color,
  81. });
  82. toast.present();
  83. }
  84. async check() {
  85. this.loading = await this.loadCtrl.create();
  86. this.loading.present();
  87. this.time && clearTimeout(this.time);
  88. this.time = setTimeout(async () => {
  89. console.log(this.name, this.idCard);
  90. if (!this.idCard || this.idCard.length != 18 || !this.name) {
  91. this.loading.dismiss();
  92. await this.presentToast('格式错误', 1500, 'danger');
  93. return;
  94. }
  95. let pass = utils.fun.IdentityCodeValid(this.idCard);
  96. console.log(pass);
  97. if (!pass) {
  98. this.loading.dismiss();
  99. await this.presentToast(
  100. '认证失败,请填写真实的身份信息',
  101. 1500,
  102. 'danger'
  103. );
  104. return;
  105. }
  106. let res: any = await this.service.postAuth(
  107. this.company,
  108. this.idCard,
  109. this.name
  110. );
  111. if (res.code == 1) {
  112. let { isok } = res.data.result;
  113. console.log(isok);
  114. if (isok) {
  115. let { sex } = res.data.result.IdCardInfor;
  116. this.anthProfile(sex);
  117. return;
  118. }
  119. this.loading.dismiss();
  120. await this.presentToast(
  121. '认证失败,请填写真实的身份信息',
  122. 1500,
  123. 'danger'
  124. );
  125. } else {
  126. this.loading.dismiss();
  127. await this.presentToast('认证失败', 1500, 'danger');
  128. }
  129. }, 500);
  130. }
  131. async anthProfile(sex: string) {
  132. let user = Parse.User.current();
  133. let query = new Parse.Query('Profile');
  134. query.equalTo('idcard', this.idCard);
  135. query.equalTo('company', this.company);
  136. query.notEqualTo('isDeleted', true);
  137. let res = await query.first();
  138. if (res && res.id) {
  139. this.loading.dismiss();
  140. await this.presentToast('认证失败,该身份已被认证', 1500, 'danger');
  141. return;
  142. }
  143. user?.set('sex', sex);
  144. user?.set('idcard', this.idCard);
  145. user?.set('name', this.name);
  146. await user?.save();
  147. if (!this.profile?.id) {
  148. let obj = Parse.Object.extend('Profile');
  149. this.profile = new obj();
  150. this.profile?.set('company', {
  151. __type: 'Pointer',
  152. className: 'Company',
  153. objectId: this.company,
  154. });
  155. this.profile?.set('user', {
  156. __type: 'Pointer',
  157. className: '_User',
  158. objectId: user?.id,
  159. });
  160. this.profile?.set('mobile', Parse.User.current()?.get('mobile'));
  161. }
  162. this.profile?.set('idcard', this.idCard);
  163. this.profile?.set('name', this.name);
  164. this.profile?.set('sex', sex);
  165. this.profile?.set('isCross', true);
  166. await this.profile?.save();
  167. if (this.profile?.id) {
  168. localStorage.setItem('profile', JSON.stringify(this.profile.toJSON()));
  169. this.loading.dismiss();
  170. this.isReal = true;
  171. await this.presentToast('认证成功', 1500, 'primary');
  172. setTimeout(() => {
  173. history.back();
  174. }, 1500);
  175. }
  176. }
  177. }