hl-core 0.0.7-beta.9 → 0.0.8

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.
Files changed (52) hide show
  1. package/.prettierrc +2 -1
  2. package/api/index.ts +66 -47
  3. package/api/interceptors.ts +4 -4
  4. package/components/Button/Btn.vue +7 -2
  5. package/components/Button/ScrollButtons.vue +6 -0
  6. package/components/Complex/ContentBlock.vue +5 -0
  7. package/components/{Layout → Dialog}/Dialog.vue +3 -27
  8. package/components/Dialog/FamilyDialog.vue +39 -0
  9. package/components/Form/FormBlock.vue +114 -0
  10. package/components/Form/FormSection.vue +18 -0
  11. package/components/Form/FormTextSection.vue +20 -0
  12. package/components/Form/FormToggle.vue +52 -0
  13. package/components/Form/ProductConditionsBlock.vue +68 -0
  14. package/components/Input/EmptyFormField.vue +5 -0
  15. package/components/Input/FileInput.vue +71 -0
  16. package/components/Input/FormInput.vue +171 -0
  17. package/components/Input/PanelInput.vue +133 -0
  18. package/components/Input/RoundedInput.vue +35 -36
  19. package/components/Layout/Drawer.vue +18 -16
  20. package/components/Layout/Header.vue +4 -18
  21. package/components/Layout/Loader.vue +1 -7
  22. package/components/Layout/SettingsPanel.vue +17 -37
  23. package/components/List/ListEmpty.vue +22 -0
  24. package/components/Menu/MenuNav.vue +22 -20
  25. package/components/Menu/MenuNavItem.vue +6 -6
  26. package/components/Pages/Anketa.vue +333 -0
  27. package/components/Pages/Auth.vue +91 -0
  28. package/components/Pages/Documents.vue +108 -0
  29. package/components/Pages/MemberForm.vue +1138 -0
  30. package/components/Pages/ProductAgreement.vue +18 -0
  31. package/components/Pages/ProductConditions.vue +349 -0
  32. package/components/Panel/PanelItem.vue +2 -4
  33. package/components/Panel/PanelSelectItem.vue +20 -0
  34. package/components/Transitions/FadeTransition.vue +5 -0
  35. package/composables/classes.ts +299 -253
  36. package/composables/constants.ts +14 -7
  37. package/composables/index.ts +55 -60
  38. package/composables/styles.ts +31 -7
  39. package/layouts/default.vue +46 -26
  40. package/layouts/full.vue +2 -12
  41. package/nuxt.config.ts +3 -0
  42. package/package.json +13 -10
  43. package/pages/500.vue +40 -12
  44. package/plugins/helperFunctionsPlugins.ts +6 -2
  45. package/plugins/storePlugin.ts +6 -5
  46. package/store/data.store.js +781 -1880
  47. package/store/member.store.ts +291 -0
  48. package/store/messages.ts +66 -51
  49. package/store/rules.js +26 -28
  50. package/types/index.ts +250 -0
  51. package/composables/models.ts +0 -43
  52. /package/store/{form.store.js → form.store.ts} +0 -0
@@ -2,7 +2,7 @@ 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, yearEnding, jwtDecode } from '../composables';
5
+ import { isValidGUID, yearEnding, jwtDecode, ErrorHandler, getKeyWithPattern, getNumber, getAgeByBirthDate } from '../composables';
6
6
  import { DataStoreClass, Contragent } from '../composables/classes';
7
7
  import { ApiClass } from '@/api';
8
8
  import { useFormStore } from './form.store';
@@ -20,20 +20,13 @@ export const useDataStore = defineStore('data', {
20
20
  formStore: useFormStore(),
21
21
  contragent: useContragentStore(),
22
22
  api: new ApiClass(),
23
- yearEnding: year =>
24
- yearEnding(year, constants.yearTitles, constants.yearCases),
25
- currentDate: () =>
26
- new Date(Date.now() - new Date().getTimezoneOffset() * 60 * 1000)
27
- .toISOString()
28
- .slice(0, -1),
23
+ yearEnding: year => yearEnding(year, constants.yearTitles, constants.yearCases),
24
+ currentDate: () => new Date(Date.now() - new Date().getTimezoneOffset() * 60 * 1000).toISOString().slice(0, -1),
29
25
  showToaster: (type, msg, timeout) =>
30
26
  Toast.useToast()(msg, {
31
27
  ...ToastOptions,
32
28
  type: Types[type.toUpperCase()],
33
- timeout:
34
- typeof timeout === ('number' || 'boolean')
35
- ? timeout
36
- : ToastOptions.timeout,
29
+ timeout: type === 'error' ? 6000 : typeof timeout === 'number' ? timeout : ToastOptions.timeout,
37
30
  }),
38
31
  }),
