hl-core 0.0.7-beta.0 → 0.0.7-beta.10

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