hl-core 0.0.7-beta.8 → 0.0.7-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,9 +2,10 @@ import { defineStore } from 'pinia';
2
2
  import { t } from './messages';
3
3
  import { rules } from './rules';
4
4
  import { Toast, Types, Positions, ToastOptions } from './toast';
5
- import { isValidGUID } from '../composables';
5
+ import { isValidGUID, yearEnding, jwtDecode } from '../composables';
6
6
  import { DataStoreClass, Contragent } from '../composables/classes';
7
7
  import { ApiClass } from '@/api';
8
+ import { useFormStore } from './form.store';
8
9
 
9
10
  export const useDataStore = defineStore('data', {
10
11
  state: () => ({
@@ -16,8 +17,11 @@ export const useDataStore = defineStore('data', {
16
17
  toastPositions: Positions,
17
18
  isValidGUID: isValidGUID,
18
19
  router: useRouter(),
20
+ formStore: useFormStore(),
19
21
  contragent: useContragentStore(),
20
22
  api: new ApiClass(),
23
+ yearEnding: year =>
24
+ yearEnding(year, constants.yearTitles, constants.yearCases),
21
25
  currentDate: () =>
22
26
  new Date(Date.now() - new Date().getTimezoneOffset() * 60 * 1000)
23
27
  .toISOString()
@@ -40,11 +44,19 @@ export const useDataStore = defineStore('data', {
40
44
  isLifetrip: state => state.product === 'lifetrip',
41
45
  isLiferenta: state => state.product === 'liferenta',
42
46
  isPension: state => state.product === 'pension',
47
+ isEveryFormDisabled: state =>
48
+ Object.values(state.formStore.isDisabled).every(i => i === true),
43
49
  },
44
50
  actions: {
45
51
  sendToParent(action, value) {
46
52
  window.parent.postMessage({ action: action, value: value }, '*');
47
53
  },
54
+ getFilesByIIN(iin) {
55
+ return this.signedDocumentList.filter(
56
+ file =>
57
+ file.iin === iin && file.fileTypeName === 'Удостоверение личности',
58
+ );
59
+ },
48
60
  async getNewAccessToken() {
49
61
  try {
50
62
  const data = {
@@ -178,6 +190,12 @@ export const useDataStore = defineStore('data', {
178
190
  isProcessEditable(statusCode) {
179
191
  return !!constants.editableStatuses.find(status => status === statusCode);
180
192
  },
193
+ isTask() {
194
+ return (
195
+ this.formStore.applicationData.processInstanceId != 0 &&
196
+ this.formStore.applicationData.isTask
197
+ );
198
+ },
181
199
  async logoutUser() {
182
200
  this.isLoading = true;
183
201
  try {
@@ -236,26 +254,110 @@ export const useDataStore = defineStore('data', {
236
254
  this.isLoading = false;
237
255
  }
238
256
  },
239
- async getDicFileTypeList() {
257
+ async deleteFile(data) {
240
258
  try {
241
- if (this.dicFileTypeList.length) {
242
- return this.dicFileTypeList;
259
+ await this.api.deleteFile(data);
260
+ this.showToaster('success', this.t('toaster.fileWasDeleted'), 3000);
261
+ } catch (err) {
262
+ this.showToaster('error', err.response.data, 2000);
263
+ }
264
+ },
265
+ async uploadFiles(data, load = true) {
266
+ try {
267
+ if (load) {
268
+ this.isLoading = true;
269
+ }
270
+ await this.api.uploadFiles(data);
271
+ return true;
272
+ } catch (err) {
273
+ this.showToaster('error', err.response.data, 5000);
274
+ return false;
275
+ } finally {
276
+ if (load) {
277
+ this.isLoading = false;
278
+ }
279
+ }
280
+ },
281
+ async getContragent(whichForm, whichIndex = null, load = true) {
282
+ if (load) {
283
+ this.isLoading = true;
284
+ }
285
+ try {
286
+ let response;
287
+ let queryData = {
288
+ firstName: '',
289
+ lastName: '',
290
+ middleName: '',
291
+ };
292
+ if (whichIndex === null) {
293
+ queryData.iin = this.formStore[whichForm].iin.replace(/-/g, '');
294
+ response = await this.api.getContragent(queryData);
295
+ }
296
+ if (whichIndex !== null) {
297
+ queryData.iin = this.formStore[whichForm][whichIndex].iin.replace(
298
+ /-/g,
299
+ '',
300
+ );
301
+ response = await this.api.getContragent(queryData);
302
+ }
303
+ if (response.totalItems > 0) {
304
+ if (response.totalItems.length === 1) {
305
+ await this.serializeContragentData(
306
+ whichForm,
307
+ response.items[0],
308
+ whichIndex,
309
+ );
310
+ } else {
311
+ const sortedByRegistrationDate = response.items.sort(
312
+ (left, right) =>
313
+ new Date(right.registrationDate) -
314
+ new Date(left.registrationDate),
315
+ );
316
+ await this.serializeContragentData(
317
+ whichForm,
318
+ sortedByRegistrationDate[0],
319
+ whichIndex,
320
+ );
321
+ }
322
+ if (whichIndex === null) {
323
+ this.formStore[whichForm].gotFromInsis = true;
324
+ } else {
325
+ this.formStore[whichForm][whichIndex].gotFromInsis = true;
326
+ }
243
327
  } else {
244
- this.dicFileTypeList = await this.api.getDicFileTypeList();
245
- return this.dicFileTypeList;
328
+ this.userNotFound = true;
246
329
  }
247
330
  } catch (err) {
248
- console.log(err.response.data);
331
+ console.log(err);
332
+ }
333
+ if (load) {
334
+ this.isLoading = false;
249
335
  }
250
336
  },
251
- async getContragentById(id, onlyGet = true) {
337
+ async getContragentById(id, whichForm, onlyGet = true, whichIndex = null) {
252
338
  if (onlyGet) {
253
339
  this.isLoading = true;
254
340
  }
255
341
  try {
342
+ if (
343
+ this.isAgentMycar() &&
344
+ whichForm == this.formStore.beneficiaryFormKey
345
+ ) {
346
+ await this.serializeContragentData(
347
+ whichForm,
348
+ this.formStore.applicationData.beneficiaryApp[0],
349
+ whichIndex,
350
+ );
351
+ this.isLoading = false;
352
+ return;
353
+ }
256
354
  const response = await this.api.getContragentById(id);
257
355
  if (response.totalItems > 0) {
258
- await this.serializeContragentData(response.items[0]);
356
+ await this.serializeContragentData(
357
+ whichForm,
358
+ response.items[0],
359
+ whichIndex,
360
+ );
259
361
  } else {
260
362
  this.isLoading = false;
261
363
  return false;
@@ -267,7 +369,7 @@ export const useDataStore = defineStore('data', {
267
369
  this.isLoading = false;
268
370
  }
269
371
  },
270
- async serializeContragentData(contragent) {
372
+ async serializeContragentData(whichForm, contragent, whichIndex = null) {
271
373
  const [
272
374
  { value: data },
273
375
  { value: contacts },
@@ -279,28 +381,51 @@ export const useDataStore = defineStore('data', {
279
381
  this.api.getContrAgentDocuments(contragent.id),
280
382
  this.api.getContrAgentAddress(contragent.id),
281
383
  ]);
282
- this.contragent.response = {
283
- contragent: contragent,
284
- };
285
- if (data && data.length) {
286
- this.contragent.response.questionnaires = data;
287
- }
288
- if (contacts && contacts.length) {
289
- this.contragent.response.contacts = contacts;
290
- }
291
- if (documents && documents.length) {
292
- this.contragent.response.documents = documents;
384
+ if (whichIndex === null) {
385
+ this.formStore[whichForm].response = {
386
+ contragent: contragent,
387
+ };
388
+ if (data && data.length) {
389
+ this.formStore[whichForm].response.questionnaires = data;
390
+ }
391
+ if (contacts && contacts.length) {
392
+ this.formStore[whichForm].response.contacts = contacts;
393
+ }
394
+ if (documents && documents.length) {
395
+ this.formStore[whichForm].response.documents = documents;
396
+ }
397
+ if (address && address.length) {
398
+ this.formStore[whichForm].response.addresses = address;
399
+ }
293
400
  }
294
- if (address && address.length) {
295
- this.contragent.response.addresses = address;
401
+ if (whichIndex !== null) {
402
+ this.formStore[whichForm][whichIndex].response = {
403
+ contragent: contragent,
404
+ };
405
+ if (data && data.length) {
406
+ this.formStore[whichForm][whichIndex].response.questionnaires = data;
407
+ }
408
+ if (contacts && contacts.length) {
409
+ this.formStore[whichForm][whichIndex].response.contacts = contacts;
410
+ }
411
+ if (documents && documents.length) {
412
+ this.formStore[whichForm][whichIndex].response.documents = documents;
413
+ }
414
+ if (address && address.length) {
415
+ this.formStore[whichForm][whichIndex].response.addresses = address;
416
+ }
296
417
  }
297
- this.parseContragent({
298
- personalData: contragent,
299
- documents: documents,
300
- contacts: contacts,
301
- data: data,
302
- address: address,
303
- });
418
+ this.parseContragent(
419
+ whichForm,
420
+ {
421
+ personalData: contragent,
422
+ documents: documents,
423
+ contacts: contacts,
424
+ data: data,
425
+ address: address,
426
+ },
427
+ whichIndex,
428
+ );
304
429
  },
305
430
  async searchContragent(iin) {
306
431
  this.isLoading = true;
@@ -323,133 +448,271 @@ export const useDataStore = defineStore('data', {
323
448
  }
324
449
  this.isLoading = false;
325
450
  },
326
- parseContragent(user) {
327
- this.contragent.verifyType = user.personalData.verifyType;
328
- this.contragent.verifyDate = user.personalData.verifyDate;
329
- this.contragent.iin = reformatIin(user.personalData.iin);
330
- this.contragent.age = user.personalData.age;
331
- const country = this.countries.find(i =>
332
- i.nameRu?.match(new RegExp(user.personalData.birthPlace, 'i')),
333
- );
334
- this.contragent.birthPlace =
335
- country && Object.keys(country).length ? country : new Value();
336
- this.contragent.gender = this.gender.find(
337
- i => i.nameRu === user.personalData.genderName,
338
- );
339
- this.contragent.gender.id = user.personalData.gender;
340
- this.contragent.birthDate = reformatDate(user.personalData.birthDate);
341
- this.contragent.genderName = user.personalData.genderName;
342
- this.contragent.lastName = user.personalData.lastName;
343
- this.contragent.longName = user.personalData.longName;
344
- this.contragent.middleName = user.personalData.middleName
345
- ? user.personalData.middleName
346
- : '';
347
- this.contragent.firstName = user.personalData.firstName;
348
- this.contragent.id = user.personalData.id;
349
- this.contragent.type = user.personalData.type;
350
- this.contragent.registrationDate = user.personalData.registrationDate;
351
-
352
- if ('documents' in user && user.documents.length) {
353
- const documentType = this.documentTypes.find(
354
- i => i.ids === user.documents[0].type,
355
- );
356
- const documentIssuer = this.documentIssuers.find(
357
- i => i.nameRu === user.documents[0].issuerNameRu,
451
+ parseContragent(whichForm, user, whichIndex = null) {
452
+ if (whichIndex === null) {
453
+ // Save User Personal Data
454
+ this.formStore[whichForm].verifyType = user.personalData.verifyType;
455
+ this.formStore[whichForm].verifyDate = user.personalData.verifyDate;
456
+ this.formStore[whichForm].iin = reformatIin(user.personalData.iin);
457
+ this.formStore[whichForm].age = user.personalData.age;
458
+ const country = this.countries.find(i =>
459
+ i.nameRu?.match(new RegExp(user.personalData.birthPlace, 'i')),
358
460
  );
359
- this.contragent.documentType = documentType
360
- ? documentType
361
- : new Value();
362
- this.contragent.documentNumber = user.documents[0].number;
363
- this.contragent.documentIssuers = documentIssuer
364
- ? documentIssuer
365
- : new Value();
366
- this.contragent.documentDate = reformatDate(
367
- user.documents[0].issueDate,
461
+ this.formStore[whichForm].birthPlace =
462
+ country && Object.keys(country).length ? country : new Value();
463
+ this.formStore[whichForm].gender = this.gender.find(
464
+ i => i.nameRu === user.personalData.genderName,
368
465
  );
369
- this.contragent.documentExpire = reformatDate(
370
- user.documents[0].expireDate,
466
+ this.formStore[whichForm].gender.id = user.personalData.gender;
467
+ this.formStore[whichForm].birthDate = reformatDate(
468
+ user.personalData.birthDate,
371
469
  );
372
- }
373
-
374
- if ('data' in user && user.data.length) {
375
- user.data.forEach(dataObject => {
376
- this.searchFromList(
377
- [
378
- 'signOfResidency',
379
- 'countryOfCitizenship',
380
- 'countryOfTaxResidency',
381
- 'economySectorCode',
382
- ],
383
- dataObject,
384
- [
385
- this.residents,
386
- this.citizenshipCountries,
387
- this.taxCountries,
388
- this.economySectorCode,
389
- ],
470
+ this.formStore[whichForm].genderName = user.personalData.genderName;
471
+ this.formStore[whichForm].lastName = user.personalData.lastName;
472
+ this.formStore[whichForm].longName = user.personalData.longName;
473
+ this.formStore[whichForm].middleName = user.personalData.middleName
474
+ ? user.personalData.middleName
475
+ : '';
476
+ this.formStore[whichForm].firstName = user.personalData.firstName;
477
+ this.formStore[whichForm].id = user.personalData.id;
478
+ this.formStore[whichForm].type = user.personalData.type;
479
+ this.formStore[whichForm].registrationDate =
480
+ user.personalData.registrationDate;
481
+ // Save User Documents Data
482
+ if ('documents' in user && user.documents.length) {
483
+ const documentType = this.documentTypes.find(
484
+ i => i.ids === user.documents[0].type,
390
485
  );
391
- });
486
+ const documentIssuer = this.documentIssuers.find(
487
+ i => i.nameRu === user.documents[0].issuerNameRu,
488
+ );
489
+ this.formStore[whichForm].documentType = documentType
490
+ ? documentType
491
+ : new Value();
492
+ this.formStore[whichForm].documentNumber = user.documents[0].number;
493
+ this.formStore[whichForm].documentIssuers = documentIssuer
494
+ ? documentIssuer
495
+ : new Value();
496
+ this.formStore[whichForm].documentDate = reformatDate(
497
+ user.documents[0].issueDate,
498
+ );
499
+ this.formStore[whichForm].documentExpire = reformatDate(
500
+ user.documents[0].expireDate,
501
+ );
502
+ }
503
+ // Document detail (residency, economy code, etc..)
504
+ if ('data' in user && user.data.length) {
505
+ user.data.forEach(dataObject => {
506
+ this.searchFromList(whichForm, dataObject);
507
+ });
508
+ }
509
+ if ('address' in user && user.address.length) {
510
+ const country = this.countries.find(i =>
511
+ i.nameRu?.match(new RegExp(user.address.countryName, 'i')),
512
+ );
513
+ const province = this.states.find(
514
+ i => i.ids === user.address[0].stateCode,
515
+ );
516
+ const localityType = this.localityTypes.find(
517
+ i => i.nameRu === user.address[0].cityTypeName,
518
+ );
519
+ const city = this.cities.find(
520
+ i => i.nameRu === user.address[0].cityName.replace('г.', ''),
521
+ );
522
+ const region = this.regions.find(
523
+ i => i.ids == user.address[0].regionCode,
524
+ );
525
+ this.formStore[whichForm].registrationCountry = country
526
+ ? country
527
+ : new Value();
528
+ this.formStore[whichForm].registrationStreet =
529
+ user.address[0].streetName;
530
+ this.formStore[whichForm].registrationCity = city
531
+ ? city
532
+ : new Value();
533
+ this.formStore[whichForm].registrationNumberApartment =
534
+ user.address[0].apartmentNumber;
535
+ this.formStore[whichForm].registrationNumberHouse =
536
+ user.address[0].blockNumber;
537
+ this.formStore[whichForm].registrationProvince = province
538
+ ? province
539
+ : new Value();
540
+ this.formStore[whichForm].registrationRegionType = localityType
541
+ ? localityType
542
+ : new Value();
543
+ this.formStore[whichForm].registrationRegion = region
544
+ ? region
545
+ : new Value();
546
+ this.formStore[whichForm].registrationQuarter =
547
+ user.address[0].kvartal;
548
+ this.formStore[whichForm].registrationMicroDistrict =
549
+ user.address[0].microRaion;
550
+ }
551
+ if ('contacts' in user && user.contacts.length) {
552
+ user.contacts.forEach(contact => {
553
+ if (contact.type === 'EMAIL' && contact.value) {
554
+ this.formStore[whichForm].email = contact.value;
555
+ }
556
+ if (contact.type === 'MOBILE' && contact.value) {
557
+ let phoneNumber = contact.value.substring(1);
558
+ this.formStore[whichForm].phoneNumber = `+7 (${phoneNumber.slice(
559
+ 0,
560
+ 3,
561
+ )}) ${phoneNumber.slice(3, 6)} ${phoneNumber.slice(
562
+ 6,
563
+ 8,
564
+ )} ${phoneNumber.slice(8)}`;
565
+ }
566
+ if (contact.type === 'HOME' && contact.value) {
567
+ let homePhone = contact.value.substring(1);
568
+ this.formStore[whichForm].homePhone = `+7 (${homePhone.slice(
569
+ 0,
570
+ 3,
571
+ )}) ${homePhone.slice(3, 6)} ${homePhone.slice(
572
+ 6,
573
+ 8,
574
+ )} ${homePhone.slice(8)}`;
575
+ }
576
+ });
577
+ }
392
578
  }
393
-
394
- if ('address' in user && user.address.length) {
395
- const country = this.countries.find(i =>
396
- i.nameRu?.match(new RegExp(user.address.countryName, 'i')),
579
+ if (whichIndex !== null) {
580
+ // Save User Personal Data
581
+ this.formStore[whichForm][whichIndex].iin = reformatIin(
582
+ user.personalData.iin,
397
583
  );
398
- const province = this.states.find(
399
- i => i.ids === user.address[0].stateCode,
400
- );
401
- const localityType = this.localityTypes.find(
402
- i => i.nameRu === user.address[0].cityTypeName,
584
+ this.formStore[whichForm][whichIndex].verifyType =
585
+ user.personalData.verifyType;
586
+ this.formStore[whichForm][whichIndex].verifyDate =
587
+ user.personalData.verifyDate;
588
+ this.formStore[whichForm][whichIndex].age = user.personalData.age;
589
+ const country = this.countries.find(i =>
590
+ i.nameRu?.match(new RegExp(user.personalData.birthPlace, 'i')),
403
591
  );
404
- const city = this.cities.find(
405
- i => i.nameRu === user.address[0].cityName.replace('г.', ''),
592
+ this.formStore[whichForm][whichIndex].birthPlace =
593
+ country && Object.keys(country).length ? country : new Value();
594
+ this.formStore[whichForm][whichIndex].gender = this.gender.find(
595
+ i => i.nameRu === user.personalData.genderName,
406
596
  );
407
- const region = this.regions.find(
408
- i => i.ids == user.address[0].regionCode,
597
+ this.formStore[whichForm][whichIndex].gender.id =
598
+ user.personalData.gender;
599
+ this.formStore[whichForm][whichIndex].birthDate = reformatDate(
600
+ user.personalData.birthDate,
409
601
  );
410
- this.contragent.registrationCountry = country ? country : new Value();
411
- this.contragent.registrationStreet = user.address[0].streetName;
412
- this.contragent.registrationCity = city ? city : new Value();
413
- this.contragent.registrationNumberApartment =
414
- user.address[0].apartmentNumber;
415
- this.contragent.registrationNumberHouse = user.address[0].blockNumber;
416
- this.contragent.registrationProvince = province
417
- ? province
418
- : new Value();
419
- this.contragent.registrationRegionType = localityType
420
- ? localityType
421
- : new Value();
422
- this.contragent.registrationRegion = region ? region : new Value();
423
- this.contragent.registrationQuarter = user.address[0].kvartal;
424
- this.contragent.registrationMicroDistrict = user.address[0].microRaion;
425
- }
426
-
427
- if ('contacts' in user && user.contacts.length) {
428
- user.contacts.forEach(contact => {
429
- if (contact.type === 'EMAIL' && contact.value) {
430
- this.contragent.email = contact.value;
431
- }
432
- if (contact.type === 'MOBILE' && contact.value) {
433
- let phoneNumber = contact.value.substring(1);
434
- this.contragent.phoneNumber = `+7 (${phoneNumber.slice(
435
- 0,
436
- 3,
437
- )}) ${phoneNumber.slice(3, 6)} ${phoneNumber.slice(
438
- 6,
439
- 8,
440
- )} ${phoneNumber.slice(8)}`;
441
- }
442
- if (contact.type === 'HOME' && contact.value) {
443
- let homePhone = contact.value.substring(1);
444
- this.contragent.homePhone = `+7 (${homePhone.slice(
445
- 0,
446
- 3,
447
- )}) ${homePhone.slice(3, 6)} ${homePhone.slice(
448
- 6,
449
- 8,
450
- )} ${homePhone.slice(8)}`;
451
- }
452
- });
602
+ this.formStore[whichForm][whichIndex].genderName =
603
+ user.personalData.genderName;
604
+ this.formStore[whichForm][whichIndex].lastName =
605
+ user.personalData.lastName;
606
+ this.formStore[whichForm][whichIndex].longName =
607
+ user.personalData.longName;
608
+ this.formStore[whichForm][whichIndex].middleName = user.personalData
609
+ .middleName
610
+ ? user.personalData.middleName
611
+ : '';
612
+ this.formStore[whichForm][whichIndex].firstName =
613
+ user.personalData.firstName;
614
+ this.formStore[whichForm][whichIndex].id = user.personalData.id;
615
+ this.formStore[whichForm][whichIndex].type = user.personalData.type;
616
+ this.formStore[whichForm][whichIndex].registrationDate =
617
+ user.personalData.registrationDate;
618
+ // Save User Documents Data
619
+ if ('documents' in user && user.documents.length) {
620
+ const documentType = this.documentTypes.find(
621
+ i => i.ids === user.documents[0].type,
622
+ );
623
+ const documentIssuer = this.documentIssuers.find(
624
+ i => i.nameRu === user.documents[0].issuerNameRu,
625
+ );
626
+ this.formStore[whichForm][whichIndex].documentType = documentType
627
+ ? documentType
628
+ : new Value();
629
+ this.formStore[whichForm][whichIndex].documentNumber =
630
+ user.documents[0].number;
631
+ this.formStore[whichForm][whichIndex].documentIssuers = documentIssuer
632
+ ? documentIssuer
633
+ : new Value();
634
+ this.formStore[whichForm][whichIndex].documentDate = reformatDate(
635
+ user.documents[0].issueDate,
636
+ );
637
+ this.formStore[whichForm][whichIndex].documentExpire = reformatDate(
638
+ user.documents[0].expireDate,
639
+ );
640
+ }
641
+ // Document detail (residency, economy code, etc..)
642
+ if ('data' in user && user.data.length) {
643
+ user.data.forEach(dataObject => {
644
+ this.searchFromList(whichForm, dataObject, whichIndex);
645
+ });
646
+ }
647
+ if ('address' in user && user.address.length) {
648
+ const country = this.countries.find(i =>
649
+ i.nameRu?.match(new RegExp(user.address.countryName, 'i')),
650
+ );
651
+ const province = this.states.find(
652
+ i => i.ids === user.address[0].stateCode,
653
+ );
654
+ const localityType = this.localityTypes.find(
655
+ i => i.nameRu === user.address[0].cityTypeName,
656
+ );
657
+ const city = this.cities.find(
658
+ i => i.nameRu === user.address[0].cityName.replace('г.', ''),
659
+ );
660
+ const region = this.regions.find(
661
+ i => i.ids == user.address[0].regionCode,
662
+ );
663
+ this.formStore[whichForm][whichIndex].registrationCountry = country
664
+ ? country
665
+ : new Value();
666
+ this.formStore[whichForm][whichIndex].registrationStreet =
667
+ user.address[0].streetName;
668
+ this.formStore[whichForm][whichIndex].registrationCity = city
669
+ ? city
670
+ : new Value();
671
+ this.formStore[whichForm][whichIndex].registrationNumberApartment =
672
+ user.address[0].apartmentNumber;
673
+ this.formStore[whichForm][whichIndex].registrationNumberHouse =
674
+ user.address[0].blockNumber;
675
+ this.formStore[whichForm][whichIndex].registrationProvince = province
676
+ ? province
677
+ : new Value();
678
+ this.formStore[whichForm][whichIndex].registrationRegionType =
679
+ localityType ? localityType : new Value();
680
+ this.formStore[whichForm][whichIndex].registrationRegion = region
681
+ ? region
682
+ : new Value();
683
+ this.formStore[whichForm][whichIndex].registrationQuarter =
684
+ user.address[0].kvartal;
685
+ this.formStore[whichForm][whichIndex].registrationMicroDistrict =
686
+ user.address[0].microRaion;
687
+ }
688
+ if ('contacts' in user && user.contacts.length) {
689
+ user.contacts.forEach(contact => {
690
+ if (contact.type === 'EMAIL' && contact.value) {
691
+ this.formStore[whichForm][whichIndex].email = contact.value;
692
+ }
693
+ if (contact.type === 'MOBILE' && contact.value) {
694
+ let phoneNumber = contact.value.substring(1);
695
+ this.formStore[whichForm][
696
+ whichIndex
697
+ ].phoneNumber = `+7 (${phoneNumber.slice(
698
+ 0,
699
+ 3,
700
+ )}) ${phoneNumber.slice(3, 6)} ${phoneNumber.slice(
701
+ 6,
702
+ 8,
703
+ )} ${phoneNumber.slice(8)}`;
704
+ }
705
+ if (contact.type === 'HOME' && contact.value) {
706
+ let homePhone = contact.value.substring(1);
707
+ this.formStore[whichForm][
708
+ whichIndex
709
+ ].homePhone = `+7 (${homePhone.slice(0, 3)}) ${homePhone.slice(
710
+ 3,
711
+ 6,
712
+ )} ${homePhone.slice(6, 8)} ${homePhone.slice(8)}`;
713
+ }
714
+ });
715
+ }
453
716
  }
454
717
  },
455
718
  async alreadyInInsis(iin, firstName, lastName, middleName) {
@@ -480,42 +743,84 @@ export const useDataStore = defineStore('data', {
480
743
  return false;
481
744
  }
482
745
  },
483
- async saveContragent(user, onlySaveAction = true) {
746
+ async saveContragent(
747
+ user,
748
+ whichForm,
749
+ onlySaveAction = true,
750
+ whichIndex = null,
751
+ ) {
484
752
  this.isLoading = true;
485
- const hasInsisId = await this.alreadyInInsis(
486
- this.contragent.iin,
487
- this.contragent.firstName,
488
- this.contragent.lastName,
489
- this.contragent.middleName,
490
- );
491
- if (hasInsisId !== false) {
492
- user.id = hasInsisId;
493
- const [
494
- { value: data },
495
- { value: contacts },
496
- { value: documents },
497
- { value: address },
498
- ] = await Promise.allSettled([
499
- this.api.getContrAgentData(user.id),
500
- this.api.getContrAgentContacts(user.id),
501
- this.api.getContrAgentDocuments(user.id),
502
- this.api.getContrAgentAddress(user.id),
503
- ]);
504
- this.contragent.response = {};
505
- if (data && data.length) {
506
- this.contragent.response.questionnaires = data;
507
- }
508
- if (contacts && contacts.length) {
509
- this.contragent.response.contacts = contacts;
510
- }
511
- if (documents && documents.length) {
512
- this.contragent.response.documents = documents;
753
+ if (whichIndex === null) {
754
+ const hasInsisId = await this.alreadyInInsis(
755
+ this.formStore[whichForm].iin,
756
+ this.formStore[whichForm].firstName,
757
+ this.formStore[whichForm].lastName,
758
+ this.formStore[whichForm].middleName,
759
+ );
760
+ if (hasInsisId !== false) {
761
+ user.id = hasInsisId;
762
+ const [
763
+ { value: data },
764
+ { value: contacts },
765
+ { value: documents },
766
+ { value: address },
767
+ ] = await Promise.allSettled([
768
+ this.api.getContrAgentData(user.id),
769
+ this.api.getContrAgentContacts(user.id),
770
+ this.api.getContrAgentDocuments(user.id),
771
+ this.api.getContrAgentAddress(user.id),
772
+ ]);
773
+ this.formStore[whichForm].response = {};
774
+ if (data && data.length) {
775
+ this.formStore[whichForm].response.questionnaires = data;
776
+ }
777
+ if (contacts && contacts.length) {
778
+ this.formStore[whichForm].response.contacts = contacts;
779
+ }
780
+ if (documents && documents.length) {
781
+ this.formStore[whichForm].response.documents = documents;
782
+ }
783
+ if (address && address.length) {
784
+ this.formStore[whichForm].response.addresses = address;
785
+ }
513
786
  }
514
- if (address && address.length) {
515
- this.contragent.response.addresses = address;
787
+ } else {
788
+ const hasInsisId = await this.alreadyInInsis(
789
+ this.formStore[whichForm][whichIndex].iin,
790
+ this.formStore[whichForm][whichIndex].firstName,
791
+ this.formStore[whichForm][whichIndex].lastName,
792
+ this.formStore[whichForm][whichIndex].middleName,
793
+ );
794
+ if (hasInsisId !== false) {
795
+ user.id = hasInsisId;
796
+ const [
797
+ { value: data },
798
+ { value: contacts },
799
+ { value: documents },
800
+ { value: address },
801
+ ] = await Promise.allSettled([
802
+ this.api.getContrAgentData(user.id),
803
+ this.api.getContrAgentContacts(user.id),
804
+ this.api.getContrAgentDocuments(user.id),
805
+ this.api.getContrAgentAddress(user.id),
806
+ ]);
807
+ this.formStore[whichForm][whichIndex].response = {};
808
+ if (data && data.length) {
809
+ this.formStore[whichForm][whichIndex].response.questionnaires =
810
+ data;
811
+ }
812
+ if (contacts && contacts.length) {
813
+ this.formStore[whichForm][whichIndex].response.contacts = contacts;
814
+ }
815
+ if (documents && documents.length) {
816
+ this.formStore[whichForm][whichIndex].response.documents =
817
+ documents;
818
+ }
819
+ if (address && address.length) {
820
+ this.formStore[whichForm][whichIndex].response.addresses = address;
821
+ }
516
822
  }
517
823
  }
518
-
519
824
  try {
520
825
  // ! SaveContragent -> Contragent
521
826
  let contragentData = {
@@ -578,6 +883,34 @@ export const useDataStore = defineStore('data', {
578
883
  questName: questName,
579
884
  };
580
885
  });
886
+ if (user.countryOfTaxResidency.ids !== '500014.3') {
887
+ user.addTaxResidency = new Value();
888
+ }
889
+ const addTaxResidency =
890
+ 'response' in user &&
891
+ 'questionnaires' in user.response &&
892
+ user.response.questionnaires.find(i => i.questId === '507777');
893
+ if (user.addTaxResidency.nameRu !== null) {
894
+ questionariesData.push({
895
+ id: addTaxResidency ? addTaxResidency.id : 0,
896
+ contragentId: user.id,
897
+ questAnswer: user.addTaxResidency.ids,
898
+ questAnswerName: user.addTaxResidency.nameRu,
899
+ questName: 'Указать если налоговое резиденство выбрано другое',
900
+ questId: '507777',
901
+ });
902
+ } else {
903
+ if (addTaxResidency && addTaxResidency.questAnswer !== null) {
904
+ questionariesData.push({
905
+ id: addTaxResidency.id,
906
+ contragentId: user.id,
907
+ questAnswer: null,
908
+ questAnswerName: null,
909
+ questName: 'Указать если налоговое резиденство выбрано другое',
910
+ questId: '507777',
911
+ });
912
+ }
913
+ }
581
914
 
582
915
  // ! SaveContragent -> Contacts
583
916
  let contactsData = [];
@@ -594,12 +927,12 @@ export const useDataStore = defineStore('data', {
594
927
  type: 'MOBILE',
595
928
  typeName: 'Сотовый телефон',
596
929
  value: formatPhone(user.phoneNumber),
597
- verifyType: this.contragent.otpTokenId
930
+ verifyType: this.formStore.otpTokenId
598
931
  ? 'BMG'
599
932
  : 'response' in user && 'contacts' in user.response
600
933
  ? user.response.contacts.find(i => i.type === 'MOBILE').verifyType
601
934
  : null,
602
- verifyDate: this.contragent.otpTokenId
935
+ verifyDate: this.formStore.otpTokenId
603
936
  ? this.currentDate()
604
937
  : 'response' in user && 'contacts' in user.response
605
938
  ? user.response.contacts.find(i => i.type === 'MOBILE').verifyDate
@@ -705,8 +1038,13 @@ export const useDataStore = defineStore('data', {
705
1038
  try {
706
1039
  const personId = await this.api.saveContragent(data);
707
1040
  if (personId) {
708
- await this.getContragentById(personId, false);
709
- this.contragent.otpTokenId = null;
1041
+ await this.getContragentById(
1042
+ personId,
1043
+ whichForm,
1044
+ false,
1045
+ whichIndex,
1046
+ );
1047
+ this.formStore.otpTokenId = null;
710
1048
  }
711
1049
  } catch (saveErr) {
712
1050
  console.log(saveErr);
@@ -731,24 +1069,262 @@ export const useDataStore = defineStore('data', {
731
1069
  }
732
1070
  return true;
733
1071
  },
734
- searchFromList(whichField, searchIt, list) {
735
- for (let index = 0; index < whichField.length; index++) {
736
- const searchFrom = list[index];
737
- const documentQuestionnaire = searchFrom.filter(
738
- i =>
739
- i.nameRu === searchIt.questAnswerName ||
740
- i.ids === searchIt.questAnswer,
741
- );
742
- if (documentQuestionnaire.length) {
743
- this.contragent[whichField[index]] = documentQuestionnaire[0];
1072
+ async saveMember(whichForm, key, whichMember, whichIndex = null) {
1073
+ let data = {};
1074
+ try {
1075
+ if (whichIndex === null) {
1076
+ data = {
1077
+ processInstanceId: this.formStore.applicationData.processInstanceId,
1078
+ insisId: this.formStore[whichForm].id,
1079
+ iin: this.formStore[whichForm].iin.replace(/-/g, ''),
1080
+ longName: this.formStore[whichForm].longName,
1081
+ isIpdl:
1082
+ this.formStore[whichForm].signOfIPDL.nameRu == 'Да'
1083
+ ? true
1084
+ : false,
1085
+ isTerror: this.formStore[whichForm].isTerror,
1086
+ isIpdlCompliance: null,
1087
+ isTerrorCompliance: null,
1088
+ };
1089
+ data.id =
1090
+ this.formStore.applicationData[key] &&
1091
+ this.formStore.applicationData[key].id
1092
+ ? this.formStore.applicationData[key].id
1093
+ : null;
1094
+ if (whichMember == 'Client') {
1095
+ data.isInsured = this.formStore.isPolicyholderInsured;
1096
+ data.isActOwnBehalf = this.formStore.isActOwnBehalf;
1097
+ data.profession = this.formStore[whichForm].job;
1098
+ data.position = this.formStore[whichForm].jobPosition;
1099
+ data.jobName = this.formStore[whichForm].jobPlace;
1100
+ data.familyStatusId = this.formStore[whichForm].familyStatus.id;
1101
+ }
1102
+ if (whichMember == 'Spokesman') {
1103
+ if (
1104
+ !!this.formStore.applicationData.spokesmanApp &&
1105
+ this.formStore.applicationData.spokesmanApp.iin !== data.iin
1106
+ ) {
1107
+ delete data.id;
1108
+ await this.api.deleteMember(
1109
+ 'Spokesman',
1110
+ this.formStore.applicationData.processInstanceId,
1111
+ );
1112
+ }
1113
+ data.migrationCard = this.formStore[whichForm].migrationCard;
1114
+ data.migrationCardIssueDate = formatDate(
1115
+ this.formStore[whichForm].migrationCardIssueDate,
1116
+ );
1117
+ data.migrationCardExpireDate = formatDate(
1118
+ this.formStore[whichForm].migrationCardExpireDate,
1119
+ );
1120
+ data.confirmDocType = this.formStore[whichForm].confirmDocType;
1121
+ data.confirmDocNumber = this.formStore[whichForm].confirmDocNumber;
1122
+ data.confirmDocIssueDate = formatDate(
1123
+ this.formStore[whichForm].migrationCardIssueDate,
1124
+ );
1125
+ data.confirmDocExpireDate = formatDate(
1126
+ this.formStore[whichForm].migrationCardExpireDate,
1127
+ );
1128
+ data.clientLongName =
1129
+ this.formStore.applicationData.clientApp.longName;
1130
+ data.notaryLongName = this.formStore[whichForm].notaryLongName;
1131
+ data.notaryLicenseNumber =
1132
+ this.formStore[whichForm].notaryLicenseNumber;
1133
+ data.notaryLicenseDate = formatDate(
1134
+ this.formStore[whichForm].notaryLicenseDate,
1135
+ );
1136
+ data.notaryLicenseIssuer =
1137
+ this.formStore[whichForm].notaryLicenseIssuer;
1138
+ data.jurLongName = this.formStore[whichForm].jurLongName;
1139
+ data.fullNameRod = this.formStore[whichForm].fullNameRod;
1140
+ data.confirmDocTypeKz = this.formStore[whichForm].confirmDocTypeKz;
1141
+ data.confirmDocTypeRod =
1142
+ this.formStore[whichForm].confirmDocTypeRod;
1143
+ data.isNotary = this.formStore[whichForm].isNotary;
1144
+ }
1145
+ }
1146
+ if (whichIndex !== null) {
1147
+ data = {
1148
+ processInstanceId: this.formStore.applicationData.processInstanceId,
1149
+ insisId: this.formStore[whichForm][whichIndex].id,
1150
+ iin: this.formStore[whichForm][whichIndex].iin.replace(/-/g, ''),
1151
+ longName: this.formStore[whichForm][whichIndex].longName,
1152
+ isIpdl:
1153
+ this.formStore[whichForm][whichIndex].signOfIPDL.nameRu == 'Да'
1154
+ ? true
1155
+ : false,
1156
+ isTerror: this.formStore[whichForm][whichIndex].isTerror,
1157
+ isIpdlCompliance: null,
1158
+ isTerrorCompliance: null,
1159
+ };
1160
+ data.id =
1161
+ this.formStore.applicationData[key] &&
1162
+ this.formStore.applicationData[key][whichIndex] &&
1163
+ this.formStore.applicationData[key][whichIndex].id
1164
+ ? this.formStore.applicationData[key][whichIndex].id
1165
+ : null;
1166
+ if (whichMember == 'Insured') {
1167
+ if (
1168
+ this.formStore.applicationData &&
1169
+ this.formStore.applicationData.insuredApp &&
1170
+ this.formStore.applicationData.insuredApp.length &&
1171
+ this.formStore.applicationData.insuredApp.every(
1172
+ i => i.iin !== data.iin,
1173
+ ) &&
1174
+ data.id !== null
1175
+ ) {
1176
+ await this.api.deleteMember('Insured', data.id);
1177
+ delete data.id;
1178
+ }
1179
+ data.isDisability = this.formStore.isPolicyholderInsured
1180
+ ? false
1181
+ : this.formStore[whichForm][whichIndex].isDisability.nameRu ==
1182
+ 'Да';
1183
+ data.disabilityGroupId = data.isDisability
1184
+ ? this.formStore[whichForm][whichIndex].disabilityGroupId.id
1185
+ : null;
1186
+ data.profession = this.formStore[whichForm][whichIndex].job;
1187
+ data.position = this.formStore[whichForm][whichIndex].jobPosition;
1188
+ data.jobName = this.formStore[whichForm][whichIndex].jobPlace;
1189
+ data.familyStatusId =
1190
+ this.formStore[whichForm][whichIndex].familyStatus.id;
1191
+ }
1192
+ if (whichMember == 'Beneficiary') {
1193
+ if (
1194
+ this.formStore.applicationData &&
1195
+ this.formStore.applicationData.beneficiaryApp &&
1196
+ this.formStore.applicationData.beneficiaryApp.length &&
1197
+ this.formStore.applicationData.beneficiaryApp.every(
1198
+ i => i.iin !== data.iin,
1199
+ ) &&
1200
+ data.id !== null
1201
+ ) {
1202
+ await this.api.deleteMember('Beneficiary', data.id);
1203
+ delete data.id;
1204
+ }
1205
+ data.familyStatusId =
1206
+ this.formStore[whichForm][whichIndex].familyStatus.id == 0
1207
+ ? null
1208
+ : this.formStore[whichForm][whichIndex].familyStatus.id;
1209
+ data.percentage = Number(
1210
+ this.formStore[whichForm][whichIndex].percentageOfPayoutAmount,
1211
+ );
1212
+ data.relationId =
1213
+ this.formStore[whichForm][whichIndex].relationDegree.ids;
1214
+ data.relationName =
1215
+ this.formStore[whichForm][whichIndex].relationDegree.nameRu;
1216
+ }
1217
+ if (whichMember == 'BeneficialOwner') {
1218
+ if (data.id === 0) {
1219
+ data.id = null;
1220
+ }
1221
+ if (
1222
+ this.formStore.applicationData &&
1223
+ this.formStore.applicationData.beneficialOwnerApp &&
1224
+ this.formStore.applicationData.beneficialOwnerApp.length &&
1225
+ this.formStore.applicationData.beneficialOwnerApp.every(
1226
+ i => i.iin !== data.iin,
1227
+ ) &&
1228
+ data.id !== null
1229
+ ) {
1230
+ await this.api.deleteMember('BeneficialOwner', data.id);
1231
+ delete data.id;
1232
+ }
1233
+ data.familyStatusId =
1234
+ this.formStore[whichForm][whichIndex].familyStatus.id;
1235
+ }
1236
+ }
1237
+ await this.api.setMember(whichMember, data);
1238
+ return true;
1239
+ } catch (err) {
1240
+ console.log(err);
1241
+ }
1242
+ },
1243
+ searchFromList(whichForm, searchIt, whichIndex = null) {
1244
+ const getQuestionariesData = () => {
1245
+ switch (searchIt.questId) {
1246
+ case '500003':
1247
+ return [this.economySectorCode, 'economySectorCode'];
1248
+ case '500011':
1249
+ return [this.residents, 'signOfResidency'];
1250
+ case '500012':
1251
+ return [this.citizenshipCountries, 'countryOfCitizenship'];
1252
+ case '500014':
1253
+ return [this.taxCountries, 'countryOfTaxResidency'];
1254
+ case '507777':
1255
+ return [this.addTaxCountries, 'addTaxResidency'];
1256
+ case '500147':
1257
+ return [[]];
1258
+ case '500148':
1259
+ return [[]];
1260
+ }
1261
+ };
1262
+
1263
+ const [searchFrom, whichField] = getQuestionariesData();
1264
+ if (searchFrom && searchFrom.length) {
1265
+ const result = searchFrom.find(i => i.ids === searchIt.questAnswer);
1266
+ if (whichIndex === null) {
1267
+ this.formStore[whichForm][whichField] = result ? result : new Value();
1268
+ } else {
1269
+ this.formStore[whichForm][whichIndex][whichField] = result
1270
+ ? result
1271
+ : new Value();
744
1272
  }
745
1273
  }
746
1274
  },
1275
+ async setSurvey(data) {
1276
+ try {
1277
+ this.isLoading = true;
1278
+ const anketaToken = await this.api.setSurvey(data);
1279
+ window.scrollTo({ top: 0, behavior: 'smooth' });
1280
+ this.showToaster('success', this.t('toaster.successSaved'), 2000);
1281
+ return anketaToken;
1282
+ } catch (error) {
1283
+ this.showToaster('error', this.t('toaster.undefinedError'), 1000);
1284
+ } finally {
1285
+ this.isLoading = false;
1286
+ }
1287
+ },
747
1288
  async getFromApi(whichField, whichRequest, parameter) {
748
- if (this[whichField].length === 0) {
1289
+ const storageValue = JSON.parse(
1290
+ localStorage.getItem(whichField) || 'null',
1291
+ );
1292
+ const currentHour = new Date().getHours();
1293
+
1294
+ const getDataCondition = () => {
1295
+ if (!storageValue) return true;
1296
+ const hasHourKey = 'hour' in storageValue;
1297
+ const hasModeKey = 'mode' in storageValue;
1298
+ const hasValueKey = 'value' in storageValue;
1299
+ if (
1300
+ storageValue &&
1301
+ (hasHourKey === false ||
1302
+ hasModeKey === false ||
1303
+ hasValueKey === false)
1304
+ )
1305
+ return true;
1306
+ if (
1307
+ storageValue &&
1308
+ (storageValue.hour !== currentHour ||
1309
+ storageValue.mode !== import.meta.env.MODE ||
1310
+ storageValue.value.length === 0)
1311
+ )
1312
+ return true;
1313
+ };
1314
+
1315
+ if (getDataCondition()) {
1316
+ this.whichField = [];
749
1317
  try {
750
- const response = await api[whichRequest](parameter);
1318
+ const response = await this.api[whichRequest](parameter);
751
1319
  if (response) {
1320
+ localStorage.setItem(
1321
+ whichField,
1322
+ JSON.stringify({
1323
+ value: response,
1324
+ hour: currentHour,
1325
+ mode: import.meta.env.MODE,
1326
+ }),
1327
+ );
752
1328
  this[whichField] = response;
753
1329
  if (
754
1330
  this[whichField].length &&
@@ -761,7 +1337,10 @@ export const useDataStore = defineStore('data', {
761
1337
  } catch (err) {
762
1338
  console.log(err);
763
1339
  }
1340
+ } else {
1341
+ this[whichField] = storageValue.value;
764
1342
  }
1343
+
765
1344
  return this[whichField];
766
1345
  },
767
1346
  async getCountries() {
@@ -776,6 +1355,12 @@ export const useDataStore = defineStore('data', {
776
1355
  async getTaxCountries() {
777
1356
  return await this.getFromApi('taxCountries', 'getTaxCountries');
778
1357
  },
1358
+ async getAdditionalTaxCountries() {
1359
+ return await this.getFromApi(
1360
+ 'addTaxCountries',
1361
+ 'getAdditionalTaxCountries',
1362
+ );
1363
+ },
779
1364
  async getStates(key) {
780
1365
  await this.getFromApi('states', 'getStates');
781
1366
  if (key && this.contragent[key] && this.contragent[key].ids !== null) {
@@ -824,6 +1409,18 @@ export const useDataStore = defineStore('data', {
824
1409
  }
825
1410
  });
826
1411
  },
1412
+ async getDicFileTypeList() {
1413
+ try {
1414
+ if (this.dicFileTypeList.length) {
1415
+ return this.dicFileTypeList;
1416
+ } else {
1417
+ this.dicFileTypeList = await this.api.getDicFileTypeList();
1418
+ return this.dicFileTypeList;
1419
+ }
1420
+ } catch (err) {
1421
+ console.log(err.response.data);
1422
+ }
1423
+ },
827
1424
  async getDocumentIssuers() {
828
1425
  return await this.getFromApi('documentIssuers', 'getDocumentIssuers');
829
1426
  },
@@ -850,6 +1447,14 @@ export const useDataStore = defineStore('data', {
850
1447
  );
851
1448
  return [...filteredRelations, ...otherRelations];
852
1449
  },
1450
+ async getProcessIndexRate() {
1451
+ const response = await this.getFromApi(
1452
+ 'processIndexRate',
1453
+ 'getProcessIndexRate',
1454
+ this.processCode,
1455
+ );
1456
+ return response ? response : [];
1457
+ },
853
1458
  async getProcessCoverTypeSum(type) {
854
1459
  return await this.getFromApi(
855
1460
  'processCoverTypeSum',
@@ -857,6 +1462,61 @@ export const useDataStore = defineStore('data', {
857
1462
  type,
858
1463
  );
859
1464
  },
1465
+ async getProcessPaymentPeriod() {
1466
+ return await this.getFromApi(
1467
+ 'processPaymentPeriod',
1468
+ 'getProcessPaymentPeriod',
1469
+ this.processCode,
1470
+ );
1471
+ },
1472
+ async getQuestionRefs(id) {
1473
+ return await this.getFromApi('questionRefs', 'getQuestionRefs', id);
1474
+ },
1475
+ async getProcessTariff() {
1476
+ return await this.getFromApi('processTariff', 'getProcessTariff');
1477
+ },
1478
+ async getAdditionalInsuranceTermsAnswers(questionId) {
1479
+ try {
1480
+ const answers = await this.api.getAdditionalInsuranceTermsAnswers(
1481
+ this.processCode,
1482
+ questionId,
1483
+ );
1484
+ answers.unshift(answers.pop());
1485
+ return answers;
1486
+ } catch (err) {
1487
+ console.log(err);
1488
+ }
1489
+ },
1490
+ async getQuestionList(
1491
+ surveyType,
1492
+ processInstanceId,
1493
+ insuredId,
1494
+ baseField,
1495
+ secondaryField,
1496
+ ) {
1497
+ if (!this[baseField].length) {
1498
+ try {
1499
+ const [{ value: baseQuestions }, { value: secondaryQuestions }] =
1500
+ await Promise.allSettled([
1501
+ this.api.getQuestionList(
1502
+ surveyType,
1503
+ processInstanceId,
1504
+ insuredId,
1505
+ ),
1506
+ this.api.getQuestionList(
1507
+ `${surveyType}second`,
1508
+ processInstanceId,
1509
+ insuredId,
1510
+ ),
1511
+ ]);
1512
+ this[baseField] = baseQuestions;
1513
+ this[secondaryField] = secondaryQuestions;
1514
+ } catch (err) {
1515
+ console.log(err);
1516
+ }
1517
+ }
1518
+ return this[baseField];
1519
+ },
860
1520
  getNumberWithSpaces(n) {
861
1521
  return n === null
862
1522
  ? null
@@ -957,6 +1617,7 @@ export const useDataStore = defineStore('data', {
957
1617
  this.getCountries(),
958
1618
  this.getCitizenshipCountries(),
959
1619
  this.getTaxCountries(),
1620
+ this.getAdditionalTaxCountries(),
960
1621
  this.getStates(),
961
1622
  this.getRegions(),
962
1623
  this.getCities(),
@@ -967,6 +1628,9 @@ export const useDataStore = defineStore('data', {
967
1628
  this.getSectorCodeList(),
968
1629
  this.getFamilyStatuses(),
969
1630
  this.getRelationTypes(),
1631
+ this.getProcessIndexRate(),
1632
+ this.getProcessTariff(),
1633
+ this.getProcessPaymentPeriod(),
970
1634
  ]);
971
1635
  },
972
1636
  async getUserGroups() {
@@ -1090,45 +1754,8 @@ export const useDataStore = defineStore('data', {
1090
1754
  this.isLoading = false;
1091
1755
  return { otpStatus, otpResponse };
1092
1756
  },
1093
- async checkOtp(otpToken, phone, code) {
1094
- try {
1095
- this.isLoading = true;
1096
- const otpData = {
1097
- tokenId: otpToken,
1098
- phoneNumber: formatPhone(phone),
1099
- code: code,
1100
- };
1101
- const otpResponse = await this.api.checkOtp(otpData);
1102
- if (otpResponse !== null) {
1103
- if ('errMessage' in otpResponse && otpResponse.errMessage !== null) {
1104
- this.showToaster('error', otpResponse.errMessage, 3000);
1105
- return false;
1106
- }
1107
- if ('status' in otpResponse && !!otpResponse.status) {
1108
- // TODO Доработать и менять значение hasAgreement.value => true
1109
- this.showToaster(
1110
- otpResponse.status !== 2 ? 'error' : 'success',
1111
- otpResponse.statusName,
1112
- 3000,
1113
- );
1114
- if (otpResponse.status === 2) {
1115
- return true;
1116
- }
1117
- }
1118
- }
1119
- return false;
1120
- } catch (err) {
1121
- console.log(err);
1122
- if ('response' in err) {
1123
- this.showToaster('error', err.response.data, 3000);
1124
- }
1125
- } finally {
1126
- this.isLoading = false;
1127
- }
1128
- return null;
1129
- },
1130
- async getProcessList() {
1131
- this.isLoading = true;
1757
+ async getProcessList() {
1758
+ this.isLoading = true;
1132
1759
  try {
1133
1760
  const processList = await this.api.getProcessList();
1134
1761
  if (this.processList === null) {
@@ -1160,6 +1787,1784 @@ export const useDataStore = defineStore('data', {
1160
1787
  }
1161
1788
  }
1162
1789
  },
1790
+ async searchAgentByName(name) {
1791
+ try {
1792
+ this.isLoading = true;
1793
+ this.AgentDataList = await this.api.searchAgentByName(name);
1794
+ if (!this.AgentDataList.length) {
1795
+ showToaster('error', this.t('toaster.notFound'), 1500);
1796
+ }
1797
+ } catch (err) {
1798
+ console.log(err);
1799
+ } finally {
1800
+ this.isLoading = false;
1801
+ }
1802
+ },
1803
+ async setINSISWorkData() {
1804
+ const data = {
1805
+ id: this.formStore.applicationData.insisWorkDataApp.id,
1806
+ processInstanceId: this.formStore.applicationData.processInstanceId,
1807
+ agentId: this.formStore.AgentData.agentId,
1808
+ agentName: this.formStore.AgentData.fullName,
1809
+ salesChannel:
1810
+ this.formStore.applicationData.insisWorkDataApp.salesChannel,
1811
+ salesChannelName:
1812
+ this.formStore.applicationData.insisWorkDataApp.salesChannelName,
1813
+ insrType: this.formStore.applicationData.insisWorkDataApp.insrType,
1814
+ saleChanellPolicy: this.formStore.SaleChanellPolicy.ids,
1815
+ saleChanellPolicyName: this.formStore.SaleChanellPolicy.nameRu,
1816
+ regionPolicy: this.formStore.RegionPolicy.ids,
1817
+ regionPolicyName: this.formStore.RegionPolicy.nameRu,
1818
+ managerPolicy: this.formStore.ManagerPolicy.ids,
1819
+ managerPolicyName: this.formStore.ManagerPolicy.nameRu,
1820
+ insuranceProgramType:
1821
+ this.formStore.applicationData.insisWorkDataApp.insuranceProgramType,
1822
+ };
1823
+ try {
1824
+ this.isLoading = true;
1825
+ await this.api.setINSISWorkData(data);
1826
+ } catch (err) {
1827
+ console.log(err);
1828
+ } finally {
1829
+ this.isLoading = false;
1830
+ }
1831
+ },
1832
+ async getDictionaryItems(dictName) {
1833
+ try {
1834
+ this.isLoading = true;
1835
+ if (!this[`${dictName}List`].length) {
1836
+ this[`${dictName}List`] = await this.api.getDictionaryItems(dictName);
1837
+ }
1838
+ } catch (err) {
1839
+ console.log(err);
1840
+ } finally {
1841
+ this.isLoading = false;
1842
+ }
1843
+ },
1844
+ async filterManagerByRegion(dictName, filterName) {
1845
+ try {
1846
+ this.isLoading = true;
1847
+ this[`${dictName}List`] = await this.api.filterManagerByRegion(
1848
+ dictName,
1849
+ filterName,
1850
+ );
1851
+ } catch (err) {
1852
+ console.log(err);
1853
+ } finally {
1854
+ this.isLoading = false;
1855
+ }
1856
+ },
1857
+ async getUnderwritingCouncilData(id) {
1858
+ try {
1859
+ const response = await this.api.getUnderwritingCouncilData(id);
1860
+ this.affilationResolution.id = response.underwritingCouncilAppDto.id;
1861
+ this.affilationResolution.date = response.underwritingCouncilAppDto.date
1862
+ ? reformatDate(response.underwritingCouncilAppDto.date)
1863
+ : null;
1864
+ this.affilationResolution.number = response.underwritingCouncilAppDto
1865
+ .number
1866
+ ? response.underwritingCouncilAppDto.number
1867
+ : null;
1868
+ } catch (err) {
1869
+ console.log(err);
1870
+ }
1871
+ },
1872
+ async setConfirmation() {
1873
+ const data = {
1874
+ id: this.affilationResolution.id,
1875
+ processInstanceId: this.affilationResolution.processInstanceId,
1876
+ number: this.affilationResolution.number,
1877
+ date: formatDate(this.affilationResolution.date),
1878
+ };
1879
+ try {
1880
+ this.isLoading = true;
1881
+ await this.api.setConfirmation(data);
1882
+ showToaster('success', this.t('toaster.successSaved'));
1883
+ return true;
1884
+ } catch (err) {
1885
+ this.showToaster('error', this.t('toaster.error'));
1886
+ return false;
1887
+ } finally {
1888
+ this.isLoading = false;
1889
+ }
1890
+ },
1891
+ async sendUnderwritingCouncilTask(data) {
1892
+ try {
1893
+ this.isLoading = true;
1894
+ await this.api.sendUnderwritingCouncilTask(data);
1895
+ showToaster('success', this.t('toaster.successOperation'), 5000);
1896
+ return true;
1897
+ } catch (err) {
1898
+ console.log(err);
1899
+ this.showToaster('error', this.t('toaster.error'), 5000);
1900
+ return false;
1901
+ } finally {
1902
+ this.isLoading = false;
1903
+ }
1904
+ },
1905
+ async definedAnswers(filter, whichSurvey, value = null, index = null) {
1906
+ if (!this.definedAnswersId[whichSurvey].hasOwnProperty(filter)) {
1907
+ this.definedAnswersId[whichSurvey][filter] =
1908
+ await this.api.definedAnswers(filter);
1909
+ }
1910
+ if (value !== null && this.definedAnswersId[whichSurvey][filter].length) {
1911
+ const answer = this.definedAnswersId[whichSurvey][filter].find(
1912
+ answer => answer.nameRu === value,
1913
+ );
1914
+ this[whichSurvey].body[index].first.answerId = answer.ids;
1915
+ }
1916
+ return this.definedAnswersId[whichSurvey];
1917
+ },
1918
+ async getPaymentTable(id) {
1919
+ try {
1920
+ const paymentResultTable = await this.api.calculatePremuim(id);
1921
+ if (paymentResultTable.length > 0) {
1922
+ this.paymentResultTable = paymentResultTable;
1923
+ } else {
1924
+ this.paymentResultTable = [];
1925
+ }
1926
+ } catch (err) {
1927
+ console.log(err);
1928
+ }
1929
+ },
1930
+ async calculate(taskId) {
1931
+ this.isLoading = true;
1932
+ try {
1933
+ let form1 = {
1934
+ baiterekApp: null,
1935
+ policyAppDto: {
1936
+ id: this.formStore.applicationData.policyAppDto.id,
1937
+ processInstanceId:
1938
+ this.formStore.applicationData.policyAppDto.processInstanceId,
1939
+ policyId: null,
1940
+ policyNumber: null,
1941
+ contractDate: this.currentDate(),
1942
+ amount:
1943
+ this.formStore.productConditionsForm.requestedSumInsured != null
1944
+ ? Number(
1945
+ this.formStore.productConditionsForm.requestedSumInsured.replace(
1946
+ /\s/g,
1947
+ '',
1948
+ ),
1949
+ )
1950
+ : null,
1951
+ premium:
1952
+ this.formStore.productConditionsForm.insurancePremiumPerMonth !=
1953
+ null
1954
+ ? Number(
1955
+ this.formStore.productConditionsForm.insurancePremiumPerMonth.replace(
1956
+ /\s/g,
1957
+ '',
1958
+ ),
1959
+ )
1960
+ : null,
1961
+ isSpokesman: this.formStore.hasRepresentative,
1962
+ coverPeriod: this.formStore.productConditionsForm.coverPeriod,
1963
+ payPeriod: this.formStore.productConditionsForm.coverPeriod,
1964
+ annualIncome: this.formStore.productConditionsForm.annualIncome
1965
+ ? Number(
1966
+ this.formStore.productConditionsForm.annualIncome.replace(
1967
+ /\s/g,
1968
+ '',
1969
+ ),
1970
+ )
1971
+ : null,
1972
+ indexRateId: this.formStore.productConditionsForm.processIndexRate
1973
+ ?.id
1974
+ ? this.formStore.productConditionsForm.processIndexRate.id
1975
+ : this.processIndexRate.find(i => i.code === '0')?.id,
1976
+ paymentPeriodId:
1977
+ this.formStore.productConditionsForm.paymentPeriod.id,
1978
+ lifeMultiply: formatProcents(
1979
+ this.formStore.productConditionsForm.lifeMultiply,
1980
+ ),
1981
+ lifeAdditive: formatProcents(
1982
+ this.formStore.productConditionsForm.lifeAdditive,
1983
+ ),
1984
+ adbMultiply: formatProcents(
1985
+ this.formStore.productConditionsForm.adbMultiply,
1986
+ ),
1987
+ adbAdditive: formatProcents(
1988
+ this.formStore.productConditionsForm.adbAdditive,
1989
+ ),
1990
+ disabilityMultiply: formatProcents(
1991
+ this.formStore.productConditionsForm.disabilityMultiply,
1992
+ ),
1993
+ disabilityAdditive: formatProcents(
1994
+ this.formStore.productConditionsForm.adbAdditive,
1995
+ ),
1996
+ riskGroup: this.formStore.productConditionsForm.riskGroup?.id
1997
+ ? this.formStore.productConditionsForm.riskGroup.id
1998
+ : 1,
1999
+ },
2000
+ addCoversDto: this.additionalInsuranceTerms,
2001
+ };
2002
+
2003
+ try {
2004
+ let id = this.formStore.applicationData.processInstanceId;
2005
+
2006
+ await this.api.setApplication(form1);
2007
+ let result;
2008
+ try {
2009
+ result = await this.api.getCalculation(id);
2010
+ } catch (err) {
2011
+ this.showToaster('error', err?.response?.data, 5000);
2012
+ }
2013
+
2014
+ const applicationData = await this.api.getApplicationData(taskId);
2015
+ this.formStore.applicationData = applicationData;
2016
+ this.additionalInsuranceTerms =
2017
+ this.formStore.applicationData.addCoverDto;
2018
+ if (
2019
+ this.formStore.productConditionsForm.insurancePremiumPerMonth !=
2020
+ null
2021
+ ) {
2022
+ this.formStore.productConditionsForm.requestedSumInsured =
2023
+ this.getNumberWithSpaces(result);
2024
+ } else {
2025
+ this.formStore.productConditionsForm.insurancePremiumPerMonth =
2026
+ this.getNumberWithSpaces(result);
2027
+ }
2028
+ this.showToaster('success', this.t('toaster.calculated'), 1000);
2029
+ } catch (err) {
2030
+ console.log(err);
2031
+ }
2032
+ } catch (err) {
2033
+ this.showToaster('error', this.t('toaster.undefinedError'), 5000);
2034
+ console.log(err, 'error');
2035
+ }
2036
+ this.isLoading = false;
2037
+ },
2038
+ async startApplication(whichForm) {
2039
+ try {
2040
+ const data = {
2041
+ clientId: this.formStore[whichForm].id,
2042
+ iin: this.formStore[whichForm].iin.replace(/-/g, ''),
2043
+ longName: this.formStore[whichForm].longName,
2044
+ processCode: this.processCode,
2045
+ policyId: 0,
2046
+ };
2047
+ const response = await this.api.startApplication(data);
2048
+ this.sendToParent(
2049
+ constants.postActions.applicationCreated,
2050
+ response.processInstanceId,
2051
+ );
2052
+ return response.processInstanceId;
2053
+ } catch (err) {
2054
+ console.log(err);
2055
+ if ('response' in err && err.response.data) {
2056
+ this.showToaster('error', err.response.data, 0);
2057
+ }
2058
+ return null;
2059
+ }
2060
+ },
2061
+ async getApplicationData(
2062
+ taskId,
2063
+ onlyGet = true,
2064
+ setMembersField = true,
2065
+ fetchMembers = true,
2066
+ setProductConditions = true,
2067
+ ) {
2068
+ if (onlyGet) {
2069
+ this.isLoading = true;
2070
+ }
2071
+ try {
2072
+ const applicationData = await this.api.getApplicationData(taskId);
2073
+ if (this.processCode !== applicationData.processCode) {
2074
+ this.isLoading = false;
2075
+ this.sendToParent(
2076
+ constants.postActions.toHomePage,
2077
+ this.t('toaster.noSuchProduct'),
2078
+ );
2079
+ return;
2080
+ }
2081
+ this.formStore.applicationData = applicationData;
2082
+ this.additionalInsuranceTerms = applicationData.addCoverDto;
2083
+
2084
+ this.formStore.canBeClaimed = await this.api.isClaimTask(taskId);
2085
+ this.formStore.applicationTaskId = taskId;
2086
+ this.formStore.RegionPolicy.nameRu =
2087
+ applicationData.insisWorkDataApp.regionPolicyName;
2088
+ this.formStore.RegionPolicy.ids =
2089
+ applicationData.insisWorkDataApp.regionPolicy;
2090
+ this.formStore.ManagerPolicy.nameRu =
2091
+ applicationData.insisWorkDataApp.managerPolicyName;
2092
+ this.formStore.ManagerPolicy.ids =
2093
+ applicationData.insisWorkDataApp.managerPolicy;
2094
+ this.formStore.SaleChanellPolicy.nameRu =
2095
+ applicationData.insisWorkDataApp.saleChanellPolicyName;
2096
+ this.formStore.SaleChanellPolicy.ids =
2097
+ applicationData.insisWorkDataApp.saleChanellPolicy;
2098
+
2099
+ this.formStore.AgentData.fullName =
2100
+ applicationData.insisWorkDataApp.agentName;
2101
+ this.formStore.AgentData.agentId =
2102
+ applicationData.insisWorkDataApp.agentId;
2103
+
2104
+ const clientData = applicationData.clientApp;
2105
+ const insuredData = applicationData.insuredApp;
2106
+ const spokesmanData = applicationData.spokesmanApp;
2107
+ const beneficiaryData = applicationData.beneficiaryApp;
2108
+ const beneficialOwnerData = applicationData.beneficialOwnerApp;
2109
+
2110
+ this.formStore.isPolicyholderInsured = clientData.isInsured;
2111
+ this.formStore.isActOwnBehalf = clientData.isActOwnBehalf;
2112
+ this.formStore.hasRepresentative = !!applicationData.spokesmanApp;
2113
+
2114
+ const beneficiaryPolicyholderIndex = beneficiaryData.findIndex(
2115
+ i => i.insisId === clientData.insisId,
2116
+ );
2117
+ this.formStore.isPolicyholderBeneficiary =
2118
+ beneficiaryPolicyholderIndex !== -1;
2119
+
2120
+ if (fetchMembers) {
2121
+ let allMembers = [
2122
+ {
2123
+ ...clientData,
2124
+ key: this.formStore.policyholderFormKey,
2125
+ index: null,
2126
+ },
2127
+ ];
2128
+
2129
+ if (spokesmanData) {
2130
+ allMembers.push({
2131
+ ...spokesmanData,
2132
+ key: this.formStore.policyholdersRepresentativeFormKey,
2133
+ index: null,
2134
+ });
2135
+ }
2136
+
2137
+ if (insuredData && insuredData.length) {
2138
+ insuredData.forEach((member, index) => {
2139
+ const inStore = this.formStore.insuredForm.find(
2140
+ each => each.id == member.insisId,
2141
+ );
2142
+ if (!inStore) {
2143
+ member.key = this.formStore.insuredFormKey;
2144
+ member.index = index;
2145
+ allMembers.push(member);
2146
+ if (this.formStore.insuredForm.length - 1 < index) {
2147
+ this.formStore.insuredForm.push(new InsuredForm());
2148
+ }
2149
+ }
2150
+ });
2151
+ }
2152
+ if (beneficiaryData && beneficiaryData.length) {
2153
+ beneficiaryData.forEach((member, index) => {
2154
+ const inStore = this.formStore.beneficiaryForm.find(
2155
+ each => each.id == member.insisId,
2156
+ );
2157
+ if (!inStore) {
2158
+ member.key = this.formStore.beneficiaryFormKey;
2159
+ member.index = index;
2160
+ allMembers.push(member);
2161
+ if (this.formStore.beneficiaryForm.length - 1 < index) {
2162
+ this.formStore.beneficiaryForm.push(new BeneficiaryForm());
2163
+ }
2164
+ }
2165
+ });
2166
+ }
2167
+ if (beneficialOwnerData && beneficialOwnerData.length) {
2168
+ beneficialOwnerData.forEach((member, index) => {
2169
+ const inStore = this.formStore.beneficialOwnerForm.find(
2170
+ each => each.id == member.insisId,
2171
+ );
2172
+ if (!inStore) {
2173
+ member.key = this.formStore.beneficialOwnerFormKey;
2174
+ member.index = index;
2175
+ allMembers.push(member);
2176
+ if (this.formStore.beneficialOwnerForm.length - 1 < index) {
2177
+ this.formStore.beneficialOwnerForm.push(
2178
+ new BeneficialOwnerForm(),
2179
+ );
2180
+ }
2181
+ }
2182
+ });
2183
+ }
2184
+
2185
+ await Promise.allSettled(
2186
+ allMembers.map(async member => {
2187
+ await this.getContragentById(
2188
+ member.insisId,
2189
+ member.key,
2190
+ false,
2191
+ member.index,
2192
+ );
2193
+ }),
2194
+ );
2195
+ }
2196
+
2197
+ if (setMembersField) {
2198
+ this.setMembersField(this.formStore.policyholderFormKey, 'clientApp');
2199
+ if (insuredData && insuredData.length) {
2200
+ insuredData.forEach((each, index) => {
2201
+ this.setMembersFieldIndex(
2202
+ this.formStore.insuredFormKey,
2203
+ 'insuredApp',
2204
+ index,
2205
+ );
2206
+ });
2207
+ }
2208
+
2209
+ if (beneficiaryData && beneficiaryData.length) {
2210
+ beneficiaryData.forEach((each, index) => {
2211
+ this.setMembersFieldIndex(
2212
+ this.formStore.beneficiaryFormKey,
2213
+ 'beneficiaryApp',
2214
+ index,
2215
+ );
2216
+ const relationDegree = this.relations.find(
2217
+ i => i.ids == each.relationId,
2218
+ );
2219
+ this.formStore.beneficiaryForm[index].relationDegree =
2220
+ relationDegree ? relationDegree : new Value();
2221
+ this.formStore.beneficiaryForm[index].percentageOfPayoutAmount =
2222
+ each.percentage;
2223
+ });
2224
+ }
2225
+
2226
+ if (beneficialOwnerData && beneficialOwnerData.length) {
2227
+ beneficialOwnerData.forEach((each, index) => {
2228
+ this.setMembersFieldIndex(
2229
+ this.formStore.beneficialOwnerFormKey,
2230
+ 'beneficialOwnerApp',
2231
+ index,
2232
+ );
2233
+ });
2234
+ }
2235
+
2236
+ if (!!spokesmanData) {
2237
+ this.formStore.policyholdersRepresentativeForm.signOfIPDL =
2238
+ spokesmanData.isIpdl ? this.ipdl[1] : this.ipdl[2];
2239
+ this.formStore.policyholdersRepresentativeForm.migrationCard =
2240
+ spokesmanData.migrationCard;
2241
+ this.formStore.policyholdersRepresentativeForm.migrationCardIssueDate =
2242
+ reformatDate(spokesmanData.migrationCardIssueDate);
2243
+ this.formStore.policyholdersRepresentativeForm.migrationCardExpireDate =
2244
+ reformatDate(spokesmanData.migrationCardExpireDate);
2245
+ this.formStore.policyholdersRepresentativeForm.confirmDocType =
2246
+ spokesmanData.confirmDocType;
2247
+ this.formStore.policyholdersRepresentativeForm.confirmDocNumber =
2248
+ spokesmanData.confirmDocNumber;
2249
+ this.formStore.policyholdersRepresentativeForm.confirmDocIssueDate =
2250
+ reformatDate(spokesmanData.confirmDocIssueDate);
2251
+ this.formStore.policyholdersRepresentativeForm.confirmDocExpireDate =
2252
+ reformatDate(spokesmanData.confirmDocExpireDate);
2253
+ this.formStore.policyholdersRepresentativeForm.notaryLongName =
2254
+ spokesmanData.notaryLongName;
2255
+ this.formStore.policyholdersRepresentativeForm.notaryLicenseNumber =
2256
+ spokesmanData.notaryLicenseNumber;
2257
+ this.formStore.policyholdersRepresentativeForm.notaryLicenseDate =
2258
+ reformatDate(spokesmanData.notaryLicenseDate);
2259
+ this.formStore.policyholdersRepresentativeForm.notaryLicenseIssuer =
2260
+ spokesmanData.notaryLicenseIssuer;
2261
+ this.formStore.policyholdersRepresentativeForm.jurLongName =
2262
+ spokesmanData.jurLongName;
2263
+ this.formStore.policyholdersRepresentativeForm.fullNameRod =
2264
+ spokesmanData.fullNameRod;
2265
+ this.formStore.policyholdersRepresentativeForm.confirmDocTypeKz =
2266
+ spokesmanData.confirmDocTypeKz;
2267
+ this.formStore.policyholdersRepresentativeForm.confirmDocTypeRod =
2268
+ spokesmanData.confirmDocTypeRod;
2269
+ this.formStore.policyholdersRepresentativeForm.isNotary =
2270
+ spokesmanData.isNotary;
2271
+ }
2272
+ }
2273
+ if (setProductConditions) {
2274
+ this.formStore.productConditionsForm.coverPeriod =
2275
+ applicationData.policyAppDto.coverPeriod;
2276
+ this.formStore.productConditionsForm.payPeriod =
2277
+ applicationData.policyAppDto.payPeriod;
2278
+ // this.formStore.productConditionsForm.annualIncome = applicationData.policyAppDto.annualIncome?.toString();
2279
+ this.formStore.productConditionsForm.lifeMultiply = parseProcents(
2280
+ applicationData.policyAppDto.lifeMultiply,
2281
+ );
2282
+ this.formStore.productConditionsForm.lifeAdditive = parseProcents(
2283
+ applicationData.policyAppDto.lifeAdditive,
2284
+ );
2285
+ this.formStore.productConditionsForm.adbMultiply = parseProcents(
2286
+ applicationData.policyAppDto.adbMultiply,
2287
+ );
2288
+ this.formStore.productConditionsForm.adbAdditive = parseProcents(
2289
+ applicationData.policyAppDto.adbAdditive,
2290
+ );
2291
+ this.formStore.productConditionsForm.disabilityMultiply =
2292
+ parseProcents(applicationData.policyAppDto.disabilityMultiply);
2293
+ this.formStore.productConditionsForm.disabilityAdditive =
2294
+ parseProcents(applicationData.policyAppDto.disabilityAdditive);
2295
+
2296
+ let processIndexRate = this.processIndexRate.find(
2297
+ item => item.id == applicationData.policyAppDto.indexRateId,
2298
+ );
2299
+ this.formStore.productConditionsForm.processIndexRate =
2300
+ processIndexRate
2301
+ ? processIndexRate
2302
+ : this.processIndexRate.find(item => item.code === '0');
2303
+
2304
+ let paymentPeriod = this.processPaymentPeriod.find(
2305
+ item => item.id == applicationData.policyAppDto.paymentPeriodId,
2306
+ );
2307
+ this.formStore.productConditionsForm.paymentPeriod = paymentPeriod
2308
+ ? paymentPeriod
2309
+ : new Value();
2310
+
2311
+ this.formStore.productConditionsForm.requestedSumInsured =
2312
+ this.getNumberWithSpaces(
2313
+ applicationData.policyAppDto.amount === null
2314
+ ? null
2315
+ : applicationData.policyAppDto.amount,
2316
+ );
2317
+ this.formStore.productConditionsForm.insurancePremiumPerMonth =
2318
+ this.getNumberWithSpaces(
2319
+ applicationData.policyAppDto.premium === null
2320
+ ? null
2321
+ : applicationData.policyAppDto.premium,
2322
+ );
2323
+
2324
+ let riskGroup = this.riskGroup.find(item => {
2325
+ if (applicationData.policyAppDto.riskGroup == 0) {
2326
+ return true;
2327
+ }
2328
+ return item.id == applicationData.policyAppDto.riskGroup;
2329
+ });
2330
+ this.formStore.productConditionsForm.riskGroup = riskGroup
2331
+ ? riskGroup
2332
+ : this.riskGroup.find(item => item.id == 1);
2333
+ }
2334
+ } catch (err) {
2335
+ console.log(err);
2336
+ if ('response' in err) {
2337
+ this.sendToParent(
2338
+ constants.postActions.toHomePage,
2339
+ err.response.data,
2340
+ );
2341
+ this.isLoading = false;
2342
+ return false;
2343
+ }
2344
+ }
2345
+ if (onlyGet) {
2346
+ this.isLoading = false;
2347
+ }
2348
+ },
2349
+ async setApplication() {
2350
+ try {
2351
+ await this.api.setApplication(this.formStore.applicationData);
2352
+ } catch (err) {
2353
+ console.log(err);
2354
+ }
2355
+ },
2356
+ async deleteTask(taskId) {
2357
+ this.isLoading = true;
2358
+ try {
2359
+ const data = {
2360
+ taskId: taskId,
2361
+ decision: 'rejectclient',
2362
+ comment: 'Клиент отказался',
2363
+ };
2364
+ await this.api.sendTask(data);
2365
+ this.showToaster('success', this.t('toaster.applicationDeleted'), 2000);
2366
+ } catch (err) {
2367
+ if ('response' in err && err.response.data) {
2368
+ this.showToaster(
2369
+ 'error',
2370
+ this.t('toaster.error') + err.response.data,
2371
+ 2000,
2372
+ );
2373
+ }
2374
+ console.log(err);
2375
+ }
2376
+ this.isLoading = false;
2377
+ },
2378
+ async sendTask(taskId, decision, comment = null) {
2379
+ this.isLoading = true;
2380
+ try {
2381
+ const data = {
2382
+ taskId: taskId,
2383
+ decision: decision,
2384
+ };
2385
+ await this.api.sendTask(
2386
+ comment === null ? data : { ...data, comment: comment },
2387
+ );
2388
+ this.showToaster('success', this.t('toaster.successOperation'), 3000);
2389
+ this.isLoading = false;
2390
+ return true;
2391
+ } catch (err) {
2392
+ console.log(err);
2393
+ if ('response' in err && err.response.data) {
2394
+ this.showToaster(
2395
+ 'error',
2396
+ this.t('toaster.error') + err.response.data,
2397
+ 2000,
2398
+ );
2399
+ }
2400
+ this.isLoading = false;
2401
+ return false;
2402
+ }
2403
+ },
2404
+ async getInvoiceData(processInstanceId) {
2405
+ try {
2406
+ const response = await this.api.getInvoiceData(processInstanceId);
2407
+ if (response) {
2408
+ return response;
2409
+ } else {
2410
+ return false;
2411
+ }
2412
+ } catch (err) {
2413
+ return false;
2414
+ }
2415
+ },
2416
+ async createInvoice() {
2417
+ try {
2418
+ const created = await this.api.createInvoice(
2419
+ this.formStore.applicationData.processInstanceId,
2420
+ this.formStore.applicationData.policyAppDto.premium,
2421
+ );
2422
+ return !!created;
2423
+ } catch (err) {
2424
+ this.isLoading = false;
2425
+ }
2426
+ },
2427
+ async sendToEpay() {
2428
+ try {
2429
+ const response = await this.api.sendToEpay(
2430
+ this.formStore.applicationData.processInstanceId,
2431
+ );
2432
+ if (response) {
2433
+ return response;
2434
+ }
2435
+ } catch (err) {
2436
+ console.log(err);
2437
+ }
2438
+ },
2439
+ setMembersField(whichForm, whichMember) {
2440
+ this.formStore[whichForm].familyStatus = this.findObject(
2441
+ 'familyStatuses',
2442
+ 'id',
2443
+ this.formStore.applicationData[whichMember].familyStatusId,
2444
+ );
2445
+ this.formStore[whichForm].signOfIPDL = this.findObject(
2446
+ 'ipdl',
2447
+ 'nameRu',
2448
+ this.formStore.applicationData[whichMember].isIpdl === null
2449
+ ? null
2450
+ : this.formStore.applicationData[whichMember].isIpdl == true
2451
+ ? 'Да'
2452
+ : 'Нет',
2453
+ );
2454
+ if (!!this.formStore.applicationData[whichMember].profession)
2455
+ this.formStore[whichForm].job =
2456
+ this.formStore.applicationData[whichMember].profession;
2457
+ if (!!this.formStore.applicationData[whichMember].position)
2458
+ this.formStore[whichForm].jobPosition =
2459
+ this.formStore.applicationData[whichMember].position;
2460
+ if (!!this.formStore.applicationData[whichMember].jobName)
2461
+ this.formStore[whichForm].jobPlace =
2462
+ this.formStore.applicationData[whichMember].jobName;
2463
+ },
2464
+ setMembersFieldIndex(whichForm, whichMember, index) {
2465
+ if ('familyStatus' in this.formStore[whichForm][index]) {
2466
+ this.formStore[whichForm][index].familyStatus = this.findObject(
2467
+ 'familyStatuses',
2468
+ 'id',
2469
+ this.formStore.applicationData[whichMember][index].familyStatusId,
2470
+ );
2471
+ }
2472
+ if ('signOfIPDL' in this.formStore[whichForm][index]) {
2473
+ this.formStore[whichForm][index].signOfIPDL = this.findObject(
2474
+ 'ipdl',
2475
+ 'nameRu',
2476
+ this.formStore.applicationData[whichMember][index].isIpdl === null
2477
+ ? null
2478
+ : this.formStore.applicationData[whichMember][index].isIpdl == true
2479
+ ? 'Да'
2480
+ : 'Нет',
2481
+ );
2482
+ }
2483
+ if (
2484
+ 'job' in this.formStore[whichForm][index] &&
2485
+ !!this.formStore.applicationData[whichMember][index].profession
2486
+ ) {
2487
+ this.formStore[whichForm][index].job =
2488
+ this.formStore.applicationData[whichMember][index].profession;
2489
+ }
2490
+ if (
2491
+ 'jobPosition' in this.formStore[whichForm][index] &&
2492
+ !!this.formStore.applicationData[whichMember][index].position
2493
+ ) {
2494
+ this.formStore[whichForm][index].jobPosition =
2495
+ this.formStore.applicationData[whichMember][index].position;
2496
+ }
2497
+ if (
2498
+ 'jobPlace' in this.formStore[whichForm][index] &&
2499
+ !!this.formStore.applicationData[whichMember][index].jobName
2500
+ ) {
2501
+ this.formStore[whichForm][index].jobPlace =
2502
+ this.formStore.applicationData[whichMember][index].jobName;
2503
+ }
2504
+ },
2505
+ findObject(from, key, searchKey) {
2506
+ const found = this[from].find(i => i[key] == searchKey);
2507
+ return found || new Value();
2508
+ },
2509
+ async signToDocument(data) {
2510
+ try {
2511
+ if (this.signUrl) {
2512
+ return this.signUrl;
2513
+ }
2514
+ const result = await this.api.signToDocument(data);
2515
+ this.signUrl = result.uri;
2516
+ return this.signUrl;
2517
+ } catch (error) {
2518
+ this.showToaster(
2519
+ 'error',
2520
+ this.t('toaster.error') + error?.response?.data,
2521
+ 2000,
2522
+ );
2523
+ }
2524
+ },
2525
+ sanitize(text) {
2526
+ if (text) {
2527
+ return text
2528
+ .replace(/\r?\n|\r/g, '')
2529
+ .replace(/\\/g, '')
2530
+ .replace(/"/g, '');
2531
+ }
2532
+ },
2533
+ async getSignedDocList(processInstanceId) {
2534
+ if (processInstanceId !== 0) {
2535
+ try {
2536
+ this.signedDocumentList = await this.api.getSignedDocList({
2537
+ processInstanceId: processInstanceId,
2538
+ });
2539
+ } catch (err) {
2540
+ console.log(err);
2541
+ }
2542
+ }
2543
+ },
2544
+ setFormsDisabled(isDisabled) {
2545
+ Object.keys(this.formStore.isDisabled).forEach(key => {
2546
+ this.formStore.isDisabled[key] = !!isDisabled;
2547
+ });
2548
+ },
2549
+ async reCalculate(processInstanceId, recalculationData, taskId, whichSum) {
2550
+ this.isLoading = true;
2551
+ try {
2552
+ const data = {
2553
+ processInstanceId: processInstanceId,
2554
+ ...recalculationData,
2555
+ };
2556
+ const recalculatedValue = await this.api.reCalculate(data);
2557
+ if (!!recalculatedValue) {
2558
+ await this.getApplicationData(taskId, false, false, false);
2559
+ this.showToaster(
2560
+ 'success',
2561
+ `${this.t('toaster.successRecalculation')}. ${
2562
+ whichSum == 'insurancePremiumPerMonth'
2563
+ ? 'Страховая премия'
2564
+ : 'Страховая сумма'
2565
+ }: ${this.getNumberWithSpaces(recalculatedValue)}₸`,
2566
+ 4000,
2567
+ );
2568
+ } else {
2569
+ this.showToaster('error', this.t('toaster.undefinedError'), 2000);
2570
+ }
2571
+ } catch (err) {
2572
+ console.log(err);
2573
+ if ('response' in err) {
2574
+ this.showToaster('error', err?.response?.data, 5000);
2575
+ } else {
2576
+ this.showToaster('error', err, 5000);
2577
+ }
2578
+ }
2579
+ this.isLoading = false;
2580
+ },
2581
+ async getValidateClientESBD(data) {
2582
+ try {
2583
+ return await this.api.getValidateClientESBD(data);
2584
+ } catch (error) {
2585
+ this.isLoading = false;
2586
+ if ('response' in error && error.response.data) {
2587
+ this.showToaster('error', error.response.data, 5000);
2588
+ }
2589
+ console.log(error);
2590
+ return false;
2591
+ }
2592
+ },
2593
+ validateMultipleMembers(localKey, applicationKey, text) {
2594
+ if (
2595
+ this.formStore[localKey].length ===
2596
+ this.formStore.applicationData[applicationKey].length
2597
+ ) {
2598
+ if (
2599
+ this.formStore[localKey].length !== 0 &&
2600
+ this.formStore.applicationData[applicationKey].length !== 0
2601
+ ) {
2602
+ const localMembers = [...this.formStore[localKey]].sort(
2603
+ (a, b) => a.id - b.id,
2604
+ );
2605
+ const applicationMembers = [
2606
+ ...this.formStore.applicationData[applicationKey],
2607
+ ].sort((a, b) => a.insisId - b.insisId);
2608
+ if (
2609
+ localMembers.every(
2610
+ (each, index) =>
2611
+ applicationMembers[index].insisId === each.id &&
2612
+ applicationMembers[index].iin === each.iin.replace(/-/g, ''),
2613
+ ) === false
2614
+ ) {
2615
+ this.showToaster(
2616
+ 'error',
2617
+ this.t('toaster.notSavedMember', { text: text }),
2618
+ 3000,
2619
+ );
2620
+ return false;
2621
+ }
2622
+ if (localKey === this.formStore.beneficiaryFormKey) {
2623
+ const sumOfPercentage = localMembers.reduce((sum, member) => {
2624
+ return sum + Number(member.percentageOfPayoutAmount);
2625
+ }, 0);
2626
+ if (sumOfPercentage !== 100) {
2627
+ this.showToaster(
2628
+ 'error',
2629
+ this.t('toaster.errorSumOrPercentage'),
2630
+ 3000,
2631
+ );
2632
+ return false;
2633
+ }
2634
+ }
2635
+ }
2636
+ } else {
2637
+ if (this.formStore[localKey].some(i => i.iin !== null)) {
2638
+ this.showToaster(
2639
+ 'error',
2640
+ this.t('toaster.notSavedMember', { text: text }),
2641
+ 3000,
2642
+ );
2643
+ return false;
2644
+ }
2645
+ if (this.formStore.applicationData[applicationKey].length !== 0) {
2646
+ this.showToaster(
2647
+ 'error',
2648
+ this.t('toaster.notSavedMember', { text: text }),
2649
+ 3000,
2650
+ );
2651
+ return false;
2652
+ } else {
2653
+ if (this.formStore[localKey][0].iin !== null) {
2654
+ this.showToaster(
2655
+ 'error',
2656
+ this.t('toaster.notSavedMember', { text: text }),
2657
+ 3000,
2658
+ );
2659
+ return false;
2660
+ }
2661
+ }
2662
+ }
2663
+ return true;
2664
+ },
2665
+ async validateAllMembers(taskId, localCheck = false) {
2666
+ if (taskId == 0) {
2667
+ this.showToaster('error', this.t('toaster.needToRunStatement'), 2000);
2668
+ return false;
2669
+ }
2670
+ if (
2671
+ this.formStore.policyholderForm.id !==
2672
+ this.formStore.applicationData.clientApp.insisId
2673
+ ) {
2674
+ this.showToaster(
2675
+ 'error',
2676
+ this.t('toaster.notSavedMember', { text: 'страхователя' }),
2677
+ 3000,
2678
+ );
2679
+ return false;
2680
+ }
2681
+ if (
2682
+ this.validateMultipleMembers(
2683
+ this.formStore.insuredFormKey,
2684
+ 'insuredApp',
2685
+ 'застрахованных',
2686
+ ) === false
2687
+ ) {
2688
+ return false;
2689
+ }
2690
+ if (
2691
+ this.validateMultipleMembers(
2692
+ this.formStore.beneficiaryFormKey,
2693
+ 'beneficiaryApp',
2694
+ 'выгодоприобретателей',
2695
+ ) === false
2696
+ ) {
2697
+ return false;
2698
+ }
2699
+ if (this.formStore.isActOwnBehalf === false) {
2700
+ if (
2701
+ this.validateMultipleMembers(
2702
+ this.formStore.beneficialOwnerFormKey,
2703
+ 'beneficialOwnerApp',
2704
+ 'бенефициарных собственников',
2705
+ ) === false
2706
+ ) {
2707
+ return false;
2708
+ }
2709
+ }
2710
+ if (this.formStore.hasRepresentative) {
2711
+ if (
2712
+ this.formStore.applicationData.spokesmanApp &&
2713
+ this.formStore.policyholdersRepresentativeForm.id !==
2714
+ this.formStore.applicationData.spokesmanApp.insisId
2715
+ ) {
2716
+ this.showToaster(
2717
+ 'error',
2718
+ this.t('toaster.notSavedMember', {
2719
+ text: 'представителя страхователя',
2720
+ }),
2721
+ 3000,
2722
+ );
2723
+ return false;
2724
+ }
2725
+ }
2726
+ const areValid =
2727
+ this.formStore.SaleChanellPolicy.nameRu &&
2728
+ this.formStore.RegionPolicy.nameRu &&
2729
+ this.formStore.ManagerPolicy.nameRu &&
2730
+ this.formStore.AgentData.fullName;
2731
+ if (areValid) {
2732
+ await this.setINSISWorkData();
2733
+ } else {
2734
+ this.isLoading = false;
2735
+ this.showToaster('error', this.t('toaster.attachManagerError'), 3000);
2736
+ return false;
2737
+ }
2738
+ if (localCheck === false) {
2739
+ try {
2740
+ if (
2741
+ this.formStore.isActOwnBehalf === true &&
2742
+ this.formStore.applicationData.beneficialOwnerApp.length !== 0
2743
+ ) {
2744
+ await Promise.allSettled(
2745
+ this.formStore.applicationData.beneficialOwnerApp.map(
2746
+ async member => {
2747
+ await this.api.deleteMember('BeneficialOwner', member.id);
2748
+ },
2749
+ ),
2750
+ );
2751
+ }
2752
+ await this.getApplicationData(taskId, false);
2753
+ } catch (err) {
2754
+ console.log(err);
2755
+ this.showToaster('error', err, 5000);
2756
+ return false;
2757
+ }
2758
+ }
2759
+
2760
+ return true;
2761
+ },
2762
+ validateAnketa(whichSurvey) {
2763
+ const list = this[whichSurvey].body;
2764
+ if (!list || (list && list.length === 0)) return false;
2765
+ let notAnswered = 0;
2766
+ for (let x = 0; x < list.length; x++) {
2767
+ if (
2768
+ (list[x].first.definedAnswers === 'N' && !list[x].first.answerText) ||
2769
+ (list[x].first.definedAnswers === 'Y' && !list[x].first.answerName)
2770
+ ) {
2771
+ notAnswered = notAnswered + 1;
2772
+ }
2773
+ }
2774
+ return notAnswered === 0;
2775
+ },
2776
+ async validateAllForms(taskId) {
2777
+ this.isLoading = true;
2778
+ const areMembersValid = await this.validateAllMembers(taskId);
2779
+ if (areMembersValid) {
2780
+ if (
2781
+ !!this.formStore.productConditionsForm.insurancePremiumPerMonth &&
2782
+ !!this.formStore.productConditionsForm.requestedSumInsured
2783
+ ) {
2784
+ const hasCritical = this.additionalInsuranceTerms?.find(
2785
+ cover =>
2786
+ cover.coverTypeName === 'Критическое заболевание Застрахованного',
2787
+ );
2788
+ if (hasCritical && hasCritical.coverSumName !== 'не включено') {
2789
+ await Promise.allSettled([
2790
+ this.getQuestionList(
2791
+ 'health',
2792
+ this.formStore.applicationData.processInstanceId,
2793
+ this.formStore.applicationData.insuredApp[0].id,
2794
+ 'surveyByHealthBase',
2795
+ 'surveyByHealthSecond',
2796
+ ),
2797
+ this.getQuestionList(
2798
+ 'critical',
2799
+ this.formStore.applicationData.processInstanceId,
2800
+ this.formStore.applicationData.insuredApp[0].id,
2801
+ 'surveyByCriticalBase',
2802
+ 'surveyByCriticalSecond',
2803
+ ),
2804
+ ]);
2805
+ await Promise.allSettled([
2806
+ ...this.surveyByHealthBase.body.map(async question => {
2807
+ await this.definedAnswers(
2808
+ question.first.id,
2809
+ 'surveyByHealthBase',
2810
+ );
2811
+ }),
2812
+ ...this.surveyByCriticalBase.body.map(async question => {
2813
+ await this.definedAnswers(
2814
+ question.first.id,
2815
+ 'surveyByCriticalBase',
2816
+ );
2817
+ }),
2818
+ ]);
2819
+ } else {
2820
+ await Promise.allSettled([
2821
+ this.getQuestionList(
2822
+ 'health',
2823
+ this.formStore.applicationData.processInstanceId,
2824
+ this.formStore.applicationData.insuredApp[0].id,
2825
+ 'surveyByHealthBase',
2826
+ 'surveyByHealthSecond',
2827
+ ),
2828
+ ]);
2829
+ await Promise.allSettled(
2830
+ this.surveyByHealthBase.body.map(async question => {
2831
+ await this.definedAnswers(
2832
+ question.first.id,
2833
+ 'surveyByHealthBase',
2834
+ );
2835
+ }),
2836
+ );
2837
+ }
2838
+
2839
+ if (this.validateAnketa('surveyByHealthBase')) {
2840
+ let hasCriticalAndItsValid = null;
2841
+ if (hasCritical && hasCritical.coverSumName !== 'не включено') {
2842
+ if (this.validateAnketa('surveyByCriticalBase')) {
2843
+ hasCriticalAndItsValid = true;
2844
+ } else {
2845
+ hasCriticalAndItsValid = false;
2846
+ this.showToaster(
2847
+ 'error',
2848
+ this.t('toaster.emptyCriticalAnketa'),
2849
+ 3000,
2850
+ );
2851
+ }
2852
+ } else {
2853
+ hasCriticalAndItsValid = null;
2854
+ }
2855
+ if (
2856
+ hasCriticalAndItsValid === true ||
2857
+ hasCriticalAndItsValid === null
2858
+ ) {
2859
+ this.isLoading = false;
2860
+ return true;
2861
+ }
2862
+ } else {
2863
+ this.showToaster(
2864
+ 'error',
2865
+ this.t('toaster.emptyHealthAnketa'),
2866
+ 3000,
2867
+ );
2868
+ }
2869
+ } else {
2870
+ this.showToaster(
2871
+ 'error',
2872
+ this.t('toaster.emptyProductConditions'),
2873
+ 3000,
2874
+ );
2875
+ }
2876
+ return false;
2877
+ }
2878
+ this.isLoading = false;
2879
+ return false;
2880
+ },
2881
+ async getContragentFromGBDFL(
2882
+ iin,
2883
+ phoneNumber,
2884
+ whichForm,
2885
+ whichIndex = null,
2886
+ ) {
2887
+ this.isLoading = true;
2888
+ try {
2889
+ const data = {
2890
+ iin: iin.replace(/-/g, ''),
2891
+ phoneNumber: formatPhone(phoneNumber),
2892
+ };
2893
+ const gbdResponse = await this.api.getContragentFromGBDFL(data);
2894
+ if (gbdResponse.status === 'PENDING') {
2895
+ this.showToaster('success', this.t('toaster.waitForClient'), 5000);
2896
+ this.isLoading = false;
2897
+ return;
2898
+ }
2899
+ if (constants.gbdErrors.find(i => i === gbdResponse.status)) {
2900
+ if (gbdResponse.status === 'TIMEOUT') {
2901
+ this.showToaster(
2902
+ 'success',
2903
+ `${gbdResponse.statusName}. Отправьте запрос еще раз`,
2904
+ 5000,
2905
+ );
2906
+ } else {
2907
+ this.showToaster('success', gbdResponse.statusName, 5000);
2908
+ }
2909
+ this.isLoading = false;
2910
+ return;
2911
+ }
2912
+ const { person } = parseXML(gbdResponse.content, true, 'person');
2913
+ const { responseInfo } = parseXML(
2914
+ gbdResponse.content,
2915
+ true,
2916
+ 'responseInfo',
2917
+ );
2918
+ if (whichIndex === null) {
2919
+ if (
2920
+ this.formStore[whichForm].gosPersonData !== null &&
2921
+ this.formStore[whichForm].gosPersonData.iin !==
2922
+ iin.replace(/-/g, '')
2923
+ ) {
2924
+ if (
2925
+ whichForm === this.formStore.policyholdersRepresentativeFormKey
2926
+ ) {
2927
+ this.formStore[whichForm].resetMember(false);
2928
+ } else {
2929
+ this.formStore[whichForm].resetForm(false);
2930
+ }
2931
+ }
2932
+ this.formStore[whichForm].gosPersonData = person;
2933
+ } else {
2934
+ if (
2935
+ this.formStore[whichForm][whichIndex].gosPersonData !== null &&
2936
+ this.formStore[whichForm][whichIndex].gosPersonData.iin !==
2937
+ iin.replace(/-/g, '')
2938
+ ) {
2939
+ this.formStore[whichForm][whichIndex].resetForm(false);
2940
+ }
2941
+ this.formStore[whichForm][whichIndex].gosPersonData = person;
2942
+ }
2943
+
2944
+ await this.getContragent(whichForm, whichIndex, false);
2945
+ if (whichIndex === null) {
2946
+ this.formStore[whichForm].verifyDate = responseInfo.responseDate;
2947
+ this.formStore[whichForm].verifyType = 'GBDFL';
2948
+ } else {
2949
+ this.formStore[whichForm][whichIndex].verifyDate =
2950
+ responseInfo.responseDate;
2951
+ this.formStore[whichForm][whichIndex].verifyType = 'GBDFL';
2952
+ }
2953
+ await this.saveInStoreUserGBDFL(person, whichForm, whichIndex);
2954
+ } catch (err) {
2955
+ console.log(err);
2956
+ if ('response' in err) {
2957
+ this.showToaster('error', err.response.data, 3000);
2958
+ }
2959
+ }
2960
+ this.isLoading = false;
2961
+ },
2962
+ async saveInStoreUserGBDFL(person, whichForm, whichIndex = null) {
2963
+ if (whichIndex === null) {
2964
+ this.formStore[whichForm].firstName = person.name;
2965
+ this.formStore[whichForm].lastName = person.surname;
2966
+ this.formStore[whichForm].middleName = person.patronymic
2967
+ ? person.patronymic
2968
+ : '';
2969
+ this.formStore[whichForm].longName = `${person.surname} ${
2970
+ person.name
2971
+ } ${person.patronymic ? person.patronymic : ''}`;
2972
+ this.formStore[whichForm].birthDate = reformatDate(person.birthDate);
2973
+ this.formStore[whichForm].genderName = person.gender.nameRu;
2974
+
2975
+ const gender = this.gender.find(i => i.id == person.gender.code);
2976
+ if (gender) this.formStore[whichForm].gender = gender;
2977
+
2978
+ const birthPlace = this.countries.find(i =>
2979
+ i.nameRu.match(new RegExp(person.birthPlace.country.nameRu, 'i')),
2980
+ );
2981
+ if (birthPlace) this.formStore[whichForm].birthPlace = birthPlace;
2982
+
2983
+ const countryOfCitizenship = this.citizenshipCountries.find(i =>
2984
+ i.nameRu.match(new RegExp(person.citizenship.nameRu, 'i')),
2985
+ );
2986
+ if (countryOfCitizenship)
2987
+ this.formStore[whichForm].countryOfCitizenship = countryOfCitizenship;
2988
+
2989
+ const regCountry = this.countries.find(i =>
2990
+ i.nameRu.match(new RegExp(person.regAddress.country.nameRu, 'i')),
2991
+ );
2992
+ if (regCountry)
2993
+ this.formStore[whichForm].registrationCountry = regCountry;
2994
+
2995
+ const regProvince = this.states.find(i =>
2996
+ i.nameRu.match(new RegExp(person.regAddress.district.nameRu, 'i')),
2997
+ );
2998
+ if (regProvince)
2999
+ this.formStore[whichForm].registrationProvince = regProvince;
3000
+
3001
+ if ('city' in person.regAddress && !!person.regAddress.city) {
3002
+ if (person.regAddress.city.includes(', ')) {
3003
+ const personCities = person.regAddress.city.split(', ');
3004
+ for (let i = 0; i < personCities.length; ++i) {
3005
+ const possibleCity = this.cities.find(i =>
3006
+ i.nameRu.includes(personCities[i]),
3007
+ );
3008
+ if (possibleCity) {
3009
+ this.formStore[whichForm].registrationCity = possibleCity;
3010
+ break;
3011
+ }
3012
+ }
3013
+ if (this.formStore[whichForm].registrationCity.nameRu === null) {
3014
+ for (let i = 0; i < personCities.length; ++i) {
3015
+ const possibleRegion = this.regions.find(i =>
3016
+ i.nameRu.includes(personCities[i]),
3017
+ );
3018
+ if (possibleRegion) {
3019
+ this.formStore[whichForm].registrationRegion = possibleRegion;
3020
+ break;
3021
+ }
3022
+ }
3023
+ }
3024
+ } else {
3025
+ const regCity = this.cities.find(i =>
3026
+ i.nameRu.match(new RegExp(person.regAddress.city, 'i')),
3027
+ );
3028
+ if (regCity) this.formStore[whichForm].registrationCity = regCity;
3029
+
3030
+ if (this.formStore[whichForm].registrationCity.nameRu === null) {
3031
+ const regRegion = this.regions.find(i =>
3032
+ i.nameRu.match(new RegExp(person.regAddress.city), 'i'),
3033
+ );
3034
+ if (regRegion)
3035
+ this.formStore[whichForm].registrationRegion = regRegion;
3036
+ }
3037
+ }
3038
+ }
3039
+
3040
+ if (
3041
+ this.formStore[whichForm].registrationCity.nameRu === null &&
3042
+ this.formStore[whichForm].registrationRegion.nameRu === null
3043
+ ) {
3044
+ const regCity = this.cities.find(
3045
+ i =>
3046
+ i.nameRu.match(
3047
+ new RegExp(person.regAddress.region.nameRu, 'i'),
3048
+ ) ||
3049
+ i.nameRu.match(
3050
+ new RegExp(person.regAddress.district.nameRu, 'i'),
3051
+ ),
3052
+ );
3053
+ if (regCity) {
3054
+ this.formStore[whichForm].registrationCity = regCity;
3055
+ const regType = this.localityTypes.find(i => i.nameRu === 'город');
3056
+ if (regType)
3057
+ this.formStore[whichForm].registrationRegionType = regType;
3058
+ } else {
3059
+ const regRegion = this.regions.find(
3060
+ i =>
3061
+ i.nameRu.match(
3062
+ new RegExp(person.regAddress.region.nameRu),
3063
+ 'i',
3064
+ ) ||
3065
+ i.nameRu.match(
3066
+ new RegExp(person.regAddress.district.nameRu, 'i'),
3067
+ ),
3068
+ );
3069
+ if (regRegion) {
3070
+ this.formStore[whichForm].registrationRegion = regRegion;
3071
+ const regType = this.localityTypes.find(
3072
+ i =>
3073
+ (i.nameRu === i.nameRu) === 'село' || i.nameRu === 'поселок',
3074
+ );
3075
+ if (regType)
3076
+ this.formStore[whichForm].registrationRegionType = regType;
3077
+ }
3078
+ }
3079
+ }
3080
+
3081
+ if (person.regAddress.street.includes(', ')) {
3082
+ const personAddress = person.regAddress.street.split(', ');
3083
+ const microDistrict = personAddress.find(i =>
3084
+ i.match(new RegExp('микрорайон', 'i')),
3085
+ );
3086
+ const quarter = personAddress.find(i =>
3087
+ i.match(new RegExp('квартал', 'i')),
3088
+ );
3089
+ const street = personAddress.find(i =>
3090
+ i.match(new RegExp('улица', 'i')),
3091
+ );
3092
+ if (microDistrict)
3093
+ this.formStore[whichForm].registrationMicroDistrict = microDistrict;
3094
+ if (quarter) this.formStore[whichForm].registrationQuarter = quarter;
3095
+ if (street) this.formStore[whichForm].registrationStreet = street;
3096
+ } else {
3097
+ if (person.regAddress.street)
3098
+ this.formStore[whichForm].registrationStreet =
3099
+ person.regAddress.street;
3100
+ }
3101
+ if (person.regAddress.building)
3102
+ this.formStore[whichForm].registrationNumberHouse =
3103
+ person.regAddress.building;
3104
+ if (person.regAddress.flat)
3105
+ this.formStore[whichForm].registrationNumberApartment =
3106
+ person.regAddress.flat;
3107
+
3108
+ // TODO Доработать логику и для остальных
3109
+ if ('length' in person.documents.document) {
3110
+ const validDocument = person.documents.document.find(
3111
+ i =>
3112
+ new Date(i.endDate) > new Date(Date.now()) &&
3113
+ i.status.code === '00' &&
3114
+ i.type.code === '002',
3115
+ );
3116
+ if (validDocument) {
3117
+ const documentType = this.documentTypes.find(i => i.ids === '1UDL');
3118
+ if (documentType)
3119
+ this.formStore[whichForm].documentType = documentType;
3120
+
3121
+ this.formStore[whichForm].documentNumber = validDocument.number;
3122
+ this.formStore[whichForm].documentExpire = reformatDate(
3123
+ validDocument.endDate,
3124
+ );
3125
+ this.formStore[whichForm].documentDate = reformatDate(
3126
+ validDocument.beginDate,
3127
+ );
3128
+ this.formStore[whichForm].documentNumber = validDocument.number;
3129
+
3130
+ const documentIssuer = this.documentIssuers.find(i =>
3131
+ i.nameRu.match(new RegExp('МВД РК', 'i')),
3132
+ );
3133
+ if (documentIssuer)
3134
+ this.formStore[whichForm].documentIssuers = documentIssuer;
3135
+ }
3136
+ } else {
3137
+ const documentType =
3138
+ person.documents.document.type.nameRu === 'УДОСТОВЕРЕНИЕ РК'
3139
+ ? this.documentTypes.find(i => i.ids === '1UDL')
3140
+ : this.documentTypes.find(i =>
3141
+ i.nameRu.match(
3142
+ new RegExp(person.documents.document.type.nameRu, 'i'),
3143
+ ),
3144
+ )
3145
+ ? this.documentTypes.find(i =>
3146
+ i.nameRu.match(
3147
+ new RegExp(person.documents.document.type.nameRu, 'i'),
3148
+ ),
3149
+ )
3150
+ : new Value();
3151
+ if (documentType)
3152
+ this.formStore[whichForm].documentType = documentType;
3153
+
3154
+ const documentNumber = person.documents.document.number;
3155
+ if (documentNumber)
3156
+ this.formStore[whichForm].documentNumber = documentNumber;
3157
+
3158
+ const documentDate = person.documents.document.beginDate;
3159
+ if (documentDate)
3160
+ this.formStore[whichForm].documentDate = reformatDate(documentDate);
3161
+
3162
+ const documentExpire = person.documents.document.endDate;
3163
+ if (documentExpire)
3164
+ this.formStore[whichForm].documentExpire =
3165
+ reformatDate(documentExpire);
3166
+
3167
+ // TODO уточнить
3168
+ const documentIssuer = this.documentIssuers.find(i =>
3169
+ i.nameRu.match(new RegExp('МВД РК', 'i')),
3170
+ );
3171
+ if (documentIssuer)
3172
+ this.formStore[whichForm].documentIssuers = documentIssuer;
3173
+ }
3174
+ const economySectorCode = this.economySectorCode.find(
3175
+ i => i.ids === '500003.9',
3176
+ );
3177
+ if (economySectorCode)
3178
+ this.formStore[whichForm].economySectorCode = economySectorCode;
3179
+ } else {
3180
+ this.formStore[whichForm][whichIndex].firstName = person.name;
3181
+ this.formStore[whichForm][whichIndex].lastName = person.surname;
3182
+ this.formStore[whichForm][whichIndex].middleName = person.patronymic
3183
+ ? person.patronymic
3184
+ : '';
3185
+ this.formStore[whichForm][whichIndex].longName = `${person.surname} ${
3186
+ person.name
3187
+ } ${person.patronymic ? person.patronymic : ''}`;
3188
+ this.formStore[whichForm][whichIndex].birthDate = reformatDate(
3189
+ person.birthDate,
3190
+ );
3191
+ this.formStore[whichForm][whichIndex].genderName = person.gender.nameRu;
3192
+
3193
+ const gender = this.gender.find(i => i.id == person.gender.code);
3194
+ if (gender) this.formStore[whichForm][whichIndex].gender = gender;
3195
+
3196
+ const birthPlace = this.countries.find(i =>
3197
+ i.nameRu.match(new RegExp(person.birthPlace.country.nameRu, 'i')),
3198
+ );
3199
+ if (birthPlace)
3200
+ this.formStore[whichForm][whichIndex].birthPlace = birthPlace;
3201
+
3202
+ const countryOfCitizenship = this.citizenshipCountries.find(i =>
3203
+ i.nameRu.match(new RegExp(person.citizenship.nameRu, 'i')),
3204
+ );
3205
+ if (countryOfCitizenship)
3206
+ this.formStore[whichForm][whichIndex].countryOfCitizenship =
3207
+ countryOfCitizenship;
3208
+
3209
+ const regCountry = this.countries.find(i =>
3210
+ i.nameRu.match(new RegExp(person.regAddress.country.nameRu, 'i')),
3211
+ );
3212
+ if (regCountry)
3213
+ this.formStore[whichForm][whichIndex].registrationCountry =
3214
+ regCountry;
3215
+
3216
+ const regProvince = this.states.find(i =>
3217
+ i.nameRu.match(new RegExp(person.regAddress.district.nameRu, 'i')),
3218
+ );
3219
+ if (regProvince)
3220
+ this.formStore[whichForm][whichIndex].registrationProvince =
3221
+ regProvince;
3222
+
3223
+ if ('city' in person.regAddress && !!person.regAddress.city) {
3224
+ if (person.regAddress.city.includes(', ')) {
3225
+ const personCities = person.regAddress.city.split(', ');
3226
+ for (let i = 0; i < personCities.length; ++i) {
3227
+ const possibleCity = this.cities.find(i =>
3228
+ i.nameRu.includes(personCities[i]),
3229
+ );
3230
+ if (possibleCity) {
3231
+ this.formStore[whichForm][whichIndex].registrationCity =
3232
+ possibleCity;
3233
+ break;
3234
+ }
3235
+ }
3236
+ if (
3237
+ this.formStore[whichForm][whichIndex].registrationCity.nameRu ===
3238
+ null
3239
+ ) {
3240
+ for (let i = 0; i < personCities.length; ++i) {
3241
+ const possibleRegion = this.regions.find(i =>
3242
+ i.nameRu.includes(personCities[i]),
3243
+ );
3244
+ if (possibleRegion) {
3245
+ this.formStore[whichForm][whichIndex].registrationRegion =
3246
+ possibleRegion;
3247
+ break;
3248
+ }
3249
+ }
3250
+ }
3251
+ } else {
3252
+ const regCity = this.cities.find(i =>
3253
+ i.nameRu.match(new RegExp(person.regAddress.city, 'i')),
3254
+ );
3255
+ if (regCity)
3256
+ this.formStore[whichForm][whichIndex].registrationCity = regCity;
3257
+ if (
3258
+ this.formStore[whichForm][whichIndex].registrationCity.nameRu ===
3259
+ null
3260
+ ) {
3261
+ const regRegion = this.regions.find(i =>
3262
+ i.nameRu.match(new RegExp(person.regAddress.city), 'i'),
3263
+ );
3264
+ if (regRegion)
3265
+ this.formStore[whichForm][whichIndex].registrationRegion =
3266
+ regRegion;
3267
+ }
3268
+ }
3269
+ }
3270
+
3271
+ if (
3272
+ this.formStore[whichForm][whichIndex].registrationCity.nameRu ===
3273
+ null &&
3274
+ this.formStore[whichForm][whichIndex].registrationRegion.nameRu ===
3275
+ null
3276
+ ) {
3277
+ const regCity = this.cities.find(
3278
+ i =>
3279
+ i.nameRu.match(
3280
+ new RegExp(person.regAddress.region.nameRu, 'i'),
3281
+ ) ||
3282
+ i.nameRu.match(
3283
+ new RegExp(person.regAddress.district.nameRu, 'i'),
3284
+ ),
3285
+ );
3286
+ if (regCity) {
3287
+ this.formStore[whichForm][whichIndex].registrationCity = regCity;
3288
+ const regType = this.localityTypes.find(i => i.nameRu === 'город');
3289
+ if (regType)
3290
+ this.formStore[whichForm][whichIndex].registrationRegionType =
3291
+ regType;
3292
+ } else {
3293
+ const regRegion = this.regions.find(
3294
+ i =>
3295
+ i.nameRu.match(
3296
+ new RegExp(person.regAddress.region.nameRu),
3297
+ 'i',
3298
+ ) ||
3299
+ i.nameRu.match(
3300
+ new RegExp(person.regAddress.district.nameRu, 'i'),
3301
+ ),
3302
+ );
3303
+ if (regRegion) {
3304
+ this.formStore[whichForm][whichIndex].registrationRegion =
3305
+ regRegion;
3306
+ const regType = this.localityTypes.find(
3307
+ i =>
3308
+ (i.nameRu === i.nameRu) === 'село' || i.nameRu === 'поселок',
3309
+ );
3310
+ if (regType)
3311
+ this.formStore[whichForm][whichIndex].registrationRegionType =
3312
+ regType;
3313
+ }
3314
+ }
3315
+ }
3316
+
3317
+ if (person.regAddress.street.includes(', ')) {
3318
+ const personAddress = person.regAddress.street.split(', ');
3319
+ const microDistrict = personAddress.find(i =>
3320
+ i.match(new RegExp('микрорайон', 'i')),
3321
+ );
3322
+ const quarter = personAddress.find(i =>
3323
+ i.match(new RegExp('квартал', 'i')),
3324
+ );
3325
+ const street = personAddress.find(i =>
3326
+ i.match(new RegExp('улица', 'i')),
3327
+ );
3328
+ if (microDistrict)
3329
+ this.formStore[whichForm][whichIndex].registrationMicroDistrict =
3330
+ microDistrict;
3331
+ if (quarter)
3332
+ this.formStore[whichForm][whichIndex].registrationQuarter = quarter;
3333
+ if (street)
3334
+ this.formStore[whichForm][whichIndex].registrationStreet = street;
3335
+ } else {
3336
+ if (person.regAddress.street)
3337
+ this.formStore[whichForm][whichIndex].registrationStreet =
3338
+ person.regAddress.street;
3339
+ }
3340
+ if (person.regAddress.building)
3341
+ this.formStore[whichForm][whichIndex].registrationNumberHouse =
3342
+ person.regAddress.building;
3343
+ if (person.regAddress.flat)
3344
+ this.formStore[whichForm][whichIndex].registrationNumberApartment =
3345
+ person.regAddress.flat;
3346
+
3347
+ // TODO Доработать логику и для остальных
3348
+ if ('length' in person.documents.document) {
3349
+ const validDocument = person.documents.document.find(
3350
+ i =>
3351
+ new Date(i.endDate) > new Date(Date.now()) &&
3352
+ i.status.code === '00' &&
3353
+ i.type.code === '002',
3354
+ );
3355
+ if (validDocument) {
3356
+ const documentType = this.documentTypes.find(i => i.ids === '1UDL');
3357
+ if (documentType)
3358
+ this.formStore[whichForm][whichIndex].documentType = documentType;
3359
+ this.formStore[whichForm][whichIndex].documentNumber =
3360
+ validDocument.number;
3361
+ this.formStore[whichForm][whichIndex].documentExpire = reformatDate(
3362
+ validDocument.endDate,
3363
+ );
3364
+ this.formStore[whichForm][whichIndex].documentDate = reformatDate(
3365
+ validDocument.beginDate,
3366
+ );
3367
+ this.formStore[whichForm][whichIndex].documentNumber =
3368
+ validDocument.number;
3369
+
3370
+ const documentIssuer = this.documentIssuers.find(i =>
3371
+ i.nameRu.match(new RegExp('МВД РК', 'i')),
3372
+ );
3373
+ if (documentIssuer)
3374
+ this.formStore[whichForm][whichIndex].documentIssuers =
3375
+ documentIssuer;
3376
+ }
3377
+ } else {
3378
+ const documentType =
3379
+ person.documents.document.type.nameRu === 'УДОСТОВЕРЕНИЕ РК'
3380
+ ? this.documentTypes.find(i => i.ids === '1UDL')
3381
+ : this.documentTypes.find(i =>
3382
+ i.nameRu.match(
3383
+ new RegExp(person.documents.document.type.nameRu, 'i'),
3384
+ ),
3385
+ )
3386
+ ? this.documentTypes.find(i =>
3387
+ i.nameRu.match(
3388
+ new RegExp(person.documents.document.type.nameRu, 'i'),
3389
+ ),
3390
+ )
3391
+ : new Value();
3392
+ if (documentType)
3393
+ this.formStore[whichForm][whichIndex].documentType = documentType;
3394
+
3395
+ const documentNumber = person.documents.document.number;
3396
+ if (documentNumber)
3397
+ this.formStore[whichForm][whichIndex].documentNumber =
3398
+ documentNumber;
3399
+
3400
+ const documentDate = person.documents.document.beginDate;
3401
+ if (documentDate)
3402
+ this.formStore[whichForm][whichIndex].documentDate =
3403
+ reformatDate(documentDate);
3404
+
3405
+ const documentExpire = person.documents.document.endDate;
3406
+ if (documentExpire)
3407
+ this.formStore[whichForm][whichIndex].documentExpire =
3408
+ reformatDate(documentExpire);
3409
+
3410
+ // TODO уточнить
3411
+ const documentIssuer = this.documentIssuers.find(i =>
3412
+ i.nameRu.match(new RegExp('МВД РК', 'i')),
3413
+ );
3414
+ if (documentIssuer)
3415
+ this.formStore[whichForm][whichIndex].documentIssuers =
3416
+ documentIssuer;
3417
+ }
3418
+ const economySectorCode = this.economySectorCode.find(
3419
+ i => i.ids === '500003.9',
3420
+ );
3421
+ if (economySectorCode)
3422
+ this.formStore[whichForm][whichIndex].economySectorCode =
3423
+ economySectorCode;
3424
+ }
3425
+ },
3426
+ async getOtpStatus(iin, phone, processInstanceId = null) {
3427
+ try {
3428
+ const otpData = {
3429
+ iin: iin.replace(/-/g, ''),
3430
+ phoneNumber: formatPhone(phone),
3431
+ type: 'AgreementOtp',
3432
+ };
3433
+ return await api.getOtpStatus(
3434
+ processInstanceId !== null && processInstanceId != 0
3435
+ ? {
3436
+ ...otpData,
3437
+ processInstanceId: processInstanceId,
3438
+ }
3439
+ : otpData,
3440
+ );
3441
+ } catch (err) {
3442
+ console.log(err);
3443
+ showToaster('error', err.response.data, 3000);
3444
+ }
3445
+ },
3446
+ async sendOtp(iin, phone, processInstanceId = null, onInit = false) {
3447
+ this.isLoading = true;
3448
+ let otpStatus = false;
3449
+ let otpResponse = {};
3450
+ try {
3451
+ if (iin && iin.length === 15 && phone && phone.length === 18) {
3452
+ const status = await this.getOtpStatus(iin, phone, processInstanceId);
3453
+ if (status === true) {
3454
+ showToaster('success', this.t('toaster.hasSuccessOtp'), 3000);
3455
+ otpStatus = true;
3456
+ this.isLoading = false;
3457
+ return { otpStatus, otpResponse };
3458
+ } else if (status === false && onInit === false) {
3459
+ const otpData = {
3460
+ iin: iin.replace(/-/g, ''),
3461
+ phoneNumber: formatPhone(phone),
3462
+ type: 'AgreementOtp',
3463
+ };
3464
+ otpResponse = await api.sendOtp(
3465
+ processInstanceId !== null && processInstanceId != 0
3466
+ ? {
3467
+ ...otpData,
3468
+ processInstanceId: processInstanceId,
3469
+ }
3470
+ : otpData,
3471
+ );
3472
+ this.isLoading = false;
3473
+ if (!!otpResponse) {
3474
+ if (
3475
+ 'errMessage' in otpResponse &&
3476
+ otpResponse.errMessage !== null
3477
+ ) {
3478
+ showToaster('error', otpResponse.errMessage, 3000);
3479
+ return { otpStatus };
3480
+ }
3481
+ if ('result' in otpResponse && otpResponse.result === null) {
3482
+ if ('statusName' in otpResponse && !!otpResponse.statusName) {
3483
+ showToaster('error', otpResponse.statusName, 3000);
3484
+ return { otpStatus };
3485
+ }
3486
+ if ('status' in otpResponse && !!otpResponse.status) {
3487
+ showToaster('error', otpResponse.status, 3000);
3488
+ return { otpStatus };
3489
+ }
3490
+ }
3491
+ if ('tokenId' in otpResponse && otpResponse.tokenId) {
3492
+ this.formStore.otpTokenId = otpResponse.tokenId;
3493
+ showToaster('success', this.t('toaster.successOtp'), 3000);
3494
+ }
3495
+ } else {
3496
+ showToaster('error', this.t('toaster.undefinedError'), 3000);
3497
+ return { otpStatus };
3498
+ }
3499
+ }
3500
+ } else {
3501
+ if (onInit === false) {
3502
+ showToaster(
3503
+ 'error',
3504
+ this.t('toaster.errorFormField', { text: 'Номер телефона, ИИН' }),
3505
+ );
3506
+ this.isLoading = false;
3507
+ }
3508
+ }
3509
+ return { otpStatus, otpResponse };
3510
+ } catch (err) {
3511
+ this.isLoading = false;
3512
+ if ('response' in err) {
3513
+ if (
3514
+ 'statusName' in err.response.data &&
3515
+ !!err.response.data.statusName
3516
+ ) {
3517
+ showToaster('error', this.t('toaster.phoneNotFoundInBMG'), 3000);
3518
+ return { otpStatus };
3519
+ }
3520
+ if ('status' in err.response.data && !!err.response.data.status) {
3521
+ showToaster('error', err.response.data.status, 3000);
3522
+ return { otpStatus };
3523
+ }
3524
+ }
3525
+ } finally {
3526
+ this.isLoading = false;
3527
+ }
3528
+ this.isLoading = false;
3529
+ return { otpStatus, otpResponse };
3530
+ },
3531
+ async checkOtp(otpToken, phone, code) {
3532
+ try {
3533
+ this.isLoading = true;
3534
+ const otpData = {
3535
+ tokenId: otpToken,
3536
+ phoneNumber: formatPhone(phone),
3537
+ code: code,
3538
+ };
3539
+ const otpResponse = await this.api.checkOtp(otpData);
3540
+ if (otpResponse !== null) {
3541
+ if ('errMessage' in otpResponse && otpResponse.errMessage !== null) {
3542
+ this.showToaster('error', otpResponse.errMessage, 3000);
3543
+ return false;
3544
+ }
3545
+ if ('status' in otpResponse && !!otpResponse.status) {
3546
+ // TODO Доработать и менять значение hasAgreement.value => true
3547
+ this.showToaster(
3548
+ otpResponse.status !== 2 ? 'error' : 'success',
3549
+ otpResponse.statusName,
3550
+ 3000,
3551
+ );
3552
+ if (otpResponse.status === 2) {
3553
+ return true;
3554
+ }
3555
+ }
3556
+ }
3557
+ return false;
3558
+ } catch (err) {
3559
+ console.log(err);
3560
+ if ('response' in err) {
3561
+ this.showToaster('error', err.response.data, 3000);
3562
+ }
3563
+ } finally {
3564
+ this.isLoading = false;
3565
+ }
3566
+ return null;
3567
+ },
1163
3568
  },
1164
3569
  });
1165
3570