39
32
  getters: {
@@ -44,30 +37,43 @@ export const useDataStore = defineStore('data', {
44
37
  isLifetrip: state => state.product === 'lifetrip',
45
38
  isLiferenta: state => state.product === 'liferenta',
46
39
  isPension: state => state.product === 'pension',
47
- isEveryFormDisabled: state =>
48
- Object.values(state.formStore.isDisabled).every(i => i === true),
40
+ isGons: state => state.product === 'gons',
41
+ isEveryFormDisabled: state => Object.values(state.formStore.isDisabled).every(i => i === true),
49
42
  },
50
43
  actions: {
44
+ isIframe() {
45
+ try {
46
+ return window.self !== window.top;
47
+ } catch (err) {
48
+ return true;
49
+ }
50
+ },
51
51
  sendToParent(action, value) {
52
52
  window.parent.postMessage({ action: action, value: value }, '*');
53
53
  },
54
+ getChildIframe() {
55
+ return document.getElementById('product-iframe');
56
+ },
57
+ sendToChild(action, value) {
58
+ const childFrame = this.getChildIframe();
59
+ if (childFrame && childFrame.contentWindow && childFrame.contentWindow.postMessage) {
60
+ childFrame.contentWindow.postMessage({ action: action, value: value }, '*');
61
+ }
62
+ },
54
63
  getFilesByIIN(iin) {
55
- return this.signedDocumentList.filter(
56
- file =>
57
- file.iin === iin && file.fileTypeName === 'Удостоверение личности',
58
- );
64
+ return iin ? this.formStore.signedDocumentList.filter(file => file.iin === iin && file.fileTypeName === 'Удостоверение личности') : null;
59
65
  },
60
66
  async getNewAccessToken() {
61
67
  try {
62
68
  const data = {
63
- accessToken: JSON.parse(localStorage.getItem('accessToken')),
64
- refreshToken: JSON.parse(localStorage.getItem('refreshToken')),
69
+ accessToken: localStorage.getItem('accessToken'),
70
+ refreshToken: localStorage.getItem('refreshToken'),
65
71
  };
66
72
  const response = await this.api.getNewAccessToken(data);
67
73
  this.accessToken = response.accessToken;
68
74
  this.refreshToken = response.refreshToken;
69
- localStorage.setItem('accessToken', JSON.stringify(this.accessToken));
70
- localStorage.setItem('refreshToken', JSON.stringify(this.refreshToken));
75
+ localStorage.setItem('accessToken', this.accessToken);
76
+ localStorage.setItem('refreshToken', this.refreshToken);
71
77
  } catch (err) {
72
78
  console.error(err);
73
79
  }
@@ -86,8 +92,7 @@ export const useDataStore = defineStore('data', {
86
92
  },
87
93
  async loginUser(login, password, numAttempt) {
88
94
  try {
89
- const token = JSON.parse(localStorage.getItem('accessToken'));
90
-
95
+ const token = localStorage.getItem('accessToken') || null;
91
96
  if (token && isValidToken(token)) {
92
97
  this.accessToken = token;
93
98
  this.getUserRoles();
@@ -102,42 +107,38 @@ export const useDataStore = defineStore('data', {
102
107
  this.refreshToken = response.refreshToken;
103
108
  this.getUserRoles();
104
109
  }
105
- if (
106
- this.isManager() ||
107
- this.isUnderwriter() ||
108
- this.isAdmin() ||
109
- this.isAgent() ||
110
- this.isCompliance() ||
111
- this.isAgentMycar() ||
112
- this.isAnalyst() ||
113
- this.isUpk()
114
- ) {
115
- localStorage.setItem('accessToken', JSON.stringify(this.accessToken));
116
- localStorage.setItem(
117
- 'refreshToken',
118
- JSON.stringify(this.refreshToken),
119
- );
110
+ if (this.controls.onAuth) {
111
+ const hasPermission =
112
+ this.isInitiator() ||
113
+ this.isUnderwriter() ||
114
+ this.isAdmin() ||
115
+ this.isCompliance() ||
116
+ this.isAnalyst() ||
117
+ this.isUpk() ||
118
+ this.isFinanceCenter() ||
119
+ this.isSupervisor() ||
120
+ this.isSupport();
121
+ if (hasPermission) {
122
+ localStorage.setItem('accessToken', this.accessToken);
123
+ localStorage.setItem('refreshToken', this.refreshToken);
124
+ } else {
125
+ this.showToaster('error', this.t('toaster.noProductPermission'), 5000);
126
+ this.accessToken = null;
127
+ this.refreshToken = null;
128
+ }
120
129
  } else {
121
- this.showToaster(
122
- 'error',
123
- this.t('toaster.noProductPermission'),
124
- 5000,
125
- );
130
+ localStorage.setItem('accessToken', this.accessToken);
131
+ localStorage.setItem('refreshToken', this.refreshToken);
126
132
  }
127
133
  } catch (err) {
128
- console.log(err);
129
- if ('response' in err) {
130
- this.showToaster('error', err.response.data, 3000);
131
- }
134
+ ErrorHandler(err);
132
135
  }
133
136
  },
134
137
  getUserRoles() {
135
138
  if (this.accessToken && this.user.roles.length === 0) {
136
139
  const decoded = jwtDecode(this.accessToken);
137
140
  this.user.id = decoded.sub;
138
- this.user.fullName = `${decoded.lastName} ${decoded.firstName} ${
139
- decoded.middleName ? decoded.middleName : ''
140
- }`;
141
+ this.user.fullName = `${decoded.lastName} ${decoded.firstName} ${decoded.middleName ? decoded.middleName : ''}`;
141
142
  const key = getKeyWithPattern(decoded, 'role');
142
143
  if (key) {
143
144
  const roles = decoded[key];
@@ -157,11 +158,7 @@ export const useDataStore = defineStore('data', {
157
158
  return !!isRole;
158
159
  },
159
160
  isInitiator() {
160
- return (
161
- this.isRole(constants.roles.manager) ||
162
- this.isRole(constants.roles.agent) ||
163
- this.isRole(constants.roles.agentMycar)
164
- );
161
+ return this.isManager() || this.isAgent() || this.isAgentMycar() || this.isManagerHalykBank() || this.isServiceManager();
165
162
  },
166
163
  isManager() {
167
164
  return this.isRole(constants.roles.manager);
@@ -175,6 +172,12 @@ export const useDataStore = defineStore('data', {
175
172
  isAgent() {
176
173
  return this.isRole(constants.roles.agent);
177
174
  },
175
+ isManagerHalykBank() {
176
+ return this.isRole(constants.roles.managerHalykBank);
177
+ },
178
+ isServiceManager() {
179
+ return this.isRole(constants.roles.serviceManager);
180
+ },
178
181
  isUnderwriter() {
179
182
  return this.isRole(constants.roles.underwriter);
180
183
  },
@@ -187,20 +190,35 @@ export const useDataStore = defineStore('data', {
187
190
  isUpk() {
188
191
  return this.isRole(constants.roles.upk);
189
192
  },
193
+ isSupport() {
194
+ return this.isRole(constants.roles.support);
195
+ },
196
+ isFinanceCenter() {
197
+ return this.isRole(constants.roles.financeCenter);
198
+ },
199
+ isSupervisor() {
200
+ return this.isRole(constants.roles.supervisor);
201
+ },
190
202
  isProcessEditable(statusCode) {
191
203
  return !!constants.editableStatuses.find(status => status === statusCode);
192
204
  },
193
205
  isTask() {
194
- return (
195
- this.formStore.applicationData.processInstanceId != 0 &&
196
- this.formStore.applicationData.isTask
197
- );
206
+ return this.formStore.applicationData.processInstanceId !== 0 && this.formStore.applicationData.isTask;
207
+ },
208
+ async resetSelected(route) {
209
+ this.settings.open = false;
210
+ this.panel.open = false;
211
+ this.panelAction = null;
212
+ this.menu.selectedItem = new MenuItem();
213
+ if (route && route.name) {
214
+ await this.router.replace({ name: route.name });
215
+ }
198
216
  },
199
217
  async logoutUser() {
200
218
  this.isLoading = true;
201
219
  try {
202
220
  const whichProduct = this.product;
203
- const token = JSON.parse(localStorage.getItem('accessToken'));
221
+ const token = localStorage.getItem('accessToken') || null;
204
222
  if (token) {
205
223
  this.$reset();
206
224
  localStorage.clear();
@@ -225,11 +243,17 @@ export const useDataStore = defineStore('data', {
225
243
  if (!['pdf', 'docx'].includes(fileType)) {
226
244
  const blob = new Blob([response], { type: `image/${fileType}` });
227
245
  const url = window.URL.createObjectURL(blob);
228
- window.open(
229
- url,
230
- '_blank',
231
- `width=${screen.width},height=${screen.height},top=70`,
232
- );
246
+ const link = document.createElement('a');
247
+ link.href = url;
248
+ if (mode === 'view') {
249
+ setTimeout(() => {
250
+ window.open(url, '_blank', `width=${screen.width},height=${screen.height},top=70`);
251
+ });
252
+ } else {
253
+ link.setAttribute('download', file.fileName);
254
+ document.body.appendChild(link);
255
+ link.click();
256
+ }
233
257
  } else {
234
258
  const blob = new Blob([response], {
235
259
  type: `application/${fileType}`,
@@ -249,7 +273,7 @@ export const useDataStore = defineStore('data', {
249
273
  }
250
274
  });
251
275
  } catch (err) {
252
- this.showToaster('error', err.response.data, 5000);
276
+ ErrorHandler(err);
253
277
  } finally {
254
278
  this.isLoading = false;
255
279
  }
@@ -262,7 +286,7 @@ export const useDataStore = defineStore('data', {
262
286
  this.showToaster('error', err.response.data, 2000);
263
287
  }
264
288
  },
265
- async uploadFiles(data, load = true) {
289
+ async uploadFiles(data, load = false) {
266
290
  try {
267
291
  if (load) {
268
292
  this.isLoading = true;
@@ -270,15 +294,14 @@ export const useDataStore = defineStore('data', {
270
294
  await this.api.uploadFiles(data);
271
295
  return true;
272
296
  } catch (err) {
273
- this.showToaster('error', err.response.data, 5000);
274
- return false;
297
+ return ErrorHandler(err);
275
298
  } finally {
276
299
  if (load) {
277
300
  this.isLoading = false;
278
301
  }
279
302
  }
280
303
  },
281
- async getContragent(whichForm, whichIndex = null, load = true) {
304
+ async getContragent(member, whichForm, whichIndex, load = true) {
282
305
  if (load) {
283
306
  this.isLoading = true;
284
307
  }
@@ -289,41 +312,16 @@ export const useDataStore = defineStore('data', {
289
312
  lastName: '',
290
313
  middleName: '',
291
314
  };
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
- }
315
+ queryData.iin = member.iin.replace(/-/g, '');
316
+ response = await this.api.getContragent(queryData);
303
317
  if (response.totalItems > 0) {
304
318
  if (response.totalItems.length === 1) {
305
- await this.serializeContragentData(
306
- whichForm,
307
- response.items[0],
308
- whichIndex,
309
- );
319
+ await this.serializeContragentData(whichForm, response.items[0], whichIndex);
310
320
  } 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;
321
+ const sortedByRegistrationDate = response.items.sort((left, right) => new Date(right.registrationDate) - new Date(left.registrationDate));
322
+ await this.serializeContragentData(whichForm, sortedByRegistrationDate[0], whichIndex);
326
323
  }
324
+ member.gotFromInsis = true;
327
325
  } else {
328
326
  this.userNotFound = true;
329
327
  }
@@ -339,25 +337,14 @@ export const useDataStore = defineStore('data', {
339
337
  this.isLoading = true;
340
338
  }
341
339
  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
- );
340
+ if (this.isMycar && this.isAgentMycar() && whichForm === this.formStore.beneficiaryFormKey) {
341
+ await this.serializeContragentData(whichForm, this.formStore.applicationData.beneficiaryApp[0], whichIndex);
351
342
  this.isLoading = false;
352
343
  return;
353
344
  }
354
345
  const response = await this.api.getContragentById(id);
355
346
  if (response.totalItems > 0) {
356
- await this.serializeContragentData(
357
- whichForm,
358
- response.items[0],
359
- whichIndex,
360
- );
347
+ await this.serializeContragentData(whichForm, response.items[0], whichIndex);
361
348
  } else {
362
349
  this.isLoading = false;
363
350
  return false;
@@ -370,12 +357,7 @@ export const useDataStore = defineStore('data', {
370
357
  }
371
358
  },
372
359
  async serializeContragentData(whichForm, contragent, whichIndex = null) {
373
- const [
374
- { value: data },
375
- { value: contacts },
376
- { value: documents },
377
- { value: address },
378
- ] = await Promise.allSettled([
360
+ const [{ value: data }, { value: contacts }, { value: documents }, { value: address }] = await Promise.allSettled([
379
361
  this.api.getContrAgentData(contragent.id),
380
362
  this.api.getContrAgentContacts(contragent.id),
381
363
  this.api.getContrAgentDocuments(contragent.id),
@@ -455,50 +437,28 @@ export const useDataStore = defineStore('data', {
455
437
  this.formStore[whichForm].verifyDate = user.personalData.verifyDate;
456
438
  this.formStore[whichForm].iin = reformatIin(user.personalData.iin);
457
439
  this.formStore[whichForm].age = user.personalData.age;
458
- const country = this.countries.find(i =>
459
- i.nameRu?.match(new RegExp(user.personalData.birthPlace, 'i')),
460
- );
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,
465
- );
440
+ const country = this.countries.find(i => i.nameRu?.match(new RegExp(user.personalData.birthPlace, 'i')));
441
+ this.formStore[whichForm].birthPlace = country && Object.keys(country).length ? country : new Value();
442
+ this.formStore[whichForm].gender = this.gender.find(i => i.nameRu === user.personalData.genderName);
466
443
  this.formStore[whichForm].gender.id = user.personalData.gender;
467
- this.formStore[whichForm].birthDate = reformatDate(
468
- user.personalData.birthDate,
469
- );
444
+ this.formStore[whichForm].birthDate = reformatDate(user.personalData.birthDate);
470
445
  this.formStore[whichForm].genderName = user.personalData.genderName;
471
446
  this.formStore[whichForm].lastName = user.personalData.lastName;
472
447
  this.formStore[whichForm].longName = user.personalData.longName;
473
- this.formStore[whichForm].middleName = user.personalData.middleName
474
- ? user.personalData.middleName
475
- : '';
448
+ this.formStore[whichForm].middleName = user.personalData.middleName ? user.personalData.middleName : '';
476
449
  this.formStore[whichForm].firstName = user.personalData.firstName;
477
450
  this.formStore[whichForm].id = user.personalData.id;
478
451
  this.formStore[whichForm].type = user.personalData.type;
479
- this.formStore[whichForm].registrationDate =
480
- user.personalData.registrationDate;
452
+ this.formStore[whichForm].registrationDate = user.personalData.registrationDate;
481
453
  // Save User Documents Data
482
454
  if ('documents' in user && user.documents.length) {
483
- const documentType = this.documentTypes.find(
484
- i => i.ids === user.documents[0].type,
485
- );
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();
455
+ const documentType = this.documentTypes.find(i => i.ids === user.documents[0].type);
456
+ const documentIssuer = this.documentIssuers.find(i => i.nameRu === user.documents[0].issuerNameRu);
457
+ this.formStore[whichForm].documentType = documentType ? documentType : new Value();
492
458
  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
- );
459
+ this.formStore[whichForm].documentIssuers = documentIssuer ? documentIssuer : new Value();
460
+ this.formStore[whichForm].documentDate = reformatDate(user.documents[0].issueDate);
461
+ this.formStore[whichForm].documentExpire = reformatDate(user.documents[0].expireDate);
502
462
  }
503
463
  // Document detail (residency, economy code, etc..)
504
464
  if ('data' in user && user.data.length) {
@@ -507,46 +467,21 @@ export const useDataStore = defineStore('data', {
507
467
  });
508
468
  }
509
469
  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;
470
+ const country = this.countries.find(i => i.nameRu?.match(new RegExp(user.address.countryName, 'i')));
471
+ const province = this.states.find(i => i.ids === user.address[0].stateCode);
472
+ const localityType = this.localityTypes.find(i => i.nameRu === user.address[0].cityTypeName);
473
+ const city = this.cities.find(i => !!user.address[0].cityName && i.nameRu === user.address[0].cityName.replace('г.', ''));
474
+ const region = this.regions.find(i => !!user.address[0].regionCode && i.ids == user.address[0].regionCode);
475
+ this.formStore[whichForm].registrationCountry = country ? country : new Value();
476
+ this.formStore[whichForm].registrationStreet = user.address[0].streetName;
477
+ this.formStore[whichForm].registrationCity = city ? city : new Value();
478
+ this.formStore[whichForm].registrationNumberApartment = user.address[0].apartmentNumber;
479
+ this.formStore[whichForm].registrationNumberHouse = user.address[0].blockNumber;
480
+ this.formStore[whichForm].registrationProvince = province ? province : new Value();
481
+ this.formStore[whichForm].registrationRegionType = localityType ? localityType : new Value();
482
+ this.formStore[whichForm].registrationRegion = region ? region : new Value();
483
+ this.formStore[whichForm].registrationQuarter = user.address[0].kvartal;
484
+ this.formStore[whichForm].registrationMicroDistrict = user.address[0].microRaion;
550
485
  }
551
486
  if ('contacts' in user && user.contacts.length) {
552
487
  user.contacts.forEach(contact => {
@@ -555,88 +490,43 @@ export const useDataStore = defineStore('data', {
555
490
  }
556
491
  if (contact.type === 'MOBILE' && contact.value) {
557
492
  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)}`;
493
+ this.formStore[whichForm].phoneNumber = `+7 (${phoneNumber.slice(0, 3)}) ${phoneNumber.slice(3, 6)} ${phoneNumber.slice(6, 8)} ${phoneNumber.slice(8)}`;
565
494
  }
566
495
  if (contact.type === 'HOME' && contact.value) {
567
496
  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)}`;
497
+ this.formStore[whichForm].homePhone = `+7 (${homePhone.slice(0, 3)}) ${homePhone.slice(3, 6)} ${homePhone.slice(6, 8)} ${homePhone.slice(8)}`;
575
498
  }
576
499
  });
577
500
  }
578
501
  }
579
502
  if (whichIndex !== null) {
580
503
  // Save User Personal Data
581
- this.formStore[whichForm][whichIndex].iin = reformatIin(
582
- user.personalData.iin,
583
- );
584
- this.formStore[whichForm][whichIndex].verifyType =
585
- user.personalData.verifyType;
586
- this.formStore[whichForm][whichIndex].verifyDate =
587
- user.personalData.verifyDate;
504
+ this.formStore[whichForm][whichIndex].iin = reformatIin(user.personalData.iin);
505
+ this.formStore[whichForm][whichIndex].verifyType = user.personalData.verifyType;
506
+ this.formStore[whichForm][whichIndex].verifyDate = user.personalData.verifyDate;
588
507
  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')),
591
- );
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,
596
- );
597
- this.formStore[whichForm][whichIndex].gender.id =
598
- user.personalData.gender;
599
- this.formStore[whichForm][whichIndex].birthDate = reformatDate(
600
- user.personalData.birthDate,
601
- );
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;
508
+ const country = this.countries.find(i => i.nameRu?.match(new RegExp(user.personalData.birthPlace, 'i')));
509
+ this.formStore[whichForm][whichIndex].birthPlace = country && Object.keys(country).length ? country : new Value();
510
+ this.formStore[whichForm][whichIndex].gender = this.gender.find(i => i.nameRu === user.personalData.genderName);
511
+ this.formStore[whichForm][whichIndex].gender.id = user.personalData.gender;
512
+ this.formStore[whichForm][whichIndex].birthDate = reformatDate(user.personalData.birthDate);
513
+ this.formStore[whichForm][whichIndex].genderName = user.personalData.genderName;
514
+ this.formStore[whichForm][whichIndex].lastName = user.personalData.lastName;
515
+ this.formStore[whichForm][whichIndex].longName = user.personalData.longName;
516
+ this.formStore[whichForm][whichIndex].middleName = user.personalData.middleName ? user.personalData.middleName : '';
517
+ this.formStore[whichForm][whichIndex].firstName = user.personalData.firstName;
614
518
  this.formStore[whichForm][whichIndex].id = user.personalData.id;
615
519
  this.formStore[whichForm][whichIndex].type = user.personalData.type;
616
- this.formStore[whichForm][whichIndex].registrationDate =
617
- user.personalData.registrationDate;
520
+ this.formStore[whichForm][whichIndex].registrationDate = user.personalData.registrationDate;
618
521
  // Save User Documents Data
619
522
  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
- );
523
+ const documentType = this.documentTypes.find(i => i.ids === user.documents[0].type);
524
+ const documentIssuer = this.documentIssuers.find(i => i.nameRu === user.documents[0].issuerNameRu);
525
+ this.formStore[whichForm][whichIndex].documentType = documentType ? documentType : new Value();
526
+ this.formStore[whichForm][whichIndex].documentNumber = user.documents[0].number;
527
+ this.formStore[whichForm][whichIndex].documentIssuers = documentIssuer ? documentIssuer : new Value();
528
+ this.formStore[whichForm][whichIndex].documentDate = reformatDate(user.documents[0].issueDate);
529
+ this.formStore[whichForm][whichIndex].documentExpire = reformatDate(user.documents[0].expireDate);
640
530
  }
641
531
  // Document detail (residency, economy code, etc..)
642
532
  if ('data' in user && user.data.length) {
@@ -645,45 +535,21 @@ export const useDataStore = defineStore('data', {
645
535
  });
646
536
  }
647
537
  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;
538
+ const country = this.countries.find(i => i.nameRu?.match(new RegExp(user.address.countryName, 'i')));
539
+ const province = this.states.find(i => i.ids === user.address[0].stateCode);
540
+ const localityType = this.localityTypes.find(i => i.nameRu === user.address[0].cityTypeName);
541
+ const city = this.cities.find(i => !!user.address[0].cityName && i.nameRu === user.address[0].cityName.replace('г.', ''));
542
+ const region = this.regions.find(i => !!user.address[0].regionCode && i.ids == user.address[0].regionCode);
543
+ this.formStore[whichForm][whichIndex].registrationCountry = country ? country : new Value();
544
+ this.formStore[whichForm][whichIndex].registrationStreet = user.address[0].streetName;
545
+ this.formStore[whichForm][whichIndex].registrationCity = city ? city : new Value();
546
+ this.formStore[whichForm][whichIndex].registrationNumberApartment = user.address[0].apartmentNumber;
547
+ this.formStore[whichForm][whichIndex].registrationNumberHouse = user.address[0].blockNumber;
548
+ this.formStore[whichForm][whichIndex].registrationProvince = province ? province : new Value();
549
+ this.formStore[whichForm][whichIndex].registrationRegionType = localityType ? localityType : new Value();
550
+ this.formStore[whichForm][whichIndex].registrationRegion = region ? region : new Value();
551
+ this.formStore[whichForm][whichIndex].registrationQuarter = user.address[0].kvartal;
552
+ this.formStore[whichForm][whichIndex].registrationMicroDistrict = user.address[0].microRaion;
687
553
  }
688
554
  if ('contacts' in user && user.contacts.length) {
689
555
  user.contacts.forEach(contact => {
@@ -692,24 +558,11 @@ export const useDataStore = defineStore('data', {
692
558
  }
693
559
  if (contact.type === 'MOBILE' && contact.value) {
694
560
  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)}`;
561
+ this.formStore[whichForm][whichIndex].phoneNumber = `+7 (${phoneNumber.slice(0, 3)}) ${phoneNumber.slice(3, 6)} ${phoneNumber.slice(6, 8)} ${phoneNumber.slice(8)}`;
704
562
  }
705
563
  if (contact.type === 'HOME' && contact.value) {
706
564
  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)}`;
565
+ this.formStore[whichForm][whichIndex].homePhone = `+7 (${homePhone.slice(0, 3)}) ${homePhone.slice(3, 6)} ${homePhone.slice(6, 8)} ${homePhone.slice(8)}`;
713
566
  }
714
567
  });
715
568
  }
@@ -728,11 +581,7 @@ export const useDataStore = defineStore('data', {
728
581
  if (contragent.totalItems.length === 1) {
729
582
  return contragent.items[0].id;
730
583
  } else {
731
- const sortedByRegistrationDate = contragent.items.sort(
732
- (left, right) =>
733
- new Date(right.registrationDate) -
734
- new Date(left.registrationDate),
735
- );
584
+ const sortedByRegistrationDate = contragent.items.sort((left, right) => new Date(right.registrationDate) - new Date(left.registrationDate));
736
585
  return sortedByRegistrationDate[0].id;
737
586
  }
738
587
  } else {
@@ -743,82 +592,29 @@ export const useDataStore = defineStore('data', {
743
592
  return false;
744
593
  }
745
594
  },
746
- async saveContragent(
747
- user,
748
- whichForm,
749
- onlySaveAction = true,
750
- whichIndex = null,
751
- ) {
752
- this.isLoading = true;
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
- }
595
+ async saveContragent(user, whichForm, whichIndex, onlySaveAction = true) {
596
+ this.isLoading = !onlySaveAction;
597
+ const hasInsisId = await this.alreadyInInsis(user.iin, user.firstName, user.lastName, user.middleName);
598
+ if (hasInsisId !== false) {
599
+ user.id = hasInsisId;
600
+ const [{ value: data }, { value: contacts }, { value: documents }, { value: address }] = await Promise.allSettled([
601
+ this.api.getContrAgentData(user.id),
602
+ this.api.getContrAgentContacts(user.id),
603
+ this.api.getContrAgentDocuments(user.id),
604
+ this.api.getContrAgentAddress(user.id),
605
+ ]);
606
+ user.response = {};
607
+ if (data && data.length) {
608
+ user.response.questionnaires = data;
786
609
  }
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
- }
610
+ if (contacts && contacts.length) {
611
+ user.response.contacts = contacts;
612
+ }
613
+ if (documents && documents.length) {
614
+ user.response.documents = documents;
615
+ }
616
+ if (address && address.length) {
617
+ user.response.addresses = address;
822
618
  }
823
619
  }
824
620
  try {
@@ -827,12 +623,7 @@ export const useDataStore = defineStore('data', {
827
623
  id: user.id,
828
624
  type: user.type,
829
625
  iin: user.iin.replace(/-/g, ''),
830
- longName:
831
- user.longName !== null
832
- ? user.longName
833
- : user.lastName + user.firstName + user.middleName
834
- ? user.middleName
835
- : '',
626
+ longName: user.longName !== null ? user.longName : user.lastName + user.firstName + user.middleName ? user.middleName : '',
836
627
  lastName: user.lastName,
837
628
  firstName: user.firstName,
838
629
  middleName: user.middleName ? user.middleName : '',
@@ -846,12 +637,7 @@ export const useDataStore = defineStore('data', {
846
637
  verifyDate: user.verifyDate,
847
638
  };
848
639
  // ! SaveContragent -> Questionnaires
849
- let questionnaires = (({
850
- economySectorCode,
851
- countryOfCitizenship,
852
- countryOfTaxResidency,
853
- signOfResidency,
854
- }) => ({
640
+ let questionnaires = (({ economySectorCode, countryOfCitizenship, countryOfTaxResidency, signOfResidency }) => ({
855
641
  economySectorCode,
856
642
  countryOfCitizenship,
857
643
  countryOfTaxResidency,
@@ -870,12 +656,7 @@ export const useDataStore = defineStore('data', {
870
656
  questName = 'Страна налогового резиденства';
871
657
  }
872
658
  return {
873
- id:
874
- 'response' in user && 'questionnaires' in user.response
875
- ? user.response.questionnaires?.find(
876
- i => i.questId == questionId,
877
- ).id
878
- : question.id,
659
+ id: 'response' in user && 'questionnaires' in user.response ? user.response.questionnaires?.find(i => i.questId == questionId).id : question.id,
879
660
  contragentId: user.id,
880
661
  questAnswer: question.ids,
881
662
  questId: questionId,
@@ -886,10 +667,7 @@ export const useDataStore = defineStore('data', {
886
667
  if (user.countryOfTaxResidency.ids !== '500014.3') {
887
668
  user.addTaxResidency = new Value();
888
669
  }
889
- const addTaxResidency =
890
- 'response' in user &&
891
- 'questionnaires' in user.response &&
892
- user.response.questionnaires.find(i => i.questId === '507777');
670
+ const addTaxResidency = 'response' in user && 'questionnaires' in user.response && user.response.questionnaires.find(i => i.questId === '507777');
893
671
  if (user.addTaxResidency.nameRu !== null) {
894
672
  questionariesData.push({
895
673
  id: addTaxResidency ? addTaxResidency.id : 0,
@@ -917,22 +695,15 @@ export const useDataStore = defineStore('data', {
917
695
  if (user.phoneNumber !== '' && user.phoneNumber !== null) {
918
696
  contactsData.push({
919
697
  contragentId: user.id,
920
- id:
921
- 'response' in user && 'contacts' in user.response
922
- ? user.response.contacts.find(i => i.type === 'MOBILE').id
923
- : 0,
698
+ id: 'response' in user && 'contacts' in user.response ? user.response.contacts.find(i => i.type === 'MOBILE').id : 0,
924
699
  newValue: '',
925
700
  note: '',
926
701
  primaryFlag: 'Y',
927
702
  type: 'MOBILE',
928
703
  typeName: 'Сотовый телефон',
929
704
  value: formatPhone(user.phoneNumber),
930
- verifyType: this.formStore.otpTokenId
931
- ? 'BMG'
932
- : 'response' in user && 'contacts' in user.response
933
- ? user.response.contacts.find(i => i.type === 'MOBILE').verifyType
934
- : null,
935
- verifyDate: this.formStore.otpTokenId
705
+ verifyType: user.otpTokenId ? 'BMG' : 'response' in user && 'contacts' in user.response ? user.response.contacts.find(i => i.type === 'MOBILE').verifyType : null,
706
+ verifyDate: user.otpTokenId
936
707
  ? this.currentDate()
937
708
  : 'response' in user && 'contacts' in user.response
938
709
  ? user.response.contacts.find(i => i.type === 'MOBILE').verifyDate
@@ -942,29 +713,19 @@ export const useDataStore = defineStore('data', {
942
713
  if (user.email !== '' && user.email !== null) {
943
714
  contactsData.push({
944
715
  contragentId: user.id,
945
- id:
946
- 'response' in user && 'contacts' in user.response
947
- ? user.response.contacts.find(i => i.type === 'EMAIL').id
948
- : 0,
716
+ id: 'response' in user && 'contacts' in user.response ? user.response.contacts.find(i => i.type === 'EMAIL').id : 0,
949
717
  newValue: '',
950
718
  note: '',
951
719
  primaryFlag: 'N',
952
720
  type: 'EMAIL',
953
721
  typeName: 'E-Mail',
954
- value: user.email
955
- ? user.email
956
- : 'response' in user && 'contacts' in user.response
957
- ? user.response.contacts.find(i => i.type === 'EMAIL').value
958
- : '',
722
+ value: user.email ? user.email : 'response' in user && 'contacts' in user.response ? user.response.contacts.find(i => i.type === 'EMAIL').value : '',
959
723
  });
960
724
  }
961
725
  if (user.homePhone !== '' && user.homePhone !== null) {
962
726
  contactsData.push({
963
727
  contragentId: user.id,
964
- id:
965
- 'response' in user && 'contacts' in user.response
966
- ? user.response.contacts.find(i => i.type === 'HOME').id
967
- : 0,
728
+ id: 'response' in user && 'contacts' in user.response ? user.response.contacts.find(i => i.type === 'HOME').id : 0,
968
729
  newValue: '',
969
730
  note: '',
970
731
  primaryFlag: 'N',
@@ -982,10 +743,7 @@ export const useDataStore = defineStore('data', {
982
743
  let documentsData = [];
983
744
  documentsData.push({
984
745
  contragentId: user.id,
985
- id:
986
- 'response' in user && 'documents' in user.response
987
- ? user.response.documents[0].id
988
- : 0,
746
+ id: 'response' in user && 'documents' in user.response ? user.response.documents[0].id : 0,
989
747
  description: null,
990
748
  expireDate: user.getDateByKey('documentExpire'),
991
749
  issueDate: user.getDateByKey('documentDate'),
@@ -1004,10 +762,7 @@ export const useDataStore = defineStore('data', {
1004
762
  // ! SaveContragent -> Addresses
1005
763
  let addressData = [];
1006
764
  addressData.push({
1007
- id:
1008
- 'response' in user && 'addresses' in user.response
1009
- ? user.response.addresses[0].id
1010
- : 0,
765
+ id: 'response' in user && 'addresses' in user.response ? user.response.addresses[0].id : 0,
1011
766
  contragentId: user.id,
1012
767
  countryCode: user.birthPlace.ids,
1013
768
  countryName: user.birthPlace.nameRu,
@@ -1035,209 +790,125 @@ export const useDataStore = defineStore('data', {
1035
790
  documents: documentsData,
1036
791
  addresses: addressData,
1037
792
  };
1038
- try {
1039
- const personId = await this.api.saveContragent(data);
1040
- if (personId) {
1041
- await this.getContragentById(
1042
- personId,
1043
- whichForm,
1044
- false,
1045
- whichIndex,
1046
- );
1047
- this.formStore.otpTokenId = null;
1048
- }
1049
- } catch (saveErr) {
1050
- console.log(saveErr);
1051
- if ('response' in saveErr) {
1052
- this.showToaster('error', saveErr.response.data, 5000);
1053
- this.isLoading = false;
1054
- return false;
1055
- }
793
+
794
+ const personId = await this.api.saveContragent(data);
795
+ if (personId) {
796
+ await this.getContragentById(personId, whichForm, false, whichIndex);
797
+ user.otpTokenId = null;
1056
798
  }
1057
799
  } catch (err) {
1058
- console.log(err);
1059
800
  this.isLoading = false;
1060
- this.showToaster(
1061
- 'error',
1062
- this.t('toaster.error') + err?.response?.data,
1063
- 2000,
1064
- );
1065
- return false;
801
+ return ErrorHandler(err);
1066
802
  }
1067
803
  if (onlySaveAction) {
1068
804
  this.isLoading = false;
1069
805
  }
1070
806
  return true;
1071
807
  },
1072
- async saveMember(whichForm, key, whichMember, whichIndex = null) {
808
+ async saveMember(member, whichMember, memberFromApplicaiton) {
1073
809
  let data = {};
1074
810
  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;
811
+ data = {
812
+ processInstanceId: this.formStore.applicationData.processInstanceId,
813
+ insisId: member.id,
814
+ iin: member.iin.replace(/-/g, ''),
815
+ longName: member.longName,
816
+ isIpdl: member.signOfIPDL.nameRu == 'Да' ? true : false,
817
+ isTerror: member.isTerror,
818
+ isIpdlCompliance: null,
819
+ isTerrorCompliance: null,
820
+ };
821
+ data.id = memberFromApplicaiton && memberFromApplicaiton.id ? memberFromApplicaiton.id : null;
822
+ if (whichMember === 'Client') {
823
+ data.isInsured = this.formStore.isPolicyholderInsured;
824
+ data.isActOwnBehalf = this.formStore.isActOwnBehalf;
825
+ data.profession = member.job;
826
+ data.position = member.jobPosition;
827
+ data.jobName = member.jobPlace;
828
+ data.familyStatusId = member.familyStatus.id;
829
+ }
830
+ if (whichMember === 'Spokesman') {
831
+ if (!!memberFromApplicaiton && memberFromApplicaiton.iin !== data.iin) {
832
+ delete data.id;
833
+ await this.api.deleteMember('Spokesman', this.formStore.applicationData.processInstanceId);
1101
834
  }
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;
835
+ data.migrationCard = member.migrationCard;
836
+ const migrationCardIssueDate = formatDate(member.migrationCardIssueDate);
837
+ if (migrationCardIssueDate) data.migrationCardIssueDate = migrationCardIssueDate.toISOString();
838
+ const migrationCardExpireDate = formatDate(member.migrationCardExpireDate);
839
+ if (migrationCardExpireDate) data.migrationCardExpireDate = migrationCardExpireDate.toISOString();
840
+ data.confirmDocType = member.confirmDocType;
841
+ data.confirmDocNumber = member.confirmDocNumber;
842
+ const confirmDocIssueDate = formatDate(member.confirmDocIssueDate);
843
+ if (confirmDocIssueDate) data.confirmDocIssueDate = confirmDocIssueDate.toISOString();
844
+ const confirmDocExpireDate = formatDate(member.confirmDocExpireDate);
845
+ if (confirmDocExpireDate) data.confirmDocExpireDate = confirmDocExpireDate.toISOString();
846
+ data.clientLongName = this.formStore.applicationData.clientApp.longName;
847
+ data.notaryLongName = member.notaryLongName;
848
+ data.notaryLicenseNumber = member.notaryLicenseNumber;
849
+ const notaryLicenseDate = formatDate(member.notaryLicenseDate);
850
+ if (notaryLicenseDate) data.notaryLicenseDate = notaryLicenseDate.toISOString();
851
+ data.notaryLicenseIssuer = member.notaryLicenseIssuer;
852
+ data.jurLongName = member.jurLongName;
853
+ data.fullNameRod = member.fullNameRod;
854
+ data.confirmDocTypeKz = member.confirmDocTypeKz;
855
+ data.confirmDocTypeRod = member.confirmDocTypeRod;
856
+ data.isNotary = member.isNotary;
857
+ }
858
+ if (whichMember === 'Insured') {
859
+ if (
860
+ this.formStore.applicationData &&
861
+ this.formStore.applicationData.insuredApp &&
862
+ this.formStore.applicationData.insuredApp.length &&
863
+ this.formStore.applicationData.insuredApp.every(i => i.iin !== data.iin) &&
864
+ data.id !== null
865
+ ) {
866
+ await this.api.deleteMember('Insured', data.id);
867
+ delete data.id;
1144
868
  }
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;
869
+ data.isDisability = this.formStore.isPolicyholderInsured ? false : member.isDisability.nameRu == 'Да';
870
+ data.disabilityGroupId = data.isDisability ? member.disabilityGroupId.id : null;
871
+ data.profession = member.job;
872
+ data.position = member.jobPosition;
873
+ data.jobName = member.jobPlace;
874
+ data.familyStatusId = member.familyStatus.id;
875
+ }
876
+ if (whichMember === 'Beneficiary') {
877
+ if (
878
+ this.formStore.applicationData &&
879
+ this.formStore.applicationData.beneficiaryApp &&
880
+ this.formStore.applicationData.beneficiaryApp.length &&
881
+ this.formStore.applicationData.beneficiaryApp.every(i => i.iin !== data.iin) &&
882
+ data.id !== null
883
+ ) {
884
+ await this.api.deleteMember('Beneficiary', data.id);
885
+ delete data.id;
1191
886
  }
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;
887
+ data.familyStatusId = member.familyStatus.id == 0 ? null : member.familyStatus.id;
888
+ data.percentage = Number(member.percentageOfPayoutAmount);
889
+ data.relationId = member.relationDegree.ids;
890
+ data.relationName = member.relationDegree.nameRu;
891
+ }
892
+ if (whichMember === 'BeneficialOwner') {
893
+ if (data.id === 0) {
894
+ data.id = null;
1216
895
  }
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;
896
+ if (
897
+ this.formStore.applicationData &&
898
+ this.formStore.applicationData.beneficialOwnerApp &&
899
+ this.formStore.applicationData.beneficialOwnerApp.length &&
900
+ this.formStore.applicationData.beneficialOwnerApp.every(i => i.iin !== data.iin) &&
901
+ data.id !== null
902
+ ) {
903
+ await this.api.deleteMember('BeneficialOwner', data.id);
904
+ delete data.id;
1235
905
  }
906
+ data.familyStatusId = member.familyStatus.id;
1236
907
  }
1237
908
  await this.api.setMember(whichMember, data);
1238
909
  return true;
1239
910
  } catch (err) {
1240
- console.log(err);
911
+ return ErrorHandler(err, err.response?.data?.errors && Object.values(err.response?.data?.errors).join(' -> '));
1241
912
  }
1242
913
  },
1243
914
  searchFromList(whichForm, searchIt, whichIndex = null) {
@@ -1266,9 +937,7 @@ export const useDataStore = defineStore('data', {
1266
937
  if (whichIndex === null) {
1267
938
  this.formStore[whichForm][whichField] = result ? result : new Value();
1268
939
  } else {
1269
- this.formStore[whichForm][whichIndex][whichField] = result
1270
- ? result
1271
- : new Value();
940
+ this.formStore[whichForm][whichIndex][whichField] = result ? result : new Value();
1272
941
  }
1273
942
  }
1274
943
  },
@@ -1276,19 +945,16 @@ export const useDataStore = defineStore('data', {
1276
945
  try {
1277
946
  this.isLoading = true;
1278
947
  const anketaToken = await this.api.setSurvey(data);
1279
- window.scrollTo({ top: 0, behavior: 'smooth' });
1280
948
  this.showToaster('success', this.t('toaster.successSaved'), 2000);
1281
949
  return anketaToken;
1282
950
  } catch (error) {
1283
- this.showToaster('error', this.t('toaster.undefinedError'), 1000);
951
+ return ErrorHandler(err);
1284
952
  } finally {
1285
953
  this.isLoading = false;
1286
954
  }
1287
955
  },
1288
- async getFromApi(whichField, whichRequest, parameter) {
1289
- const storageValue = JSON.parse(
1290
- localStorage.getItem(whichField) || 'null',
1291
- );
956
+ async getFromApi(whichField, whichRequest, parameter, reset = false) {
957
+ const storageValue = JSON.parse(localStorage.getItem(whichField) || 'null');
1292
958
  const currentHour = new Date().getHours();
1293
959
 
1294
960
  const getDataCondition = () => {
@@ -1296,24 +962,11 @@ export const useDataStore = defineStore('data', {
1296
962
  const hasHourKey = 'hour' in storageValue;
1297
963
  const hasModeKey = 'mode' in storageValue;
1298
964
  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;
965
+ if (storageValue && (hasHourKey === false || hasModeKey === false || hasValueKey === false)) return true;
966
+ if (storageValue && (storageValue.hour !== currentHour || storageValue.mode !== import.meta.env.MODE || storageValue.value.length === 0)) return true;
1313
967
  };
1314
-
1315
- if (getDataCondition()) {
1316
- this.whichField = [];
968
+ if (!!getDataCondition() || reset === true) {
969
+ this[whichField] = [];
1317
970
  try {
1318
971
  const response = await this.api[whichRequest](parameter);
1319
972
  if (response) {
@@ -1326,13 +979,6 @@ export const useDataStore = defineStore('data', {
1326
979
  }),
1327
980
  );
1328
981
  this[whichField] = response;
1329
- if (
1330
- this[whichField].length &&
1331
- this[whichField][this[whichField].length - 1].nameRu ==
1332
- 'невключено'
1333
- ) {
1334
- this[whichField].unshift(this[whichField].pop());
1335
- }
1336
982
  }
1337
983
  } catch (err) {
1338
984
  console.log(err);
@@ -1347,47 +993,39 @@ export const useDataStore = defineStore('data', {
1347
993
  return await this.getFromApi('countries', 'getCountries');
1348
994
  },
1349
995
  async getCitizenshipCountries() {
1350
- return await this.getFromApi(
1351
- 'citizenshipCountries',
1352
- 'getCitizenshipCountries',
1353
- );
996
+ return await this.getFromApi('citizenshipCountries', 'getCitizenshipCountries');
1354
997
  },
1355
998
  async getTaxCountries() {
1356
999
  return await this.getFromApi('taxCountries', 'getTaxCountries');
1357
1000
  },
1358
1001
  async getAdditionalTaxCountries() {
1359
- return await this.getFromApi(
1360
- 'addTaxCountries',
1361
- 'getAdditionalTaxCountries',
1362
- );
1002
+ return await this.getFromApi('addTaxCountries', 'getAdditionalTaxCountries');
1363
1003
  },
1364
- async getStates(key) {
1004
+ async getStates(key, member) {
1365
1005
  await this.getFromApi('states', 'getStates');
1366
- if (key && this.contragent[key] && this.contragent[key].ids !== null) {
1367
- return this.states.filter(i => i.code === this.contragent[key].ids);
1006
+ if (key && member[key] && member[key].ids !== null) {
1007
+ return this.states.filter(i => i.code === member[key].ids);
1368
1008
  }
1369
1009
  return this.states;
1370
1010
  },
1371
- async getRegions(key) {
1011
+ async getRegions(key, member) {
1372
1012
  await this.getFromApi('regions', 'getRegions');
1373
- if (key && this.contragent[key] && this.contragent[key].ids !== null) {
1374
- return this.regions.filter(i => i.code === this.contragent[key].ids);
1013
+ if (key && member[key] && member[key].ids !== null) {
1014
+ return this.regions.filter(i => i.code === member[key].ids);
1375
1015
  }
1376
- let registrationProvince = this.contragent.registrationProvince;
1377
- if (registrationProvince.ids !== null) {
1378
- return this.regions.filter(i => i.code === registrationProvince.ids);
1016
+ if (member.registrationProvince.ids !== null) {
1017
+ return this.regions.filter(i => i.code === member.registrationProvince.ids);
1379
1018
  } else {
1380
1019
  return this.regions;
1381
1020
  }
1382
1021
  },
1383
- async getCities(key) {
1022
+ async getCities(key, member) {
1384
1023
  await this.getFromApi('cities', 'getCities');
1385
- if (key && this.contragent[key] && this.contragent[key].ids !== null) {
1386
- return this.cities.filter(i => i.code === this.contragent[key].ids);
1024
+ if (key && member[key] && member[key].ids !== null) {
1025
+ return this.cities.filter(i => i.code === member[key].ids);
1387
1026
  }
1388
- let registrationProvince = this.contragent.registrationProvince;
1389
- if (registrationProvince.ids !== null) {
1390
- return this.cities.filter(i => i.code === registrationProvince.ids);
1027
+ if (member.registrationProvince.ids !== null) {
1028
+ return this.cities.filter(i => i.code === member.registrationProvince.ids);
1391
1029
  } else {
1392
1030
  return this.cities;
1393
1031
  }
@@ -1396,10 +1034,7 @@ export const useDataStore = defineStore('data', {
1396
1034
  return await this.getFromApi('localityTypes', 'getLocalityTypes');
1397
1035
  },
1398
1036
  async getDocumentTypes() {
1399
- const document_list = await this.getFromApi(
1400
- 'documentTypes',
1401
- 'getDocumentTypes',
1402
- );
1037
+ const document_list = await this.getFromApi('documentTypes', 'getDocumentTypes');
1403
1038
  await this.getDicFileTypeList();
1404
1039
  return document_list.filter(doc => {
1405
1040
  for (const dic of this.dicFileTypeList) {
@@ -1429,124 +1064,67 @@ export const useDataStore = defineStore('data', {
1429
1064
  },
1430
1065
  async getSectorCodeList() {
1431
1066
  await this.getFromApi('economySectorCode', 'getSectorCode');
1432
- if (this.economySectorCode[1].ids != '500003.9') {
1433
- this.economySectorCode = this.economySectorCode.reverse();
1434
- }
1435
1067
  return this.economySectorCode;
1436
1068
  },
1437
1069
  async getFamilyStatuses() {
1438
1070
  return await this.getFromApi('familyStatuses', 'getFamilyStatuses');
1439
1071
  },
1440
1072
  async getRelationTypes() {
1073
+ // TODO Remove this & add filtering in openPanel method
1441
1074
  await this.getFromApi('relations', 'getRelationTypes');
1442
- const filteredRelations = this.relations.filter(
1443
- i => Number(i.ids) >= 6 && Number(i.ids) <= 15,
1444
- );
1445
- const otherRelations = this.relations.filter(
1446
- i => Number(i.ids) < 6 || Number(i.ids) > 15,
1447
- );
1075
+ const filteredRelations = this.relations.filter(i => Number(i.ids) >= 6 && Number(i.ids) <= 15);
1076
+ const otherRelations = this.relations.filter(i => Number(i.ids) < 6 || Number(i.ids) > 15);
1448
1077
  return [...filteredRelations, ...otherRelations];
1449
1078
  },
1450
1079
  async getProcessIndexRate() {
1451
- const response = await this.getFromApi(
1452
- 'processIndexRate',
1453
- 'getProcessIndexRate',
1454
- this.processCode,
1455
- );
1080
+ const response = await this.getFromApi('processIndexRate', 'getProcessIndexRate', this.processCode);
1456
1081
  return response ? response : [];
1457
1082
  },
1458
1083
  async getProcessCoverTypeSum(type) {
1459
- return await this.getFromApi(
1460
- 'processCoverTypeSum',
1461
- 'getProcessCoverTypeSum',
1462
- type,
1463
- );
1084
+ return await this.getFromApi('processCoverTypeSum', 'getProcessCoverTypeSum', type);
1464
1085
  },
1465
1086
  async getProcessPaymentPeriod() {
1466
- return await this.getFromApi(
1467
- 'processPaymentPeriod',
1468
- 'getProcessPaymentPeriod',
1469
- this.processCode,
1470
- );
1087
+ return await this.getFromApi('processPaymentPeriod', 'getProcessPaymentPeriod', this.processCode);
1471
1088
  },
1472
1089
  async getQuestionRefs(id) {
1473
- return await this.getFromApi('questionRefs', 'getQuestionRefs', id);
1090
+ return await this.getFromApi('questionRefs', 'getQuestionRefs', id, true);
1474
1091
  },
1475
1092
  async getProcessTariff() {
1476
1093
  return await this.getFromApi('processTariff', 'getProcessTariff');
1477
1094
  },
1478
1095
  async getAdditionalInsuranceTermsAnswers(questionId) {
1479
1096
  try {
1480
- const answers = await this.api.getAdditionalInsuranceTermsAnswers(
1481
- this.processCode,
1482
- questionId,
1483
- );
1484
- answers.unshift(answers.pop());
1097
+ const answers = await this.api.getAdditionalInsuranceTermsAnswers(this.processCode, questionId);
1485
1098
  return answers;
1486
1099
  } catch (err) {
1487
1100
  console.log(err);
1488
1101
  }
1489
1102
  },
1490
- async getQuestionList(
1491
- surveyType,
1492
- processInstanceId,
1493
- insuredId,
1494
- baseField,
1495
- secondaryField,
1496
- ) {
1497
- if (!this[baseField].length) {
1103
+ async getQuestionList(surveyType, processInstanceId, insuredId, baseField, secondaryField) {
1104
+ if (!this.formStore[baseField] || (this.formStore[baseField] && !this.formStore[baseField].length)) {
1498
1105
  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;
1106
+ const [{ value: baseQuestions }, { value: secondaryQuestions }] = await Promise.allSettled([
1107
+ this.api.getQuestionList(surveyType, processInstanceId, insuredId),
1108
+ this.api.getQuestionListSecond(`${surveyType}second`, processInstanceId, insuredId),
1109
+ ]);
1110
+ this.formStore[baseField] = baseQuestions;
1111
+ this.formStore[secondaryField] = secondaryQuestions;
1514
1112
  } catch (err) {
1515
1113
  console.log(err);
1516
1114
  }
1517
1115
  }
1518
- return this[baseField];
1116
+ return this.formStore[baseField];
1519
1117
  },
1520
1118
  getNumberWithSpaces(n) {
1521
- return n === null
1522
- ? null
1523
- : Number(
1524
- (typeof n === 'string' ? n : n.toFixed().toString()).replace(
1525
- /[^0-9]+/g,
1526
- '',
1527
- ),
1528
- ).toLocaleString('ru');
1529
- },
1530
- async getTaskList(
1531
- search = '',
1532
- groupCode = 'Work',
1533
- onlyGet = false,
1534
- needToReturn = false,
1535
- key = 'dateCreated',
1536
- processInstanceId = null,
1537
- byOneProcess = null,
1538
- ) {
1119
+ return n === null ? null : Number((typeof n === 'string' ? n : n.toFixed().toString()).replace(/[^0-9]+/g, '')).toLocaleString('ru');
1120
+ },
1121
+ async getTaskList(search = '', groupCode = 'Work', onlyGet = false, needToReturn = false, key = 'dateCreated', processInstanceId = null, byOneProcess = null) {
1539
1122
  if (onlyGet === false) {
1540
1123
  this.isLoading = true;
1541
1124
  }
1542
1125
  try {
1543
1126
  const column = this.isColumnAsc[key] === null ? 'dateCreated' : key;
1544
- const direction =
1545
- this.isColumnAsc[key] === null
1546
- ? 'desc'
1547
- : this.isColumnAsc[key] === true
1548
- ? 'asc'
1549
- : 'desc';
1127
+ const direction = this.isColumnAsc[key] === null ? 'desc' : this.isColumnAsc[key] === true ? 'asc' : 'desc';
1550
1128
  const query = {
1551
1129
  pageIndex: processInstanceId === null ? this.historyPageIndex - 1 : 0,
1552
1130
  pageSize: this.historyPageSize,
@@ -1560,11 +1138,7 @@ export const useDataStore = defineStore('data', {
1560
1138
  delete query.processCodes;
1561
1139
  query.processCode = byOneProcess;
1562
1140
  }
1563
- const taskList = await this.api.getTaskList(
1564
- processInstanceId === null
1565
- ? query
1566
- : { ...query, processInstanceId: processInstanceId },
1567
- );
1141
+ const taskList = await this.api.getTaskList(processInstanceId === null ? query : { ...query, processInstanceId: processInstanceId });
1568
1142
  if (needToReturn) {
1569
1143
  this.isLoading = false;
1570
1144
  return taskList.items;
@@ -1643,117 +1217,6 @@ export const useDataStore = defineStore('data', {
1643
1217
  this.isLoading = false;
1644
1218
  }
1645
1219
  },
1646
- async getOtpStatus(iin, phone, processInstanceId = null) {
1647
- try {
1648
- const otpData = {
1649
- iin: iin.replace(/-/g, ''),
1650
- phoneNumber: formatPhone(phone),
1651
- type: 'AgreementOtp',
1652
- };
1653
- return await this.api.getOtpStatus(
1654
- processInstanceId !== null && processInstanceId != 0
1655
- ? {
1656
- ...otpData,
1657
- processInstanceId: processInstanceId,
1658
- }
1659
- : otpData,
1660
- );
1661
- } catch (err) {
1662
- console.log(err);
1663
- this.showToaster('error', err.response.data, 3000);
1664
- }
1665
- },
1666
- async sendOtp(iin, phone, processInstanceId = null, onInit = false) {
1667
- this.isLoading = true;
1668
- let otpStatus = false;
1669
- let otpResponse = {};
1670
- try {
1671
- if (iin && iin.length === 15 && phone && phone.length === 18) {
1672
- const status = await this.getOtpStatus(iin, phone, processInstanceId);
1673
- if (status === true) {
1674
- this.showToaster('success', this.t('toaster.hasSuccessOtp'), 3000);
1675
- otpStatus = true;
1676
- this.isLoading = false;
1677
- return { otpStatus, otpResponse };
1678
- } else if (status === false && onInit === false) {
1679
- const otpData = {
1680
- iin: iin.replace(/-/g, ''),
1681
- phoneNumber: formatPhone(phone),
1682
- type: 'AgreementOtp',
1683
- };
1684
- otpResponse = await this.api.sendOtp(
1685
- processInstanceId !== null && processInstanceId != 0
1686
- ? {
1687
- ...otpData,
1688
- processInstanceId: processInstanceId,
1689
- }
1690
- : otpData,
1691
- );
1692
- this.isLoading = false;
1693
- if (!!otpResponse) {
1694
- if (
1695
- 'errMessage' in otpResponse &&
1696
- otpResponse.errMessage !== null
1697
- ) {
1698
- this.showToaster('error', otpResponse.errMessage, 3000);
1699
- return { otpStatus };
1700
- }
1701
- if ('result' in otpResponse && otpResponse.result === null) {
1702
- if ('statusName' in otpResponse && !!otpResponse.statusName) {
1703
- this.showToaster('error', otpResponse.statusName, 3000);
1704
- return { otpStatus };
1705
- }
1706
- if ('status' in otpResponse && !!otpResponse.status) {
1707
- this.showToaster('error', otpResponse.status, 3000);
1708
- return { otpStatus };
1709
- }
1710
- }
1711
- if ('tokenId' in otpResponse && otpResponse.tokenId) {
1712
- this.contragent.otpTokenId = otpResponse.tokenId;
1713
- this.showToaster('success', this.t('toaster.successOtp'), 3000);
1714
- }
1715
- } else {
1716
- this.showToaster('error', this.t('toaster.undefinedError'), 3000);
1717
- return { otpStatus };
1718
- }
1719
- }
1720
- } else {
1721
- if (onInit === false) {
1722
- this.showToaster(
1723
- 'error',
1724
- this.t('toaster.errorFormField', {
1725
- text: 'Номер телефона, ИИН',
1726
- }),
1727
- );
1728
- this.isLoading = false;
1729
- }
1730
- }
1731
- return { otpStatus, otpResponse };
1732
- } catch (err) {
1733
- this.isLoading = false;
1734
- if ('response' in err) {
1735
- if (
1736
- 'statusName' in err.response.data &&
1737
- !!err.response.data.statusName
1738
- ) {
1739
- this.showToaster(
1740
- 'error',
1741
- this.t('toaster.phoneNotFoundInBMG'),
1742
- 3000,
1743
- );
1744
- return { otpStatus };
1745
- }
1746
- if ('status' in err.response.data && !!err.response.data.status) {
1747
- this.showToaster('error', err.response.data.status, 3000);
1748
- return { otpStatus };
1749
- }
1750
- }
1751
- } finally {
1752
- this.isLoading = false;
1753
- }
1754
- this.isLoading = false;
1755
- return { otpStatus, otpResponse };
1756
- },
1757
1220
  async getProcessList() {
1758
1221
  this.isLoading = true;
1759
1222
  try {
@@ -1792,7 +1255,7 @@ export const useDataStore = defineStore('data', {
1792
1255
  this.isLoading = true;
1793
1256
  this.AgentDataList = await this.api.searchAgentByName(name);
1794
1257
  if (!this.AgentDataList.length) {
1795
- showToaster('error', this.t('toaster.notFound'), 1500);
1258
+ this.showToaster('error', this.t('toaster.notFound'), 1500);
1796
1259
  }
1797
1260
  } catch (err) {
1798
1261
  console.log(err);
@@ -1806,10 +1269,8 @@ export const useDataStore = defineStore('data', {
1806
1269
  processInstanceId: this.formStore.applicationData.processInstanceId,
1807
1270
  agentId: this.formStore.AgentData.agentId,
1808
1271
  agentName: this.formStore.AgentData.fullName,
1809
- salesChannel:
1810
- this.formStore.applicationData.insisWorkDataApp.salesChannel,
1811
- salesChannelName:
1812
- this.formStore.applicationData.insisWorkDataApp.salesChannelName,
1272
+ salesChannel: this.formStore.applicationData.insisWorkDataApp.salesChannel,
1273
+ salesChannelName: this.formStore.applicationData.insisWorkDataApp.salesChannelName,
1813
1274
  insrType: this.formStore.applicationData.insisWorkDataApp.insrType,
1814
1275
  saleChanellPolicy: this.formStore.SaleChanellPolicy.ids,
1815
1276
  saleChanellPolicyName: this.formStore.SaleChanellPolicy.nameRu,
@@ -1817,8 +1278,7 @@ export const useDataStore = defineStore('data', {
1817
1278
  regionPolicyName: this.formStore.RegionPolicy.nameRu,
1818
1279
  managerPolicy: this.formStore.ManagerPolicy.ids,
1819
1280
  managerPolicyName: this.formStore.ManagerPolicy.nameRu,
1820
- insuranceProgramType:
1821
- this.formStore.applicationData.insisWorkDataApp.insuranceProgramType,
1281
+ insuranceProgramType: this.formStore.applicationData.insisWorkDataApp.insuranceProgramType,
1822
1282
  };
1823
1283
  try {
1824
1284
  this.isLoading = true;
@@ -1829,25 +1289,10 @@ export const useDataStore = defineStore('data', {
1829
1289
  this.isLoading = false;
1830
1290
  }
1831
1291
  },
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
1292
  async filterManagerByRegion(dictName, filterName) {
1845
1293
  try {
1846
1294
  this.isLoading = true;
1847
- this[`${dictName}List`] = await this.api.filterManagerByRegion(
1848
- dictName,
1849
- filterName,
1850
- );
1295
+ this[`${dictName}List`] = await this.api.filterManagerByRegion(dictName, filterName);
1851
1296
  } catch (err) {
1852
1297
  console.log(err);
1853
1298
  } finally {
@@ -1857,29 +1302,24 @@ export const useDataStore = defineStore('data', {
1857
1302
  async getUnderwritingCouncilData(id) {
1858
1303
  try {
1859
1304
  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;
1305
+ this.formStore.affilationResolution.id = response.underwritingCouncilAppDto.id;
1306
+ this.formStore.affilationResolution.date = response.underwritingCouncilAppDto.date ? reformatDate(response.underwritingCouncilAppDto.date) : null;
1307
+ this.formStore.affilationResolution.number = response.underwritingCouncilAppDto.number ? response.underwritingCouncilAppDto.number : null;
1868
1308
  } catch (err) {
1869
1309
  console.log(err);
1870
1310
  }
1871
1311
  },
1872
1312
  async setConfirmation() {
1873
1313
  const data = {
1874
- id: this.affilationResolution.id,
1875
- processInstanceId: this.affilationResolution.processInstanceId,
1876
- number: this.affilationResolution.number,
1877
- date: formatDate(this.affilationResolution.date),
1314
+ id: this.formStore.affilationResolution.id,
1315
+ processInstanceId: this.formStore.affilationResolution.processInstanceId,
1316
+ number: this.formStore.affilationResolution.number,
1317
+ date: formatDate(this.formStore.affilationResolution.date)?.toISOString(),
1878
1318
  };
1879
1319
  try {
1880
1320
  this.isLoading = true;
1881
1321
  await this.api.setConfirmation(data);
1882
- showToaster('success', this.t('toaster.successSaved'));
1322
+ this.showToaster('success', this.t('toaster.successSaved'));
1883
1323
  return true;
1884
1324
  } catch (err) {
1885
1325
  this.showToaster('error', this.t('toaster.error'));
@@ -1892,7 +1332,7 @@ export const useDataStore = defineStore('data', {
1892
1332
  try {
1893
1333
  this.isLoading = true;
1894
1334
  await this.api.sendUnderwritingCouncilTask(data);
1895
- showToaster('success', this.t('toaster.successOperation'), 5000);
1335
+ this.showToaster('success', this.t('toaster.successOperation'), 5000);
1896
1336
  return true;
1897
1337
  } catch (err) {
1898
1338
  console.log(err);
@@ -1903,17 +1343,14 @@ export const useDataStore = defineStore('data', {
1903
1343
  }
1904
1344
  },
1905
1345
  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);
1346
+ if (!this.formStore.definedAnswersId[whichSurvey].hasOwnProperty(filter)) {
1347
+ this.formStore.definedAnswersId[whichSurvey][filter] = await this.api.definedAnswers(filter);
1909
1348
  }
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;
1349
+ if (value !== null && this.formStore.definedAnswersId[whichSurvey][filter].length) {
1350
+ const answer = this.formStore.definedAnswersId[whichSurvey][filter].find(answer => answer.nameRu === value);
1351
+ this.formStore[whichSurvey].body[index].first.answerId = answer.ids;
1915
1352
  }
1916
- return this.definedAnswersId[whichSurvey];
1353
+ return this.formStore.definedAnswersId[whichSurvey];
1917
1354
  },
1918
1355
  async getPaymentTable(id) {
1919
1356
  try {
@@ -1927,6 +1364,47 @@ export const useDataStore = defineStore('data', {
1927
1364
  console.log(err);
1928
1365
  }
1929
1366
  },
1367
+ async getDefaultCalculationData(showLoader = false) {
1368
+ this.isLoading = showLoader;
1369
+ try {
1370
+ const calculationData = await this.api.getDefaultCalculationData();
1371
+ return calculationData;
1372
+ } catch (err) {
1373
+ ErrorHandler(err);
1374
+ } finally {
1375
+ this.isLoading = false;
1376
+ }
1377
+ },
1378
+ async calculateWithoutApplication(showLoader = false) {
1379
+ this.isLoading = showLoader;
1380
+ try {
1381
+ const calculationData = {
1382
+ signDate: formatDate(this.formStore.productConditionsForm.signDate)?.toISOString(),
1383
+ birthDate: formatDate(this.formStore.productConditionsForm.birthDate)?.toISOString(),
1384
+ gender: this.formStore.productConditionsForm.gender.id,
1385
+ amount: getNumber(this.formStore.productConditionsForm.requestedSumInsured),
1386
+ premium: getNumber(this.formStore.productConditionsForm.insurancePremiumPerMonth),
1387
+ coverPeriod: this.formStore.productConditionsForm.coverPeriod,
1388
+ payPeriod: this.formStore.productConditionsForm.coverPeriod,
1389
+ indexRateId: this.formStore.productConditionsForm.processIndexRate?.id
1390
+ ? this.formStore.productConditionsForm.processIndexRate.id
1391
+ : this.processIndexRate.find(i => i.code === '0')?.id,
1392
+ paymentPeriodId: this.formStore.productConditionsForm.paymentPeriod.id,
1393
+ addCovers: this.formStore.additionalInsuranceTermsWithout,
1394
+ };
1395
+ console.log(calculationData);
1396
+ const calculationResponse = await this.api.calculateWithoutApplication(calculationData);
1397
+ this.formStore.productConditionsForm.requestedSumInsured = this.getNumberWithSpaces(calculationResponse.amount);
1398
+ this.formStore.productConditionsForm.insurancePremiumPerMonth = this.getNumberWithSpaces(calculationResponse.premium);
1399
+ this.formStore.additionalInsuranceTermsWithout = calculationResponse.addCovers;
1400
+ this.showToaster('success', this.t('toaster.calculated'), 1000);
1401
+ } catch (err) {
1402
+ ErrorHandler(err);
1403
+ } finally {
1404
+ this.isLoading = false;
1405
+ return !!this.formStore.productConditionsForm.requestedSumInsured && !!this.formStore.productConditionsForm.insurancePremiumPerMonth;
1406
+ }
1407
+ },
1930
1408
  async calculate(taskId) {
1931
1409
  this.isLoading = true;
1932
1410
  try {
@@ -1934,70 +1412,32 @@ export const useDataStore = defineStore('data', {
1934
1412
  baiterekApp: null,
1935
1413
  policyAppDto: {
1936
1414
  id: this.formStore.applicationData.policyAppDto.id,
1937
- processInstanceId:
1938
- this.formStore.applicationData.policyAppDto.processInstanceId,
1415
+ processInstanceId: this.formStore.applicationData.policyAppDto.processInstanceId,
1939
1416
  policyId: null,
1940
1417
  policyNumber: null,
1941
1418
  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,
1419
+ amount: this.formStore.productConditionsForm.requestedSumInsured != null ? Number(this.formStore.productConditionsForm.requestedSumInsured.replace(/\s/g, '')) : null,
1951
1420
  premium:
1952
- this.formStore.productConditionsForm.insurancePremiumPerMonth !=
1953
- null
1954
- ? Number(
1955
- this.formStore.productConditionsForm.insurancePremiumPerMonth.replace(
1956
- /\s/g,
1957
- '',
1958
- ),
1959
- )
1421
+ this.formStore.productConditionsForm.insurancePremiumPerMonth != null
1422
+ ? Number(this.formStore.productConditionsForm.insurancePremiumPerMonth.replace(/\s/g, ''))
1960
1423
  : null,
1961
1424
  isSpokesman: this.formStore.hasRepresentative,
1962
1425
  coverPeriod: this.formStore.productConditionsForm.coverPeriod,
1963
1426
  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
1427
+ annualIncome: this.formStore.productConditionsForm.annualIncome ? Number(this.formStore.productConditionsForm.annualIncome.replace(/\s/g, '')) : null,
1428
+ indexRateId: this.formStore.productConditionsForm.processIndexRate?.id
1974
1429
  ? this.formStore.productConditionsForm.processIndexRate.id
1975
1430
  : 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,
1431
+ paymentPeriodId: this.formStore.productConditionsForm.paymentPeriod.id,
1432
+ lifeMultiply: formatProcents(this.formStore.productConditionsForm.lifeMultiply),
1433
+ lifeAdditive: formatProcents(this.formStore.productConditionsForm.lifeAdditive),
1434
+ adbMultiply: formatProcents(this.formStore.productConditionsForm.adbMultiply),
1435
+ adbAdditive: formatProcents(this.formStore.productConditionsForm.adbAdditive),
1436
+ disabilityMultiply: formatProcents(this.formStore.productConditionsForm.disabilityMultiply),
1437
+ disabilityAdditive: formatProcents(this.formStore.productConditionsForm.adbAdditive),
1438
+ riskGroup: this.formStore.productConditionsForm.riskGroup?.id ? this.formStore.productConditionsForm.riskGroup.id : 1,
1999
1439
  },
2000
- addCoversDto: this.additionalInsuranceTerms,
1440
+ addCoversDto: this.formStore.additionalInsuranceTerms,
2001
1441
  };
2002
1442
 
2003
1443
  try {
@@ -2013,58 +1453,39 @@ export const useDataStore = defineStore('data', {
2013
1453
 
2014
1454
  const applicationData = await this.api.getApplicationData(taskId);
2015
1455
  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);
1456
+ this.formStore.additionalInsuranceTerms = this.formStore.applicationData.addCoverDto;
1457
+ if (this.formStore.productConditionsForm.insurancePremiumPerMonth != null) {
1458
+ this.formStore.productConditionsForm.requestedSumInsured = this.getNumberWithSpaces(result);
2024
1459
  } else {
2025
- this.formStore.productConditionsForm.insurancePremiumPerMonth =
2026
- this.getNumberWithSpaces(result);
1460
+ this.formStore.productConditionsForm.insurancePremiumPerMonth = this.getNumberWithSpaces(result);
2027
1461
  }
2028
1462
  this.showToaster('success', this.t('toaster.calculated'), 1000);
2029
1463
  } catch (err) {
2030
1464
  console.log(err);
2031
1465
  }
2032
1466
  } catch (err) {
2033
- this.showToaster('error', this.t('toaster.undefinedError'), 5000);
1467
+ ErrorHandler(err);
2034
1468
  console.log(err, 'error');
2035
1469
  }
2036
1470
  this.isLoading = false;
2037
1471
  },
2038
- async startApplication(whichForm) {
1472
+ async startApplication(member) {
2039
1473
  try {
2040
1474
  const data = {
2041
- clientId: this.formStore[whichForm].id,
2042
- iin: this.formStore[whichForm].iin.replace(/-/g, ''),
2043
- longName: this.formStore[whichForm].longName,
1475
+ clientId: member.id,
1476
+ iin: member.iin.replace(/-/g, ''),
1477
+ longName: member.longName,
2044
1478
  processCode: this.processCode,
2045
1479
  policyId: 0,
2046
1480
  };
2047
1481
  const response = await this.api.startApplication(data);
2048
- this.sendToParent(
2049
- constants.postActions.applicationCreated,
2050
- response.processInstanceId,
2051
- );
1482
+ this.sendToParent(constants.postActions.applicationCreated, response.processInstanceId);
2052
1483
  return response.processInstanceId;
2053
1484
  } 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;
1485
+ return ErrorHandler(err);
2059
1486
  }
2060
1487
  },
2061
- async getApplicationData(
2062
- taskId,
2063
- onlyGet = true,
2064
- setMembersField = true,
2065
- fetchMembers = true,
2066
- setProductConditions = true,
2067
- ) {
1488
+ async getApplicationData(taskId, onlyGet = true, setMembersField = true, fetchMembers = true, setProductConditions = true) {
2068
1489
  if (onlyGet) {
2069
1490
  this.isLoading = true;
2070
1491
  }
@@ -2072,34 +1493,23 @@ export const useDataStore = defineStore('data', {
2072
1493
  const applicationData = await this.api.getApplicationData(taskId);
2073
1494
  if (this.processCode !== applicationData.processCode) {
2074
1495
  this.isLoading = false;
2075
- this.sendToParent(
2076
- constants.postActions.toHomePage,
2077
- this.t('toaster.noSuchProduct'),
2078
- );
1496
+ this.sendToParent(constants.postActions.toHomePage, this.t('toaster.noSuchProduct'));
2079
1497
  return;
2080
1498
  }
2081
1499
  this.formStore.applicationData = applicationData;
2082
- this.additionalInsuranceTerms = applicationData.addCoverDto;
1500
+ this.formStore.additionalInsuranceTerms = applicationData.addCoverDto;
2083
1501
 
2084
1502
  this.formStore.canBeClaimed = await this.api.isClaimTask(taskId);
2085
1503
  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;
1504
+ this.formStore.RegionPolicy.nameRu = applicationData.insisWorkDataApp.regionPolicyName;
1505
+ this.formStore.RegionPolicy.ids = applicationData.insisWorkDataApp.regionPolicy;
1506
+ this.formStore.ManagerPolicy.nameRu = applicationData.insisWorkDataApp.managerPolicyName;
1507
+ this.formStore.ManagerPolicy.ids = applicationData.insisWorkDataApp.managerPolicy;
1508
+ this.formStore.SaleChanellPolicy.nameRu = applicationData.insisWorkDataApp.saleChanellPolicyName;
1509
+ this.formStore.SaleChanellPolicy.ids = applicationData.insisWorkDataApp.saleChanellPolicy;
1510
+
1511
+ this.formStore.AgentData.fullName = applicationData.insisWorkDataApp.agentName;
1512
+ this.formStore.AgentData.agentId = applicationData.insisWorkDataApp.agentId;
2103
1513
 
2104
1514
  const clientData = applicationData.clientApp;
2105
1515
  const insuredData = applicationData.insuredApp;
@@ -2111,11 +1521,8 @@ export const useDataStore = defineStore('data', {
2111
1521
  this.formStore.isActOwnBehalf = clientData.isActOwnBehalf;
2112
1522
  this.formStore.hasRepresentative = !!applicationData.spokesmanApp;
2113
1523
 
2114
- const beneficiaryPolicyholderIndex = beneficiaryData.findIndex(
2115
- i => i.insisId === clientData.insisId,
2116
- );
2117
- this.formStore.isPolicyholderBeneficiary =
2118
- beneficiaryPolicyholderIndex !== -1;
1524
+ const beneficiaryPolicyholderIndex = beneficiaryData.findIndex(i => i.insisId === clientData.insisId);
1525
+ this.formStore.isPolicyholderBeneficiary = beneficiaryPolicyholderIndex !== -1;
2119
1526
 
2120
1527
  if (fetchMembers) {
2121
1528
  let allMembers = [
@@ -2136,9 +1543,7 @@ export const useDataStore = defineStore('data', {
2136
1543
 
2137
1544
  if (insuredData && insuredData.length) {
2138
1545
  insuredData.forEach((member, index) => {
2139
- const inStore = this.formStore.insuredForm.find(
2140
- each => each.id == member.insisId,
2141
- );
1546
+ const inStore = this.formStore.insuredForm.find(each => each.id == member.insisId);
2142
1547
  if (!inStore) {
2143
1548
  member.key = this.formStore.insuredFormKey;
2144
1549
  member.index = index;
@@ -2151,9 +1556,7 @@ export const useDataStore = defineStore('data', {
2151
1556
  }
2152
1557
  if (beneficiaryData && beneficiaryData.length) {
2153
1558
  beneficiaryData.forEach((member, index) => {
2154
- const inStore = this.formStore.beneficiaryForm.find(
2155
- each => each.id == member.insisId,
2156
- );
1559
+ const inStore = this.formStore.beneficiaryForm.find(each => each.id == member.insisId);
2157
1560
  if (!inStore) {
2158
1561
  member.key = this.formStore.beneficiaryFormKey;
2159
1562
  member.index = index;
@@ -2166,17 +1569,13 @@ export const useDataStore = defineStore('data', {
2166
1569
  }
2167
1570
  if (beneficialOwnerData && beneficialOwnerData.length) {
2168
1571
  beneficialOwnerData.forEach((member, index) => {
2169
- const inStore = this.formStore.beneficialOwnerForm.find(
2170
- each => each.id == member.insisId,
2171
- );
1572
+ const inStore = this.formStore.beneficialOwnerForm.find(each => each.id == member.insisId);
2172
1573
  if (!inStore) {
2173
1574
  member.key = this.formStore.beneficialOwnerFormKey;
2174
1575
  member.index = index;
2175
1576
  allMembers.push(member);
2176
1577
  if (this.formStore.beneficialOwnerForm.length - 1 < index) {
2177
- this.formStore.beneficialOwnerForm.push(
2178
- new BeneficialOwnerForm(),
2179
- );
1578
+ this.formStore.beneficialOwnerForm.push(new BeneficialOwnerForm());
2180
1579
  }
2181
1580
  }
2182
1581
  });
@@ -2184,12 +1583,7 @@ export const useDataStore = defineStore('data', {
2184
1583
 
2185
1584
  await Promise.allSettled(
2186
1585
  allMembers.map(async member => {
2187
- await this.getContragentById(
2188
- member.insisId,
2189
- member.key,
2190
- false,
2191
- member.index,
2192
- );
1586
+ await this.getContragentById(member.insisId, member.key, false, member.index);
2193
1587
  }),
2194
1588
  );
2195
1589
  }
@@ -2198,128 +1592,68 @@ export const useDataStore = defineStore('data', {
2198
1592
  this.setMembersField(this.formStore.policyholderFormKey, 'clientApp');
2199
1593
  if (insuredData && insuredData.length) {
2200
1594
  insuredData.forEach((each, index) => {
2201
- this.setMembersFieldIndex(
2202
- this.formStore.insuredFormKey,
2203
- 'insuredApp',
2204
- index,
2205
- );
1595
+ this.setMembersFieldIndex(this.formStore.insuredFormKey, 'insuredApp', index);
2206
1596
  });
2207
1597
  }
2208
1598
 
2209
1599
  if (beneficiaryData && beneficiaryData.length) {
2210
1600
  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;
1601
+ this.setMembersFieldIndex(this.formStore.beneficiaryFormKey, 'beneficiaryApp', index);
1602
+ const relationDegree = this.relations.find(i => i.ids == each.relationId);
1603
+ this.formStore.beneficiaryForm[index].relationDegree = relationDegree ? relationDegree : new Value();
1604
+ this.formStore.beneficiaryForm[index].percentageOfPayoutAmount = each.percentage;
2223
1605
  });
2224
1606
  }
2225
1607
 
2226
1608
  if (beneficialOwnerData && beneficialOwnerData.length) {
2227
1609
  beneficialOwnerData.forEach((each, index) => {
2228
- this.setMembersFieldIndex(
2229
- this.formStore.beneficialOwnerFormKey,
2230
- 'beneficialOwnerApp',
2231
- index,
2232
- );
1610
+ this.setMembersFieldIndex(this.formStore.beneficialOwnerFormKey, 'beneficialOwnerApp', index);
2233
1611
  });
2234
1612
  }
2235
1613
 
2236
1614
  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;
1615
+ this.formStore.policyholdersRepresentativeForm.signOfIPDL = spokesmanData.isIpdl ? this.ipdl[1] : this.ipdl[2];
1616
+ this.formStore.policyholdersRepresentativeForm.migrationCard = spokesmanData.migrationCard;
1617
+ this.formStore.policyholdersRepresentativeForm.migrationCardIssueDate = reformatDate(spokesmanData.migrationCardIssueDate);
1618
+ this.formStore.policyholdersRepresentativeForm.migrationCardExpireDate = reformatDate(spokesmanData.migrationCardExpireDate);
1619
+ this.formStore.policyholdersRepresentativeForm.confirmDocType = spokesmanData.confirmDocType;
1620
+ this.formStore.policyholdersRepresentativeForm.confirmDocNumber = spokesmanData.confirmDocNumber;
1621
+ this.formStore.policyholdersRepresentativeForm.confirmDocIssueDate = reformatDate(spokesmanData.confirmDocIssueDate);
1622
+ this.formStore.policyholdersRepresentativeForm.confirmDocExpireDate = reformatDate(spokesmanData.confirmDocExpireDate);
1623
+ this.formStore.policyholdersRepresentativeForm.notaryLongName = spokesmanData.notaryLongName;
1624
+ this.formStore.policyholdersRepresentativeForm.notaryLicenseNumber = spokesmanData.notaryLicenseNumber;
1625
+ this.formStore.policyholdersRepresentativeForm.notaryLicenseDate = reformatDate(spokesmanData.notaryLicenseDate);
1626
+ this.formStore.policyholdersRepresentativeForm.notaryLicenseIssuer = spokesmanData.notaryLicenseIssuer;
1627
+ this.formStore.policyholdersRepresentativeForm.jurLongName = spokesmanData.jurLongName;
1628
+ this.formStore.policyholdersRepresentativeForm.fullNameRod = spokesmanData.fullNameRod;
1629
+ this.formStore.policyholdersRepresentativeForm.confirmDocTypeKz = spokesmanData.confirmDocTypeKz;
1630
+ this.formStore.policyholdersRepresentativeForm.confirmDocTypeRod = spokesmanData.confirmDocTypeRod;
1631
+ this.formStore.policyholdersRepresentativeForm.isNotary = spokesmanData.isNotary;
2271
1632
  }
2272
1633
  }
2273
1634
  if (setProductConditions) {
2274
- this.formStore.productConditionsForm.coverPeriod =
2275
- applicationData.policyAppDto.coverPeriod;
2276
- this.formStore.productConditionsForm.payPeriod =
2277
- applicationData.policyAppDto.payPeriod;
1635
+ this.formStore.productConditionsForm.coverPeriod = applicationData.policyAppDto.coverPeriod;
1636
+ this.formStore.productConditionsForm.payPeriod = applicationData.policyAppDto.payPeriod;
2278
1637
  // 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);
1638
+ this.formStore.productConditionsForm.lifeMultiply = parseProcents(applicationData.policyAppDto.lifeMultiply);
1639
+ this.formStore.productConditionsForm.lifeAdditive = parseProcents(applicationData.policyAppDto.lifeAdditive);
1640
+ this.formStore.productConditionsForm.adbMultiply = parseProcents(applicationData.policyAppDto.adbMultiply);
1641
+ this.formStore.productConditionsForm.adbAdditive = parseProcents(applicationData.policyAppDto.adbAdditive);
1642
+ this.formStore.productConditionsForm.disabilityMultiply = parseProcents(applicationData.policyAppDto.disabilityMultiply);
1643
+ this.formStore.productConditionsForm.disabilityAdditive = parseProcents(applicationData.policyAppDto.disabilityAdditive);
2295
1644
 
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');
1645
+ let processIndexRate = this.processIndexRate.find(item => item.id == applicationData.policyAppDto.indexRateId);
1646
+ this.formStore.productConditionsForm.processIndexRate = processIndexRate ? processIndexRate : this.processIndexRate.find(item => item.code === '0');
1647
+
1648
+ let paymentPeriod = this.processPaymentPeriod.find(item => item.id == applicationData.policyAppDto.paymentPeriodId);
1649
+ this.formStore.productConditionsForm.paymentPeriod = paymentPeriod ? paymentPeriod : new Value();
2303
1650
 
2304
- let paymentPeriod = this.processPaymentPeriod.find(
2305
- item => item.id == applicationData.policyAppDto.paymentPeriodId,
1651
+ this.formStore.productConditionsForm.requestedSumInsured = this.getNumberWithSpaces(
1652
+ applicationData.policyAppDto.amount === null ? null : applicationData.policyAppDto.amount,
1653
+ );
1654
+ this.formStore.productConditionsForm.insurancePremiumPerMonth = this.getNumberWithSpaces(
1655
+ applicationData.policyAppDto.premium === null ? null : applicationData.policyAppDto.premium,
2306
1656
  );
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
1657
 
2324
1658
  let riskGroup = this.riskGroup.find(item => {
2325
1659
  if (applicationData.policyAppDto.riskGroup == 0) {
@@ -2327,17 +1661,12 @@ export const useDataStore = defineStore('data', {
2327
1661
  }
2328
1662
  return item.id == applicationData.policyAppDto.riskGroup;
2329
1663
  });
2330
- this.formStore.productConditionsForm.riskGroup = riskGroup
2331
- ? riskGroup
2332
- : this.riskGroup.find(item => item.id == 1);
1664
+ this.formStore.productConditionsForm.riskGroup = riskGroup ? riskGroup : this.riskGroup.find(item => item.id == 1);
2333
1665
  }
2334
1666
  } catch (err) {
2335
1667
  console.log(err);
2336
1668
  if ('response' in err) {
2337
- this.sendToParent(
2338
- constants.postActions.toHomePage,
2339
- err.response.data,
2340
- );
1669
+ this.sendToParent(constants.postActions.toHomePage, err.response.data);
2341
1670
  this.isLoading = false;
2342
1671
  return false;
2343
1672
  }
@@ -2365,11 +1694,7 @@ export const useDataStore = defineStore('data', {
2365
1694
  this.showToaster('success', this.t('toaster.applicationDeleted'), 2000);
2366
1695
  } catch (err) {
2367
1696
  if ('response' in err && err.response.data) {
2368
- this.showToaster(
2369
- 'error',
2370
- this.t('toaster.error') + err.response.data,
2371
- 2000,
2372
- );
1697
+ this.showToaster('error', this.t('toaster.error') + err.response.data, 2000);
2373
1698
  }
2374
1699
  console.log(err);
2375
1700
  }
@@ -2382,25 +1707,59 @@ export const useDataStore = defineStore('data', {
2382
1707
  taskId: taskId,
2383
1708
  decision: decision,
2384
1709
  };
2385
- await this.api.sendTask(
2386
- comment === null ? data : { ...data, comment: comment },
2387
- );
1710
+ await this.api.sendTask(comment === null ? data : { ...data, comment: comment });
2388
1711
  this.showToaster('success', this.t('toaster.successOperation'), 3000);
2389
1712
  this.isLoading = false;
2390
1713
  return true;
2391
1714
  } catch (err) {
2392
1715
  console.log(err);
2393
1716
  if ('response' in err && err.response.data) {
2394
- this.showToaster(
2395
- 'error',
2396
- this.t('toaster.error') + err.response.data,
2397
- 2000,
2398
- );
1717
+ this.showToaster('error', this.t('toaster.error') + err.response.data, 2000);
2399
1718
  }
2400
1719
  this.isLoading = false;
2401
1720
  return false;
2402
1721
  }
2403
1722
  },
1723
+ async handleTask(action, taskId, comment) {
1724
+ if (action && Object.keys(constants.actions).includes(action)) {
1725
+ switch (action) {
1726
+ case constants.actions.claim: {
1727
+ try {
1728
+ this.isLoading = true;
1729
+ await this.api.claimTask(this.formStore.applicationTaskId);
1730
+ await this.getApplicationData(taskId, false, false, false);
1731
+ this.showToaster('success', this.t('toaster.successOperation'), 3000);
1732
+ } catch (err) {
1733
+ console.log(err);
1734
+ if ('response' in err && err.response.data) {
1735
+ this.showToaster('error', err.response.data, 3000);
1736
+ }
1737
+ }
1738
+ }
1739
+ case constants.actions.reject:
1740
+ case constants.actions.return:
1741
+ case constants.actions.rejectclient:
1742
+ case constants.actions.accept: {
1743
+ try {
1744
+ await this.sendTask(taskId, action, comment);
1745
+ this.formStore.$reset();
1746
+ if (this.isEFO) {
1747
+ await this.router.push({ name: 'Insurance-Product' });
1748
+ } else {
1749
+ this.sendToParent(constants.postActions.toHomePage, this.t('toaster.successOperation') + 'SUCCESS');
1750
+ }
1751
+ } catch (err) {
1752
+ console.log(err);
1753
+ if ('response' in err && err.response.data) {
1754
+ this.showToaster('error', err.response.data, 3000);
1755
+ }
1756
+ }
1757
+ }
1758
+ }
1759
+ } else {
1760
+ console.error('No handleTask action');
1761
+ }
1762
+ },
2404
1763
  async getInvoiceData(processInstanceId) {
2405
1764
  try {
2406
1765
  const response = await this.api.getInvoiceData(processInstanceId);
@@ -2415,10 +1774,7 @@ export const useDataStore = defineStore('data', {
2415
1774
  },
2416
1775
  async createInvoice() {
2417
1776
  try {
2418
- const created = await this.api.createInvoice(
2419
- this.formStore.applicationData.processInstanceId,
2420
- this.formStore.applicationData.policyAppDto.premium,
2421
- );
1777
+ const created = await this.api.createInvoice(this.formStore.applicationData.processInstanceId, this.formStore.applicationData.policyAppDto.premium);
2422
1778
  return !!created;
2423
1779
  } catch (err) {
2424
1780
  this.isLoading = false;
@@ -2426,9 +1782,7 @@ export const useDataStore = defineStore('data', {
2426
1782
  },
2427
1783
  async sendToEpay() {
2428
1784
  try {
2429
- const response = await this.api.sendToEpay(
2430
- this.formStore.applicationData.processInstanceId,
2431
- );
1785
+ const response = await this.api.sendToEpay(this.formStore.applicationData.processInstanceId);
2432
1786
  if (response) {
2433
1787
  return response;
2434
1788
  }
@@ -2437,69 +1791,35 @@ export const useDataStore = defineStore('data', {
2437
1791
  }
2438
1792
  },
2439
1793
  setMembersField(whichForm, whichMember) {
2440
- this.formStore[whichForm].familyStatus = this.findObject(
2441
- 'familyStatuses',
2442
- 'id',
2443
- this.formStore.applicationData[whichMember].familyStatusId,
2444
- );
1794
+ this.formStore[whichForm].familyStatus = this.findObject('familyStatuses', 'id', this.formStore.applicationData[whichMember].familyStatusId);
2445
1795
  this.formStore[whichForm].signOfIPDL = this.findObject(
2446
1796
  'ipdl',
2447
1797
  'nameRu',
2448
- this.formStore.applicationData[whichMember].isIpdl === null
2449
- ? null
2450
- : this.formStore.applicationData[whichMember].isIpdl == true
2451
- ? 'Да'
2452
- : 'Нет',
1798
+ this.formStore.applicationData[whichMember].isIpdl === null ? null : this.formStore.applicationData[whichMember].isIpdl == true ? 'Да' : 'Нет',
2453
1799
  );
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;
1800
+ if (!!this.formStore.applicationData[whichMember].profession) this.formStore[whichForm].job = this.formStore.applicationData[whichMember].profession;
1801
+ if (!!this.formStore.applicationData[whichMember].position) this.formStore[whichForm].jobPosition = this.formStore.applicationData[whichMember].position;
1802
+ if (!!this.formStore.applicationData[whichMember].jobName) this.formStore[whichForm].jobPlace = this.formStore.applicationData[whichMember].jobName;
2463
1803
  },
2464
1804
  setMembersFieldIndex(whichForm, whichMember, index) {
2465
1805
  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
- );
1806
+ this.formStore[whichForm][index].familyStatus = this.findObject('familyStatuses', 'id', this.formStore.applicationData[whichMember][index].familyStatusId);
2471
1807
  }
2472
1808
  if ('signOfIPDL' in this.formStore[whichForm][index]) {
2473
1809
  this.formStore[whichForm][index].signOfIPDL = this.findObject(
2474
1810
  'ipdl',
2475
1811
  'nameRu',
2476
- this.formStore.applicationData[whichMember][index].isIpdl === null
2477
- ? null
2478
- : this.formStore.applicationData[whichMember][index].isIpdl == true
2479
- ? 'Да'
2480
- : 'Нет',
1812
+ this.formStore.applicationData[whichMember][index].isIpdl === null ? null : this.formStore.applicationData[whichMember][index].isIpdl == true ? 'Да' : 'Нет',
2481
1813
  );
2482
1814
  }
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;
1815
+ if ('job' in this.formStore[whichForm][index] && !!this.formStore.applicationData[whichMember][index].profession) {
1816
+ this.formStore[whichForm][index].job = this.formStore.applicationData[whichMember][index].profession;
2489
1817
  }
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;
1818
+ if ('jobPosition' in this.formStore[whichForm][index] && !!this.formStore.applicationData[whichMember][index].position) {
1819
+ this.formStore[whichForm][index].jobPosition = this.formStore.applicationData[whichMember][index].position;
2496
1820
  }
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;
1821
+ if ('jobPlace' in this.formStore[whichForm][index] && !!this.formStore.applicationData[whichMember][index].jobName) {
1822
+ this.formStore[whichForm][index].jobPlace = this.formStore.applicationData[whichMember][index].jobName;
2503
1823
  }
2504
1824
  },
2505
1825
  findObject(from, key, searchKey) {
@@ -2508,18 +1828,14 @@ export const useDataStore = defineStore('data', {
2508
1828
  },
2509
1829
  async signToDocument(data) {
2510
1830
  try {
2511
- if (this.signUrl) {
2512
- return this.signUrl;
1831
+ if (this.formStore.signUrl) {
1832
+ return this.formStore.signUrl;
2513
1833
  }
2514
1834
  const result = await this.api.signToDocument(data);
2515
- this.signUrl = result.uri;
2516
- return this.signUrl;
1835
+ this.formStore.signUrl = result.uri;
1836
+ return this.formStore.signUrl;
2517
1837
  } catch (error) {
2518
- this.showToaster(
2519
- 'error',
2520
- this.t('toaster.error') + error?.response?.data,
2521
- 2000,
2522
- );
1838
+ this.showToaster('error', this.t('toaster.error') + error?.response?.data, 2000);
2523
1839
  }
2524
1840
  },
2525
1841
  sanitize(text) {
@@ -2533,7 +1849,7 @@ export const useDataStore = defineStore('data', {
2533
1849
  async getSignedDocList(processInstanceId) {
2534
1850
  if (processInstanceId !== 0) {
2535
1851
  try {
2536
- this.signedDocumentList = await this.api.getSignedDocList({
1852
+ this.formStore.signedDocumentList = await this.api.getSignedDocList({
2537
1853
  processInstanceId: processInstanceId,
2538
1854
  });
2539
1855
  } catch (err) {
@@ -2558,15 +1874,11 @@ export const useDataStore = defineStore('data', {
2558
1874
  await this.getApplicationData(taskId, false, false, false);
2559
1875
  this.showToaster(
2560
1876
  'success',
2561
- `${this.t('toaster.successRecalculation')}. ${
2562
- whichSum == 'insurancePremiumPerMonth'
2563
- ? 'Страховая премия'
2564
- : 'Страховая сумма'
2565
- }: ${this.getNumberWithSpaces(recalculatedValue)}₸`,
1877
+ `${this.t('toaster.successRecalculation')}. ${whichSum == 'insurancePremiumPerMonth' ? 'Страховая премия' : 'Страховая сумма'}: ${this.getNumberWithSpaces(
1878
+ recalculatedValue,
1879
+ )}₸`,
2566
1880
  4000,
2567
1881
  );
2568
- } else {
2569
- this.showToaster('error', this.t('toaster.undefinedError'), 2000);
2570
1882
  }
2571
1883
  } catch (err) {
2572
1884
  console.log(err);
@@ -2591,32 +1903,12 @@ export const useDataStore = defineStore('data', {
2591
1903
  }
2592
1904
  },
2593
1905
  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
- );
1906
+ if (this.formStore[localKey].length === this.formStore.applicationData[applicationKey].length) {
1907
+ if (this.formStore[localKey].length !== 0 && this.formStore.applicationData[applicationKey].length !== 0) {
1908
+ const localMembers = [...this.formStore[localKey]].sort((a, b) => a.id - b.id);
1909
+ const applicationMembers = [...this.formStore.applicationData[applicationKey]].sort((a, b) => a.insisId - b.insisId);
1910
+ if (localMembers.every((each, index) => applicationMembers[index].insisId === each.id && applicationMembers[index].iin === each.iin.replace(/-/g, '')) === false) {
1911
+ this.showToaster('error', this.t('toaster.notSavedMember').replace('{text}', text), 3000);
2620
1912
  return false;
2621
1913
  }
2622
1914
  if (localKey === this.formStore.beneficiaryFormKey) {
@@ -2624,38 +1916,22 @@ export const useDataStore = defineStore('data', {
2624
1916
  return sum + Number(member.percentageOfPayoutAmount);
2625
1917
  }, 0);
2626
1918
  if (sumOfPercentage !== 100) {
2627
- this.showToaster(
2628
- 'error',
2629
- this.t('toaster.errorSumOrPercentage'),
2630
- 3000,
2631
- );
1919
+ this.showToaster('error', this.t('toaster.errorSumOrPercentage'), 3000);
2632
1920
  return false;
2633
1921
  }
2634
1922
  }
2635
1923
  }
2636
1924
  } else {
2637
1925
  if (this.formStore[localKey].some(i => i.iin !== null)) {
2638
- this.showToaster(
2639
- 'error',
2640
- this.t('toaster.notSavedMember', { text: text }),
2641
- 3000,
2642
- );
1926
+ this.showToaster('error', this.t('toaster.notSavedMember').replace('{text}', text), 3000);
2643
1927
  return false;
2644
1928
  }
2645
1929
  if (this.formStore.applicationData[applicationKey].length !== 0) {
2646
- this.showToaster(
2647
- 'error',
2648
- this.t('toaster.notSavedMember', { text: text }),
2649
- 3000,
2650
- );
1930
+ this.showToaster('error', this.t('toaster.notSavedMember').replace('{text}', text), 3000);
2651
1931
  return false;
2652
1932
  } else {
2653
1933
  if (this.formStore[localKey][0].iin !== null) {
2654
- this.showToaster(
2655
- 'error',
2656
- this.t('toaster.notSavedMember', { text: text }),
2657
- 3000,
2658
- );
1934
+ this.showToaster('error', this.t('toaster.notSavedMember').replace('{text}', text), 3000);
2659
1935
  return false;
2660
1936
  }
2661
1937
  }
@@ -2667,52 +1943,23 @@ export const useDataStore = defineStore('data', {
2667
1943
  this.showToaster('error', this.t('toaster.needToRunStatement'), 2000);
2668
1944
  return false;
2669
1945
  }
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
- );
1946
+ if (this.formStore.policyholderForm.id !== this.formStore.applicationData.clientApp.insisId) {
1947
+ this.showToaster('error', this.t('toaster.notSavedMember').replace('{text}', 'страхователя'), 3000);
2679
1948
  return false;
2680
1949
  }
2681
- if (
2682
- this.validateMultipleMembers(
2683
- this.formStore.insuredFormKey,
2684
- 'insuredApp',
2685
- 'застрахованных',
2686
- ) === false
2687
- ) {
1950
+ if (this.validateMultipleMembers(this.formStore.insuredFormKey, 'insuredApp', 'застрахованных') === false) {
2688
1951
  return false;
2689
1952
  }
2690
- if (
2691
- this.validateMultipleMembers(
2692
- this.formStore.beneficiaryFormKey,
2693
- 'beneficiaryApp',
2694
- 'выгодоприобретателей',
2695
- ) === false
2696
- ) {
1953
+ if (this.validateMultipleMembers(this.formStore.beneficiaryFormKey, 'beneficiaryApp', 'выгодоприобретателей') === false) {
2697
1954
  return false;
2698
1955
  }
2699
1956
  if (this.formStore.isActOwnBehalf === false) {
2700
- if (
2701
- this.validateMultipleMembers(
2702
- this.formStore.beneficialOwnerFormKey,
2703
- 'beneficialOwnerApp',
2704
- 'бенефициарных собственников',
2705
- ) === false
2706
- ) {
1957
+ if (this.validateMultipleMembers(this.formStore.beneficialOwnerFormKey, 'beneficialOwnerApp', 'бенефициарных собственников') === false) {
2707
1958
  return false;
2708
1959
  }
2709
1960
  }
2710
1961
  if (this.formStore.hasRepresentative) {
2711
- if (
2712
- this.formStore.applicationData.spokesmanApp &&
2713
- this.formStore.policyholdersRepresentativeForm.id !==
2714
- this.formStore.applicationData.spokesmanApp.insisId
2715
- ) {
1962
+ if (this.formStore.applicationData.spokesmanApp && this.formStore.policyholdersRepresentativeForm.id !== this.formStore.applicationData.spokesmanApp.insisId) {
2716
1963
  this.showToaster(
2717
1964
  'error',
2718
1965
  this.t('toaster.notSavedMember', {
@@ -2723,11 +1970,7 @@ export const useDataStore = defineStore('data', {
2723
1970
  return false;
2724
1971
  }
2725
1972
  }
2726
- const areValid =
2727
- this.formStore.SaleChanellPolicy.nameRu &&
2728
- this.formStore.RegionPolicy.nameRu &&
2729
- this.formStore.ManagerPolicy.nameRu &&
2730
- this.formStore.AgentData.fullName;
1973
+ const areValid = this.formStore.SaleChanellPolicy.nameRu && this.formStore.RegionPolicy.nameRu && this.formStore.ManagerPolicy.nameRu && this.formStore.AgentData.fullName;
2731
1974
  if (areValid) {
2732
1975
  await this.setINSISWorkData();
2733
1976
  } else {
@@ -2737,16 +1980,11 @@ export const useDataStore = defineStore('data', {
2737
1980
  }
2738
1981
  if (localCheck === false) {
2739
1982
  try {
2740
- if (
2741
- this.formStore.isActOwnBehalf === true &&
2742
- this.formStore.applicationData.beneficialOwnerApp.length !== 0
2743
- ) {
1983
+ if (this.formStore.isActOwnBehalf === true && this.formStore.applicationData.beneficialOwnerApp.length !== 0) {
2744
1984
  await Promise.allSettled(
2745
- this.formStore.applicationData.beneficialOwnerApp.map(
2746
- async member => {
2747
- await this.api.deleteMember('BeneficialOwner', member.id);
2748
- },
2749
- ),
1985
+ this.formStore.applicationData.beneficialOwnerApp.map(async member => {
1986
+ await this.api.deleteMember('BeneficialOwner', member.id);
1987
+ }),
2750
1988
  );
2751
1989
  }
2752
1990
  await this.getApplicationData(taskId, false);
@@ -2760,14 +1998,11 @@ export const useDataStore = defineStore('data', {
2760
1998
  return true;
2761
1999
  },
2762
2000
  validateAnketa(whichSurvey) {
2763
- const list = this[whichSurvey].body;
2001
+ const list = this.formStore[whichSurvey].body;
2764
2002
  if (!list || (list && list.length === 0)) return false;
2765
2003
  let notAnswered = 0;
2766
2004
  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
- ) {
2005
+ if ((list[x].first.definedAnswers === 'N' && !list[x].first.answerText) || (list[x].first.definedAnswers === 'Y' && !list[x].first.answerName)) {
2771
2006
  notAnswered = notAnswered + 1;
2772
2007
  }
2773
2008
  }
@@ -2777,14 +2012,8 @@ export const useDataStore = defineStore('data', {
2777
2012
  this.isLoading = true;
2778
2013
  const areMembersValid = await this.validateAllMembers(taskId);
2779
2014
  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
- );
2015
+ if (!!this.formStore.productConditionsForm.insurancePremiumPerMonth && !!this.formStore.productConditionsForm.requestedSumInsured) {
2016
+ const hasCritical = this.formStore.additionalInsuranceTerms?.find(cover => cover.coverTypeName === 'Критическое заболевание Застрахованного');
2788
2017
  if (hasCritical && hasCritical.coverSumName !== 'не включено') {
2789
2018
  await Promise.allSettled([
2790
2019
  this.getQuestionList(
@@ -2803,17 +2032,11 @@ export const useDataStore = defineStore('data', {
2803
2032
  ),
2804
2033
  ]);
2805
2034
  await Promise.allSettled([
2806
- ...this.surveyByHealthBase.body.map(async question => {
2807
- await this.definedAnswers(
2808
- question.first.id,
2809
- 'surveyByHealthBase',
2810
- );
2035
+ ...this.formStore.surveyByHealthBase.body.map(async question => {
2036
+ await this.definedAnswers(question.first.id, 'surveyByHealthBase');
2811
2037
  }),
2812
- ...this.surveyByCriticalBase.body.map(async question => {
2813
- await this.definedAnswers(
2814
- question.first.id,
2815
- 'surveyByCriticalBase',
2816
- );
2038
+ ...this.formStore.surveyByCriticalBase.body.map(async question => {
2039
+ await this.definedAnswers(question.first.id, 'surveyByCriticalBase');
2817
2040
  }),
2818
2041
  ]);
2819
2042
  } else {
@@ -2828,10 +2051,7 @@ export const useDataStore = defineStore('data', {
2828
2051
  ]);
2829
2052
  await Promise.allSettled(
2830
2053
  this.surveyByHealthBase.body.map(async question => {
2831
- await this.definedAnswers(
2832
- question.first.id,
2833
- 'surveyByHealthBase',
2834
- );
2054
+ await this.definedAnswers(question.first.id, 'surveyByHealthBase');
2835
2055
  }),
2836
2056
  );
2837
2057
  }
@@ -2843,47 +2063,66 @@ export const useDataStore = defineStore('data', {
2843
2063
  hasCriticalAndItsValid = true;
2844
2064
  } else {
2845
2065
  hasCriticalAndItsValid = false;
2846
- this.showToaster(
2847
- 'error',
2848
- this.t('toaster.emptyCriticalAnketa'),
2849
- 3000,
2850
- );
2066
+ this.showToaster('error', this.t('toaster.emptyCriticalAnketa'), 3000);
2851
2067
  }
2852
2068
  } else {
2853
2069
  hasCriticalAndItsValid = null;
2854
2070
  }
2855
- if (
2856
- hasCriticalAndItsValid === true ||
2857
- hasCriticalAndItsValid === null
2858
- ) {
2071
+ if (hasCriticalAndItsValid === true || hasCriticalAndItsValid === null) {
2859
2072
  this.isLoading = false;
2860
2073
  return true;
2861
2074
  }
2862
2075
  } else {
2863
- this.showToaster(
2864
- 'error',
2865
- this.t('toaster.emptyHealthAnketa'),
2866
- 3000,
2867
- );
2076
+ this.showToaster('error', this.t('toaster.emptyHealthAnketa'), 3000);
2868
2077
  }
2869
2078
  } else {
2870
- this.showToaster(
2871
- 'error',
2872
- this.t('toaster.emptyProductConditions'),
2873
- 3000,
2874
- );
2079
+ this.showToaster('error', this.t('toaster.emptyProductConditions'), 3000);
2875
2080
  }
2876
2081
  return false;
2877
2082
  }
2878
2083
  this.isLoading = false;
2879
2084
  return false;
2880
2085
  },
2881
- async getContragentFromGBDFL(
2882
- iin,
2883
- phoneNumber,
2884
- whichForm,
2885
- whichIndex = null,
2886
- ) {
2086
+ async getFamilyInfo(iin, phoneNumber) {
2087
+ this.isLoading = true;
2088
+ try {
2089
+ const familyResponse = await this.api.getFamilyInfo({ iin: iin.replace(/-/g, ''), phoneNumber: formatPhone(phoneNumber) });
2090
+ if (familyResponse.status === 'PENDING') {
2091
+ this.showToaster('success', this.t('toaster.waitForClient'), 5000);
2092
+ this.isLoading = false;
2093
+ return;
2094
+ }
2095
+ if (constants.gbdErrors.find(i => i === familyResponse.status)) {
2096
+ if (familyResponse.status === 'TIMEOUT') {
2097
+ this.showToaster('success', `${familyResponse.statusName}. Отправьте запрос еще раз`, 5000);
2098
+ } else {
2099
+ this.showToaster('error', familyResponse.statusName, 5000);
2100
+ }
2101
+ this.isLoading = false;
2102
+ return;
2103
+ }
2104
+ if (familyResponse.infoList && familyResponse.infoList.birthInfos && familyResponse.infoList.birthInfos.length) {
2105
+ const filteredBirthInfos = familyResponse.infoList.birthInfos.filter(
2106
+ member => member.childBirthDate && getAgeByBirthDate(member.childBirthDate) <= 15 && typeof member.childLifeStatus === 'number' && member.childLifeStatus === 0,
2107
+ );
2108
+ if (filteredBirthInfos && filteredBirthInfos.length) {
2109
+ this.formStore.birthInfos = filteredBirthInfos;
2110
+ this.showToaster('success', this.t('toaster.pickFamilyMember'), 3000);
2111
+ } else {
2112
+ this.formStore.birthInfos = [];
2113
+ this.showToaster('error', this.t('toaster.notFound'), 3000);
2114
+ }
2115
+ } else {
2116
+ this.formStore.birthInfos = [];
2117
+ this.showToaster('error', this.t('toaster.notFound'), 3000);
2118
+ }
2119
+ } catch (err) {
2120
+ ErrorHandler(err);
2121
+ } finally {
2122
+ this.isLoading = false;
2123
+ }
2124
+ },
2125
+ async getContragentFromGBDFL(iin, phoneNumber, whichForm, whichIndex) {
2887
2126
  this.isLoading = true;
2888
2127
  try {
2889
2128
  const data = {
@@ -2898,11 +2137,7 @@ export const useDataStore = defineStore('data', {
2898
2137
  }
2899
2138
  if (constants.gbdErrors.find(i => i === gbdResponse.status)) {
2900
2139
  if (gbdResponse.status === 'TIMEOUT') {
2901
- this.showToaster(
2902
- 'success',
2903
- `${gbdResponse.statusName}. Отправьте запрос еще раз`,
2904
- 5000,
2905
- );
2140
+ this.showToaster('success', `${gbdResponse.statusName}. Отправьте запрос еще раз`, 5000);
2906
2141
  } else {
2907
2142
  this.showToaster('success', gbdResponse.statusName, 5000);
2908
2143
  }
@@ -2910,44 +2145,25 @@ export const useDataStore = defineStore('data', {
2910
2145
  return;
2911
2146
  }
2912
2147
  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
- }
2148
+ const { responseInfo } = parseXML(gbdResponse.content, true, 'responseInfo');
2149
+ if (typeof whichIndex !== 'number') {
2150
+ if (this.formStore[whichForm].gosPersonData !== null && this.formStore[whichForm].gosPersonData.iin !== iin.replace(/-/g, '')) {
2151
+ this.formStore[whichForm].resetMember(false);
2931
2152
  }
2932
2153
  this.formStore[whichForm].gosPersonData = person;
2933
2154
  } 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);
2155
+ if (this.formStore[whichForm][whichIndex].gosPersonData !== null && this.formStore[whichForm][whichIndex].gosPersonData.iin !== iin.replace(/-/g, '')) {
2156
+ this.formStore[whichForm][whichIndex].resetMember(false);
2940
2157
  }
2941
2158
  this.formStore[whichForm][whichIndex].gosPersonData = person;
2942
2159
  }
2943
2160
 
2944
- await this.getContragent(whichForm, whichIndex, false);
2945
- if (whichIndex === null) {
2161
+ await this.getContragent(typeof whichIndex === 'number' ? this.formStore[whichForm][whichIndex] : this.formStore[whichForm], whichForm, whichIndex, false);
2162
+ if (typeof whichIndex !== 'number') {
2946
2163
  this.formStore[whichForm].verifyDate = responseInfo.responseDate;
2947
2164
  this.formStore[whichForm].verifyType = 'GBDFL';
2948
2165
  } else {
2949
- this.formStore[whichForm][whichIndex].verifyDate =
2950
- responseInfo.responseDate;
2166
+ this.formStore[whichForm][whichIndex].verifyDate = responseInfo.responseDate;
2951
2167
  this.formStore[whichForm][whichIndex].verifyType = 'GBDFL';
2952
2168
  }
2953
2169
  await this.saveInStoreUserGBDFL(person, whichForm, whichIndex);
@@ -2963,48 +2179,31 @@ export const useDataStore = defineStore('data', {
2963
2179
  if (whichIndex === null) {
2964
2180
  this.formStore[whichForm].firstName = person.name;
2965
2181
  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 : ''}`;
2182
+ this.formStore[whichForm].middleName = person.patronymic ? person.patronymic : '';
2183
+ this.formStore[whichForm].longName = `${person.surname} ${person.name} ${person.patronymic ? person.patronymic : ''}`;
2972
2184
  this.formStore[whichForm].birthDate = reformatDate(person.birthDate);
2973
2185
  this.formStore[whichForm].genderName = person.gender.nameRu;
2974
2186
 
2975
2187
  const gender = this.gender.find(i => i.id == person.gender.code);
2976
2188
  if (gender) this.formStore[whichForm].gender = gender;
2977
2189
 
2978
- const birthPlace = this.countries.find(i =>
2979
- i.nameRu.match(new RegExp(person.birthPlace.country.nameRu, 'i')),
2980
- );
2190
+ const birthPlace = this.countries.find(i => i.nameRu.match(new RegExp(person.birthPlace.country.nameRu, 'i')));
2981
2191
  if (birthPlace) this.formStore[whichForm].birthPlace = birthPlace;
2982
2192
 
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;
2193
+ const countryOfCitizenship = this.citizenshipCountries.find(i => i.nameRu.match(new RegExp(person.citizenship.nameRu, 'i')));
2194
+ if (countryOfCitizenship) this.formStore[whichForm].countryOfCitizenship = countryOfCitizenship;
2988
2195
 
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;
2196
+ const regCountry = this.countries.find(i => i.nameRu.match(new RegExp(person.regAddress.country.nameRu, 'i')));
2197
+ if (regCountry) this.formStore[whichForm].registrationCountry = regCountry;
2994
2198
 
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;
2199
+ const regProvince = this.states.find(i => i.nameRu.match(new RegExp(person.regAddress.district.nameRu, 'i')));
2200
+ if (regProvince) this.formStore[whichForm].registrationProvince = regProvince;
3000
2201
 
3001
2202
  if ('city' in person.regAddress && !!person.regAddress.city) {
3002
2203
  if (person.regAddress.city.includes(', ')) {
3003
2204
  const personCities = person.regAddress.city.split(', ');
3004
2205
  for (let i = 0; i < personCities.length; ++i) {
3005
- const possibleCity = this.cities.find(i =>
3006
- i.nameRu.includes(personCities[i]),
3007
- );
2206
+ const possibleCity = this.cities.find(i => i.nameRu.includes(personCities[i]));
3008
2207
  if (possibleCity) {
3009
2208
  this.formStore[whichForm].registrationCity = possibleCity;
3010
2209
  break;
@@ -3012,9 +2211,7 @@ export const useDataStore = defineStore('data', {
3012
2211
  }
3013
2212
  if (this.formStore[whichForm].registrationCity.nameRu === null) {
3014
2213
  for (let i = 0; i < personCities.length; ++i) {
3015
- const possibleRegion = this.regions.find(i =>
3016
- i.nameRu.includes(personCities[i]),
3017
- );
2214
+ const possibleRegion = this.regions.find(i => i.nameRu.includes(personCities[i]));
3018
2215
  if (possibleRegion) {
3019
2216
  this.formStore[whichForm].registrationRegion = possibleRegion;
3020
2217
  break;
@@ -3022,548 +2219,252 @@ export const useDataStore = defineStore('data', {
3022
2219
  }
3023
2220
  }
3024
2221
  } else {
3025
- const regCity = this.cities.find(i =>
3026
- i.nameRu.match(new RegExp(person.regAddress.city, 'i')),
3027
- );
2222
+ const regCity = this.cities.find(i => i.nameRu.match(new RegExp(person.regAddress.city, 'i')));
3028
2223
  if (regCity) this.formStore[whichForm].registrationCity = regCity;
3029
2224
 
3030
2225
  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;
2226
+ const regRegion = this.regions.find(i => i.nameRu.match(new RegExp(person.regAddress.city), 'i'));
2227
+ if (regRegion) this.formStore[whichForm].registrationRegion = regRegion;
3036
2228
  }
3037
2229
  }
3038
2230
  }
3039
2231
 
3040
- if (
3041
- this.formStore[whichForm].registrationCity.nameRu === null &&
3042
- this.formStore[whichForm].registrationRegion.nameRu === null
3043
- ) {
2232
+ if (this.formStore[whichForm].registrationCity.nameRu === null && this.formStore[whichForm].registrationRegion.nameRu === null) {
3044
2233
  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
- ),
2234
+ i => i.nameRu.match(new RegExp(person.regAddress.region.nameRu, 'i')) || i.nameRu.match(new RegExp(person.regAddress.district.nameRu, 'i')),
3052
2235
  );
3053
2236
  if (regCity) {
3054
2237
  this.formStore[whichForm].registrationCity = regCity;
3055
2238
  const regType = this.localityTypes.find(i => i.nameRu === 'город');
3056
- if (regType)
3057
- this.formStore[whichForm].registrationRegionType = regType;
2239
+ if (regType) this.formStore[whichForm].registrationRegionType = regType;
3058
2240
  } else {
3059
2241
  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
- ),
2242
+ i => i.nameRu.match(new RegExp(person.regAddress.region.nameRu), 'i') || i.nameRu.match(new RegExp(person.regAddress.district.nameRu, 'i')),
3068
2243
  );
3069
2244
  if (regRegion) {
3070
2245
  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;
2246
+ const regType = this.localityTypes.find(i => (i.nameRu === i.nameRu) === 'село' || i.nameRu === 'поселок');
2247
+ if (regType) this.formStore[whichForm].registrationRegionType = regType;
3077
2248
  }
3078
2249
  }
3079
2250
  }
3080
2251
 
3081
2252
  if (person.regAddress.street.includes(', ')) {
3082
2253
  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;
2254
+ const microDistrict = personAddress.find(i => i.match(new RegExp('микрорайон', 'i')));
2255
+ const quarter = personAddress.find(i => i.match(new RegExp('квартал', 'i')));
2256
+ const street = personAddress.find(i => i.match(new RegExp('улица', 'i')));
2257
+ if (microDistrict) this.formStore[whichForm].registrationMicroDistrict = microDistrict;
3094
2258
  if (quarter) this.formStore[whichForm].registrationQuarter = quarter;
3095
2259
  if (street) this.formStore[whichForm].registrationStreet = street;
3096
2260
  } else {
3097
- if (person.regAddress.street)
3098
- this.formStore[whichForm].registrationStreet =
3099
- person.regAddress.street;
2261
+ if (person.regAddress.street) this.formStore[whichForm].registrationStreet = person.regAddress.street;
3100
2262
  }
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;
2263
+ if (person.regAddress.building) this.formStore[whichForm].registrationNumberHouse = person.regAddress.building;
2264
+ if (person.regAddress.flat) this.formStore[whichForm].registrationNumberApartment = person.regAddress.flat;
3107
2265
 
3108
2266
  // TODO Доработать логику и для остальных
3109
2267
  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
- );
2268
+ const validDocument = person.documents.document.find(i => new Date(i.endDate) > new Date(Date.now()) && i.status.code === '00' && i.type.code === '002');
3116
2269
  if (validDocument) {
3117
2270
  const documentType = this.documentTypes.find(i => i.ids === '1UDL');
3118
- if (documentType)
3119
- this.formStore[whichForm].documentType = documentType;
2271
+ if (documentType) this.formStore[whichForm].documentType = documentType;
3120
2272
 
3121
2273
  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
- );
2274
+ this.formStore[whichForm].documentExpire = reformatDate(validDocument.endDate);
2275
+ this.formStore[whichForm].documentDate = reformatDate(validDocument.beginDate);
3128
2276
  this.formStore[whichForm].documentNumber = validDocument.number;
3129
2277
 
3130
- const documentIssuer = this.documentIssuers.find(i =>
3131
- i.nameRu.match(new RegExp('МВД РК', 'i')),
3132
- );
3133
- if (documentIssuer)
3134
- this.formStore[whichForm].documentIssuers = documentIssuer;
2278
+ const documentIssuer = this.documentIssuers.find(i => i.nameRu.match(new RegExp('МВД РК', 'i')));
2279
+ if (documentIssuer) this.formStore[whichForm].documentIssuers = documentIssuer;
3135
2280
  }
3136
2281
  } else {
3137
2282
  const documentType =
3138
2283
  person.documents.document.type.nameRu === 'УДОСТОВЕРЕНИЕ РК'
3139
2284
  ? 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
- )
2285
+ : this.documentTypes.find(i => i.nameRu.match(new RegExp(person.documents.document.type.nameRu, 'i')))
2286
+ ? this.documentTypes.find(i => i.nameRu.match(new RegExp(person.documents.document.type.nameRu, 'i')))
3150
2287
  : new Value();
3151
- if (documentType)
3152
- this.formStore[whichForm].documentType = documentType;
2288
+ if (documentType) this.formStore[whichForm].documentType = documentType;
3153
2289
 
3154
2290
  const documentNumber = person.documents.document.number;
3155
- if (documentNumber)
3156
- this.formStore[whichForm].documentNumber = documentNumber;
2291
+ if (documentNumber) this.formStore[whichForm].documentNumber = documentNumber;
3157
2292
 
3158
2293
  const documentDate = person.documents.document.beginDate;
3159
- if (documentDate)
3160
- this.formStore[whichForm].documentDate = reformatDate(documentDate);
2294
+ if (documentDate) this.formStore[whichForm].documentDate = reformatDate(documentDate);
3161
2295
 
3162
2296
  const documentExpire = person.documents.document.endDate;
3163
- if (documentExpire)
3164
- this.formStore[whichForm].documentExpire =
3165
- reformatDate(documentExpire);
2297
+ if (documentExpire) this.formStore[whichForm].documentExpire = reformatDate(documentExpire);
3166
2298
 
3167
2299
  // 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;
2300
+ const documentIssuer = this.documentIssuers.find(i => i.nameRu.match(new RegExp('МВД РК', 'i')));
2301
+ if (documentIssuer) this.formStore[whichForm].documentIssuers = documentIssuer;
3173
2302
  }
3174
- const economySectorCode = this.economySectorCode.find(
3175
- i => i.ids === '500003.9',
3176
- );
3177
- if (economySectorCode)
3178
- this.formStore[whichForm].economySectorCode = economySectorCode;
2303
+ const economySectorCode = this.economySectorCode.find(i => i.ids === '500003.9');
2304
+ if (economySectorCode) this.formStore[whichForm].economySectorCode = economySectorCode;
3179
2305
  } else {
3180
2306
  this.formStore[whichForm][whichIndex].firstName = person.name;
3181
2307
  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
- );
2308
+ this.formStore[whichForm][whichIndex].middleName = person.patronymic ? person.patronymic : '';
2309
+ this.formStore[whichForm][whichIndex].longName = `${person.surname} ${person.name} ${person.patronymic ? person.patronymic : ''}`;
2310
+ this.formStore[whichForm][whichIndex].birthDate = reformatDate(person.birthDate);
3191
2311
  this.formStore[whichForm][whichIndex].genderName = person.gender.nameRu;
3192
2312
 
3193
2313
  const gender = this.gender.find(i => i.id == person.gender.code);
3194
2314
  if (gender) this.formStore[whichForm][whichIndex].gender = gender;
3195
2315
 
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;
2316
+ const birthPlace = this.countries.find(i => i.nameRu.match(new RegExp(person.birthPlace.country.nameRu, 'i')));
2317
+ if (birthPlace) this.formStore[whichForm][whichIndex].birthPlace = birthPlace;
3201
2318
 
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;
2319
+ const countryOfCitizenship = this.citizenshipCountries.find(i => i.nameRu.match(new RegExp(person.citizenship.nameRu, 'i')));
2320
+ if (countryOfCitizenship) this.formStore[whichForm][whichIndex].countryOfCitizenship = countryOfCitizenship;
3208
2321
 
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;
2322
+ const regCountry = this.countries.find(i => i.nameRu.match(new RegExp(person.regAddress.country.nameRu, 'i')));
2323
+ if (regCountry) this.formStore[whichForm][whichIndex].registrationCountry = regCountry;
3215
2324
 
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;
2325
+ const regProvince = this.states.find(i => i.nameRu.match(new RegExp(person.regAddress.district.nameRu, 'i')));
2326
+ if (regProvince) this.formStore[whichForm][whichIndex].registrationProvince = regProvince;
3222
2327
 
3223
2328
  if ('city' in person.regAddress && !!person.regAddress.city) {
3224
2329
  if (person.regAddress.city.includes(', ')) {
3225
2330
  const personCities = person.regAddress.city.split(', ');
3226
2331
  for (let i = 0; i < personCities.length; ++i) {
3227
- const possibleCity = this.cities.find(i =>
3228
- i.nameRu.includes(personCities[i]),
3229
- );
2332
+ const possibleCity = this.cities.find(i => i.nameRu.includes(personCities[i]));
3230
2333
  if (possibleCity) {
3231
- this.formStore[whichForm][whichIndex].registrationCity =
3232
- possibleCity;
2334
+ this.formStore[whichForm][whichIndex].registrationCity = possibleCity;
3233
2335
  break;
3234
2336
  }
3235
2337
  }
3236
- if (
3237
- this.formStore[whichForm][whichIndex].registrationCity.nameRu ===
3238
- null
3239
- ) {
2338
+ if (this.formStore[whichForm][whichIndex].registrationCity.nameRu === null) {
3240
2339
  for (let i = 0; i < personCities.length; ++i) {
3241
- const possibleRegion = this.regions.find(i =>
3242
- i.nameRu.includes(personCities[i]),
3243
- );
2340
+ const possibleRegion = this.regions.find(i => i.nameRu.includes(personCities[i]));
3244
2341
  if (possibleRegion) {
3245
- this.formStore[whichForm][whichIndex].registrationRegion =
3246
- possibleRegion;
2342
+ this.formStore[whichForm][whichIndex].registrationRegion = possibleRegion;
3247
2343
  break;
3248
2344
  }
3249
2345
  }
3250
2346
  }
3251
2347
  } 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;
2348
+ const regCity = this.cities.find(i => i.nameRu.match(new RegExp(person.regAddress.city, 'i')));
2349
+ if (regCity) this.formStore[whichForm][whichIndex].registrationCity = regCity;
2350
+ if (this.formStore[whichForm][whichIndex].registrationCity.nameRu === null) {
2351
+ const regRegion = this.regions.find(i => i.nameRu.match(new RegExp(person.regAddress.city), 'i'));
2352
+ if (regRegion) this.formStore[whichForm][whichIndex].registrationRegion = regRegion;
3267
2353
  }
3268
2354
  }
3269
2355
  }
3270
2356
 
3271
- if (
3272
- this.formStore[whichForm][whichIndex].registrationCity.nameRu ===
3273
- null &&
3274
- this.formStore[whichForm][whichIndex].registrationRegion.nameRu ===
3275
- null
3276
- ) {
2357
+ if (this.formStore[whichForm][whichIndex].registrationCity.nameRu === null && this.formStore[whichForm][whichIndex].registrationRegion.nameRu === null) {
3277
2358
  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
- ),
2359
+ i => i.nameRu.match(new RegExp(person.regAddress.region.nameRu, 'i')) || i.nameRu.match(new RegExp(person.regAddress.district.nameRu, 'i')),
3285
2360
  );
3286
2361
  if (regCity) {
3287
2362
  this.formStore[whichForm][whichIndex].registrationCity = regCity;
3288
2363
  const regType = this.localityTypes.find(i => i.nameRu === 'город');
3289
- if (regType)
3290
- this.formStore[whichForm][whichIndex].registrationRegionType =
3291
- regType;
2364
+ if (regType) this.formStore[whichForm][whichIndex].registrationRegionType = regType;
3292
2365
  } else {
3293
2366
  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
- ),
2367
+ i => i.nameRu.match(new RegExp(person.regAddress.region.nameRu), 'i') || i.nameRu.match(new RegExp(person.regAddress.district.nameRu, 'i')),
3302
2368
  );
3303
2369
  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;
2370
+ this.formStore[whichForm][whichIndex].registrationRegion = regRegion;
2371
+ const regType = this.localityTypes.find(i => (i.nameRu === i.nameRu) === 'село' || i.nameRu === 'поселок');
2372
+ if (regType) this.formStore[whichForm][whichIndex].registrationRegionType = regType;
3313
2373
  }
3314
2374
  }
3315
2375
  }
3316
2376
 
3317
2377
  if (person.regAddress.street.includes(', ')) {
3318
2378
  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;
2379
+ const microDistrict = personAddress.find(i => i.match(new RegExp('микрорайон', 'i')));
2380
+ const quarter = personAddress.find(i => i.match(new RegExp('квартал', 'i')));
2381
+ const street = personAddress.find(i => i.match(new RegExp('улица', 'i')));
2382
+ if (microDistrict) this.formStore[whichForm][whichIndex].registrationMicroDistrict = microDistrict;
2383
+ if (quarter) this.formStore[whichForm][whichIndex].registrationQuarter = quarter;
2384
+ if (street) this.formStore[whichForm][whichIndex].registrationStreet = street;
3335
2385
  } else {
3336
- if (person.regAddress.street)
3337
- this.formStore[whichForm][whichIndex].registrationStreet =
3338
- person.regAddress.street;
2386
+ if (person.regAddress.street) this.formStore[whichForm][whichIndex].registrationStreet = person.regAddress.street;
3339
2387
  }
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;
2388
+ if (person.regAddress.building) this.formStore[whichForm][whichIndex].registrationNumberHouse = person.regAddress.building;
2389
+ if (person.regAddress.flat) this.formStore[whichForm][whichIndex].registrationNumberApartment = person.regAddress.flat;
3346
2390
 
3347
2391
  // TODO Доработать логику и для остальных
3348
2392
  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
- );
2393
+ const validDocument = person.documents.document.find(i => new Date(i.endDate) > new Date(Date.now()) && i.status.code === '00' && i.type.code === '002');
3355
2394
  if (validDocument) {
3356
2395
  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;
2396
+ if (documentType) this.formStore[whichForm][whichIndex].documentType = documentType;
2397
+ this.formStore[whichForm][whichIndex].documentNumber = validDocument.number;
2398
+ this.formStore[whichForm][whichIndex].documentExpire = reformatDate(validDocument.endDate);
2399
+ this.formStore[whichForm][whichIndex].documentDate = reformatDate(validDocument.beginDate);
2400
+ this.formStore[whichForm][whichIndex].documentNumber = validDocument.number;
2401
+
2402
+ const documentIssuer = this.documentIssuers.find(i => i.nameRu.match(new RegExp('МВД РК', 'i')));
2403
+ if (documentIssuer) this.formStore[whichForm][whichIndex].documentIssuers = documentIssuer;
3376
2404
  }
3377
2405
  } else {
3378
2406
  const documentType =
3379
2407
  person.documents.document.type.nameRu === 'УДОСТОВЕРЕНИЕ РК'
3380
2408
  ? 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
- )
2409
+ : this.documentTypes.find(i => i.nameRu.match(new RegExp(person.documents.document.type.nameRu, 'i')))
2410
+ ? this.documentTypes.find(i => i.nameRu.match(new RegExp(person.documents.document.type.nameRu, 'i')))
3391
2411
  : new Value();
3392
- if (documentType)
3393
- this.formStore[whichForm][whichIndex].documentType = documentType;
2412
+ if (documentType) this.formStore[whichForm][whichIndex].documentType = documentType;
3394
2413
 
3395
2414
  const documentNumber = person.documents.document.number;
3396
- if (documentNumber)
3397
- this.formStore[whichForm][whichIndex].documentNumber =
3398
- documentNumber;
2415
+ if (documentNumber) this.formStore[whichForm][whichIndex].documentNumber = documentNumber;
3399
2416
 
3400
2417
  const documentDate = person.documents.document.beginDate;
3401
- if (documentDate)
3402
- this.formStore[whichForm][whichIndex].documentDate =
3403
- reformatDate(documentDate);
2418
+ if (documentDate) this.formStore[whichForm][whichIndex].documentDate = reformatDate(documentDate);
3404
2419
 
3405
2420
  const documentExpire = person.documents.document.endDate;
3406
- if (documentExpire)
3407
- this.formStore[whichForm][whichIndex].documentExpire =
3408
- reformatDate(documentExpire);
2421
+ if (documentExpire) this.formStore[whichForm][whichIndex].documentExpire = reformatDate(documentExpire);
3409
2422
 
3410
2423
  // 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;
2424
+ const documentIssuer = this.documentIssuers.find(i => i.nameRu.match(new RegExp('МВД РК', 'i')));
2425
+ if (documentIssuer) this.formStore[whichForm][whichIndex].documentIssuers = documentIssuer;
3417
2426
  }
3418
- const economySectorCode = this.economySectorCode.find(
3419
- i => i.ids === '500003.9',
3420
- );
3421
- if (economySectorCode)
3422
- this.formStore[whichForm][whichIndex].economySectorCode =
3423
- economySectorCode;
2427
+ const economySectorCode = this.economySectorCode.find(i => i.ids === '500003.9');
2428
+ if (economySectorCode) this.formStore[whichForm][whichIndex].economySectorCode = economySectorCode;
3424
2429
  }
3425
2430
  },
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);
2431
+ hasJobSection(whichForm) {
2432
+ switch (whichForm) {
2433
+ case this.formStore.beneficiaryFormKey:
2434
+ case this.formStore.beneficialOwnerFormKey:
2435
+ case this.formStore.policyholdersRepresentativeFormKey:
2436
+ return false;
2437
+ default:
2438
+ return true;
3444
2439
  }
3445
2440
  },
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;
2441
+ hasBirthSection(whichForm) {
2442
+ if (this.isGons) return false;
2443
+ switch (whichForm) {
2444
+ case this.formStore.beneficiaryFormKey:
2445
+ return false;
2446
+ default:
2447
+ return true;
3527
2448
  }
3528
- this.isLoading = false;
3529
- return { otpStatus, otpResponse };
3530
2449
  },
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;
2450
+ hasPlaceSection(whichForm) {
2451
+ switch (whichForm) {
2452
+ default:
2453
+ return true;
2454
+ }
2455
+ },
2456
+ hasDocumentSection(whichForm) {
2457
+ switch (whichForm) {
2458
+ default:
2459
+ return true;
2460
+ }
2461
+ },
2462
+ hasContactSection(whichForm) {
2463
+ if (this.isGons) return false;
2464
+ switch (whichForm) {
2465
+ default:
2466
+ return true;
3565
2467
  }
3566
- return null;
3567
2468
  },
3568
2469
  },
3569
2470
  });