bankcard.component.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import { Component, OnInit } from '@angular/core';
  2. import { NavComponent } from '../../../app/components/nav/nav.component';
  3. import * as Parse from 'parse';
  4. import { HttpClient } from '@angular/common/http';
  5. import { IonicModule, ToastController } from '@ionic/angular';
  6. @Component({
  7. selector: 'app-bankcard',
  8. templateUrl: './bankcard.component.html',
  9. styleUrls: ['./bankcard.component.scss'],
  10. standalone: true,
  11. imports: [IonicModule,NavComponent],
  12. })
  13. export class BankcardComponent implements OnInit {
  14. constructor(
  15. private http: HttpClient,
  16. public toastController: ToastController
  17. ) {}
  18. company: string = localStorage.getItem('company') || '';
  19. account: any = null;
  20. bankinfo: any = {
  21. bankcard: '',
  22. name: '',
  23. idcard: '',
  24. mobile: '',
  25. };
  26. adding: boolean = false;
  27. isModalOpen: boolean = false;
  28. setOpen(isOpen: boolean) {
  29. this.isModalOpen = isOpen;
  30. }
  31. async ngOnInit() {
  32. await this.getAccountInfo();
  33. }
  34. async getAccountInfo() {
  35. let user = Parse.User.current();
  36. let Account = new Parse.Query('Account');
  37. Account.equalTo('user', user?.id);
  38. Account.equalTo('company', this.company);
  39. let account = await Account.first();
  40. if (account && account.id) {
  41. this.account = account.toJSON();
  42. console.log(this.account);
  43. }
  44. }
  45. footer = [
  46. {
  47. text: '取消',
  48. onPress: () => {
  49. console.log('ok');
  50. this.onClose();
  51. },
  52. },
  53. {
  54. text: '确定',
  55. onPress: () => {
  56. console.log('ok');
  57. if (this.adding) {
  58. return;
  59. }
  60. this.adding = true;
  61. this.confirm();
  62. },
  63. },
  64. ];
  65. onClose() {
  66. this.isModalOpen = false;
  67. }
  68. async confirm() {
  69. let cardInfo = this.bankinfo;
  70. for (const key in cardInfo) {
  71. if (!cardInfo[key]) {
  72. const toast = await this.toastController.create({
  73. message: '请将信息填写完整',
  74. color: 'warning',
  75. duration: 100000,
  76. });
  77. toast.present();
  78. this.adding = false;
  79. return;
  80. }
  81. }
  82. this.verifyCard().then(async (res: any) => {
  83. if (res.data.code == 200) {
  84. if (res.data.data.result == 0 || res.data.data.result == 1) {
  85. this.bankinfo.bankname = res.data.data.bank_info.bank;
  86. this.bankinfo.logo = res.data.data.bank_info.logo;
  87. if (this.account.bank && this.account.bank.length > 0) {
  88. this.account.bank.push(this.bankinfo);
  89. } else {
  90. this.account.bank = [this.bankinfo];
  91. }
  92. this.updateAccount();
  93. this.isModalOpen = false;
  94. setTimeout(() => {
  95. this.adding = false;
  96. }, 800);
  97. } else {
  98. const toast = await this.toastController.create({
  99. message: '卡状态异常,请更换卡',
  100. color: 'warning',
  101. duration: 100000,
  102. });
  103. toast.present();
  104. this.adding = false;
  105. return;
  106. }
  107. } else if (res.data.code == 400) {
  108. const toast = await this.toastController.create({
  109. message: res.data.msg,
  110. color: 'warning',
  111. duration: 100000,
  112. });
  113. toast.present();
  114. this.adding = false;
  115. return;
  116. } else {
  117. const toast = await this.toastController.create({
  118. message: '服务错误请稍后重试',
  119. color: 'warning',
  120. duration: 100000,
  121. });
  122. toast.present();
  123. this.adding = false;
  124. return;
  125. }
  126. });
  127. }
  128. async verifyCard() {
  129. return new Promise((resolve, reject) => {
  130. this.http
  131. .post('https://test.fmode.cn/api/apig/bankcard', {
  132. company: this.company,
  133. bankcard: this.bankinfo.bankcard,
  134. name: this.bankinfo.name,
  135. idcard: this.bankinfo.idcard,
  136. mobile: this.bankinfo.mobile,
  137. })
  138. .subscribe((res: any) => {
  139. console.log(res);
  140. resolve(res);
  141. });
  142. });
  143. }
  144. async updateAccount() {
  145. let Account = new Parse.Query('Account');
  146. let account = await Account.get(this.account.objectId);
  147. if (account) {
  148. account.set('bank', this.account.bank);
  149. await account.save();
  150. }
  151. }
  152. addCard() {
  153. this.isModalOpen = true;
  154. }
  155. }