|
@@ -0,0 +1,165 @@
|
|
|
|
+import { Component, OnInit } from '@angular/core';
|
|
|
|
+import { FormsModule } from '@angular/forms';
|
|
|
|
+import { IonicModule, LoadingController, ModalController, ToastController } from '@ionic/angular';
|
|
|
|
+import { HttpService } from '../../../services/http.service';
|
|
|
|
+import * as utils from '../../../services/utils'
|
|
|
|
+import { AgreementComponent } from '../../login/agreement/agreement.component';
|
|
|
|
+import * as Parse from 'parse';
|
|
|
|
+
|
|
|
|
+@Component({
|
|
|
|
+ selector: 'app-certification',
|
|
|
|
+ templateUrl: './certification.component.html',
|
|
|
|
+ styleUrls: ['./certification.component.scss'],
|
|
|
|
+ standalone: true,
|
|
|
|
+ imports: [IonicModule,FormsModule],
|
|
|
|
+})
|
|
|
|
+export class CertificationComponent implements OnInit {
|
|
|
|
+
|
|
|
|
+ name: string = ''
|
|
|
|
+ idCard: string = ''
|
|
|
|
+ title: string = '根据相关法律法规要求,用户需先进行实名认证,方可使用本平台。请尽快完成下方实名认证,本平台将对您的信息严格保密。'
|
|
|
|
+ company:any = window.localStorage.getItem("company")
|
|
|
|
+ isReal: boolean = false
|
|
|
|
+ loading: any
|
|
|
|
+ time: any //节流
|
|
|
|
+ secretName: any
|
|
|
|
+ secretIdCard:any
|
|
|
|
+ agreement: boolean = false;
|
|
|
|
+ registerAgreement: any;
|
|
|
|
+
|
|
|
|
+ constructor(
|
|
|
|
+ private service: HttpService,
|
|
|
|
+ public loadCtrl: LoadingController,
|
|
|
|
+ private modalController: ModalController,
|
|
|
|
+ public toastController: ToastController,
|
|
|
|
+ ) { }
|
|
|
|
+
|
|
|
|
+ ngOnInit() {
|
|
|
|
+ this.getAgreement()
|
|
|
|
+ this.getProfile()
|
|
|
|
+ }
|
|
|
|
+ getAgreement() {
|
|
|
|
+ let Agreement = new Parse.Query('ContractAgreement');
|
|
|
|
+ Agreement.equalTo('company', this.company);
|
|
|
|
+ Agreement.equalTo('type', 'register');
|
|
|
|
+ Agreement.first().then((res) => {
|
|
|
|
+ console.log(res);
|
|
|
|
+ this.registerAgreement = res;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ async getProfile() {
|
|
|
|
+ let uid = Parse.User.current()?.id
|
|
|
|
+ let query = new Parse.Query("Profile")
|
|
|
|
+ query.equalTo("user", uid)
|
|
|
|
+ query.equalTo("isCross", true)
|
|
|
|
+ let res = await query.first()
|
|
|
|
+ if (res && res.id) {
|
|
|
|
+ this.isReal = true
|
|
|
|
+ this.secretIdCard = res.get('idcard').slice(0,6)
|
|
|
|
+ this.secretName = res.get('name').slice(0,1)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ async showAgreement() {
|
|
|
|
+ const modal = await this.modalController.create({
|
|
|
|
+ component: AgreementComponent,
|
|
|
|
+ cssClass: 'my-custom-class',
|
|
|
|
+ componentProps: {
|
|
|
|
+ agreement: this.registerAgreement,
|
|
|
|
+ },
|
|
|
|
+ });
|
|
|
|
+ return await modal.present();
|
|
|
|
+ }
|
|
|
|
+ back() {
|
|
|
|
+ history.back()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async presentToast(title:string, time:number, color:string) {
|
|
|
|
+ const toast = await this.toastController.create({
|
|
|
|
+ message: title,
|
|
|
|
+ duration: time,
|
|
|
|
+ color: color
|
|
|
|
+ });
|
|
|
|
+ toast.present();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async check() {
|
|
|
|
+ this.loading = await this.loadCtrl.create()
|
|
|
|
+ this.loading.present()
|
|
|
|
+
|
|
|
|
+ this.time && clearTimeout(this.time)
|
|
|
|
+
|
|
|
|
+ this.time = setTimeout(async () => {
|
|
|
|
+ console.log(this.name, this.idCard);
|
|
|
|
+ if (!this.idCard || this.idCard.length != 18 || !this.name) {
|
|
|
|
+ this.loading.dismiss()
|
|
|
|
+ await this.presentToast('格式错误', 1500, 'danger')
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ let pass = utils.fun.IdentityCodeValid(this.idCard)
|
|
|
|
+ console.log(pass);
|
|
|
|
+ if (!pass) {
|
|
|
|
+ this.loading.dismiss()
|
|
|
|
+ await this.presentToast('认证失败,请填写真实的身份信息', 1500, 'danger')
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ let res: any = await this.service.postAuth(this.company, this.idCard, this.name)
|
|
|
|
+ if (res.code == 1) {
|
|
|
|
+ let { isok } = res.data.result
|
|
|
|
+ console.log(isok);
|
|
|
|
+ if (isok) {
|
|
|
|
+ let { sex } = res.data.result.IdCardInfor
|
|
|
|
+ this.anthProfile(sex)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ this.loading.dismiss()
|
|
|
|
+ await this.presentToast('认证失败,请填写真实的身份信息', 1500, 'danger')
|
|
|
|
+ } else {
|
|
|
|
+ this.loading.dismiss()
|
|
|
|
+ await this.presentToast('认证失败', 1500, 'danger')
|
|
|
|
+ }
|
|
|
|
+ }, 500);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async anthProfile(sex: string) {
|
|
|
|
+ let uid = Parse.User.current()?.id
|
|
|
|
+ let query = new Parse.Query("Profile")
|
|
|
|
+ query.equalTo("idcard", this.idCard)
|
|
|
|
+ query.equalTo("company", this.company)
|
|
|
|
+ let res = await query.first()
|
|
|
|
+ if (res && res.id) {
|
|
|
|
+ this.loading.dismiss()
|
|
|
|
+ await this.presentToast('认证失败,该身份已被认证', 1500, 'danger')
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ let obj = Parse.Object.extend("Profile")
|
|
|
|
+ let profile = new obj()
|
|
|
|
+ profile.set("company", {
|
|
|
|
+ __type: "Pointer",
|
|
|
|
+ className: "Company",
|
|
|
|
+ objectId: this.company,
|
|
|
|
+ })
|
|
|
|
+ profile.set("user", {
|
|
|
|
+ __type: "Pointer",
|
|
|
|
+ className: "_User",
|
|
|
|
+ objectId: uid,
|
|
|
|
+ })
|
|
|
|
+ profile.set("idcard", this.idCard)
|
|
|
|
+ profile.set("name", this.name)
|
|
|
|
+ profile.set("isCross", true)
|
|
|
|
+ profile.set("sex", sex)
|
|
|
|
+ let r = await profile.save()
|
|
|
|
+ if (r && r.id) {
|
|
|
|
+ console.log(r.id);
|
|
|
|
+ localStorage.setItem("profile", r.id)
|
|
|
|
+ this.loading.dismiss()
|
|
|
|
+ this.isReal = true
|
|
|
|
+ await this.presentToast('认证成功', 1500, 'primary')
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ this.back()
|
|
|
|
+ }, 1800);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|