From 53f60e15c3c02de2dc040a21af55c811c76dcba2 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Mon, 21 Jun 2021 17:24:00 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BA=D0=BE=D1=81=D1=82=D1=8B=D0=BB=D0=B8=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B3=D0=B8=D1=81=D1=82=D1=80=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Effects/reactions/gibddReactions.ts | 332 ++++++++++++------ 1 file changed, 220 insertions(+), 112 deletions(-) diff --git a/src/client/stores/CalculationStore/Effects/reactions/gibddReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/gibddReactions.ts index bb9c08f..e5161bd 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/gibddReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/gibddReactions.ts @@ -439,151 +439,259 @@ const gibddReactions: IReactionEffect[] = [ }, }), - (calculationStore, calculationProcess) => ({ + // (calculationStore, calculationProcess) => ({ + // expression: () => { + // return { + // lead: calculationStore.getOption('selectLead'), + // opportunity: calculationStore.getOption('selectOpportunity'), + // objectRegistration: calculationStore.getValue('objectRegistration'), + // regionRegistration: calculationStore.getValue('regionRegistration'), + // }; + // }, + // effect: ({ lead, opportunity, objectRegistration, regionRegistration }) => { + // if (calculationProcess.hasProcess(Process.LoadKp)) { + // return; + // } + // calculationStore.setStatus( + // 'selectLegalClientRegion', + // ElementStatus.Default, + // ); + + // let evo_legal_regionid = calculationStore.getOption('selectQuote') + // ?.evo_legal_regionid; + // if (objectRegistration === 100000000) { + // evo_legal_regionid = regionRegistration; + // calculationStore.setStatus( + // 'selectLegalClientRegion', + // ElementStatus.Disabled, + // ); + // } else { + // const evo_region_fias_id = get( + // lead.accountidData || opportunity.accountidData, + // 'evo_address_legalidData.evo_region_fias_id', + // undefined, + // ); + // if (evo_region_fias_id) { + // calculationStore.setValue('legalClientRegion', evo_region_fias_id); + // calculationStore.setStatus( + // 'selectLegalClientRegion', + // ElementStatus.Disabled, + // ); + + // const targetLegalClientRegion = calculationStore.getOption( + // 'selectLegalClientRegion', + // { + // evo_fias_id: evo_region_fias_id, + // }, + // ); + // if (targetLegalClientRegion) { + // evo_legal_regionid = targetLegalClientRegion.evo_regionid; + // } + // } + // } + // calculationStore.setValue('legalClientRegion', evo_legal_regionid); + // }, + // options: { + // fireImmediately: true, + // }, + // }), + + // temp + calculationStore => ({ expression: () => { return { lead: calculationStore.getOption('selectLead'), opportunity: calculationStore.getOption('selectOpportunity'), - objectRegistration: calculationStore.getValue('objectRegistration'), - regionRegistration: calculationStore.getValue('regionRegistration'), }; }, - effect: ({ lead, opportunity, objectRegistration, regionRegistration }) => { - if (calculationProcess.hasProcess(Process.LoadKp)) { - return; - } - calculationStore.setStatus( - 'selectLegalClientRegion', - ElementStatus.Default, - ); + effect: ({ lead, opportunity }) => { + let evo_legal_regionid; - let evo_legal_regionid = calculationStore.getOption('selectQuote') - ?.evo_legal_regionid; - if (objectRegistration === 100000000) { - evo_legal_regionid = regionRegistration; - calculationStore.setStatus( + let accountidData = {}; + + if (lead) { + accountidData = lead.accountidData; + } + + if (opportunity) { + accountidData = opportunity.accountidData; + } + const evo_region_fias_id = get( + accountidData, + 'evo_address_legalidData.evo_region_fias_id', + undefined, + ); + if (evo_region_fias_id) { + calculationStore.setValue('legalClientRegion', evo_region_fias_id); + + const targetLegalClientRegion = calculationStore.getOption( 'selectLegalClientRegion', - ElementStatus.Disabled, + { + evo_fias_id: evo_region_fias_id, + }, ); - } else { - const evo_region_fias_id = get( - lead.accountidData || opportunity.accountidData, - 'evo_address_legalidData.evo_region_fias_id', - undefined, - ); - if (evo_region_fias_id) { - calculationStore.setValue('legalClientRegion', evo_region_fias_id); + if (targetLegalClientRegion) { calculationStore.setStatus( 'selectLegalClientRegion', ElementStatus.Disabled, ); - - const targetLegalClientRegion = calculationStore.getOption( - 'selectLegalClientRegion', - { - evo_fias_id: evo_region_fias_id, - }, - ); - if (targetLegalClientRegion) { - evo_legal_regionid = targetLegalClientRegion.evo_regionid; - } + evo_legal_regionid = targetLegalClientRegion.evo_regionid; } + + calculationStore.setValue('legalClientRegion', evo_legal_regionid); + } else { + calculationStore.setStatus( + 'selectLegalClientRegion', + ElementStatus.Default, + ); + + calculationStore.setValue('legalClientRegion', null); } - calculationStore.setValue('legalClientRegion', evo_legal_regionid); - }, - options: { - fireImmediately: true, }, }), - (calculationStore, calculationProcess) => ({ + // (calculationStore, calculationProcess) => ({ + // expression: () => { + // return { + // lead: calculationStore.getOption('selectLead'), + // opportunity: calculationStore.getOption('selectOpportunity'), + // townOptions: calculationStore.getOptions('selectLegalClientTown'), + // }; + // }, + // effect: ({ lead, opportunity, townOptions }) => { + // if ( + // calculationProcess.hasProcess(Process.LoadKp) || + // !townOptions || + // townOptions.length === 0 + // ) { + // return; + // } + // calculationStore.setStatus( + // 'selectLegalClientTown', + // ElementStatus.Default, + // ); + + // let evo_legal_townid = calculationStore.getOption('selectQuote') + // ?.evo_legal_townid; + + // const evo_city_fias_id = get( + // lead.accountidData || opportunity.accountidData, + // 'evo_address_legalidData.evo_city_fias_id', + // undefined, + // ); + // if (evo_city_fias_id) { + // calculationStore.setStatus( + // 'selectLegalClientTown', + // ElementStatus.Disabled, + // ); + + // const targetLegalClientTown = calculationStore.getOption( + // 'selectLegalClientTown', + // { + // evo_fias_id: evo_city_fias_id, + // }, + // ); + // if (targetLegalClientTown) { + // evo_legal_townid = targetLegalClientTown.evo_townid; + // calculationStore.setValue( + // 'legalClientTown', + // targetLegalClientTown.evo_townid, + // ); + // } + // } + // calculationStore.setValue('legalClientTown', evo_legal_townid); + // }, + // }), + + // temp + calculationStore => ({ expression: () => { return { lead: calculationStore.getOption('selectLead'), opportunity: calculationStore.getOption('selectOpportunity'), - townOptions: calculationStore.getOptions('selectLegalClientTown'), }; }, - effect: ({ lead, opportunity, townOptions }) => { - if ( - calculationProcess.hasProcess(Process.LoadKp) || - !townOptions || - townOptions.length === 0 - ) { - return; - } - calculationStore.setStatus( - 'selectLegalClientTown', - ElementStatus.Default, - ); + effect: ({ lead, opportunity }) => { + setTimeout(() => { + let evo_legal_townid; - let evo_legal_townid = calculationStore.getOption('selectQuote') - ?.evo_legal_townid; + let accountidData = {}; - const evo_city_fias_id = get( - lead.accountidData || opportunity.accountidData, - 'evo_address_legalidData.evo_city_fias_id', - undefined, - ); - if (evo_city_fias_id) { - calculationStore.setStatus( - 'selectLegalClientTown', - ElementStatus.Disabled, + if (lead) { + accountidData = lead.accountidData; + } + + if (opportunity) { + accountidData = opportunity.accountidData; + } + + const evo_city_fias_id = get( + accountidData, + 'evo_address_legalidData.evo_city_fias_id', + undefined, ); - - const targetLegalClientTown = calculationStore.getOption( - 'selectLegalClientTown', - { - evo_fias_id: evo_city_fias_id, - }, - ); - if (targetLegalClientTown) { - evo_legal_townid = targetLegalClientTown.evo_townid; - calculationStore.setValue( - 'legalClientTown', - targetLegalClientTown.evo_townid, + if (evo_city_fias_id) { + const targetLegalClientTown = calculationStore.getOption( + 'selectLegalClientTown', + { + evo_fias_id: evo_city_fias_id, + }, ); + if (targetLegalClientTown) { + calculationStore.setStatus( + 'selectLegalClientTown', + ElementStatus.Disabled, + ); + evo_legal_townid = targetLegalClientTown.evo_townid; + } + calculationStore.setValue('legalClientTown', evo_legal_townid); + } else { + calculationStore.setStatus( + 'selectLegalClientTown', + ElementStatus.Default, + ); + + calculationStore.setValue('legalClientTown', null); } - } - calculationStore.setValue('legalClientTown', evo_legal_townid); + }, 2000); }, }), - (calculationStore, calculationProcess) => ({ - expression: () => { - return { - ...calculationStore.getValues([ - 'regionRegistration', - 'objectRegistration', - 'legalClientTown', - ]), - townRegistrationOptions: calculationStore.getOption( - 'selectTownRegistration', - ), - }; - }, - effect: ({ objectRegistration, legalClientTown }) => { - if (objectRegistration === 100000001) { - calculationStore.setStatus( - 'selectTownRegistration', - ElementStatus.Default, - ); - calculationStore.setFilter('selectTownRegistration', towns => - towns.filter(town => town.evo_businessunit_evolution === true), - ); - } else { - calculationStore.setStatus( - 'selectTownRegistration', - ElementStatus.Disabled, - ); - calculationStore.setFilter('selectTownRegistration', undefined); + // (calculationStore, calculationProcess) => ({ + // expression: () => { + // return { + // ...calculationStore.getValues([ + // 'regionRegistration', + // 'objectRegistration', + // 'legalClientTown', + // ]), + // townRegistrationOptions: calculationStore.getOption( + // 'selectTownRegistration', + // ), + // }; + // }, + // effect: ({ objectRegistration, legalClientTown }) => { + // if (objectRegistration === 100000001) { + // calculationStore.setStatus( + // 'selectTownRegistration', + // ElementStatus.Default, + // ); + // calculationStore.setFilter('selectTownRegistration', towns => + // towns.filter(town => town.evo_businessunit_evolution === true), + // ); + // } else { + // calculationStore.setStatus( + // 'selectTownRegistration', + // ElementStatus.Disabled, + // ); + // calculationStore.setFilter('selectTownRegistration', undefined); - if (!calculationProcess.hasProcess(Process.LoadKp)) { - calculationStore.setValue('townRegistration', legalClientTown); - } - } - }, - }), + // if (!calculationProcess.hasProcess(Process.LoadKp)) { + // calculationStore.setValue('townRegistration', legalClientTown); + // } + // } + // }, + // }), ]; export default gibddReactions;