hl-core 0.0.7-beta.1 → 0.0.7-beta.11

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 (42) hide show
  1. package/.prettierrc +2 -1
  2. package/api/index.ts +545 -0
  3. package/api/interceptors.ts +38 -0
  4. package/components/Button/Btn.vue +57 -0
  5. package/components/Button/BtnIcon.vue +47 -0
  6. package/components/Button/SortArrow.vue +21 -0
  7. package/components/Complex/Content.vue +5 -0
  8. package/components/Complex/ContentBlock.vue +5 -0
  9. package/components/Complex/Page.vue +43 -0
  10. package/components/Input/FormInput.vue +136 -0
  11. package/components/Input/RoundedInput.vue +136 -0
  12. package/components/Layout/Dialog.vue +84 -0
  13. package/components/Layout/Drawer.vue +42 -0
  14. package/components/Layout/Header.vue +48 -0
  15. package/components/Layout/Loader.vue +35 -0
  16. package/components/Layout/SettingsPanel.vue +33 -0
  17. package/components/Menu/MenuNav.vue +125 -0
  18. package/components/Menu/MenuNavItem.vue +27 -0
  19. package/components/Panel/PanelItem.vue +5 -0
  20. package/components/Transitions/FadeTransition.vue +5 -0
  21. package/composables/axios.ts +11 -0
  22. package/composables/classes.ts +1081 -0
  23. package/composables/constants.ts +61 -0
  24. package/composables/index.ts +133 -2
  25. package/composables/models.ts +43 -0
  26. package/composables/styles.ts +34 -8
  27. package/layouts/clear.vue +3 -0
  28. package/layouts/default.vue +37 -0
  29. package/layouts/full.vue +6 -0
  30. package/nuxt.config.ts +23 -4
  31. package/package.json +15 -4
  32. package/pages/500.vue +48 -0
  33. package/plugins/helperFunctionsPlugins.ts +11 -2
  34. package/plugins/storePlugin.ts +0 -2
  35. package/plugins/vuetifyPlugin.ts +10 -0
  36. package/store/data.store.js +2632 -6
  37. package/store/form.store.js +8 -0
  38. package/store/messages.ts +118 -27
  39. package/store/rules.js +7 -26
  40. package/tailwind.config.js +10 -0
  41. package/components/Button/GreenBtn.vue +0 -33
  42. package/store/app.store.js +0 -12
@@ -2,27 +2,2653 @@ 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';
6
+ import { DataStoreClass, Contragent } from '../composables/classes';
7
+ import { ApiClass } from '@/api';
8
+ import { useFormStore } from './form.store';
5
9
 
