hl-core 0.0.8-beta.7 → 0.0.8-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -113,23 +113,38 @@ export const useMemberStore = defineStore('members', {
113
113
  return 'Spokesman';
114
114
  }
115
115
  },
116
+ getMemberApplicationCode(whichForm: MemberKeys) {
117
+ switch (whichForm) {
118
+ case this.formStore.policyholderFormKey:
119
+ return 'clientApp';
120
+ case this.formStore.insuredFormKey:
121
+ return 'insuredApp';
122
+ case this.formStore.beneficiaryFormKey:
123
+ return 'beneficiaryApp';
124
+ case this.formStore.beneficialOwnerFormKey:
125
+ return 'beneficialOwnerApp';
126
+ case this.formStore.policyholdersRepresentativeFormKey:
127
+ return 'spokesmanApp';
128
+ }
129
+ },
116
130
  clearMember(whichForm: MemberKeys, whichIndex?: number) {
117
131
  if (!whichForm) return false;
118
132
  if (!this.isStatementEditible(whichForm)) return false;
119
133
  if (!this.validateInitiator()) return false;
120
134
  if (whichForm === this.formStore.policyholderFormKey || whichForm === this.formStore.policyholdersRepresentativeFormKey) {
121
- this.formStore[whichForm].resetMember();
135
+ //@ts-ignore
136
+ this.formStore[whichForm] = this.getMemberClass(whichForm);
122
137
  }
123
138
  if (typeof whichIndex === 'number') {
124
139
  if (this.formStore[whichForm].length === 1) {
125
- this.formStore[whichForm][whichIndex].resetMember();
140
+ this.formStore[whichForm][whichIndex] = this.getMemberClass(whichForm);
126
141
  } else {
127
142
  this.formStore[whichForm].splice(whichIndex, 1);
128
143
  }
129
144
  }
130
145
  return true;
131
146
  },
132
- async deleteMember(taskId: string, whichForm: MemberKeys, whichIndex?: number) {
147
+ async deleteMember(taskId: string, whichForm: MemberKeys, whichIndex?: number, refetch: boolean = true) {
133
148
  if (!whichForm) return false;
134
149
  if (!this.isStatementEditible(whichForm)) return false;
135
150
  if (!this.validateInitiator()) return false;
@@ -144,13 +159,88 @@ export const useMemberStore = defineStore('members', {
144
159
  } else {
145
160
  if (memberData) await this.dataStore.api.deleteMember(memberCode, memberData.id as number);
146
161
  }
147
- if (memberData) await this.dataStore.getApplicationData(taskId, true, true, true, false);
162
+ if (memberData && refetch) await this.dataStore.getApplicationData(taskId, true, true, true, false);
148
163
  return this.clearMember(whichForm, whichIndex);
149
164
  } catch (err) {
150
165
  console.log(err);
151
166
  return ErrorHandler(err);
152
167
  }
153
168
  },
169
+ async transferPolicyholder(to: MemberKeys) {
170
+ if (!to) return false;
171
+ if (!this.validateInitiator()) return false;
172
+ const fromMember = this.formStore.policyholderForm;
173
+ const successTranser = ref<boolean>(false);
174
+ const toIndex = ref<number | null>(null);
175
+ const taskId = useRoute().params.taskId as string;
176
+
177
+ if (this.dataStore.members[this.getMemberApplicationCode(to)!].isMultiple === false) {
178
+ if (this.formStore[to][0].id !== 0 && this.formStore[to][0].iin !== fromMember.iin) {
179
+ await this.deleteMember(taskId, to, 0, false);
180
+ }
181
+ this.formStore[to][0] = fromMember;
182
+ toIndex.value = 0;
183
+ successTranser.value = true;
184
+ } else {
185
+ if (this.formStore[to].every((member: Member) => member.id !== 0)) {
186
+ this.formStore[to].push(fromMember);
187
+ toIndex.value = this.formStore[to].length - 1;
188
+ successTranser.value = true;
189
+ } else {
190
+ const index = this.formStore[to].findIndex((member: Member) => member.id === 0);
191
+ if (index !== -1) {
192
+ this.formStore[to][index] = fromMember;
193
+ toIndex.value = index;
194
+ successTranser.value = true;
195
+ } else {
196
+ this.formStore[to].push(fromMember);
197
+ toIndex.value = this.formStore[to].length - 1;
198
+ successTranser.value = true;
199
+ }
200
+ }
201
+ }
202
+
203
+ if (successTranser.value === true) {
204
+ if (toIndex.value !== null && taskId !== '0' && this.formStore.applicationData.processInstanceId !== 0) {
205
+ const hasSaved = await this.dataStore.saveMember(this.formStore[to][toIndex.value], this.getMemberCode(to), this.getMemberFromApplication(to, toIndex.value));
206
+ if (hasSaved) {
207
+ await this.dataStore.getApplicationData(taskId, false, true, true, false);
208
+ this.dataStore.showToaster('success', this.dataStore.t('toaster.successSaved'));
209
+ this.dataStore.showToaster('warning', this.dataStore.t('toaster.formFieldEmptyWarning'), 3000);
210
+ return true;
211
+ } else {
212
+ this.dataStore.showToaster('error', this.dataStore.t('error.memberSave'));
213
+ return false;
214
+ }
215
+ } else {
216
+ return true;
217
+ }
218
+ } else {
219
+ this.dataStore.showToaster('error', this.dataStore.t('error.memberCopy'));
220
+ return false;
221
+ }
222
+ },
223
+ async retransferPolicyholder(from: MemberKeys) {
224
+ if (!from) return false;
225
+ if (!this.validateInitiator()) return false;
226
+ const client = this.formStore.policyholderForm;
227
+ const index = this.formStore[from].findIndex((member: Member) => member.id === client.id);
228
+ const taskId = useRoute().params.taskId as string;
229
+ if (index !== -1) {
230
+ const fromCode = this.getMemberApplicationCode(from);
231
+ const fromMember = this.formStore[from][index];
232
+ const applicationList = this.formStore.applicationData[fromCode!];
233
+ const fromIndex = applicationList && applicationList.length ? applicationList.findIndex((member: any) => member.insisId === fromMember.id) : null;
234
+ if (fromMember.id !== 0 && fromIndex !== -1) {
235
+ await this.deleteMember(taskId, from, index);
236
+ } else {
237
+ this.clearMember(from, index);
238
+ }
239
+ } else {
240
+ // @ts-ignore
241
+ this.formStore[from] = [this.getMemberClass(from)];
242
+ }
243
+ },
154
244
  addMember(whichForm: MemberKeys) {
155
245
  if (!whichForm) return false;
156
246
  if (!this.isStatementEditible(whichForm)) return false;