|
@@ -61,6 +61,8 @@ export class CertificationComponent implements OnInit {
|
|
|
this.profile = await query.first();
|
|
|
if (this.profile?.id) {
|
|
|
this.isReal = this.profile.get('isCross');
|
|
|
+ if (this.isReal)
|
|
|
+ localStorage.setItem('profile', JSON.stringify(this.profile.toJSON()));
|
|
|
this.secretIdCard = this.profile.get('idcard')?.slice(0, 6);
|
|
|
this.secretName = this.profile.get('name')?.slice(0, 1);
|
|
|
}
|
|
@@ -86,10 +88,16 @@ export class CertificationComponent implements OnInit {
|
|
|
}
|
|
|
|
|
|
async check() {
|
|
|
+ if(!this.agreement){
|
|
|
+ this.presentToast('请先阅读且同意隐私协议',1500,'danger')
|
|
|
+ return
|
|
|
+ }
|
|
|
this.loading = await this.loadCtrl.create();
|
|
|
this.loading.present();
|
|
|
this.time && clearTimeout(this.time);
|
|
|
this.time = setTimeout(async () => {
|
|
|
+ this.name = this.name.trim();
|
|
|
+ this.idCard = this.idCard.trim();
|
|
|
console.log(this.name, this.idCard);
|
|
|
if (!this.idCard || this.idCard.length != 18 || !this.name) {
|
|
|
this.loading.dismiss();
|
|
@@ -107,7 +115,11 @@ export class CertificationComponent implements OnInit {
|
|
|
);
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+ if(this.getAgeFromIdCard(this.idCard) < 18){
|
|
|
+ this.loading.dismiss();
|
|
|
+ await this.presentToast('根据平台规定,仅限满18周岁用户使用。',1500,'danger')
|
|
|
+ return
|
|
|
+ }
|
|
|
let res: any = await this.service.postAuth(
|
|
|
this.company,
|
|
|
this.idCard,
|
|
@@ -117,8 +129,8 @@ export class CertificationComponent implements OnInit {
|
|
|
let { isok } = res.data.result;
|
|
|
console.log(isok);
|
|
|
if (isok) {
|
|
|
- let { sex } = res.data.result.IdCardInfor;
|
|
|
- this.anthProfile(sex);
|
|
|
+ let { sex,city } = res.data.result.IdCardInfor;
|
|
|
+ this.anthProfile(sex,city);
|
|
|
return;
|
|
|
}
|
|
|
this.loading.dismiss();
|
|
@@ -134,7 +146,7 @@ export class CertificationComponent implements OnInit {
|
|
|
}, 500);
|
|
|
}
|
|
|
|
|
|
- async anthProfile(sex: string) {
|
|
|
+ async anthProfile(sex: string,city:string) {
|
|
|
let user = Parse.User.current();
|
|
|
let query = new Parse.Query('Profile');
|
|
|
query.equalTo('idcard', this.idCard);
|
|
@@ -168,6 +180,7 @@ export class CertificationComponent implements OnInit {
|
|
|
this.profile?.set('idcard', this.idCard);
|
|
|
this.profile?.set('name', this.name);
|
|
|
this.profile?.set('sex', sex);
|
|
|
+ this.profile?.set('city', city);
|
|
|
this.profile?.set('isCross', true);
|
|
|
await this.profile?.save();
|
|
|
if (this.profile?.id) {
|
|
@@ -180,4 +193,24 @@ export class CertificationComponent implements OnInit {
|
|
|
}, 1500);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ getAgeFromIdCard(idCard: string): number {
|
|
|
+ // 提取出生日期部分
|
|
|
+ const birthDateStr = idCard.substring(6, 14);
|
|
|
+ const year = parseInt(birthDateStr.substring(0, 4), 10);
|
|
|
+ const month = parseInt(birthDateStr.substring(4, 6), 10);
|
|
|
+ const day = parseInt(birthDateStr.substring(6, 8), 10);
|
|
|
+ // 创建出生日期对象
|
|
|
+ const birthDate = new Date(year, month - 1, day);
|
|
|
+ // 获取当前日期
|
|
|
+ const today = new Date();
|
|
|
+ // 计算年龄
|
|
|
+ let age = today.getFullYear() - birthDate.getFullYear();
|
|
|
+ const monthDiff = today.getMonth() - birthDate.getMonth();
|
|
|
+ if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {
|
|
|
+ age--;
|
|
|
+ }
|
|
|
+ return age;
|
|
|
+ }
|
|
|
+
|
|
|
}
|