6
10
  export const useDataStore = defineStore('data', {
7
11
  state: () => ({
12
+ ...new DataStoreClass(),
8
13
  t: t,
9
14
  rules: rules,
10
15
  toast: Toast,
11
16
  toastTypes: Types,
12
17
  toastPositions: Positions,
18
+ isValidGUID: isValidGUID,
19
+ router: useRouter(),
20
+ formStore: useFormStore(),
21
+ contragent: useContragentStore(),
22
+ api: new ApiClass(),
23
+ yearEnding: year => yearEnding(year, constants.yearTitles, constants.yearCases),
24
+ currentDate: () => new Date(Date.now() - new Date().getTimezoneOffset() * 60 * 1000).toISOString().slice(0, -1),
13
25
  showToaster: (type, msg, timeout) =>
14
26
  Toast.useToast()(msg, {
15
27
  ...ToastOptions,
16
28
  type: Types[type.toUpperCase()],
17
- timeout:
18
- typeof timeout === ('number' || 'boolean')
19
- ? timeout
20
- : ToastOptions.timeout,
29
+ timeout: typeof timeout === ('number' || 'boolean') ? timeout : ToastOptions.timeout,
21
30
  }),
22
31
  }),
32
+ getters: {
33
+ isEFO: state => state.product === 'efo',
34
+ isBaiterek: state => state.product === 'baiterek',
35
+ isBolashak: state => state.product === 'bolashak',
36
+ isMycar: state => state.product === 'mycar',
37
+ isLifetrip: state => state.product === 'lifetrip',
38
+ isLiferenta: state => state.product === 'liferenta',
39
+ isPension: state => state.product === 'pension',
40
+ isEveryFormDisabled: state => Object.values(state.formStore.isDisabled).every(i => i === true),
41
+ },
23
42
  actions: {
24
- async loginUser(...data) {
25
- console.log(...data);
43
+ sendToParent(action, value) {
44
+ window.parent.postMessage({ action: action, value: value }, '*');
45
+ },
46
+ getFilesByIIN(iin) {
47
+ return this.signedDocumentList.filter(file => file.iin === iin && file.fileTypeName === 'Удостоверение личности');
48
+ },
49
+ async getNewAccessToken() {
50
+ try {
51
+ const data = {
52
+ accessToken: localStorage.getItem('accessToken'),
53
+ refreshToken: localStorage.getItem('refreshToken'),
54
+ };
55
+ const response = await this.api.getNewAccessToken(data);
56
+ this.accessToken = response.accessToken;
57
+ this.refreshToken = response.refreshToken;
58
+ localStorage.setItem('accessToken', this.accessToken);
59
+ localStorage.setItem('refreshToken', this.refreshToken);
60
+ } catch (err) {
61
+ console.error(err);
62
+ }
63
+ },
64
+ async getDictionaryItems(dictName) {
65
+ try {
66
+ this.isLoading = true;
67
+ if (!this[`${dictName}List`].length) {
68
+ this[`${dictName}List`] = await this.api.getDictionaryItems(dictName);
69
+ }
70
+ } catch (err) {
71
+ console.log(err);
72
+ } finally {
73
+ this.isLoading = false;
74
+ }
75
+ },
76
+ async loginUser(login, password, numAttempt) {
77
+ try {
78
+ const token = localStorage.getItem('accessToken') || null;
79
+
80
+ if (token && isValidToken(token)) {
81
+ this.accessToken = token;
82
+ this.getUserRoles();
83
+ } else {
84
+ const response = await this.api.loginUser({
85
+ login: login,
86
+ password: password,
87
+ numAttempt: numAttempt,
88
+ });
89
+
90
+ this.accessToken = response.accessToken;
91
+ this.refreshToken = response.refreshToken;
92
+ this.getUserRoles();
93
+ }
94
+ if (
95
+ this.isManager() ||
96
+ this.isUnderwriter() ||
97
+ this.isAdmin() ||
98
+ this.isAgent() ||
99
+ this.isCompliance() ||
100
+ this.isAgentMycar() ||
101
+ this.isAnalyst() ||
102
+ this.isUpk() ||
103
+ this.isFinanceCenter() ||
104
+ this.isSupervisor()
105
+ ) {
106
+ localStorage.setItem('accessToken', this.accessToken);
107
+ localStorage.setItem('refreshToken', this.refreshToken);
108
+ } else {
109
+ this.showToaster('error', this.t('toaster.noProductPermission'), 5000);
110
+ }
111
+ } catch (err) {
112
+ console.log(err);
113
+ if ('response' in err) {
114
+ this.showToaster('error', err.response.data, 3000);
115
+ }
116
+ }
117
+ },
118
+ getUserRoles() {
119
+ if (this.accessToken && this.user.roles.length === 0) {
120
+ const decoded = jwtDecode(this.accessToken);
121
+ this.user.id = decoded.sub;
122
+ this.user.fullName = `${decoded.lastName} ${decoded.firstName} ${decoded.middleName ? decoded.middleName : ''}`;
123
+ const key = getKeyWithPattern(decoded, 'role');
124
+ if (key) {
125
+ const roles = decoded[key];
126
+ if (typeof roles === constants.types.string) {
127
+ this.user.roles.push(roles);
128
+ } else if (typeof roles === constants.types.array) {
129
+ this.user.roles = roles;
130
+ }
131
+ }
132
+ }
133
+ },
134
+ isRole(whichRole) {
135
+ if (this.user.roles.length === 0) {
136
+ this.getUserRoles();
137
+ }
138
+ const isRole = this.user.roles.find(i => i === whichRole);
139
+ return !!isRole;
140
+ },
141
+ isInitiator() {
142
+ return this.isRole(constants.roles.manager) || this.isRole(constants.roles.agent) || this.isRole(constants.roles.agentMycar);
143
+ },
144
+ isManager() {
145
+ return this.isRole(constants.roles.manager);
146
+ },
147
+ isCompliance() {
148
+ return this.isRole(constants.roles.compliance);
149
+ },
150
+ isAdmin() {
151
+ return this.isRole(constants.roles.admin);
152
+ },
153
+ isAgent() {
154
+ return this.isRole(constants.roles.agent);
155
+ },
156
+ isUnderwriter() {
157
+ return this.isRole(constants.roles.underwriter);
158
+ },
159
+ isAgentMycar() {
160
+ return this.isRole(constants.roles.agentMycar);
161
+ },
162
+ isAnalyst() {
163
+ return this.isRole(constants.roles.analyst);
164
+ },
165
+ isUpk() {
166
+ return this.isRole(constants.roles.upk);
167
+ },
168
+ isFinanceCenter() {
169
+ return this.isRole(constants.roles.financeCenter);
170
+ },
171
+ isSupervisor() {
172
+ return this.isRole(constants.roles.supervisor);
173
+ },
174
+
175
+ isProcessEditable(statusCode) {
176
+ return !!constants.editableStatuses.find(status => status === statusCode);
177
+ },
178
+ isTask() {
179
+ return this.formStore.applicationData.processInstanceId != 0 && this.formStore.applicationData.isTask;
180
+ },
181
+ async logoutUser() {
182
+ this.isLoading = true;
183
+ try {
184
+ const whichProduct = this.product;
185
+ const token = localStorage.getItem('accessToken') || null;
186
+ if (token) {
187
+ this.$reset();
188
+ localStorage.clear();
189
+
190
+ if (whichProduct === 'efo') {
191
+ await this.router.push({ name: 'Auth' });
192
+ } else {
193
+ this.sendToParent(constants.postActions.toAuth, null);
194
+ }
195
+ } else {
196
+ this.showToaster('error', this.t('toaster.undefinedError'), 3000);
197
+ }
198
+ } catch (err) {
199
+ console.log(err);
200
+ }
201
+ this.isLoading = false;
202
+ },
203
+ async getFile(file, mode = 'view', fileType = 'pdf') {
204
+ try {
205
+ this.isLoading = true;
206
+ await this.api.getFile(file.id).then(response => {
207
+ if (!['pdf', 'docx'].includes(fileType)) {
208
+ const blob = new Blob([response], { type: `image/${fileType}` });
209
+ const url = window.URL.createObjectURL(blob);
210
+ window.open(url, '_blank', `width=${screen.width},height=${screen.height},top=70`);
211
+ } else {
212
+ const blob = new Blob([response], {
213
+ type: `application/${fileType}`,
214
+ });
215
+ const url = window.URL.createObjectURL(blob);
216
+ const link = document.createElement('a');
217
+ link.href = url;
218
+ if (mode === 'view') {
219
+ setTimeout(() => {
220
+ window.open(url, '_blank', `right=100`);
221
+ });
222
+ } else {
223
+ link.setAttribute('download', file.fileName);
224
+ document.body.appendChild(link);
225
+ link.click();
226
+ }
227
+ }
228
+ });
229
+ } catch (err) {
230
+ this.showToaster('error', err.response.data, 5000);
231
+ } finally {
232
+ this.isLoading = false;
233
+ }
234
+ },
235
+ async deleteFile(data) {
236
+ try {
237
+ await this.api.deleteFile(data);
238
+ this.showToaster('success', this.t('toaster.fileWasDeleted'), 3000);
239
+ } catch (err) {
240
+ this.showToaster('error', err.response.data, 2000);
241
+ }
242
+ },
243
+ async uploadFiles(data, load = true) {
244
+ try {
245
+ if (load) {
246
+ this.isLoading = true;
247
+ }
248
+ await this.api.uploadFiles(data);
249
+ return true;
250
+ } catch (err) {
251
+ this.showToaster('error', err.response.data, 5000);
252
+ return false;
253
+ } finally {
254
+ if (load) {
255
+ this.isLoading = false;
256
+ }
257
+ }
258
+ },
259
+ async getContragent(whichForm, whichIndex = null, load = true) {
260
+ if (load) {
261
+ this.isLoading = true;
262
+ }
263
+ try {
264
+ let response;
265
+ let queryData = {
266
+ firstName: '',
267
+ lastName: '',
268
+ middleName: '',
269
+ };
270
+ if (whichIndex === null) {
271
+ queryData.iin = this.formStore[whichForm].iin.replace(/-/g, '');
272
+ response = await this.api.getContragent(queryData);
273
+ }
274
+ if (whichIndex !== null) {
275
+ queryData.iin = this.formStore[whichForm][whichIndex].iin.replace(/-/g, '');
276
+ response = await this.api.getContragent(queryData);
277
+ }
278
+ if (response.totalItems > 0) {
279
+ if (response.totalItems.length === 1) {
280
+ await this.serializeContragentData(whichForm, response.items[0], whichIndex);
281
+ } else {
282
+ const sortedByRegistrationDate = response.items.sort((left, right) => new Date(right.registrationDate) - new Date(left.registrationDate));
283
+ await this.serializeContragentData(whichForm, sortedByRegistrationDate[0], whichIndex);
284
+ }
285
+ if (whichIndex === null) {
286
+ this.formStore[whichForm].gotFromInsis = true;
287
+ } else {
288
+ this.formStore[whichForm][whichIndex].gotFromInsis = true;
289
+ }
290
+ } else {
291
+ this.userNotFound = true;
292
+ }
293
+ } catch (err) {
294
+ console.log(err);
295
+ }
296
+ if (load) {
297
+ this.isLoading = false;
298
+ }
299
+ },
300
+ async getContragentById(id, whichForm, onlyGet = true, whichIndex = null) {
301
+ if (onlyGet) {
302
+ this.isLoading = true;
303
+ }
304
+ try {
305
+ if (this.isAgentMycar() && whichForm == this.formStore.beneficiaryFormKey) {
306
+ await this.serializeContragentData(whichForm, this.formStore.applicationData.beneficiaryApp[0], whichIndex);
307
+ this.isLoading = false;
308
+ return;
309
+ }
310
+ const response = await this.api.getContragentById(id);
311
+ if (response.totalItems > 0) {
312
+ await this.serializeContragentData(whichForm, response.items[0], whichIndex);
313
+ } else {
314
+ this.isLoading = false;
315
+ return false;
316
+ }
317
+ } catch (err) {
318
+ console.log(err);
319
+ }
320
+ if (onlyGet) {
321
+ this.isLoading = false;
322
+ }
323
+ },
324
+ async serializeContragentData(whichForm, contragent, whichIndex = null) {
325
+ const [{ value: data }, { value: contacts }, { value: documents }, { value: address }] = await Promise.allSettled([
326
+ this.api.getContrAgentData(contragent.id),
327
+ this.api.getContrAgentContacts(contragent.id),
328
+ this.api.getContrAgentDocuments(contragent.id),
329
+ this.api.getContrAgentAddress(contragent.id),
330
+ ]);
331
+ if (whichIndex === null) {
332
+ this.formStore[whichForm].response = {
333
+ contragent: contragent,
334
+ };
335
+ if (data && data.length) {
336
+ this.formStore[whichForm].response.questionnaires = data;
337
+ }
338
+ if (contacts && contacts.length) {
339
+ this.formStore[whichForm].response.contacts = contacts;
340
+ }
341
+ if (documents && documents.length) {
342
+ this.formStore[whichForm].response.documents = documents;
343
+ }
344
+ if (address && address.length) {
345
+ this.formStore[whichForm].response.addresses = address;
346
+ }
347
+ }
348
+ if (whichIndex !== null) {
349
+ this.formStore[whichForm][whichIndex].response = {
350
+ contragent: contragent,
351
+ };
352
+ if (data && data.length) {
353
+ this.formStore[whichForm][whichIndex].response.questionnaires = data;
354
+ }
355
+ if (contacts && contacts.length) {
356
+ this.formStore[whichForm][whichIndex].response.contacts = contacts;
357
+ }
358
+ if (documents && documents.length) {
359
+ this.formStore[whichForm][whichIndex].response.documents = documents;
360
+ }
361
+ if (address && address.length) {
362
+ this.formStore[whichForm][whichIndex].response.addresses = address;
363
+ }
364
+ }
365
+ this.parseContragent(
366
+ whichForm,
367
+ {
368
+ personalData: contragent,
369
+ documents: documents,
370
+ contacts: contacts,
371
+ data: data,
372
+ address: address,
373
+ },
374
+ whichIndex,
375
+ );
376
+ },
377
+ async searchContragent(iin) {
378
+ this.isLoading = true;
379
+ try {
380
+ let queryData = {
381
+ iin: iin.replace(/-/g, ''),
382
+ firstName: '',
383
+ lastName: '',
384
+ middleName: '',
385
+ };
386
+ const response = await this.api.getContragent(queryData);
387
+ if (response.totalItems > 0) {
388
+ this.contragentList = response.items;
389
+ } else {
390
+ this.contragentList = [];
391
+ }
392
+ } catch (err) {
393
+ console.log(err);
394
+ this.contragentList = [];
395
+ }
396
+ this.isLoading = false;
397
+ },
398
+ parseContragent(whichForm, user, whichIndex = null) {
399
+ if (whichIndex === null) {
400
+ // Save User Personal Data
401
+ this.formStore[whichForm].verifyType = user.personalData.verifyType;
402
+ this.formStore[whichForm].verifyDate = user.personalData.verifyDate;
403
+ this.formStore[whichForm].iin = reformatIin(user.personalData.iin);
404
+ this.formStore[whichForm].age = user.personalData.age;
405
+ const country = this.countries.find(i => i.nameRu?.match(new RegExp(user.personalData.birthPlace, 'i')));
406
+ this.formStore[whichForm].birthPlace = country && Object.keys(country).length ? country : new Value();
407
+ this.formStore[whichForm].gender = this.gender.find(i => i.nameRu === user.personalData.genderName);
408
+ this.formStore[whichForm].gender.id = user.personalData.gender;
409
+ this.formStore[whichForm].birthDate = reformatDate(user.personalData.birthDate);
410
+ this.formStore[whichForm].genderName = user.personalData.genderName;
411
+ this.formStore[whichForm].lastName = user.personalData.lastName;
412
+ this.formStore[whichForm].longName = user.personalData.longName;
413
+ this.formStore[whichForm].middleName = user.personalData.middleName ? user.personalData.middleName : '';
414
+ this.formStore[whichForm].firstName = user.personalData.firstName;
415
+ this.formStore[whichForm].id = user.personalData.id;
416
+ this.formStore[whichForm].type = user.personalData.type;
417
+ this.formStore[whichForm].registrationDate = user.personalData.registrationDate;
418
+ // Save User Documents Data
419
+ if ('documents' in user && user.documents.length) {
420
+ const documentType = this.documentTypes.find(i => i.ids === user.documents[0].type);
421
+ const documentIssuer = this.documentIssuers.find(i => i.nameRu === user.documents[0].issuerNameRu);
422
+ this.formStore[whichForm].documentType = documentType ? documentType : new Value();
423
+ this.formStore[whichForm].documentNumber = user.documents[0].number;
424
+ this.formStore[whichForm].documentIssuers = documentIssuer ? documentIssuer : new Value();
425
+ this.formStore[whichForm].documentDate = reformatDate(user.documents[0].issueDate);
426
+ this.formStore[whichForm].documentExpire = reformatDate(user.documents[0].expireDate);
427
+ }
428
+ // Document detail (residency, economy code, etc..)
429
+ if ('data' in user && user.data.length) {
430
+ user.data.forEach(dataObject => {
431
+ this.searchFromList(whichForm, dataObject);
432
+ });
433
+ }
434
+ if ('address' in user && user.address.length) {
435
+ const country = this.countries.find(i => i.nameRu?.match(new RegExp(user.address.countryName, 'i')));
436
+ const province = this.states.find(i => i.ids === user.address[0].stateCode);
437
+ const localityType = this.localityTypes.find(i => i.nameRu === user.address[0].cityTypeName);
438
+ const city = this.cities.find(i => !!user.address[0].cityName && i.nameRu === user.address[0].cityName.replace('г.', ''));
439
+ const region = this.regions.find(i => !!user.address[0].regionCode && i.ids == user.address[0].regionCode);
440
+ this.formStore[whichForm].registrationCountry = country ? country : new Value();
441
+ this.formStore[whichForm].registrationStreet = user.address[0].streetName;
442
+ this.formStore[whichForm].registrationCity = city ? city : new Value();
443
+ this.formStore[whichForm].registrationNumberApartment = user.address[0].apartmentNumber;
444
+ this.formStore[whichForm].registrationNumberHouse = user.address[0].blockNumber;
445
+ this.formStore[whichForm].registrationProvince = province ? province : new Value();
446
+ this.formStore[whichForm].registrationRegionType = localityType ? localityType : new Value();
447
+ this.formStore[whichForm].registrationRegion = region ? region : new Value();
448
+ this.formStore[whichForm].registrationQuarter = user.address[0].kvartal;
449
+ this.formStore[whichForm].registrationMicroDistrict = user.address[0].microRaion;
450
+ }
451
+ if ('contacts' in user && user.contacts.length) {
452
+ user.contacts.forEach(contact => {
453
+ if (contact.type === 'EMAIL' && contact.value) {
454
+ this.formStore[whichForm].email = contact.value;
455
+ }
456
+ if (contact.type === 'MOBILE' && contact.value) {
457
+ let phoneNumber = contact.value.substring(1);
458
+ this.formStore[whichForm].phoneNumber = `+7 (${phoneNumber.slice(0, 3)}) ${phoneNumber.slice(3, 6)} ${phoneNumber.slice(6, 8)} ${phoneNumber.slice(8)}`;
459
+ }
460
+ if (contact.type === 'HOME' && contact.value) {
461
+ let homePhone = contact.value.substring(1);
462
+ this.formStore[whichForm].homePhone = `+7 (${homePhone.slice(0, 3)}) ${homePhone.slice(3, 6)} ${homePhone.slice(6, 8)} ${homePhone.slice(8)}`;
463
+ }
464
+ });
465
+ }
466
+ }
467
+ if (whichIndex !== null) {
468
+ // Save User Personal Data
469
+ this.formStore[whichForm][whichIndex].iin = reformatIin(user.personalData.iin);
470
+ this.formStore[whichForm][whichIndex].verifyType = user.personalData.verifyType;
471
+ this.formStore[whichForm][whichIndex].verifyDate = user.personalData.verifyDate;
472
+ this.formStore[whichForm][whichIndex].age = user.personalData.age;
473
+ const country = this.countries.find(i => i.nameRu?.match(new RegExp(user.personalData.birthPlace, 'i')));
474
+ this.formStore[whichForm][whichIndex].birthPlace = country && Object.keys(country).length ? country : new Value();
475
+ this.formStore[whichForm][whichIndex].gender = this.gender.find(i => i.nameRu === user.personalData.genderName);
476
+ this.formStore[whichForm][whichIndex].gender.id = user.personalData.gender;
477
+ this.formStore[whichForm][whichIndex].birthDate = reformatDate(user.personalData.birthDate);
478
+ this.formStore[whichForm][whichIndex].genderName = user.personalData.genderName;
479
+ this.formStore[whichForm][whichIndex].lastName = user.personalData.lastName;
480
+ this.formStore[whichForm][whichIndex].longName = user.personalData.longName;
481
+ this.formStore[whichForm][whichIndex].middleName = user.personalData.middleName ? user.personalData.middleName : '';
482
+ this.formStore[whichForm][whichIndex].firstName = user.personalData.firstName;
483
+ this.formStore[whichForm][whichIndex].id = user.personalData.id;
484
+ this.formStore[whichForm][whichIndex].type = user.personalData.type;
485
+ this.formStore[whichForm][whichIndex].registrationDate = user.personalData.registrationDate;
486
+ // Save User Documents Data
487
+ if ('documents' in user && user.documents.length) {
488
+ const documentType = this.documentTypes.find(i => i.ids === user.documents[0].type);
489
+ const documentIssuer = this.documentIssuers.find(i => i.nameRu === user.documents[0].issuerNameRu);
490
+ this.formStore[whichForm][whichIndex].documentType = documentType ? documentType : new Value();
491
+ this.formStore[whichForm][whichIndex].documentNumber = user.documents[0].number;
492
+ this.formStore[whichForm][whichIndex].documentIssuers = documentIssuer ? documentIssuer : new Value();
493
+ this.formStore[whichForm][whichIndex].documentDate = reformatDate(user.documents[0].issueDate);
494
+ this.formStore[whichForm][whichIndex].documentExpire = reformatDate(user.documents[0].expireDate);
495
+ }
496
+ // Document detail (residency, economy code, etc..)
497
+ if ('data' in user && user.data.length) {
498
+ user.data.forEach(dataObject => {
499
+ this.searchFromList(whichForm, dataObject, whichIndex);
500
+ });
501
+ }
502
+ if ('address' in user && user.address.length) {
503
+ const country = this.countries.find(i => i.nameRu?.match(new RegExp(user.address.countryName, 'i')));
504
+ const province = this.states.find(i => i.ids === user.address[0].stateCode);
505
+ const localityType = this.localityTypes.find(i => i.nameRu === user.address[0].cityTypeName);
506
+ const city = this.cities.find(i => !!user.address[0].cityName && i.nameRu === user.address[0].cityName.replace('г.', ''));
507
+ const region = this.regions.find(i => !!user.address[0].regionCode && i.ids == user.address[0].regionCode);
508
+ this.formStore[whichForm][whichIndex].registrationCountry = country ? country : new Value();
509
+ this.formStore[whichForm][whichIndex].registrationStreet = user.address[0].streetName;
510
+ this.formStore[whichForm][whichIndex].registrationCity = city ? city : new Value();
511
+ this.formStore[whichForm][whichIndex].registrationNumberApartment = user.address[0].apartmentNumber;
512
+ this.formStore[whichForm][whichIndex].registrationNumberHouse = user.address[0].blockNumber;
513
+ this.formStore[whichForm][whichIndex].registrationProvince = province ? province : new Value();
514
+ this.formStore[whichForm][whichIndex].registrationRegionType = localityType ? localityType : new Value();
515
+ this.formStore[whichForm][whichIndex].registrationRegion = region ? region : new Value();
516
+ this.formStore[whichForm][whichIndex].registrationQuarter = user.address[0].kvartal;
517
+ this.formStore[whichForm][whichIndex].registrationMicroDistrict = user.address[0].microRaion;
518
+ }
519
+ if ('contacts' in user && user.contacts.length) {
520
+ user.contacts.forEach(contact => {
521
+ if (contact.type === 'EMAIL' && contact.value) {
522
+ this.formStore[whichForm][whichIndex].email = contact.value;
523
+ }
524
+ if (contact.type === 'MOBILE' && contact.value) {
525
+ let phoneNumber = contact.value.substring(1);
526
+ this.formStore[whichForm][whichIndex].phoneNumber = `+7 (${phoneNumber.slice(0, 3)}) ${phoneNumber.slice(3, 6)} ${phoneNumber.slice(6, 8)} ${phoneNumber.slice(8)}`;
527
+ }
528
+ if (contact.type === 'HOME' && contact.value) {
529
+ let homePhone = contact.value.substring(1);
530
+ this.formStore[whichForm][whichIndex].homePhone = `+7 (${homePhone.slice(0, 3)}) ${homePhone.slice(3, 6)} ${homePhone.slice(6, 8)} ${homePhone.slice(8)}`;
531
+ }
532
+ });
533
+ }
534
+ }
535
+ },
536
+ async alreadyInInsis(iin, firstName, lastName, middleName) {
537
+ try {
538
+ const queryData = {
539
+ iin: iin.replaceAll('-', ''),
540
+ firstName: !!firstName ? firstName : '',
541
+ lastName: !!lastName ? lastName : '',
542
+ middleName: !!middleName ? middleName : '',
543
+ };
544
+ const contragent = await this.api.getContragent(queryData);
545
+ if (contragent.totalItems > 0) {
546
+ if (contragent.totalItems.length === 1) {
547
+ return contragent.items[0].id;
548
+ } else {
549
+ const sortedByRegistrationDate = contragent.items.sort((left, right) => new Date(right.registrationDate) - new Date(left.registrationDate));
550
+ return sortedByRegistrationDate[0].id;
551
+ }
552
+ } else {
553
+ return false;
554
+ }
555
+ } catch (err) {
556
+ console.log(err);
557
+ return false;
558
+ }
559
+ },
560
+ async saveContragent(user, whichForm, onlySaveAction = true, whichIndex = null) {
561
+ this.isLoading = true;
562
+ if (whichIndex === null) {
563
+ const hasInsisId = await this.alreadyInInsis(
564
+ this.formStore[whichForm].iin,
565
+ this.formStore[whichForm].firstName,
566
+ this.formStore[whichForm].lastName,
567
+ this.formStore[whichForm].middleName,
568
+ );
569
+ if (hasInsisId !== false) {
570
+ user.id = hasInsisId;
571
+ const [{ value: data }, { value: contacts }, { value: documents }, { value: address }] = await Promise.allSettled([
572
+ this.api.getContrAgentData(user.id),
573
+ this.api.getContrAgentContacts(user.id),
574
+ this.api.getContrAgentDocuments(user.id),
575
+ this.api.getContrAgentAddress(user.id),
576
+ ]);
577
+ this.formStore[whichForm].response = {};
578
+ if (data && data.length) {
579
+ this.formStore[whichForm].response.questionnaires = data;
580
+ }
581
+ if (contacts && contacts.length) {
582
+ this.formStore[whichForm].response.contacts = contacts;
583
+ }
584
+ if (documents && documents.length) {
585
+ this.formStore[whichForm].response.documents = documents;
586
+ }
587
+ if (address && address.length) {
588
+ this.formStore[whichForm].response.addresses = address;
589
+ }
590
+ }
591
+ } else {
592
+ const hasInsisId = await this.alreadyInInsis(
593
+ this.formStore[whichForm][whichIndex].iin,
594
+ this.formStore[whichForm][whichIndex].firstName,
595
+ this.formStore[whichForm][whichIndex].lastName,
596
+ this.formStore[whichForm][whichIndex].middleName,
597
+ );
598
+ if (hasInsisId !== false) {
599
+ user.id = hasInsisId;
600
+ const [{ value: data }, { value: contacts }, { value: documents }, { value: address }] = await Promise.allSettled([
601
+ this.api.getContrAgentData(user.id),
602
+ this.api.getContrAgentContacts(user.id),
603
+ this.api.getContrAgentDocuments(user.id),
604
+ this.api.getContrAgentAddress(user.id),
605
+ ]);
606
+ this.formStore[whichForm][whichIndex].response = {};
607
+ if (data && data.length) {
608
+ this.formStore[whichForm][whichIndex].response.questionnaires = data;
609
+ }
610
+ if (contacts && contacts.length) {
611
+ this.formStore[whichForm][whichIndex].response.contacts = contacts;
612
+ }
613
+ if (documents && documents.length) {
614
+ this.formStore[whichForm][whichIndex].response.documents = documents;
615
+ }
616
+ if (address && address.length) {
617
+ this.formStore[whichForm][whichIndex].response.addresses = address;
618
+ }
619
+ }
620
+ }
621
+ try {
622
+ // ! SaveContragent -> Contragent
623
+ let contragentData = {
624
+ id: user.id,
625
+ type: user.type,
626
+ iin: user.iin.replace(/-/g, ''),
627
+ longName: user.longName !== null ? user.longName : user.lastName + user.firstName + user.middleName ? user.middleName : '',
628
+ lastName: user.lastName,
629
+ firstName: user.firstName,
630
+ middleName: user.middleName ? user.middleName : '',
631
+ birthDate: user.getDateByKey('birthDate'),
632
+ gender: user.gender.id,
633
+ genderName: user.genderName ? user.genderName : user.gender.nameRu,
634
+ birthPlace: user.birthPlace.nameRu,
635
+ age: user.age,
636
+ registrationDate: user.registrationDate,
637
+ verifyType: user.verifyType,
638
+ verifyDate: user.verifyDate,
639
+ };
640
+ // ! SaveContragent -> Questionnaires
641
+ let questionnaires = (({ economySectorCode, countryOfCitizenship, countryOfTaxResidency, signOfResidency }) => ({
642
+ economySectorCode,
643
+ countryOfCitizenship,
644
+ countryOfTaxResidency,
645
+ signOfResidency,
646
+ }))(user);
647
+ let questionariesData = Object.values(questionnaires).map(question => {
648
+ let questName = '';
649
+ let questionId = parseInt(question.ids).toString();
650
+ if (questionId === '500003') {
651
+ questName = 'Код сектора экономики';
652
+ } else if (questionId === '500011') {
653
+ questName = 'Признак резидентства';
654
+ } else if (questionId === '500012') {
655
+ questName = 'Страна гражданства';
656
+ } else if (questionId === '500014') {
657
+ questName = 'Страна налогового резиденства';
658
+ }
659
+ return {
660
+ id: 'response' in user && 'questionnaires' in user.response ? user.response.questionnaires?.find(i => i.questId == questionId).id : question.id,
661
+ contragentId: user.id,
662
+ questAnswer: question.ids,
663
+ questId: questionId,
664
+ questAnswerName: question.nameRu,
665
+ questName: questName,
666
+ };
667
+ });
668
+ if (user.countryOfTaxResidency.ids !== '500014.3') {
669
+ user.addTaxResidency = new Value();
670
+ }
671
+ const addTaxResidency = 'response' in user && 'questionnaires' in user.response && user.response.questionnaires.find(i => i.questId === '507777');
672
+ if (user.addTaxResidency.nameRu !== null) {
673
+ questionariesData.push({
674
+ id: addTaxResidency ? addTaxResidency.id : 0,
675
+ contragentId: user.id,
676
+ questAnswer: user.addTaxResidency.ids,
677
+ questAnswerName: user.addTaxResidency.nameRu,
678
+ questName: 'Указать если налоговое резиденство выбрано другое',
679
+ questId: '507777',
680
+ });
681
+ } else {
682
+ if (addTaxResidency && addTaxResidency.questAnswer !== null) {
683
+ questionariesData.push({
684
+ id: addTaxResidency.id,
685
+ contragentId: user.id,
686
+ questAnswer: null,
687
+ questAnswerName: null,
688
+ questName: 'Указать если налоговое резиденство выбрано другое',
689
+ questId: '507777',
690
+ });
691
+ }
692
+ }
693
+
694
+ // ! SaveContragent -> Contacts
695
+ let contactsData = [];
696
+ if (user.phoneNumber !== '' && user.phoneNumber !== null) {
697
+ contactsData.push({
698
+ contragentId: user.id,
699
+ id: 'response' in user && 'contacts' in user.response ? user.response.contacts.find(i => i.type === 'MOBILE').id : 0,
700
+ newValue: '',
701
+ note: '',
702
+ primaryFlag: 'Y',
703
+ type: 'MOBILE',
704
+ typeName: 'Сотовый телефон',
705
+ value: formatPhone(user.phoneNumber),
706
+ verifyType: this.formStore.otpTokenId
707
+ ? 'BMG'
708
+ : 'response' in user && 'contacts' in user.response
709
+ ? user.response.contacts.find(i => i.type === 'MOBILE').verifyType
710
+ : null,
711
+ verifyDate: this.formStore.otpTokenId
712
+ ? this.currentDate()
713
+ : 'response' in user && 'contacts' in user.response
714
+ ? user.response.contacts.find(i => i.type === 'MOBILE').verifyDate
715
+ : null,
716
+ });
717
+ }
718
+ if (user.email !== '' && user.email !== null) {
719
+ contactsData.push({
720
+ contragentId: user.id,
721
+ id: 'response' in user && 'contacts' in user.response ? user.response.contacts.find(i => i.type === 'EMAIL').id : 0,
722
+ newValue: '',
723
+ note: '',
724
+ primaryFlag: 'N',
725
+ type: 'EMAIL',
726
+ typeName: 'E-Mail',
727
+ value: user.email ? user.email : 'response' in user && 'contacts' in user.response ? user.response.contacts.find(i => i.type === 'EMAIL').value : '',
728
+ });
729
+ }
730
+ if (user.homePhone !== '' && user.homePhone !== null) {
731
+ contactsData.push({
732
+ contragentId: user.id,
733
+ id: 'response' in user && 'contacts' in user.response ? user.response.contacts.find(i => i.type === 'HOME').id : 0,
734
+ newValue: '',
735
+ note: '',
736
+ primaryFlag: 'N',
737
+ type: 'HOME',
738
+ typeName: 'Домашний телефон',
739
+ value: user.homePhone
740
+ ? formatPhone(user.homePhone)
741
+ : 'response' in user && 'contacts' in user.response
742
+ ? user.response.contacts.find(i => i.type === 'HOME').value
743
+ : '',
744
+ });
745
+ }
746
+
747
+ // ! SaveContragent -> Documents
748
+ let documentsData = [];
749
+ documentsData.push({
750
+ contragentId: user.id,
751
+ id: 'response' in user && 'documents' in user.response ? user.response.documents[0].id : 0,
752
+ description: null,
753
+ expireDate: user.getDateByKey('documentExpire'),
754
+ issueDate: user.getDateByKey('documentDate'),
755
+ issuerId: Number(user.documentIssuers.ids),
756
+ issuerName: user.documentIssuers.nameKz,
757
+ issuerNameRu: user.documentIssuers.nameRu,
758
+ note: null,
759
+ number: user.documentNumber,
760
+ type: user.documentType.ids,
761
+ typeName: user.documentType.nameRu,
762
+ serial: null,
763
+ verifyType: user.verifyType,
764
+ verifyDate: user.verifyDate,
765
+ });
766
+
767
+ // ! SaveContragent -> Addresses
768
+ let addressData = [];
769
+ addressData.push({
770
+ id: 'response' in user && 'addresses' in user.response ? user.response.addresses[0].id : 0,
771
+ contragentId: user.id,
772
+ countryCode: user.birthPlace.ids,
773
+ countryName: user.birthPlace.nameRu,
774
+ stateCode: user.registrationProvince.ids,
775
+ stateName: user.registrationProvince.nameRu,
776
+ cityCode: user.registrationCity.code,
777
+ cityName: user.registrationCity.nameRu,
778
+ regionCode: user.registrationRegion.ids,
779
+ regionName: user.registrationRegion.nameRu,
780
+ streetName: user.registrationStreet,
781
+ kvartal: user.registrationQuarter,
782
+ microRaion: user.registrationMicroDistrict,
783
+ cityTypeId: Number(user.registrationRegionType.ids),
784
+ cityTypeName: user.registrationRegionType.nameRu,
785
+ blockNumber: user.registrationNumberHouse,
786
+ apartmentNumber: user.registrationNumberApartment,
787
+ address: `${user.birthPlace.nameRu}, ${user.registrationRegionType.nameRu} ${user.registrationCity.nameRu}, ул. ${user.registrationStreet}, д. ${user.registrationNumberHouse} кв. ${user.registrationNumberApartment}`,
788
+ type: 'H',
789
+ });
790
+
791
+ const data = {
792
+ contragent: contragentData,
793
+ questionaries: questionariesData,
794
+ contacts: contactsData,
795
+ documents: documentsData,
796
+ addresses: addressData,
797
+ };
798
+ try {
799
+ const personId = await this.api.saveContragent(data);
800
+ if (personId) {
801
+ await this.getContragentById(personId, whichForm, false, whichIndex);
802
+ this.formStore.otpTokenId = null;
803
+ }
804
+ } catch (saveErr) {
805
+ console.log(saveErr);
806
+ if ('response' in saveErr) {
807
+ this.showToaster('error', saveErr.response.data, 5000);
808
+ this.isLoading = false;
809
+ return false;
810
+ }
811
+ }
812
+ } catch (err) {
813
+ console.log(err);
814
+ this.isLoading = false;
815
+ this.showToaster('error', this.t('toaster.error') + err?.response?.data, 2000);
816
+ return false;
817
+ }
818
+ if (onlySaveAction) {
819
+ this.isLoading = false;
820
+ }
821
+ return true;
822
+ },
823
+ async saveMember(whichForm, key, whichMember, whichIndex = null) {
824
+ let data = {};
825
+ try {
826
+ if (whichIndex === null) {
827
+ data = {
828
+ processInstanceId: this.formStore.applicationData.processInstanceId,
829
+ insisId: this.formStore[whichForm].id,
830
+ iin: this.formStore[whichForm].iin.replace(/-/g, ''),
831
+ longName: this.formStore[whichForm].longName,
832
+ isIpdl: this.formStore[whichForm].signOfIPDL.nameRu == 'Да' ? true : false,
833
+ isTerror: this.formStore[whichForm].isTerror,
834
+ isIpdlCompliance: null,
835
+ isTerrorCompliance: null,
836
+ };
837
+ data.id = this.formStore.applicationData[key] && this.formStore.applicationData[key].id ? this.formStore.applicationData[key].id : null;
838
+ if (whichMember == 'Client') {
839
+ data.isInsured = this.formStore.isPolicyholderInsured;
840
+ data.isActOwnBehalf = this.formStore.isActOwnBehalf;
841
+ data.profession = this.formStore[whichForm].job;
842
+ data.position = this.formStore[whichForm].jobPosition;
843
+ data.jobName = this.formStore[whichForm].jobPlace;
844
+ data.familyStatusId = this.formStore[whichForm].familyStatus.id;
845
+ }
846
+ if (whichMember == 'Spokesman') {
847
+ if (!!this.formStore.applicationData.spokesmanApp && this.formStore.applicationData.spokesmanApp.iin !== data.iin) {
848
+ delete data.id;
849
+ await this.api.deleteMember('Spokesman', this.formStore.applicationData.processInstanceId);
850
+ }
851
+ data.migrationCard = this.formStore[whichForm].migrationCard;
852
+ data.migrationCardIssueDate = formatDate(this.formStore[whichForm].migrationCardIssueDate);
853
+ data.migrationCardExpireDate = formatDate(this.formStore[whichForm].migrationCardExpireDate);
854
+ data.confirmDocType = this.formStore[whichForm].confirmDocType;
855
+ data.confirmDocNumber = this.formStore[whichForm].confirmDocNumber;
856
+ data.confirmDocIssueDate = formatDate(this.formStore[whichForm].migrationCardIssueDate);
857
+ data.confirmDocExpireDate = formatDate(this.formStore[whichForm].migrationCardExpireDate);
858
+ data.clientLongName = this.formStore.applicationData.clientApp.longName;
859
+ data.notaryLongName = this.formStore[whichForm].notaryLongName;
860
+ data.notaryLicenseNumber = this.formStore[whichForm].notaryLicenseNumber;
861
+ data.notaryLicenseDate = formatDate(this.formStore[whichForm].notaryLicenseDate);
862
+ data.notaryLicenseIssuer = this.formStore[whichForm].notaryLicenseIssuer;
863
+ data.jurLongName = this.formStore[whichForm].jurLongName;
864
+ data.fullNameRod = this.formStore[whichForm].fullNameRod;
865
+ data.confirmDocTypeKz = this.formStore[whichForm].confirmDocTypeKz;
866
+ data.confirmDocTypeRod = this.formStore[whichForm].confirmDocTypeRod;
867
+ data.isNotary = this.formStore[whichForm].isNotary;
868
+ }
869
+ }
870
+ if (whichIndex !== null) {
871
+ data = {
872
+ processInstanceId: this.formStore.applicationData.processInstanceId,
873
+ insisId: this.formStore[whichForm][whichIndex].id,
874
+ iin: this.formStore[whichForm][whichIndex].iin.replace(/-/g, ''),
875
+ longName: this.formStore[whichForm][whichIndex].longName,
876
+ isIpdl: this.formStore[whichForm][whichIndex].signOfIPDL.nameRu == 'Да' ? true : false,
877
+ isTerror: this.formStore[whichForm][whichIndex].isTerror,
878
+ isIpdlCompliance: null,
879
+ isTerrorCompliance: null,
880
+ };
881
+ data.id =
882
+ this.formStore.applicationData[key] && this.formStore.applicationData[key][whichIndex] && this.formStore.applicationData[key][whichIndex].id
883
+ ? this.formStore.applicationData[key][whichIndex].id
884
+ : null;
885
+ if (whichMember == 'Insured') {
886
+ if (
887
+ this.formStore.applicationData &&
888
+ this.formStore.applicationData.insuredApp &&
889
+ this.formStore.applicationData.insuredApp.length &&
890
+ this.formStore.applicationData.insuredApp.every(i => i.iin !== data.iin) &&
891
+ data.id !== null
892
+ ) {
893
+ await this.api.deleteMember('Insured', data.id);
894
+ delete data.id;
895
+ }
896
+ data.isDisability = this.formStore.isPolicyholderInsured ? false : this.formStore[whichForm][whichIndex].isDisability.nameRu == 'Да';
897
+ data.disabilityGroupId = data.isDisability ? this.formStore[whichForm][whichIndex].disabilityGroupId.id : null;
898
+ data.profession = this.formStore[whichForm][whichIndex].job;
899
+ data.position = this.formStore[whichForm][whichIndex].jobPosition;
900
+ data.jobName = this.formStore[whichForm][whichIndex].jobPlace;
901
+ data.familyStatusId = this.formStore[whichForm][whichIndex].familyStatus.id;
902
+ }
903
+ if (whichMember == 'Beneficiary') {
904
+ if (
905
+ this.formStore.applicationData &&
906
+ this.formStore.applicationData.beneficiaryApp &&
907
+ this.formStore.applicationData.beneficiaryApp.length &&
908
+ this.formStore.applicationData.beneficiaryApp.every(i => i.iin !== data.iin) &&
909
+ data.id !== null
910
+ ) {
911
+ await this.api.deleteMember('Beneficiary', data.id);
912
+ delete data.id;
913
+ }
914
+ data.familyStatusId = this.formStore[whichForm][whichIndex].familyStatus.id == 0 ? null : this.formStore[whichForm][whichIndex].familyStatus.id;
915
+ data.percentage = Number(this.formStore[whichForm][whichIndex].percentageOfPayoutAmount);
916
+ data.relationId = this.formStore[whichForm][whichIndex].relationDegree.ids;
917
+ data.relationName = this.formStore[whichForm][whichIndex].relationDegree.nameRu;
918
+ }
919
+ if (whichMember == 'BeneficialOwner') {
920
+ if (data.id === 0) {
921
+ data.id = null;
922
+ }
923
+ if (
924
+ this.formStore.applicationData &&
925
+ this.formStore.applicationData.beneficialOwnerApp &&
926
+ this.formStore.applicationData.beneficialOwnerApp.length &&
927
+ this.formStore.applicationData.beneficialOwnerApp.every(i => i.iin !== data.iin) &&
928
+ data.id !== null
929
+ ) {
930
+ await this.api.deleteMember('BeneficialOwner', data.id);
931
+ delete data.id;
932
+ }
933
+ data.familyStatusId = this.formStore[whichForm][whichIndex].familyStatus.id;
934
+ }
935
+ }
936
+ await this.api.setMember(whichMember, data);
937
+ return true;
938
+ } catch (err) {
939
+ console.log(err);
940
+ }
941
+ },
942
+ searchFromList(whichForm, searchIt, whichIndex = null) {
943
+ const getQuestionariesData = () => {
944
+ switch (searchIt.questId) {
945
+ case '500003':
946
+ return [this.economySectorCode, 'economySectorCode'];
947
+ case '500011':
948
+ return [this.residents, 'signOfResidency'];
949
+ case '500012':
950
+ return [this.citizenshipCountries, 'countryOfCitizenship'];
951
+ case '500014':
952
+ return [this.taxCountries, 'countryOfTaxResidency'];
953
+ case '507777':
954
+ return [this.addTaxCountries, 'addTaxResidency'];
955
+ case '500147':
956
+ return [[]];
957
+ case '500148':
958
+ return [[]];
959
+ }
960
+ };
961
+
962
+ const [searchFrom, whichField] = getQuestionariesData();
963
+ if (searchFrom && searchFrom.length) {
964
+ const result = searchFrom.find(i => i.ids === searchIt.questAnswer);
965
+ if (whichIndex === null) {
966
+ this.formStore[whichForm][whichField] = result ? result : new Value();
967
+ } else {
968
+ this.formStore[whichForm][whichIndex][whichField] = result ? result : new Value();
969
+ }
970
+ }
971
+ },
972
+ async setSurvey(data) {
973
+ try {
974
+ this.isLoading = true;
975
+ const anketaToken = await this.api.setSurvey(data);
976
+ window.scrollTo({ top: 0, behavior: 'smooth' });
977
+ this.showToaster('success', this.t('toaster.successSaved'), 2000);
978
+ return anketaToken;
979
+ } catch (error) {
980
+ this.showToaster('error', this.t('toaster.undefinedError'), 1000);
981
+ } finally {
982
+ this.isLoading = false;
983
+ }
984
+ },
985
+ async getFromApi(whichField, whichRequest, parameter) {
986
+ const storageValue = JSON.parse(localStorage.getItem(whichField) || 'null');
987
+ const currentHour = new Date().getHours();
988
+
989
+ const getDataCondition = () => {
990
+ if (!storageValue) return true;
991
+ const hasHourKey = 'hour' in storageValue;
992
+ const hasModeKey = 'mode' in storageValue;
993
+ const hasValueKey = 'value' in storageValue;
994
+ if (storageValue && (hasHourKey === false || hasModeKey === false || hasValueKey === false)) return true;
995
+ if (storageValue && (storageValue.hour !== currentHour || storageValue.mode !== import.meta.env.MODE || storageValue.value.length === 0)) return true;
996
+ };
997
+
998
+ if (getDataCondition()) {
999
+ this.whichField = [];
1000
+ try {
1001
+ const response = await this.api[whichRequest](parameter);
1002
+ if (response) {
1003
+ localStorage.setItem(
1004
+ whichField,
1005
+ JSON.stringify({
1006
+ value: response,
1007
+ hour: currentHour,
1008
+ mode: import.meta.env.MODE,
1009
+ }),
1010
+ );
1011
+ this[whichField] = response;
1012
+ if (this[whichField].length && this[whichField][this[whichField].length - 1].nameRu == 'невключено') {
1013
+ this[whichField].unshift(this[whichField].pop());
1014
+ }
1015
+ }
1016
+ } catch (err) {
1017
+ console.log(err);
1018
+ }
1019
+ } else {
1020
+ this[whichField] = storageValue.value;
1021
+ }
1022
+
1023
+ return this[whichField];
1024
+ },
1025
+ async getCountries() {
1026
+ return await this.getFromApi('countries', 'getCountries');
1027
+ },
1028
+ async getCitizenshipCountries() {
1029
+ return await this.getFromApi('citizenshipCountries', 'getCitizenshipCountries');
1030
+ },
1031
+ async getTaxCountries() {
1032
+ return await this.getFromApi('taxCountries', 'getTaxCountries');
1033
+ },
1034
+ async getAdditionalTaxCountries() {
1035
+ return await this.getFromApi('addTaxCountries', 'getAdditionalTaxCountries');
1036
+ },
1037
+ async getStates(key) {
1038
+ await this.getFromApi('states', 'getStates');
1039
+ if (key && this.contragent[key] && this.contragent[key].ids !== null) {
1040
+ return this.states.filter(i => i.code === this.contragent[key].ids);
1041
+ }
1042
+ return this.states;
1043
+ },
1044
+ async getRegions(key) {
1045
+ await this.getFromApi('regions', 'getRegions');
1046
+ if (key && this.contragent[key] && this.contragent[key].ids !== null) {
1047
+ return this.regions.filter(i => i.code === this.contragent[key].ids);
1048
+ }
1049
+ let registrationProvince = this.contragent.registrationProvince;
1050
+ if (registrationProvince.ids !== null) {
1051
+ return this.regions.filter(i => i.code === registrationProvince.ids);
1052
+ } else {
1053
+ return this.regions;
1054
+ }
1055
+ },
1056
+ async getCities(key) {
1057
+ await this.getFromApi('cities', 'getCities');
1058
+ if (key && this.contragent[key] && this.contragent[key].ids !== null) {
1059
+ return this.cities.filter(i => i.code === this.contragent[key].ids);
1060
+ }
1061
+ let registrationProvince = this.contragent.registrationProvince;
1062
+ if (registrationProvince.ids !== null) {
1063
+ return this.cities.filter(i => i.code === registrationProvince.ids);
1064
+ } else {
1065
+ return this.cities;
1066
+ }
1067
+ },
1068
+ async getLocalityTypes() {
1069
+ return await this.getFromApi('localityTypes', 'getLocalityTypes');
1070
+ },
1071
+ async getDocumentTypes() {
1072
+ const document_list = await this.getFromApi('documentTypes', 'getDocumentTypes');
1073
+ await this.getDicFileTypeList();
1074
+ return document_list.filter(doc => {
1075
+ for (const dic of this.dicFileTypeList) {
1076
+ if (doc.nameRu === dic.nameRu) {
1077
+ return doc;
1078
+ }
1079
+ }
1080
+ });
1081
+ },
1082
+ async getDicFileTypeList() {
1083
+ try {
1084
+ if (this.dicFileTypeList.length) {
1085
+ return this.dicFileTypeList;
1086
+ } else {
1087
+ this.dicFileTypeList = await this.api.getDicFileTypeList();
1088
+ return this.dicFileTypeList;
1089
+ }
1090
+ } catch (err) {
1091
+ console.log(err.response.data);
1092
+ }
1093
+ },
1094
+ async getDocumentIssuers() {
1095
+ return await this.getFromApi('documentIssuers', 'getDocumentIssuers');
1096
+ },
1097
+ async getResidents() {
1098
+ return await this.getFromApi('residents', 'getResidents');
1099
+ },
1100
+ async getSectorCodeList() {
1101
+ await this.getFromApi('economySectorCode', 'getSectorCode');
1102
+ if (this.economySectorCode[1].ids != '500003.9') {
1103
+ this.economySectorCode = this.economySectorCode.reverse();
1104
+ }
1105
+ return this.economySectorCode;
1106
+ },
1107
+ async getFamilyStatuses() {
1108
+ return await this.getFromApi('familyStatuses', 'getFamilyStatuses');
1109
+ },
1110
+ async getRelationTypes() {
1111
+ await this.getFromApi('relations', 'getRelationTypes');
1112
+ const filteredRelations = this.relations.filter(i => Number(i.ids) >= 6 && Number(i.ids) <= 15);
1113
+ const otherRelations = this.relations.filter(i => Number(i.ids) < 6 || Number(i.ids) > 15);
1114
+ return [...filteredRelations, ...otherRelations];
1115
+ },
1116
+ async getProcessIndexRate() {
1117
+ const response = await this.getFromApi('processIndexRate', 'getProcessIndexRate', this.processCode);
1118
+ return response ? response : [];
1119
+ },
1120
+ async getProcessCoverTypeSum(type) {
1121
+ return await this.getFromApi('processCoverTypeSum', 'getProcessCoverTypeSum', type);
1122
+ },
1123
+ async getProcessPaymentPeriod() {
1124
+ return await this.getFromApi('processPaymentPeriod', 'getProcessPaymentPeriod', this.processCode);
1125
+ },
1126
+ async getQuestionRefs(id) {
1127
+ return await this.getFromApi('questionRefs', 'getQuestionRefs', id);
1128
+ },
1129
+ async getProcessTariff() {
1130
+ return await this.getFromApi('processTariff', 'getProcessTariff');
1131
+ },
1132
+ async getAdditionalInsuranceTermsAnswers(questionId) {
1133
+ try {
1134
+ const answers = await this.api.getAdditionalInsuranceTermsAnswers(this.processCode, questionId);
1135
+ answers.unshift(answers.pop());
1136
+ return answers;
1137
+ } catch (err) {
1138
+ console.log(err);
1139
+ }
1140
+ },
1141
+ async getQuestionList(surveyType, processInstanceId, insuredId, baseField, secondaryField) {
1142
+ if (!this[baseField].length) {
1143
+ try {
1144
+ const [{ value: baseQuestions }, { value: secondaryQuestions }] = await Promise.allSettled([
1145
+ this.api.getQuestionList(surveyType, processInstanceId, insuredId),
1146
+ this.api.getQuestionList(`${surveyType}second`, processInstanceId, insuredId),
1147
+ ]);
1148
+ this[baseField] = baseQuestions;
1149
+ this[secondaryField] = secondaryQuestions;
1150
+ } catch (err) {
1151
+ console.log(err);
1152
+ }
1153
+ }
1154
+ return this[baseField];
1155
+ },
1156
+ getNumberWithSpaces(n) {
1157
+ return n === null ? null : Number((typeof n === 'string' ? n : n.toFixed().toString()).replace(/[^0-9]+/g, '')).toLocaleString('ru');
1158
+ },
1159
+ async getTaskList(search = '', groupCode = 'Work', onlyGet = false, needToReturn = false, key = 'dateCreated', processInstanceId = null, byOneProcess = null) {
1160
+ if (onlyGet === false) {
1161
+ this.isLoading = true;
1162
+ }
1163
+ try {
1164
+ const column = this.isColumnAsc[key] === null ? 'dateCreated' : key;
1165
+ const direction = this.isColumnAsc[key] === null ? 'desc' : this.isColumnAsc[key] === true ? 'asc' : 'desc';
1166
+ const query = {
1167
+ pageIndex: processInstanceId === null ? this.historyPageIndex - 1 : 0,
1168
+ pageSize: this.historyPageSize,
1169
+ search: search ? search.replace(/-/g, '') : '',
1170
+ column: column,
1171
+ direction: direction,
1172
+ groupCode: groupCode,
1173
+ processCodes: Object.values(constants.products),
1174
+ };
1175
+ if (byOneProcess !== null) {
1176
+ delete query.processCodes;
1177
+ query.processCode = byOneProcess;
1178
+ }
1179
+ const taskList = await this.api.getTaskList(processInstanceId === null ? query : { ...query, processInstanceId: processInstanceId });
1180
+ if (needToReturn) {
1181
+ this.isLoading = false;
1182
+ return taskList.items;
1183
+ } else {
1184
+ this.taskList = taskList.items;
1185
+ this.historyTotalItems = taskList.totalItems;
1186
+ }
1187
+ } catch (err) {
1188
+ this.showToaster('error', err?.response?.data, 2000);
1189
+ console.log(err);
1190
+ } finally {
1191
+ this.isLoading = false;
1192
+ }
1193
+ if (onlyGet === false) {
1194
+ this.isLoading = false;
1195
+ }
1196
+ },
1197
+ async getProcessHistoryList(id) {
1198
+ try {
1199
+ const processHistory = await this.api.getProcessHistory(id);
1200
+ if (processHistory.length > 0) {
1201
+ return processHistory;
1202
+ } else {
1203
+ return [];
1204
+ }
1205
+ } catch (err) {
1206
+ console.log(err);
1207
+ }
1208
+ },
1209
+ async getProcessHistory(id) {
1210
+ this.isLoading = true;
1211
+ try {
1212
+ const processHistory = await this.api.getProcessHistory(id);
1213
+ if (processHistory.length > 0) {
1214
+ this.processHistory = processHistory.reverse();
1215
+ } else {
1216
+ this.processHistory = [];
1217
+ }
1218
+ } catch (err) {
1219
+ console.log(err);
1220
+ }
1221
+ this.isLoading = false;
1222
+ },
1223
+ findObject(from, key, searchKey) {
1224
+ const found = this[from].find(i => i[key] == searchKey);
1225
+ return found || new Value();
1226
+ },
1227
+ async getAllFormsData() {
1228
+ await Promise.allSettled([
1229
+ this.getCountries(),
1230
+ this.getCitizenshipCountries(),
1231
+ this.getTaxCountries(),
1232
+ this.getAdditionalTaxCountries(),
1233
+ this.getStates(),
1234
+ this.getRegions(),
1235
+ this.getCities(),
1236
+ this.getLocalityTypes(),
1237
+ this.getDocumentTypes(),
1238
+ this.getDocumentIssuers(),
1239
+ this.getResidents(),
1240
+ this.getSectorCodeList(),
1241
+ this.getFamilyStatuses(),
1242
+ this.getRelationTypes(),
1243
+ this.getProcessIndexRate(),
1244
+ this.getProcessTariff(),
1245
+ this.getProcessPaymentPeriod(),
1246
+ ]);
1247
+ },
1248
+ async getUserGroups() {
1249
+ try {
1250
+ this.isLoading = true;
1251
+ this.userGroups = await this.api.getUserGroups();
1252
+ } catch (err) {
1253
+ console.log(err);
1254
+ } finally {
1255
+ this.isLoading = false;
1256
+ }
1257
+ },
1258
+ async getOtpStatus(iin, phone, processInstanceId = null) {
1259
+ try {
1260
+ const otpData = {
1261
+ iin: iin.replace(/-/g, ''),
1262
+ phoneNumber: formatPhone(phone),
1263
+ type: 'AgreementOtp',
1264
+ };
1265
+ return await this.api.getOtpStatus(
1266
+ processInstanceId !== null && processInstanceId != 0
1267
+ ? {
1268
+ ...otpData,
1269
+ processInstanceId: processInstanceId,
1270
+ }
1271
+ : otpData,
1272
+ );
1273
+ } catch (err) {
1274
+ console.log(err);
1275
+ this.showToaster('error', err.response.data, 3000);
1276
+ }
1277
+ },
1278
+ async sendOtp(iin, phone, processInstanceId = null, onInit = false) {
1279
+ this.isLoading = true;
1280
+ let otpStatus = false;
1281
+ let otpResponse = {};
1282
+ try {
1283
+ if (iin && iin.length === 15 && phone && phone.length === 18) {
1284
+ const status = await this.getOtpStatus(iin, phone, processInstanceId);
1285
+ if (status === true) {
1286
+ this.showToaster('success', this.t('toaster.hasSuccessOtp'), 3000);
1287
+ otpStatus = true;
1288
+ this.isLoading = false;
1289
+ return { otpStatus, otpResponse };
1290
+ } else if (status === false && onInit === false) {
1291
+ const otpData = {
1292
+ iin: iin.replace(/-/g, ''),
1293
+ phoneNumber: formatPhone(phone),
1294
+ type: 'AgreementOtp',
1295
+ };
1296
+ otpResponse = await this.api.sendOtp(
1297
+ processInstanceId !== null && processInstanceId != 0
1298
+ ? {
1299
+ ...otpData,
1300
+ processInstanceId: processInstanceId,
1301
+ }
1302
+ : otpData,
1303
+ );
1304
+ this.isLoading = false;
1305
+ if (!!otpResponse) {
1306
+ if ('errMessage' in otpResponse && otpResponse.errMessage !== null) {
1307
+ this.showToaster('error', otpResponse.errMessage, 3000);
1308
+ return { otpStatus };
1309
+ }
1310
+ if ('result' in otpResponse && otpResponse.result === null) {
1311
+ if ('statusName' in otpResponse && !!otpResponse.statusName) {
1312
+ this.showToaster('error', otpResponse.statusName, 3000);
1313
+ return { otpStatus };
1314
+ }
1315
+ if ('status' in otpResponse && !!otpResponse.status) {
1316
+ this.showToaster('error', otpResponse.status, 3000);
1317
+ return { otpStatus };
1318
+ }
1319
+ }
1320
+ if ('tokenId' in otpResponse && otpResponse.tokenId) {
1321
+ this.contragent.otpTokenId = otpResponse.tokenId;
1322
+ this.showToaster('success', this.t('toaster.successOtp'), 3000);
1323
+ }
1324
+ } else {
1325
+ this.showToaster('error', this.t('toaster.undefinedError'), 3000);
1326
+ return { otpStatus };
1327
+ }
1328
+ }
1329
+ } else {
1330
+ if (onInit === false) {
1331
+ this.showToaster(
1332
+ 'error',
1333
+ this.t('toaster.errorFormField', {
1334
+ text: 'Номер телефона, ИИН',
1335
+ }),
1336
+ );
1337
+ this.isLoading = false;
1338
+ }
1339
+ }
1340
+ return { otpStatus, otpResponse };
1341
+ } catch (err) {
1342
+ this.isLoading = false;
1343
+ if ('response' in err) {
1344
+ if ('statusName' in err.response.data && !!err.response.data.statusName) {
1345
+ this.showToaster('error', this.t('toaster.phoneNotFoundInBMG'), 3000);
1346
+ return { otpStatus };
1347
+ }
1348
+ if ('status' in err.response.data && !!err.response.data.status) {
1349
+ this.showToaster('error', err.response.data.status, 3000);
1350
+ return { otpStatus };
1351
+ }
1352
+ }
1353
+ } finally {
1354
+ this.isLoading = false;
1355
+ }
1356
+ this.isLoading = false;
1357
+ return { otpStatus, otpResponse };
1358
+ },
1359
+ async getProcessList() {
1360
+ this.isLoading = true;
1361
+ try {
1362
+ const processList = await this.api.getProcessList();
1363
+ if (this.processList === null) {
1364
+ this.processList = processList;
1365
+ }
1366
+ } catch (err) {
1367
+ console.log(err);
1368
+ }
1369
+ this.isLoading = false;
1370
+ },
1371
+ sortTaskList(key) {
1372
+ if (this.taskList.length !== 0) {
1373
+ if (key in this.isColumnAsc) {
1374
+ if (this.isColumnAsc[key] === true) {
1375
+ this.isColumnAsc = { ...InitialColumns() };
1376
+ this.isColumnAsc[key] = false;
1377
+ return;
1378
+ }
1379
+ if (this.isColumnAsc[key] === false) {
1380
+ this.isColumnAsc = { ...InitialColumns() };
1381
+ this.isColumnAsc[key] = null;
1382
+ return;
1383
+ }
1384
+ if (this.isColumnAsc[key] === null) {
1385
+ this.isColumnAsc = { ...InitialColumns() };
1386
+ this.isColumnAsc[key] = true;
1387
+ return;
1388
+ }
1389
+ }
1390
+ }
1391
+ },
1392
+ async searchAgentByName(name) {
1393
+ try {
1394
+ this.isLoading = true;
1395
+ this.AgentDataList = await this.api.searchAgentByName(name);
1396
+ if (!this.AgentDataList.length) {
1397
+ showToaster('error', this.t('toaster.notFound'), 1500);
1398
+ }
1399
+ } catch (err) {
1400
+ console.log(err);
1401
+ } finally {
1402
+ this.isLoading = false;
1403
+ }
1404
+ },
1405
+ async setINSISWorkData() {
1406
+ const data = {
1407
+ id: this.formStore.applicationData.insisWorkDataApp.id,
1408
+ processInstanceId: this.formStore.applicationData.processInstanceId,
1409
+ agentId: this.formStore.AgentData.agentId,
1410
+ agentName: this.formStore.AgentData.fullName,
1411
+ salesChannel: this.formStore.applicationData.insisWorkDataApp.salesChannel,
1412
+ salesChannelName: this.formStore.applicationData.insisWorkDataApp.salesChannelName,
1413
+ insrType: this.formStore.applicationData.insisWorkDataApp.insrType,
1414
+ saleChanellPolicy: this.formStore.SaleChanellPolicy.ids,
1415
+ saleChanellPolicyName: this.formStore.SaleChanellPolicy.nameRu,
1416
+ regionPolicy: this.formStore.RegionPolicy.ids,
1417
+ regionPolicyName: this.formStore.RegionPolicy.nameRu,
1418
+ managerPolicy: this.formStore.ManagerPolicy.ids,
1419
+ managerPolicyName: this.formStore.ManagerPolicy.nameRu,
1420
+ insuranceProgramType: this.formStore.applicationData.insisWorkDataApp.insuranceProgramType,
1421
+ };
1422
+ try {
1423
+ this.isLoading = true;
1424
+ await this.api.setINSISWorkData(data);
1425
+ } catch (err) {
1426
+ console.log(err);
1427
+ } finally {
1428
+ this.isLoading = false;
1429
+ }
1430
+ },
1431
+ async getDictionaryItems(dictName) {
1432
+ try {
1433
+ this.isLoading = true;
1434
+ if (!this[`${dictName}List`].length) {
1435
+ this[`${dictName}List`] = await this.api.getDictionaryItems(dictName);
1436
+ }
1437
+ } catch (err) {
1438
+ console.log(err);
1439
+ } finally {
1440
+ this.isLoading = false;
1441
+ }
1442
+ },
1443
+ async filterManagerByRegion(dictName, filterName) {
1444
+ try {
1445
+ this.isLoading = true;
1446
+ this[`${dictName}List`] = await this.api.filterManagerByRegion(dictName, filterName);
1447
+ } catch (err) {
1448
+ console.log(err);
1449
+ } finally {
1450
+ this.isLoading = false;
1451
+ }
1452
+ },
1453
+ async getUnderwritingCouncilData(id) {
1454
+ try {
1455
+ const response = await this.api.getUnderwritingCouncilData(id);
1456
+ this.affilationResolution.id = response.underwritingCouncilAppDto.id;
1457
+ this.affilationResolution.date = response.underwritingCouncilAppDto.date ? reformatDate(response.underwritingCouncilAppDto.date) : null;
1458
+ this.affilationResolution.number = response.underwritingCouncilAppDto.number ? response.underwritingCouncilAppDto.number : null;
1459
+ } catch (err) {
1460
+ console.log(err);
1461
+ }
1462
+ },
1463
+ async setConfirmation() {
1464
+ const data = {
1465
+ id: this.affilationResolution.id,
1466
+ processInstanceId: this.affilationResolution.processInstanceId,
1467
+ number: this.affilationResolution.number,
1468
+ date: formatDate(this.affilationResolution.date),
1469
+ };
1470
+ try {
1471
+ this.isLoading = true;
1472
+ await this.api.setConfirmation(data);
1473
+ showToaster('success', this.t('toaster.successSaved'));
1474
+ return true;
1475
+ } catch (err) {
1476
+ this.showToaster('error', this.t('toaster.error'));
1477
+ return false;
1478
+ } finally {
1479
+ this.isLoading = false;
1480
+ }
1481
+ },
1482
+ async sendUnderwritingCouncilTask(data) {
1483
+ try {
1484
+ this.isLoading = true;
1485
+ await this.api.sendUnderwritingCouncilTask(data);
1486
+ showToaster('success', this.t('toaster.successOperation'), 5000);
1487
+ return true;
1488
+ } catch (err) {
1489
+ console.log(err);
1490
+ this.showToaster('error', this.t('toaster.error'), 5000);
1491
+ return false;
1492
+ } finally {
1493
+ this.isLoading = false;
1494
+ }
1495
+ },
1496
+ async definedAnswers(filter, whichSurvey, value = null, index = null) {
1497
+ if (!this.definedAnswersId[whichSurvey].hasOwnProperty(filter)) {
1498
+ this.definedAnswersId[whichSurvey][filter] = await this.api.definedAnswers(filter);
1499
+ }
1500
+ if (value !== null && this.definedAnswersId[whichSurvey][filter].length) {
1501
+ const answer = this.definedAnswersId[whichSurvey][filter].find(answer => answer.nameRu === value);
1502
+ this[whichSurvey].body[index].first.answerId = answer.ids;
1503
+ }
1504
+ return this.definedAnswersId[whichSurvey];
1505
+ },
1506
+ async getPaymentTable(id) {
1507
+ try {
1508
+ const paymentResultTable = await this.api.calculatePremuim(id);
1509
+ if (paymentResultTable.length > 0) {
1510
+ this.paymentResultTable = paymentResultTable;
1511
+ } else {
1512
+ this.paymentResultTable = [];
1513
+ }
1514
+ } catch (err) {
1515
+ console.log(err);
1516
+ }
1517
+ },
1518
+ async calculate(taskId) {
1519
+ this.isLoading = true;
1520
+ try {
1521
+ let form1 = {
1522
+ baiterekApp: null,
1523
+ policyAppDto: {
1524
+ id: this.formStore.applicationData.policyAppDto.id,
1525
+ processInstanceId: this.formStore.applicationData.policyAppDto.processInstanceId,
1526
+ policyId: null,
1527
+ policyNumber: null,
1528
+ contractDate: this.currentDate(),
1529
+ amount: this.formStore.productConditionsForm.requestedSumInsured != null ? Number(this.formStore.productConditionsForm.requestedSumInsured.replace(/\s/g, '')) : null,
1530
+ premium:
1531
+ this.formStore.productConditionsForm.insurancePremiumPerMonth != null
1532
+ ? Number(this.formStore.productConditionsForm.insurancePremiumPerMonth.replace(/\s/g, ''))
1533
+ : null,
1534
+ isSpokesman: this.formStore.hasRepresentative,
1535
+ coverPeriod: this.formStore.productConditionsForm.coverPeriod,
1536
+ payPeriod: this.formStore.productConditionsForm.coverPeriod,
1537
+ annualIncome: this.formStore.productConditionsForm.annualIncome ? Number(this.formStore.productConditionsForm.annualIncome.replace(/\s/g, '')) : null,
1538
+ indexRateId: this.formStore.productConditionsForm.processIndexRate?.id
1539
+ ? this.formStore.productConditionsForm.processIndexRate.id
1540
+ : this.processIndexRate.find(i => i.code === '0')?.id,
1541
+ paymentPeriodId: this.formStore.productConditionsForm.paymentPeriod.id,
1542
+ lifeMultiply: formatProcents(this.formStore.productConditionsForm.lifeMultiply),
1543
+ lifeAdditive: formatProcents(this.formStore.productConditionsForm.lifeAdditive),
1544
+ adbMultiply: formatProcents(this.formStore.productConditionsForm.adbMultiply),
1545
+ adbAdditive: formatProcents(this.formStore.productConditionsForm.adbAdditive),
1546
+ disabilityMultiply: formatProcents(this.formStore.productConditionsForm.disabilityMultiply),
1547
+ disabilityAdditive: formatProcents(this.formStore.productConditionsForm.adbAdditive),
1548
+ riskGroup: this.formStore.productConditionsForm.riskGroup?.id ? this.formStore.productConditionsForm.riskGroup.id : 1,
1549
+ },
1550
+ addCoversDto: this.additionalInsuranceTerms,
1551
+ };
1552
+
1553
+ try {
1554
+ let id = this.formStore.applicationData.processInstanceId;
1555
+
1556
+ await this.api.setApplication(form1);
1557
+ let result;
1558
+ try {
1559
+ result = await this.api.getCalculation(id);
1560
+ } catch (err) {
1561
+ this.showToaster('error', err?.response?.data, 5000);
1562
+ }
1563
+
1564
+ const applicationData = await this.api.getApplicationData(taskId);
1565
+ this.formStore.applicationData = applicationData;
1566
+ this.additionalInsuranceTerms = this.formStore.applicationData.addCoverDto;
1567
+ if (this.formStore.productConditionsForm.insurancePremiumPerMonth != null) {
1568
+ this.formStore.productConditionsForm.requestedSumInsured = this.getNumberWithSpaces(result);
1569
+ } else {
1570
+ this.formStore.productConditionsForm.insurancePremiumPerMonth = this.getNumberWithSpaces(result);
1571
+ }
1572
+ this.showToaster('success', this.t('toaster.calculated'), 1000);
1573
+ } catch (err) {
1574
+ console.log(err);
1575
+ }
1576
+ } catch (err) {
1577
+ this.showToaster('error', this.t('toaster.undefinedError'), 5000);
1578
+ console.log(err, 'error');
1579
+ }
1580
+ this.isLoading = false;
1581
+ },
1582
+ async startApplication(whichForm) {
1583
+ try {
1584
+ const data = {
1585
+ clientId: this.formStore[whichForm].id,
1586
+ iin: this.formStore[whichForm].iin.replace(/-/g, ''),
1587
+ longName: this.formStore[whichForm].longName,
1588
+ processCode: this.processCode,
1589
+ policyId: 0,
1590
+ };
1591
+ const response = await this.api.startApplication(data);
1592
+ this.sendToParent(constants.postActions.applicationCreated, response.processInstanceId);
1593
+ return response.processInstanceId;
1594
+ } catch (err) {
1595
+ console.log(err);
1596
+ if ('response' in err && err.response.data) {
1597
+ this.showToaster('error', err.response.data, 0);
1598
+ }
1599
+ return null;
1600
+ }
1601
+ },
1602
+ async getApplicationData(taskId, onlyGet = true, setMembersField = true, fetchMembers = true, setProductConditions = true) {
1603
+ if (onlyGet) {
1604
+ this.isLoading = true;
1605
+ }
1606
+ try {
1607
+ const applicationData = await this.api.getApplicationData(taskId);
1608
+ if (this.processCode !== applicationData.processCode) {
1609
+ this.isLoading = false;
1610
+ this.sendToParent(constants.postActions.toHomePage, this.t('toaster.noSuchProduct'));
1611
+ return;
1612
+ }
1613
+ this.formStore.applicationData = applicationData;
1614
+ this.additionalInsuranceTerms = applicationData.addCoverDto;
1615
+
1616
+ this.formStore.canBeClaimed = await this.api.isClaimTask(taskId);
1617
+ this.formStore.applicationTaskId = taskId;
1618
+ this.formStore.RegionPolicy.nameRu = applicationData.insisWorkDataApp.regionPolicyName;
1619
+ this.formStore.RegionPolicy.ids = applicationData.insisWorkDataApp.regionPolicy;
1620
+ this.formStore.ManagerPolicy.nameRu = applicationData.insisWorkDataApp.managerPolicyName;
1621
+ this.formStore.ManagerPolicy.ids = applicationData.insisWorkDataApp.managerPolicy;
1622
+ this.formStore.SaleChanellPolicy.nameRu = applicationData.insisWorkDataApp.saleChanellPolicyName;
1623
+ this.formStore.SaleChanellPolicy.ids = applicationData.insisWorkDataApp.saleChanellPolicy;
1624
+
1625
+ this.formStore.AgentData.fullName = applicationData.insisWorkDataApp.agentName;
1626
+ this.formStore.AgentData.agentId = applicationData.insisWorkDataApp.agentId;
1627
+
1628
+ const clientData = applicationData.clientApp;
1629
+ const insuredData = applicationData.insuredApp;
1630
+ const spokesmanData = applicationData.spokesmanApp;
1631
+ const beneficiaryData = applicationData.beneficiaryApp;
1632
+ const beneficialOwnerData = applicationData.beneficialOwnerApp;
1633
+
1634
+ this.formStore.isPolicyholderInsured = clientData.isInsured;
1635
+ this.formStore.isActOwnBehalf = clientData.isActOwnBehalf;
1636
+ this.formStore.hasRepresentative = !!applicationData.spokesmanApp;
1637
+
1638
+ const beneficiaryPolicyholderIndex = beneficiaryData.findIndex(i => i.insisId === clientData.insisId);
1639
+ this.formStore.isPolicyholderBeneficiary = beneficiaryPolicyholderIndex !== -1;
1640
+
1641
+ if (fetchMembers) {
1642
+ let allMembers = [
1643
+ {
1644
+ ...clientData,
1645
+ key: this.formStore.policyholderFormKey,
1646
+ index: null,
1647
+ },
1648
+ ];
1649
+
1650
+ if (spokesmanData) {
1651
+ allMembers.push({
1652
+ ...spokesmanData,
1653
+ key: this.formStore.policyholdersRepresentativeFormKey,
1654
+ index: null,
1655
+ });
1656
+ }
1657
+
1658
+ if (insuredData && insuredData.length) {
1659
+ insuredData.forEach((member, index) => {
1660
+ const inStore = this.formStore.insuredForm.find(each => each.id == member.insisId);
1661
+ if (!inStore) {
1662
+ member.key = this.formStore.insuredFormKey;
1663
+ member.index = index;
1664
+ allMembers.push(member);
1665
+ if (this.formStore.insuredForm.length - 1 < index) {
1666
+ this.formStore.insuredForm.push(new InsuredForm());
1667
+ }
1668
+ }
1669
+ });
1670
+ }
1671
+ if (beneficiaryData && beneficiaryData.length) {
1672
+ beneficiaryData.forEach((member, index) => {
1673
+ const inStore = this.formStore.beneficiaryForm.find(each => each.id == member.insisId);
1674
+ if (!inStore) {
1675
+ member.key = this.formStore.beneficiaryFormKey;
1676
+ member.index = index;
1677
+ allMembers.push(member);
1678
+ if (this.formStore.beneficiaryForm.length - 1 < index) {
1679
+ this.formStore.beneficiaryForm.push(new BeneficiaryForm());
1680
+ }
1681
+ }
1682
+ });
1683
+ }
1684
+ if (beneficialOwnerData && beneficialOwnerData.length) {
1685
+ beneficialOwnerData.forEach((member, index) => {
1686
+ const inStore = this.formStore.beneficialOwnerForm.find(each => each.id == member.insisId);
1687
+ if (!inStore) {
1688
+ member.key = this.formStore.beneficialOwnerFormKey;
1689
+ member.index = index;
1690
+ allMembers.push(member);
1691
+ if (this.formStore.beneficialOwnerForm.length - 1 < index) {
1692
+ this.formStore.beneficialOwnerForm.push(new BeneficialOwnerForm());
1693
+ }
1694
+ }
1695
+ });
1696
+ }
1697
+
1698
+ await Promise.allSettled(
1699
+ allMembers.map(async member => {
1700
+ await this.getContragentById(member.insisId, member.key, false, member.index);
1701
+ }),
1702
+ );
1703
+ }
1704
+
1705
+ if (setMembersField) {
1706
+ this.setMembersField(this.formStore.policyholderFormKey, 'clientApp');
1707
+ if (insuredData && insuredData.length) {
1708
+ insuredData.forEach((each, index) => {
1709
+ this.setMembersFieldIndex(this.formStore.insuredFormKey, 'insuredApp', index);
1710
+ });
1711
+ }
1712
+
1713
+ if (beneficiaryData && beneficiaryData.length) {
1714
+ beneficiaryData.forEach((each, index) => {
1715
+ this.setMembersFieldIndex(this.formStore.beneficiaryFormKey, 'beneficiaryApp', index);
1716
+ const relationDegree = this.relations.find(i => i.ids == each.relationId);
1717
+ this.formStore.beneficiaryForm[index].relationDegree = relationDegree ? relationDegree : new Value();
1718
+ this.formStore.beneficiaryForm[index].percentageOfPayoutAmount = each.percentage;
1719
+ });
1720
+ }
1721
+
1722
+ if (beneficialOwnerData && beneficialOwnerData.length) {
1723
+ beneficialOwnerData.forEach((each, index) => {
1724
+ this.setMembersFieldIndex(this.formStore.beneficialOwnerFormKey, 'beneficialOwnerApp', index);
1725
+ });
1726
+ }
1727
+
1728
+ if (!!spokesmanData) {
1729
+ this.formStore.policyholdersRepresentativeForm.signOfIPDL = spokesmanData.isIpdl ? this.ipdl[1] : this.ipdl[2];
1730
+ this.formStore.policyholdersRepresentativeForm.migrationCard = spokesmanData.migrationCard;
1731
+ this.formStore.policyholdersRepresentativeForm.migrationCardIssueDate = reformatDate(spokesmanData.migrationCardIssueDate);
1732
+ this.formStore.policyholdersRepresentativeForm.migrationCardExpireDate = reformatDate(spokesmanData.migrationCardExpireDate);
1733
+ this.formStore.policyholdersRepresentativeForm.confirmDocType = spokesmanData.confirmDocType;
1734
+ this.formStore.policyholdersRepresentativeForm.confirmDocNumber = spokesmanData.confirmDocNumber;
1735
+ this.formStore.policyholdersRepresentativeForm.confirmDocIssueDate = reformatDate(spokesmanData.confirmDocIssueDate);
1736
+ this.formStore.policyholdersRepresentativeForm.confirmDocExpireDate = reformatDate(spokesmanData.confirmDocExpireDate);
1737
+ this.formStore.policyholdersRepresentativeForm.notaryLongName = spokesmanData.notaryLongName;
1738
+ this.formStore.policyholdersRepresentativeForm.notaryLicenseNumber = spokesmanData.notaryLicenseNumber;
1739
+ this.formStore.policyholdersRepresentativeForm.notaryLicenseDate = reformatDate(spokesmanData.notaryLicenseDate);
1740
+ this.formStore.policyholdersRepresentativeForm.notaryLicenseIssuer = spokesmanData.notaryLicenseIssuer;
1741
+ this.formStore.policyholdersRepresentativeForm.jurLongName = spokesmanData.jurLongName;
1742
+ this.formStore.policyholdersRepresentativeForm.fullNameRod = spokesmanData.fullNameRod;
1743
+ this.formStore.policyholdersRepresentativeForm.confirmDocTypeKz = spokesmanData.confirmDocTypeKz;
1744
+ this.formStore.policyholdersRepresentativeForm.confirmDocTypeRod = spokesmanData.confirmDocTypeRod;
1745
+ this.formStore.policyholdersRepresentativeForm.isNotary = spokesmanData.isNotary;
1746
+ }
1747
+ }
1748
+ if (setProductConditions) {
1749
+ this.formStore.productConditionsForm.coverPeriod = applicationData.policyAppDto.coverPeriod;
1750
+ this.formStore.productConditionsForm.payPeriod = applicationData.policyAppDto.payPeriod;
1751
+ // this.formStore.productConditionsForm.annualIncome = applicationData.policyAppDto.annualIncome?.toString();
1752
+ this.formStore.productConditionsForm.lifeMultiply = parseProcents(applicationData.policyAppDto.lifeMultiply);
1753
+ this.formStore.productConditionsForm.lifeAdditive = parseProcents(applicationData.policyAppDto.lifeAdditive);
1754
+ this.formStore.productConditionsForm.adbMultiply = parseProcents(applicationData.policyAppDto.adbMultiply);
1755
+ this.formStore.productConditionsForm.adbAdditive = parseProcents(applicationData.policyAppDto.adbAdditive);
1756
+ this.formStore.productConditionsForm.disabilityMultiply = parseProcents(applicationData.policyAppDto.disabilityMultiply);
1757
+ this.formStore.productConditionsForm.disabilityAdditive = parseProcents(applicationData.policyAppDto.disabilityAdditive);
1758
+
1759
+ let processIndexRate = this.processIndexRate.find(item => item.id == applicationData.policyAppDto.indexRateId);
1760
+ this.formStore.productConditionsForm.processIndexRate = processIndexRate ? processIndexRate : this.processIndexRate.find(item => item.code === '0');
1761
+
1762
+ let paymentPeriod = this.processPaymentPeriod.find(item => item.id == applicationData.policyAppDto.paymentPeriodId);
1763
+ this.formStore.productConditionsForm.paymentPeriod = paymentPeriod ? paymentPeriod : new Value();
1764
+
1765
+ this.formStore.productConditionsForm.requestedSumInsured = this.getNumberWithSpaces(
1766
+ applicationData.policyAppDto.amount === null ? null : applicationData.policyAppDto.amount,
1767
+ );
1768
+ this.formStore.productConditionsForm.insurancePremiumPerMonth = this.getNumberWithSpaces(
1769
+ applicationData.policyAppDto.premium === null ? null : applicationData.policyAppDto.premium,
1770
+ );
1771
+
1772
+ let riskGroup = this.riskGroup.find(item => {
1773
+ if (applicationData.policyAppDto.riskGroup == 0) {
1774
+ return true;
1775
+ }
1776
+ return item.id == applicationData.policyAppDto.riskGroup;
1777
+ });
1778
+ this.formStore.productConditionsForm.riskGroup = riskGroup ? riskGroup : this.riskGroup.find(item => item.id == 1);
1779
+ }
1780
+ } catch (err) {
1781
+ console.log(err);
1782
+ if ('response' in err) {
1783
+ this.sendToParent(constants.postActions.toHomePage, err.response.data);
1784
+ this.isLoading = false;
1785
+ return false;
1786
+ }
1787
+ }
1788
+ if (onlyGet) {
1789
+ this.isLoading = false;
1790
+ }
1791
+ },
1792
+ async setApplication() {
1793
+ try {
1794
+ await this.api.setApplication(this.formStore.applicationData);
1795
+ } catch (err) {
1796
+ console.log(err);
1797
+ }
1798
+ },
1799
+ async deleteTask(taskId) {
1800
+ this.isLoading = true;
1801
+ try {
1802
+ const data = {
1803
+ taskId: taskId,
1804
+ decision: 'rejectclient',
1805
+ comment: 'Клиент отказался',
1806
+ };
1807
+ await this.api.sendTask(data);
1808
+ this.showToaster('success', this.t('toaster.applicationDeleted'), 2000);
1809
+ } catch (err) {
1810
+ if ('response' in err && err.response.data) {
1811
+ this.showToaster('error', this.t('toaster.error') + err.response.data, 2000);
1812
+ }
1813
+ console.log(err);
1814
+ }
1815
+ this.isLoading = false;
1816
+ },
1817
+ async sendTask(taskId, decision, comment = null) {
1818
+ this.isLoading = true;
1819
+ try {
1820
+ const data = {
1821
+ taskId: taskId,
1822
+ decision: decision,
1823
+ };
1824
+ await this.api.sendTask(comment === null ? data : { ...data, comment: comment });
1825
+ this.showToaster('success', this.t('toaster.successOperation'), 3000);
1826
+ this.isLoading = false;
1827
+ return true;
1828
+ } catch (err) {
1829
+ console.log(err);
1830
+ if ('response' in err && err.response.data) {
1831
+ this.showToaster('error', this.t('toaster.error') + err.response.data, 2000);
1832
+ }
1833
+ this.isLoading = false;
1834
+ return false;
1835
+ }
1836
+ },
1837
+ async handleTask(action, taskId, comment) {
1838
+ if (action && Object.keys(constants.actions).includes(action)) {
1839
+ switch (action) {
1840
+ case constants.actions.claim: {
1841
+ try {
1842
+ this.isLoading = true;
1843
+ await this.api.claimTask(this.formStore.applicationTaskId);
1844
+ await this.getApplicationData(taskId, false, false, false);
1845
+ this.showToaster('success', this.t('toaster.successOperation'), 3000);
1846
+ } catch (err) {
1847
+ console.log(err);
1848
+ if ('response' in err && err.response.data) {
1849
+ this.showToaster('error', err.response.data, 3000);
1850
+ }
1851
+ }
1852
+ }
1853
+ case constants.actions.reject:
1854
+ case constants.actions.return:
1855
+ case constants.actions.rejectclient:
1856
+ case constants.actions.accept: {
1857
+ try {
1858
+ await this.sendTask(taskId, action, comment);
1859
+ this.formStore.$reset();
1860
+ if (this.isEFO) {
1861
+ await this.router.push({ name: 'Insurance-Product' });
1862
+ } else {
1863
+ this.sendToParent(constants.postActions.toHomePage, this.t('toaster.successOperation') + 'SUCCESS');
1864
+ }
1865
+ } catch (err) {
1866
+ console.log(err);
1867
+ if ('response' in err && err.response.data) {
1868
+ this.showToaster('error', err.response.data, 3000);
1869
+ }
1870
+ }
1871
+ }
1872
+ }
1873
+ } else {
1874
+ console.error('No handleTask action');
1875
+ }
1876
+ },
1877
+ async getInvoiceData(processInstanceId) {
1878
+ try {
1879
+ const response = await this.api.getInvoiceData(processInstanceId);
1880
+ if (response) {
1881
+ return response;
1882
+ } else {
1883
+ return false;
1884
+ }
1885
+ } catch (err) {
1886
+ return false;
1887
+ }
1888
+ },
1889
+ async createInvoice() {
1890
+ try {
1891
+ const created = await this.api.createInvoice(this.formStore.applicationData.processInstanceId, this.formStore.applicationData.policyAppDto.premium);
1892
+ return !!created;
1893
+ } catch (err) {
1894
+ this.isLoading = false;
1895
+ }
1896
+ },
1897
+ async sendToEpay() {
1898
+ try {
1899
+ const response = await this.api.sendToEpay(this.formStore.applicationData.processInstanceId);
1900
+ if (response) {
1901
+ return response;
1902
+ }
1903
+ } catch (err) {
1904
+ console.log(err);
1905
+ }
1906
+ },
1907
+ setMembersField(whichForm, whichMember) {
1908
+ this.formStore[whichForm].familyStatus = this.findObject('familyStatuses', 'id', this.formStore.applicationData[whichMember].familyStatusId);
1909
+ this.formStore[whichForm].signOfIPDL = this.findObject(
1910
+ 'ipdl',
1911
+ 'nameRu',
1912
+ this.formStore.applicationData[whichMember].isIpdl === null ? null : this.formStore.applicationData[whichMember].isIpdl == true ? 'Да' : 'Нет',
1913
+ );
1914
+ if (!!this.formStore.applicationData[whichMember].profession) this.formStore[whichForm].job = this.formStore.applicationData[whichMember].profession;
1915
+ if (!!this.formStore.applicationData[whichMember].position) this.formStore[whichForm].jobPosition = this.formStore.applicationData[whichMember].position;
1916
+ if (!!this.formStore.applicationData[whichMember].jobName) this.formStore[whichForm].jobPlace = this.formStore.applicationData[whichMember].jobName;
1917
+ },
1918
+ setMembersFieldIndex(whichForm, whichMember, index) {
1919
+ if ('familyStatus' in this.formStore[whichForm][index]) {
1920
+ this.formStore[whichForm][index].familyStatus = this.findObject('familyStatuses', 'id', this.formStore.applicationData[whichMember][index].familyStatusId);
1921
+ }
1922
+ if ('signOfIPDL' in this.formStore[whichForm][index]) {
1923
+ this.formStore[whichForm][index].signOfIPDL = this.findObject(
1924
+ 'ipdl',
1925
+ 'nameRu',
1926
+ this.formStore.applicationData[whichMember][index].isIpdl === null ? null : this.formStore.applicationData[whichMember][index].isIpdl == true ? 'Да' : 'Нет',
1927
+ );
1928
+ }
1929
+ if ('job' in this.formStore[whichForm][index] && !!this.formStore.applicationData[whichMember][index].profession) {
1930
+ this.formStore[whichForm][index].job = this.formStore.applicationData[whichMember][index].profession;
1931
+ }
1932
+ if ('jobPosition' in this.formStore[whichForm][index] && !!this.formStore.applicationData[whichMember][index].position) {
1933
+ this.formStore[whichForm][index].jobPosition = this.formStore.applicationData[whichMember][index].position;
1934
+ }
1935
+ if ('jobPlace' in this.formStore[whichForm][index] && !!this.formStore.applicationData[whichMember][index].jobName) {
1936
+ this.formStore[whichForm][index].jobPlace = this.formStore.applicationData[whichMember][index].jobName;
1937
+ }
1938
+ },
1939
+ findObject(from, key, searchKey) {
1940
+ const found = this[from].find(i => i[key] == searchKey);
1941
+ return found || new Value();
1942
+ },
1943
+ async signToDocument(data) {
1944
+ try {
1945
+ if (this.signUrl) {
1946
+ return this.signUrl;
1947
+ }
1948
+ const result = await this.api.signToDocument(data);
1949
+ this.signUrl = result.uri;
1950
+ return this.signUrl;
1951
+ } catch (error) {
1952
+ this.showToaster('error', this.t('toaster.error') + error?.response?.data, 2000);
1953
+ }
1954
+ },
1955
+ sanitize(text) {
1956
+ if (text) {
1957
+ return text
1958
+ .replace(/\r?\n|\r/g, '')
1959
+ .replace(/\\/g, '')
1960
+ .replace(/"/g, '');
1961
+ }
1962
+ },
1963
+ async getSignedDocList(processInstanceId) {
1964
+ if (processInstanceId !== 0) {
1965
+ try {
1966
+ this.signedDocumentList = await this.api.getSignedDocList({
1967
+ processInstanceId: processInstanceId,
1968
+ });
1969
+ } catch (err) {
1970
+ console.log(err);
1971
+ }
1972
+ }
1973
+ },
1974
+ setFormsDisabled(isDisabled) {
1975
+ Object.keys(this.formStore.isDisabled).forEach(key => {
1976
+ this.formStore.isDisabled[key] = !!isDisabled;
1977
+ });
1978
+ },
1979
+ async reCalculate(processInstanceId, recalculationData, taskId, whichSum) {
1980
+ this.isLoading = true;
1981
+ try {
1982
+ const data = {
1983
+ processInstanceId: processInstanceId,
1984
+ ...recalculationData,
1985
+ };
1986
+ const recalculatedValue = await this.api.reCalculate(data);
1987
+ if (!!recalculatedValue) {
1988
+ await this.getApplicationData(taskId, false, false, false);
1989
+ this.showToaster(
1990
+ 'success',
1991
+ `${this.t('toaster.successRecalculation')}. ${whichSum == 'insurancePremiumPerMonth' ? 'Страховая премия' : 'Страховая сумма'}: ${this.getNumberWithSpaces(
1992
+ recalculatedValue,
1993
+ )}₸`,
1994
+ 4000,
1995
+ );
1996
+ } else {
1997
+ this.showToaster('error', this.t('toaster.undefinedError'), 2000);
1998
+ }
1999
+ } catch (err) {
2000
+ console.log(err);
2001
+ if ('response' in err) {
2002
+ this.showToaster('error', err?.response?.data, 5000);
2003
+ } else {
2004
+ this.showToaster('error', err, 5000);
2005
+ }
2006
+ }
2007
+ this.isLoading = false;
2008
+ },
2009
+ async getValidateClientESBD(data) {
2010
+ try {
2011
+ return await this.api.getValidateClientESBD(data);
2012
+ } catch (error) {
2013
+ this.isLoading = false;
2014
+ if ('response' in error && error.response.data) {
2015
+ this.showToaster('error', error.response.data, 5000);
2016
+ }
2017
+ console.log(error);
2018
+ return false;
2019
+ }
2020
+ },
2021
+ validateMultipleMembers(localKey, applicationKey, text) {
2022
+ if (this.formStore[localKey].length === this.formStore.applicationData[applicationKey].length) {
2023
+ if (this.formStore[localKey].length !== 0 && this.formStore.applicationData[applicationKey].length !== 0) {
2024
+ const localMembers = [...this.formStore[localKey]].sort((a, b) => a.id - b.id);
2025
+ const applicationMembers = [...this.formStore.applicationData[applicationKey]].sort((a, b) => a.insisId - b.insisId);
2026
+ if (localMembers.every((each, index) => applicationMembers[index].insisId === each.id && applicationMembers[index].iin === each.iin.replace(/-/g, '')) === false) {
2027
+ this.showToaster('error', this.t('toaster.notSavedMember', { text: text }), 3000);
2028
+ return false;
2029
+ }
2030
+ if (localKey === this.formStore.beneficiaryFormKey) {
2031
+ const sumOfPercentage = localMembers.reduce((sum, member) => {
2032
+ return sum + Number(member.percentageOfPayoutAmount);
2033
+ }, 0);
2034
+ if (sumOfPercentage !== 100) {
2035
+ this.showToaster('error', this.t('toaster.errorSumOrPercentage'), 3000);
2036
+ return false;
2037
+ }
2038
+ }
2039
+ }
2040
+ } else {
2041
+ if (this.formStore[localKey].some(i => i.iin !== null)) {
2042
+ this.showToaster('error', this.t('toaster.notSavedMember', { text: text }), 3000);
2043
+ return false;
2044
+ }
2045
+ if (this.formStore.applicationData[applicationKey].length !== 0) {
2046
+ this.showToaster('error', this.t('toaster.notSavedMember', { text: text }), 3000);
2047
+ return false;
2048
+ } else {
2049
+ if (this.formStore[localKey][0].iin !== null) {
2050
+ this.showToaster('error', this.t('toaster.notSavedMember', { text: text }), 3000);
2051
+ return false;
2052
+ }
2053
+ }
2054
+ }
2055
+ return true;
2056
+ },
2057
+ async validateAllMembers(taskId, localCheck = false) {
2058
+ if (taskId == 0) {
2059
+ this.showToaster('error', this.t('toaster.needToRunStatement'), 2000);
2060
+ return false;
2061
+ }
2062
+ if (this.formStore.policyholderForm.id !== this.formStore.applicationData.clientApp.insisId) {
2063
+ this.showToaster('error', this.t('toaster.notSavedMember', { text: 'страхователя' }), 3000);
2064
+ return false;
2065
+ }
2066
+ if (this.validateMultipleMembers(this.formStore.insuredFormKey, 'insuredApp', 'застрахованных') === false) {
2067
+ return false;
2068
+ }
2069
+ if (this.validateMultipleMembers(this.formStore.beneficiaryFormKey, 'beneficiaryApp', 'выгодоприобретателей') === false) {
2070
+ return false;
2071
+ }
2072
+ if (this.formStore.isActOwnBehalf === false) {
2073
+ if (this.validateMultipleMembers(this.formStore.beneficialOwnerFormKey, 'beneficialOwnerApp', 'бенефициарных собственников') === false) {
2074
+ return false;
2075
+ }
2076
+ }
2077
+ if (this.formStore.hasRepresentative) {
2078
+ if (this.formStore.applicationData.spokesmanApp && this.formStore.policyholdersRepresentativeForm.id !== this.formStore.applicationData.spokesmanApp.insisId) {
2079
+ this.showToaster(
2080
+ 'error',
2081
+ this.t('toaster.notSavedMember', {
2082
+ text: 'представителя страхователя',
2083
+ }),
2084
+ 3000,
2085
+ );
2086
+ return false;
2087
+ }
2088
+ }
2089
+ const areValid = this.formStore.SaleChanellPolicy.nameRu && this.formStore.RegionPolicy.nameRu && this.formStore.ManagerPolicy.nameRu && this.formStore.AgentData.fullName;
2090
+ if (areValid) {
2091
+ await this.setINSISWorkData();
2092
+ } else {
2093
+ this.isLoading = false;
2094
+ this.showToaster('error', this.t('toaster.attachManagerError'), 3000);
2095
+ return false;
2096
+ }
2097
+ if (localCheck === false) {
2098
+ try {
2099
+ if (this.formStore.isActOwnBehalf === true && this.formStore.applicationData.beneficialOwnerApp.length !== 0) {
2100
+ await Promise.allSettled(
2101
+ this.formStore.applicationData.beneficialOwnerApp.map(async member => {
2102
+ await this.api.deleteMember('BeneficialOwner', member.id);
2103
+ }),
2104
+ );
2105
+ }
2106
+ await this.getApplicationData(taskId, false);
2107
+ } catch (err) {
2108
+ console.log(err);
2109
+ this.showToaster('error', err, 5000);
2110
+ return false;
2111
+ }
2112
+ }
2113
+
2114
+ return true;
2115
+ },
2116
+ validateAnketa(whichSurvey) {
2117
+ const list = this[whichSurvey].body;
2118
+ if (!list || (list && list.length === 0)) return false;
2119
+ let notAnswered = 0;
2120
+ for (let x = 0; x < list.length; x++) {
2121
+ if ((list[x].first.definedAnswers === 'N' && !list[x].first.answerText) || (list[x].first.definedAnswers === 'Y' && !list[x].first.answerName)) {
2122
+ notAnswered = notAnswered + 1;
2123
+ }
2124
+ }
2125
+ return notAnswered === 0;
2126
+ },
2127
+ async validateAllForms(taskId) {
2128
+ this.isLoading = true;
2129
+ const areMembersValid = await this.validateAllMembers(taskId);
2130
+ if (areMembersValid) {
2131
+ if (!!this.formStore.productConditionsForm.insurancePremiumPerMonth && !!this.formStore.productConditionsForm.requestedSumInsured) {
2132
+ const hasCritical = this.additionalInsuranceTerms?.find(cover => cover.coverTypeName === 'Критическое заболевание Застрахованного');
2133
+ if (hasCritical && hasCritical.coverSumName !== 'не включено') {
2134
+ await Promise.allSettled([
2135
+ this.getQuestionList(
2136
+ 'health',
2137
+ this.formStore.applicationData.processInstanceId,
2138
+ this.formStore.applicationData.insuredApp[0].id,
2139
+ 'surveyByHealthBase',
2140
+ 'surveyByHealthSecond',
2141
+ ),
2142
+ this.getQuestionList(
2143
+ 'critical',
2144
+ this.formStore.applicationData.processInstanceId,
2145
+ this.formStore.applicationData.insuredApp[0].id,
2146
+ 'surveyByCriticalBase',
2147
+ 'surveyByCriticalSecond',
2148
+ ),
2149
+ ]);
2150
+ await Promise.allSettled([
2151
+ ...this.surveyByHealthBase.body.map(async question => {
2152
+ await this.definedAnswers(question.first.id, 'surveyByHealthBase');
2153
+ }),
2154
+ ...this.surveyByCriticalBase.body.map(async question => {
2155
+ await this.definedAnswers(question.first.id, 'surveyByCriticalBase');
2156
+ }),
2157
+ ]);
2158
+ } else {
2159
+ await Promise.allSettled([
2160
+ this.getQuestionList(
2161
+ 'health',
2162
+ this.formStore.applicationData.processInstanceId,
2163
+ this.formStore.applicationData.insuredApp[0].id,
2164
+ 'surveyByHealthBase',
2165
+ 'surveyByHealthSecond',
2166
+ ),
2167
+ ]);
2168
+ await Promise.allSettled(
2169
+ this.surveyByHealthBase.body.map(async question => {
2170
+ await this.definedAnswers(question.first.id, 'surveyByHealthBase');
2171
+ }),
2172
+ );
2173
+ }
2174
+
2175
+ if (this.validateAnketa('surveyByHealthBase')) {
2176
+ let hasCriticalAndItsValid = null;
2177
+ if (hasCritical && hasCritical.coverSumName !== 'не включено') {
2178
+ if (this.validateAnketa('surveyByCriticalBase')) {
2179
+ hasCriticalAndItsValid = true;
2180
+ } else {
2181
+ hasCriticalAndItsValid = false;
2182
+ this.showToaster('error', this.t('toaster.emptyCriticalAnketa'), 3000);
2183
+ }
2184
+ } else {
2185
+ hasCriticalAndItsValid = null;
2186
+ }
2187
+ if (hasCriticalAndItsValid === true || hasCriticalAndItsValid === null) {
2188
+ this.isLoading = false;
2189
+ return true;
2190
+ }
2191
+ } else {
2192
+ this.showToaster('error', this.t('toaster.emptyHealthAnketa'), 3000);
2193
+ }
2194
+ } else {
2195
+ this.showToaster('error', this.t('toaster.emptyProductConditions'), 3000);
2196
+ }
2197
+ return false;
2198
+ }
2199
+ this.isLoading = false;
2200
+ return false;
2201
+ },
2202
+ async getContragentFromGBDFL(iin, phoneNumber, whichForm, whichIndex = null) {
2203
+ this.isLoading = true;
2204
+ try {
2205
+ const data = {
2206
+ iin: iin.replace(/-/g, ''),
2207
+ phoneNumber: formatPhone(phoneNumber),
2208
+ };
2209
+ const gbdResponse = await this.api.getContragentFromGBDFL(data);
2210
+ if (gbdResponse.status === 'PENDING') {
2211
+ this.showToaster('success', this.t('toaster.waitForClient'), 5000);
2212
+ this.isLoading = false;
2213
+ return;
2214
+ }
2215
+ if (constants.gbdErrors.find(i => i === gbdResponse.status)) {
2216
+ if (gbdResponse.status === 'TIMEOUT') {
2217
+ this.showToaster('success', `${gbdResponse.statusName}. Отправьте запрос еще раз`, 5000);
2218
+ } else {
2219
+ this.showToaster('success', gbdResponse.statusName, 5000);
2220
+ }
2221
+ this.isLoading = false;
2222
+ return;
2223
+ }
2224
+ const { person } = parseXML(gbdResponse.content, true, 'person');
2225
+ const { responseInfo } = parseXML(gbdResponse.content, true, 'responseInfo');
2226
+ if (whichIndex === null) {
2227
+ if (this.formStore[whichForm].gosPersonData !== null && this.formStore[whichForm].gosPersonData.iin !== iin.replace(/-/g, '')) {
2228
+ if (whichForm === this.formStore.policyholdersRepresentativeFormKey) {
2229
+ this.formStore[whichForm].resetMember(false);
2230
+ } else {
2231
+ this.formStore[whichForm].resetForm(false);
2232
+ }
2233
+ }
2234
+ this.formStore[whichForm].gosPersonData = person;
2235
+ } else {
2236
+ if (this.formStore[whichForm][whichIndex].gosPersonData !== null && this.formStore[whichForm][whichIndex].gosPersonData.iin !== iin.replace(/-/g, '')) {
2237
+ this.formStore[whichForm][whichIndex].resetForm(false);
2238
+ }
2239
+ this.formStore[whichForm][whichIndex].gosPersonData = person;
2240
+ }
2241
+
2242
+ await this.getContragent(whichForm, whichIndex, false);
2243
+ if (whichIndex === null) {
2244
+ this.formStore[whichForm].verifyDate = responseInfo.responseDate;
2245
+ this.formStore[whichForm].verifyType = 'GBDFL';
2246
+ } else {
2247
+ this.formStore[whichForm][whichIndex].verifyDate = responseInfo.responseDate;
2248
+ this.formStore[whichForm][whichIndex].verifyType = 'GBDFL';
2249
+ }
2250
+ await this.saveInStoreUserGBDFL(person, whichForm, whichIndex);
2251
+ } catch (err) {
2252
+ console.log(err);
2253
+ if ('response' in err) {
2254
+ this.showToaster('error', err.response.data, 3000);
2255
+ }
2256
+ }
2257
+ this.isLoading = false;
2258
+ },
2259
+ async saveInStoreUserGBDFL(person, whichForm, whichIndex = null) {
2260
+ if (whichIndex === null) {
2261
+ this.formStore[whichForm].firstName = person.name;
2262
+ this.formStore[whichForm].lastName = person.surname;
2263
+ this.formStore[whichForm].middleName = person.patronymic ? person.patronymic : '';
2264
+ this.formStore[whichForm].longName = `${person.surname} ${person.name} ${person.patronymic ? person.patronymic : ''}`;
2265
+ this.formStore[whichForm].birthDate = reformatDate(person.birthDate);
2266
+ this.formStore[whichForm].genderName = person.gender.nameRu;
2267
+
2268
+ const gender = this.gender.find(i => i.id == person.gender.code);
2269
+ if (gender) this.formStore[whichForm].gender = gender;
2270
+
2271
+ const birthPlace = this.countries.find(i => i.nameRu.match(new RegExp(person.birthPlace.country.nameRu, 'i')));
2272
+ if (birthPlace) this.formStore[whichForm].birthPlace = birthPlace;
2273
+
2274
+ const countryOfCitizenship = this.citizenshipCountries.find(i => i.nameRu.match(new RegExp(person.citizenship.nameRu, 'i')));
2275
+ if (countryOfCitizenship) this.formStore[whichForm].countryOfCitizenship = countryOfCitizenship;
2276
+
2277
+ const regCountry = this.countries.find(i => i.nameRu.match(new RegExp(person.regAddress.country.nameRu, 'i')));
2278
+ if (regCountry) this.formStore[whichForm].registrationCountry = regCountry;
2279
+
2280
+ const regProvince = this.states.find(i => i.nameRu.match(new RegExp(person.regAddress.district.nameRu, 'i')));
2281
+ if (regProvince) this.formStore[whichForm].registrationProvince = regProvince;
2282
+
2283
+ if ('city' in person.regAddress && !!person.regAddress.city) {
2284
+ if (person.regAddress.city.includes(', ')) {
2285
+ const personCities = person.regAddress.city.split(', ');
2286
+ for (let i = 0; i < personCities.length; ++i) {
2287
+ const possibleCity = this.cities.find(i => i.nameRu.includes(personCities[i]));
2288
+ if (possibleCity) {
2289
+ this.formStore[whichForm].registrationCity = possibleCity;
2290
+ break;
2291
+ }
2292
+ }
2293
+ if (this.formStore[whichForm].registrationCity.nameRu === null) {
2294
+ for (let i = 0; i < personCities.length; ++i) {
2295
+ const possibleRegion = this.regions.find(i => i.nameRu.includes(personCities[i]));
2296
+ if (possibleRegion) {
2297
+ this.formStore[whichForm].registrationRegion = possibleRegion;
2298
+ break;
2299
+ }
2300
+ }
2301
+ }
2302
+ } else {
2303
+ const regCity = this.cities.find(i => i.nameRu.match(new RegExp(person.regAddress.city, 'i')));
2304
+ if (regCity) this.formStore[whichForm].registrationCity = regCity;
2305
+
2306
+ if (this.formStore[whichForm].registrationCity.nameRu === null) {
2307
+ const regRegion = this.regions.find(i => i.nameRu.match(new RegExp(person.regAddress.city), 'i'));
2308
+ if (regRegion) this.formStore[whichForm].registrationRegion = regRegion;
2309
+ }
2310
+ }
2311
+ }
2312
+
2313
+ if (this.formStore[whichForm].registrationCity.nameRu === null && this.formStore[whichForm].registrationRegion.nameRu === null) {
2314
+ const regCity = this.cities.find(
2315
+ i => i.nameRu.match(new RegExp(person.regAddress.region.nameRu, 'i')) || i.nameRu.match(new RegExp(person.regAddress.district.nameRu, 'i')),
2316
+ );
2317
+ if (regCity) {
2318
+ this.formStore[whichForm].registrationCity = regCity;
2319
+ const regType = this.localityTypes.find(i => i.nameRu === 'город');
2320
+ if (regType) this.formStore[whichForm].registrationRegionType = regType;
2321
+ } else {
2322
+ const regRegion = this.regions.find(
2323
+ i => i.nameRu.match(new RegExp(person.regAddress.region.nameRu), 'i') || i.nameRu.match(new RegExp(person.regAddress.district.nameRu, 'i')),
2324
+ );
2325
+ if (regRegion) {
2326
+ this.formStore[whichForm].registrationRegion = regRegion;
2327
+ const regType = this.localityTypes.find(i => (i.nameRu === i.nameRu) === 'село' || i.nameRu === 'поселок');
2328
+ if (regType) this.formStore[whichForm].registrationRegionType = regType;
2329
+ }
2330
+ }
2331
+ }
2332
+
2333
+ if (person.regAddress.street.includes(', ')) {
2334
+ const personAddress = person.regAddress.street.split(', ');
2335
+ const microDistrict = personAddress.find(i => i.match(new RegExp('микрорайон', 'i')));
2336
+ const quarter = personAddress.find(i => i.match(new RegExp('квартал', 'i')));
2337
+ const street = personAddress.find(i => i.match(new RegExp('улица', 'i')));
2338
+ if (microDistrict) this.formStore[whichForm].registrationMicroDistrict = microDistrict;
2339
+ if (quarter) this.formStore[whichForm].registrationQuarter = quarter;
2340
+ if (street) this.formStore[whichForm].registrationStreet = street;
2341
+ } else {
2342
+ if (person.regAddress.street) this.formStore[whichForm].registrationStreet = person.regAddress.street;
2343
+ }
2344
+ if (person.regAddress.building) this.formStore[whichForm].registrationNumberHouse = person.regAddress.building;
2345
+ if (person.regAddress.flat) this.formStore[whichForm].registrationNumberApartment = person.regAddress.flat;
2346
+
2347
+ // TODO Доработать логику и для остальных
2348
+ if ('length' in person.documents.document) {
2349
+ const validDocument = person.documents.document.find(i => new Date(i.endDate) > new Date(Date.now()) && i.status.code === '00' && i.type.code === '002');
2350
+ if (validDocument) {
2351
+ const documentType = this.documentTypes.find(i => i.ids === '1UDL');
2352
+ if (documentType) this.formStore[whichForm].documentType = documentType;
2353
+
2354
+ this.formStore[whichForm].documentNumber = validDocument.number;
2355
+ this.formStore[whichForm].documentExpire = reformatDate(validDocument.endDate);
2356
+ this.formStore[whichForm].documentDate = reformatDate(validDocument.beginDate);
2357
+ this.formStore[whichForm].documentNumber = validDocument.number;
2358
+
2359
+ const documentIssuer = this.documentIssuers.find(i => i.nameRu.match(new RegExp('МВД РК', 'i')));
2360
+ if (documentIssuer) this.formStore[whichForm].documentIssuers = documentIssuer;
2361
+ }
2362
+ } else {
2363
+ const documentType =
2364
+ person.documents.document.type.nameRu === 'УДОСТОВЕРЕНИЕ РК'
2365
+ ? this.documentTypes.find(i => i.ids === '1UDL')
2366
+ : this.documentTypes.find(i => i.nameRu.match(new RegExp(person.documents.document.type.nameRu, 'i')))
2367
+ ? this.documentTypes.find(i => i.nameRu.match(new RegExp(person.documents.document.type.nameRu, 'i')))
2368
+ : new Value();
2369
+ if (documentType) this.formStore[whichForm].documentType = documentType;
2370
+
2371
+ const documentNumber = person.documents.document.number;
2372
+ if (documentNumber) this.formStore[whichForm].documentNumber = documentNumber;
2373
+
2374
+ const documentDate = person.documents.document.beginDate;
2375
+ if (documentDate) this.formStore[whichForm].documentDate = reformatDate(documentDate);
2376
+
2377
+ const documentExpire = person.documents.document.endDate;
2378
+ if (documentExpire) this.formStore[whichForm].documentExpire = reformatDate(documentExpire);
2379
+
2380
+ // TODO уточнить
2381
+ const documentIssuer = this.documentIssuers.find(i => i.nameRu.match(new RegExp('МВД РК', 'i')));
2382
+ if (documentIssuer) this.formStore[whichForm].documentIssuers = documentIssuer;
2383
+ }
2384
+ const economySectorCode = this.economySectorCode.find(i => i.ids === '500003.9');
2385
+ if (economySectorCode) this.formStore[whichForm].economySectorCode = economySectorCode;
2386
+ } else {
2387
+ this.formStore[whichForm][whichIndex].firstName = person.name;
2388
+ this.formStore[whichForm][whichIndex].lastName = person.surname;
2389
+ this.formStore[whichForm][whichIndex].middleName = person.patronymic ? person.patronymic : '';
2390
+ this.formStore[whichForm][whichIndex].longName = `${person.surname} ${person.name} ${person.patronymic ? person.patronymic : ''}`;
2391
+ this.formStore[whichForm][whichIndex].birthDate = reformatDate(person.birthDate);
2392
+ this.formStore[whichForm][whichIndex].genderName = person.gender.nameRu;
2393
+
2394
+ const gender = this.gender.find(i => i.id == person.gender.code);
2395
+ if (gender) this.formStore[whichForm][whichIndex].gender = gender;
2396
+
2397
+ const birthPlace = this.countries.find(i => i.nameRu.match(new RegExp(person.birthPlace.country.nameRu, 'i')));
2398
+ if (birthPlace) this.formStore[whichForm][whichIndex].birthPlace = birthPlace;
2399
+
2400
+ const countryOfCitizenship = this.citizenshipCountries.find(i => i.nameRu.match(new RegExp(person.citizenship.nameRu, 'i')));
2401
+ if (countryOfCitizenship) this.formStore[whichForm][whichIndex].countryOfCitizenship = countryOfCitizenship;
2402
+
2403
+ const regCountry = this.countries.find(i => i.nameRu.match(new RegExp(person.regAddress.country.nameRu, 'i')));
2404
+ if (regCountry) this.formStore[whichForm][whichIndex].registrationCountry = regCountry;
2405
+
2406
+ const regProvince = this.states.find(i => i.nameRu.match(new RegExp(person.regAddress.district.nameRu, 'i')));
2407
+ if (regProvince) this.formStore[whichForm][whichIndex].registrationProvince = regProvince;
2408
+
2409
+ if ('city' in person.regAddress && !!person.regAddress.city) {
2410
+ if (person.regAddress.city.includes(', ')) {
2411
+ const personCities = person.regAddress.city.split(', ');
2412
+ for (let i = 0; i < personCities.length; ++i) {
2413
+ const possibleCity = this.cities.find(i => i.nameRu.includes(personCities[i]));
2414
+ if (possibleCity) {
2415
+ this.formStore[whichForm][whichIndex].registrationCity = possibleCity;
2416
+ break;
2417
+ }
2418
+ }
2419
+ if (this.formStore[whichForm][whichIndex].registrationCity.nameRu === null) {
2420
+ for (let i = 0; i < personCities.length; ++i) {
2421
+ const possibleRegion = this.regions.find(i => i.nameRu.includes(personCities[i]));
2422
+ if (possibleRegion) {
2423
+ this.formStore[whichForm][whichIndex].registrationRegion = possibleRegion;
2424
+ break;
2425
+ }
2426
+ }
2427
+ }
2428
+ } else {
2429
+ const regCity = this.cities.find(i => i.nameRu.match(new RegExp(person.regAddress.city, 'i')));
2430
+ if (regCity) this.formStore[whichForm][whichIndex].registrationCity = regCity;
2431
+ if (this.formStore[whichForm][whichIndex].registrationCity.nameRu === null) {
2432
+ const regRegion = this.regions.find(i => i.nameRu.match(new RegExp(person.regAddress.city), 'i'));
2433
+ if (regRegion) this.formStore[whichForm][whichIndex].registrationRegion = regRegion;
2434
+ }
2435
+ }
2436
+ }
2437
+
2438
+ if (this.formStore[whichForm][whichIndex].registrationCity.nameRu === null && this.formStore[whichForm][whichIndex].registrationRegion.nameRu === null) {
2439
+ const regCity = this.cities.find(
2440
+ i => i.nameRu.match(new RegExp(person.regAddress.region.nameRu, 'i')) || i.nameRu.match(new RegExp(person.regAddress.district.nameRu, 'i')),
2441
+ );
2442
+ if (regCity) {
2443
+ this.formStore[whichForm][whichIndex].registrationCity = regCity;
2444
+ const regType = this.localityTypes.find(i => i.nameRu === 'город');
2445
+ if (regType) this.formStore[whichForm][whichIndex].registrationRegionType = regType;
2446
+ } else {
2447
+ const regRegion = this.regions.find(
2448
+ i => i.nameRu.match(new RegExp(person.regAddress.region.nameRu), 'i') || i.nameRu.match(new RegExp(person.regAddress.district.nameRu, 'i')),
2449
+ );
2450
+ if (regRegion) {
2451
+ this.formStore[whichForm][whichIndex].registrationRegion = regRegion;
2452
+ const regType = this.localityTypes.find(i => (i.nameRu === i.nameRu) === 'село' || i.nameRu === 'поселок');
2453
+ if (regType) this.formStore[whichForm][whichIndex].registrationRegionType = regType;
2454
+ }
2455
+ }
2456
+ }
2457
+
2458
+ if (person.regAddress.street.includes(', ')) {
2459
+ const personAddress = person.regAddress.street.split(', ');
2460
+ const microDistrict = personAddress.find(i => i.match(new RegExp('микрорайон', 'i')));
2461
+ const quarter = personAddress.find(i => i.match(new RegExp('квартал', 'i')));
2462
+ const street = personAddress.find(i => i.match(new RegExp('улица', 'i')));
2463
+ if (microDistrict) this.formStore[whichForm][whichIndex].registrationMicroDistrict = microDistrict;
2464
+ if (quarter) this.formStore[whichForm][whichIndex].registrationQuarter = quarter;
2465
+ if (street) this.formStore[whichForm][whichIndex].registrationStreet = street;
2466
+ } else {
2467
+ if (person.regAddress.street) this.formStore[whichForm][whichIndex].registrationStreet = person.regAddress.street;
2468
+ }
2469
+ if (person.regAddress.building) this.formStore[whichForm][whichIndex].registrationNumberHouse = person.regAddress.building;
2470
+ if (person.regAddress.flat) this.formStore[whichForm][whichIndex].registrationNumberApartment = person.regAddress.flat;
2471
+
2472
+ // TODO Доработать логику и для остальных
2473
+ if ('length' in person.documents.document) {
2474
+ const validDocument = person.documents.document.find(i => new Date(i.endDate) > new Date(Date.now()) && i.status.code === '00' && i.type.code === '002');
2475
+ if (validDocument) {
2476
+ const documentType = this.documentTypes.find(i => i.ids === '1UDL');
2477
+ if (documentType) this.formStore[whichForm][whichIndex].documentType = documentType;
2478
+ this.formStore[whichForm][whichIndex].documentNumber = validDocument.number;
2479
+ this.formStore[whichForm][whichIndex].documentExpire = reformatDate(validDocument.endDate);
2480
+ this.formStore[whichForm][whichIndex].documentDate = reformatDate(validDocument.beginDate);
2481
+ this.formStore[whichForm][whichIndex].documentNumber = validDocument.number;
2482
+
2483
+ const documentIssuer = this.documentIssuers.find(i => i.nameRu.match(new RegExp('МВД РК', 'i')));
2484
+ if (documentIssuer) this.formStore[whichForm][whichIndex].documentIssuers = documentIssuer;
2485
+ }
2486
+ } else {
2487
+ const documentType =
2488
+ person.documents.document.type.nameRu === 'УДОСТОВЕРЕНИЕ РК'
2489
+ ? this.documentTypes.find(i => i.ids === '1UDL')
2490
+ : this.documentTypes.find(i => i.nameRu.match(new RegExp(person.documents.document.type.nameRu, 'i')))
2491
+ ? this.documentTypes.find(i => i.nameRu.match(new RegExp(person.documents.document.type.nameRu, 'i')))
2492
+ : new Value();
2493
+ if (documentType) this.formStore[whichForm][whichIndex].documentType = documentType;
2494
+
2495
+ const documentNumber = person.documents.document.number;
2496
+ if (documentNumber) this.formStore[whichForm][whichIndex].documentNumber = documentNumber;
2497
+
2498
+ const documentDate = person.documents.document.beginDate;
2499
+ if (documentDate) this.formStore[whichForm][whichIndex].documentDate = reformatDate(documentDate);
2500
+
2501
+ const documentExpire = person.documents.document.endDate;
2502
+ if (documentExpire) this.formStore[whichForm][whichIndex].documentExpire = reformatDate(documentExpire);
2503
+
2504
+ // TODO уточнить
2505
+ const documentIssuer = this.documentIssuers.find(i => i.nameRu.match(new RegExp('МВД РК', 'i')));
2506
+ if (documentIssuer) this.formStore[whichForm][whichIndex].documentIssuers = documentIssuer;
2507
+ }
2508
+ const economySectorCode = this.economySectorCode.find(i => i.ids === '500003.9');
2509
+ if (economySectorCode) this.formStore[whichForm][whichIndex].economySectorCode = economySectorCode;
2510
+ }
2511
+ },
2512
+ async getOtpStatus(iin, phone, processInstanceId = null) {
2513
+ try {
2514
+ const otpData = {
2515
+ iin: iin.replace(/-/g, ''),
2516
+ phoneNumber: formatPhone(phone),
2517
+ type: 'AgreementOtp',
2518
+ };
2519
+ return await api.getOtpStatus(
2520
+ processInstanceId !== null && processInstanceId != 0
2521
+ ? {
2522
+ ...otpData,
2523
+ processInstanceId: processInstanceId,
2524
+ }
2525
+ : otpData,
2526
+ );
2527
+ } catch (err) {
2528
+ console.log(err);
2529
+ showToaster('error', err.response.data, 3000);
2530
+ }
2531
+ },
2532
+ async sendOtp(iin, phone, processInstanceId = null, onInit = false) {
2533
+ this.isLoading = true;
2534
+ let otpStatus = false;
2535
+ let otpResponse = {};
2536
+ try {
2537
+ if (iin && iin.length === 15 && phone && phone.length === 18) {
2538
+ const status = await this.getOtpStatus(iin, phone, processInstanceId);
2539
+ if (status === true) {
2540
+ showToaster('success', this.t('toaster.hasSuccessOtp'), 3000);
2541
+ otpStatus = true;
2542
+ this.isLoading = false;
2543
+ return { otpStatus, otpResponse };
2544
+ } else if (status === false && onInit === false) {
2545
+ const otpData = {
2546
+ iin: iin.replace(/-/g, ''),
2547
+ phoneNumber: formatPhone(phone),
2548
+ type: 'AgreementOtp',
2549
+ };
2550
+ otpResponse = await api.sendOtp(
2551
+ processInstanceId !== null && processInstanceId != 0
2552
+ ? {
2553
+ ...otpData,
2554
+ processInstanceId: processInstanceId,
2555
+ }
2556
+ : otpData,
2557
+ );
2558
+ this.isLoading = false;
2559
+ if (!!otpResponse) {
2560
+ if ('errMessage' in otpResponse && otpResponse.errMessage !== null) {
2561
+ showToaster('error', otpResponse.errMessage, 3000);
2562
+ return { otpStatus };
2563
+ }
2564
+ if ('result' in otpResponse && otpResponse.result === null) {
2565
+ if ('statusName' in otpResponse && !!otpResponse.statusName) {
2566
+ showToaster('error', otpResponse.statusName, 3000);
2567
+ return { otpStatus };
2568
+ }
2569
+ if ('status' in otpResponse && !!otpResponse.status) {
2570
+ showToaster('error', otpResponse.status, 3000);
2571
+ return { otpStatus };
2572
+ }
2573
+ }
2574
+ if ('tokenId' in otpResponse && otpResponse.tokenId) {
2575
+ this.formStore.otpTokenId = otpResponse.tokenId;
2576
+ showToaster('success', this.t('toaster.successOtp'), 3000);
2577
+ }
2578
+ } else {
2579
+ showToaster('error', this.t('toaster.undefinedError'), 3000);
2580
+ return { otpStatus };
2581
+ }
2582
+ }
2583
+ } else {
2584
+ if (onInit === false) {
2585
+ showToaster('error', this.t('toaster.errorFormField', { text: 'Номер телефона, ИИН' }));
2586
+ this.isLoading = false;
2587
+ }
2588
+ }
2589
+ return { otpStatus, otpResponse };
2590
+ } catch (err) {
2591
+ this.isLoading = false;
2592
+ if ('response' in err) {
2593
+ if ('statusName' in err.response.data && !!err.response.data.statusName) {
2594
+ showToaster('error', this.t('toaster.phoneNotFoundInBMG'), 3000);
2595
+ return { otpStatus };
2596
+ }
2597
+ if ('status' in err.response.data && !!err.response.data.status) {
2598
+ showToaster('error', err.response.data.status, 3000);
2599
+ return { otpStatus };
2600
+ }
2601
+ }
2602
+ } finally {
2603
+ this.isLoading = false;
2604
+ }
2605
+ this.isLoading = false;
2606
+ return { otpStatus, otpResponse };
2607
+ },
2608
+ async checkOtp(otpToken, phone, code) {
2609
+ try {
2610
+ this.isLoading = true;
2611
+ const otpData = {
2612
+ tokenId: otpToken,
2613
+ phoneNumber: formatPhone(phone),
2614
+ code: code,
2615
+ };
2616
+ const otpResponse = await this.api.checkOtp(otpData);
2617
+ if (otpResponse !== null) {
2618
+ if ('errMessage' in otpResponse && otpResponse.errMessage !== null) {
2619
+ this.showToaster('error', otpResponse.errMessage, 3000);
2620
+ return false;
2621
+ }
2622
+ if ('status' in otpResponse && !!otpResponse.status) {
2623
+ // TODO Доработать и менять значение hasAgreement.value => true
2624
+ this.showToaster(otpResponse.status !== 2 ? 'error' : 'success', otpResponse.statusName, 3000);
2625
+ if (otpResponse.status === 2) {
2626
+ return true;
2627
+ }
2628
+ }
2629
+ }
2630
+ return false;
2631
+ } catch (err) {
2632
+ console.log(err);
2633
+ if ('response' in err) {
2634
+ this.showToaster('error', err.response.data, 3000);
2635
+ }
2636
+ } finally {
2637
+ this.isLoading = false;
2638
+ }
2639
+ return null;
26
2640
  },
27
2641
  },
28
2642
  });
2643
+
2644
+ export const useContragentStore = defineStore('contragent', {
2645
+ state: () => ({
2646
+ ...new Contragent(),
2647
+ formatDate: new Contragent().formatDate,
2648
+ getDateByKey: new Contragent().getDateByKey,
2649
+ getBirthDate: new Contragent().getBirthDate,
2650
+ getDocumentExpireDate: new Contragent().getDocumentExpireDate,
2651
+ getDocumentDate: new Contragent().getDocumentDate,
2652
+ getAgeByBirthDate: new Contragent().getAgeByBirthDate,
2653
+ }),
2654
+ });