hl-core 0.0.7-beta.9 → 0.0.8-beta.1

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