From 670978cb0b2bf5acae9a7b53de31e511a669fef0 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Wed, 11 Jan 2023 19:37:53 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B0=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=B2=20=D0=BF=D0=BE=D0=BB=D0=B5=20selectDealerRewardCondit?= =?UTF-8?q?ion=20:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Если selectDealerRewardCondition пусто, то DealerRewardSumm обнуляется и закрывается для редактирования Если в списке selectDealerRewardCondition есть запись, у которой evo_reward_condition.evo_agency_agreementid. Выплата без других агентов (evo_reward_without_other_agent) = True, то сбрасывают значение и закрываются для выбора поля: тест15.11 - указываю Авилон - сбрасывает другие АВ, но при этом я после этого могу их выбрать заново selectDealerBroker selectIndAgent selectCalcDoubleAgent selectCalcBroker selectCalcFinDepartment иначе selectDealerBroker открываем для редактирования selectIndAgent заполняется значением из Интереса selectCalcDoubleAgent заполняется значением из Интереса selectCalcBroker заполняется значением из Интереса selectCalcFinDepartment заполняется значением из Интереса --- .../supplier-agent/reactions/agents.ts | 553 ++++++++++-------- 1 file changed, 312 insertions(+), 241 deletions(-) diff --git a/apps/web/process/supplier-agent/reactions/agents.ts b/apps/web/process/supplier-agent/reactions/agents.ts index b000f47..0ddf5ed 100644 --- a/apps/web/process/supplier-agent/reactions/agents.ts +++ b/apps/web/process/supplier-agent/reactions/agents.ts @@ -92,6 +92,20 @@ export function fillReactions({ store, apolloClient }: ReactionsContext) { }); } +class Helper { + enabled: boolean; + /** + * + */ + constructor() { + this.enabled = false; + } + + trigger = () => { + this.enabled = !this.enabled; + }; +} + export function commonReactions({ store, apolloClient }: ReactionsContext) { const { $calculation } = store; @@ -119,47 +133,56 @@ export function commonReactions({ store, apolloClient }: ReactionsContext) { selectFinDepartment */ - reaction( - () => $calculation.element('selectDealerRewardCondition').getValue(), - async (rewardConditionId) => { - function fillAgents() { - const leadid = $calculation.element('selectLead').getValue(); - fillAgentsFromLead.fillIndAgent(store, apolloClient, leadid); - fillAgentsFromLead.fillCalcDoubleAgent(store, apolloClient, leadid); - fillAgentsFromLead.fillCalcBroker(store, apolloClient, leadid); - fillAgentsFromLead.fillFinDepartment(store, apolloClient, leadid); + { + const helper = new Helper(); + reaction( + () => $calculation.element('selectDealerRewardCondition').getValue(), + async (rewardConditionId) => { + function fillAgents() { + const leadid = $calculation.element('selectLead').getValue(); + fillAgentsFromLead.fillIndAgent(store, apolloClient, leadid); + fillAgentsFromLead.fillCalcDoubleAgent(store, apolloClient, leadid); + fillAgentsFromLead.fillCalcBroker(store, apolloClient, leadid); + fillAgentsFromLead.fillFinDepartment(store, apolloClient, leadid); + } + + if (!rewardConditionId) { + if (helper.enabled === true) { + helper.trigger(); + fillAgents(); + } + + return; + } + + const { + data: { evo_reward_condition }, + } = await apolloClient.query< + CRMTypes.GetRewardWithoutOtherAgentQuery, + CRMTypes.GetRewardWithoutOtherAgentQueryVariables + >({ + query: QUERY_GET_REWARD_WITHOUT_OTHER_AGENT, + variables: { + conditionId: rewardConditionId, + }, + }); + + if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) { + helper.trigger(); + + $calculation.element('selectDealerBroker').resetValue(); + $calculation.element('selectIndAgent').reset(); + $calculation.element('selectCalcDoubleAgent').reset(); + $calculation.element('selectCalcBroker').reset(); + $calculation.element('selectCalcFinDepartment').reset(); + } else { + helper.trigger(); + + fillAgents(); + } } - - if (!rewardConditionId) { - fillAgents(); - - return; - } - - const { - data: { evo_reward_condition }, - } = await apolloClient.query< - CRMTypes.GetRewardWithoutOtherAgentQuery, - CRMTypes.GetRewardWithoutOtherAgentQueryVariables - >({ - query: QUERY_GET_REWARD_WITHOUT_OTHER_AGENT, - variables: { - conditionId: rewardConditionId, - }, - }); - - if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) { - $calculation.element('selectDealerBroker').reset(); - $calculation.element('selectIndAgent').reset(); - $calculation.element('selectCalcDoubleAgent').reset(); - $calculation.element('selectCalcBroker').reset(); - $calculation.element('selectCalcFinDepartment').reset(); - } else { - fillAgents(); - } - } - ); - + ); + } /** * Добавить реакцию на изменение списка в поле selectDealerBrokerRewardCondition : @@ -181,48 +204,58 @@ export function commonReactions({ store, apolloClient }: ReactionsContext) { selectCalcBrokerRewardCondition заполняется значением из Интереса selectFinDepartmentRewardCondtion заполняется значением из Интереса */ - reaction( - () => $calculation.element('selectDealerBrokerRewardCondition').getValue(), - async (rewardConditionId) => { - function fillAgents() { - const leadid = $calculation.element('selectLead').getValue(); - fillAgentsFromLead.fillIndAgent(store, apolloClient, leadid); - fillAgentsFromLead.fillCalcDoubleAgent(store, apolloClient, leadid); - fillAgentsFromLead.fillCalcBroker(store, apolloClient, leadid); - fillAgentsFromLead.fillFinDepartment(store, apolloClient, leadid); + + { + const helper = new Helper(); + reaction( + () => $calculation.element('selectDealerBrokerRewardCondition').getValue(), + async (rewardConditionId) => { + function fillAgents() { + const leadid = $calculation.element('selectLead').getValue(); + fillAgentsFromLead.fillIndAgent(store, apolloClient, leadid); + fillAgentsFromLead.fillCalcDoubleAgent(store, apolloClient, leadid); + fillAgentsFromLead.fillCalcBroker(store, apolloClient, leadid); + fillAgentsFromLead.fillFinDepartment(store, apolloClient, leadid); + } + + if (!rewardConditionId) { + if (helper.enabled === true) { + helper.trigger(); + fillAgents(); + } + + return; + } + + const { + data: { evo_reward_condition }, + } = await apolloClient.query< + CRMTypes.GetRewardWithoutOtherAgentQuery, + CRMTypes.GetRewardWithoutOtherAgentQueryVariables + >({ + query: QUERY_GET_REWARD_WITHOUT_OTHER_AGENT, + variables: { + conditionId: rewardConditionId, + }, + }); + + if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) { + helper.trigger(); + + $calculation.element('selectDealerPerson').block(); + $calculation.element('selectIndAgent').reset(); + $calculation.element('selectCalcDoubleAgent').reset(); + $calculation.element('selectCalcBroker').reset(); + $calculation.element('selectCalcFinDepartment').reset(); + } else { + helper.trigger(); + + $calculation.element('selectDealerPerson').unblock(); + fillAgents(); + } } - - if (!rewardConditionId) { - fillAgents(); - - return; - } - - const { - data: { evo_reward_condition }, - } = await apolloClient.query< - CRMTypes.GetRewardWithoutOtherAgentQuery, - CRMTypes.GetRewardWithoutOtherAgentQueryVariables - >({ - query: QUERY_GET_REWARD_WITHOUT_OTHER_AGENT, - variables: { - conditionId: rewardConditionId, - }, - }); - - if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) { - $calculation.element('selectDealerPerson').block(); - $calculation.element('selectIndAgent').reset(); - $calculation.element('selectCalcDoubleAgent').reset(); - $calculation.element('selectCalcBroker').reset(); - $calculation.element('selectCalcFinDepartment').reset(); - } else { - $calculation.element('selectDealerPerson').unblock(); - fillAgents(); - } - } - ); - + ); + } /** * Добавить реакцию на изменение списка в поле selectIndAgentRewardCondition : @@ -245,46 +278,56 @@ export function commonReactions({ store, apolloClient }: ReactionsContext) { selectCalcFinDepartment заполняется значением из Интереса */ - reaction( - () => $calculation.element('selectIndAgentRewardCondition').getValue(), - async (rewardConditionId) => { - function fillAgents() { - const leadid = $calculation.element('selectLead').getValue(); - fillAgentsFromLead.fillCalcDoubleAgent(store, apolloClient, leadid); - fillAgentsFromLead.fillCalcBroker(store, apolloClient, leadid); - fillAgentsFromLead.fillFinDepartment(store, apolloClient, leadid); + { + const helper = new Helper(); + reaction( + () => $calculation.element('selectIndAgentRewardCondition').getValue(), + async (rewardConditionId) => { + function fillAgents() { + const leadid = $calculation.element('selectLead').getValue(); + fillAgentsFromLead.fillCalcDoubleAgent(store, apolloClient, leadid); + fillAgentsFromLead.fillCalcBroker(store, apolloClient, leadid); + fillAgentsFromLead.fillFinDepartment(store, apolloClient, leadid); + } + + if (!rewardConditionId) { + if (helper.enabled === true) { + helper.trigger(); + fillAgents(); + } + + return; + } + + const { + data: { evo_reward_condition }, + } = await apolloClient.query< + CRMTypes.GetRewardWithoutOtherAgentQuery, + CRMTypes.GetRewardWithoutOtherAgentQueryVariables + >({ + query: QUERY_GET_REWARD_WITHOUT_OTHER_AGENT, + variables: { + conditionId: rewardConditionId, + }, + }); + + if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) { + helper.trigger(); + + $calculation.element('selectDealerPerson').block(); + $calculation.element('selectDealerBroker').resetValue(); + $calculation.element('selectCalcDoubleAgent').reset(); + $calculation.element('selectCalcBroker').reset(); + $calculation.element('selectCalcFinDepartment').reset(); + } else { + helper.trigger(); + + $calculation.element('selectDealerPerson').unblock(); + fillAgents(); + } } - - if (!rewardConditionId) { - fillAgents(); - - return; - } - - const { - data: { evo_reward_condition }, - } = await apolloClient.query< - CRMTypes.GetRewardWithoutOtherAgentQuery, - CRMTypes.GetRewardWithoutOtherAgentQueryVariables - >({ - query: QUERY_GET_REWARD_WITHOUT_OTHER_AGENT, - variables: { - conditionId: rewardConditionId, - }, - }); - - if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) { - $calculation.element('selectDealerPerson').block(); - $calculation.element('selectDealerBroker').reset(); - $calculation.element('selectCalcDoubleAgent').reset(); - $calculation.element('selectCalcBroker').reset(); - $calculation.element('selectCalcFinDepartment').reset(); - } else { - $calculation.element('selectDealerPerson').unblock(); - fillAgents(); - } - } - ); + ); + } /** * Добавить реакцию на изменение списка в поле selectCalcDoubleAgentRewardCondition : @@ -308,48 +351,57 @@ export function commonReactions({ store, apolloClient }: ReactionsContext) { selectCalcFinDepartment заполняется значением из Интереса */ - reaction( - () => $calculation.element('selectCalcDoubleAgentRewardCondition').getValue(), - async (rewardConditionId) => { - function fillAgents() { - const leadid = $calculation.element('selectLead').getValue(); - fillAgentsFromLead.fillIndAgent(store, apolloClient, leadid); - fillAgentsFromLead.fillCalcBroker(store, apolloClient, leadid); - fillAgentsFromLead.fillFinDepartment(store, apolloClient, leadid); + { + const helper = new Helper(); + reaction( + () => $calculation.element('selectCalcDoubleAgentRewardCondition').getValue(), + async (rewardConditionId) => { + function fillAgents() { + const leadid = $calculation.element('selectLead').getValue(); + fillAgentsFromLead.fillIndAgent(store, apolloClient, leadid); + fillAgentsFromLead.fillCalcBroker(store, apolloClient, leadid); + fillAgentsFromLead.fillFinDepartment(store, apolloClient, leadid); + } + + if (!rewardConditionId) { + if (helper.enabled === true) { + helper.trigger(); + fillAgents(); + } + + return; + } + + const { + data: { evo_reward_condition }, + } = await apolloClient.query< + CRMTypes.GetRewardWithoutOtherAgentQuery, + CRMTypes.GetRewardWithoutOtherAgentQueryVariables + >({ + query: QUERY_GET_REWARD_WITHOUT_OTHER_AGENT, + variables: { + conditionId: rewardConditionId, + }, + }); + + if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) { + helper.trigger(); + + $calculation.element('selectDealerPerson').block(); + $calculation.element('selectDealerBroker').resetValue(); + $calculation.element('selectIndAgent').reset(); + $calculation.element('selectCalcBroker').reset(); + $calculation.element('selectCalcFinDepartment').reset(); + } else { + helper.trigger(); + + $calculation.element('selectDealerPerson').unblock(); + $calculation.element('selectDealerBroker').unblock(); + fillAgents(); + } } - - if (!rewardConditionId) { - fillAgents(); - - return; - } - - const { - data: { evo_reward_condition }, - } = await apolloClient.query< - CRMTypes.GetRewardWithoutOtherAgentQuery, - CRMTypes.GetRewardWithoutOtherAgentQueryVariables - >({ - query: QUERY_GET_REWARD_WITHOUT_OTHER_AGENT, - variables: { - conditionId: rewardConditionId, - }, - }); - - if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) { - $calculation.element('selectDealerPerson').block(); - $calculation.element('selectDealerBroker').reset(); - $calculation.element('selectIndAgent').reset(); - $calculation.element('selectCalcBroker').reset(); - $calculation.element('selectCalcFinDepartment').reset(); - } else { - $calculation.element('selectDealerPerson').unblock(); - $calculation.element('selectDealerBroker').unblock(); - fillAgents(); - } - } - ); - + ); + } /** * @description * Добавить реакцию на изменение списка в поле selectCalcBrokerRewardCondition: @@ -372,47 +424,57 @@ export function commonReactions({ store, apolloClient }: ReactionsContext) { selectCalcDoubleAgent заполняется значением из Интереса selectCalcFinDepartment заполняется значением из Интереса */ - reaction( - () => $calculation.element('selectCalcBrokerRewardCondition').getValue(), - async (rewardConditionId) => { - function fillAgents() { - const leadid = $calculation.element('selectLead').getValue(); - fillAgentsFromLead.fillIndAgent(store, apolloClient, leadid); - fillAgentsFromLead.fillCalcDoubleAgent(store, apolloClient, leadid); - fillAgentsFromLead.fillFinDepartment(store, apolloClient, leadid); + { + const helper = new Helper(); + reaction( + () => $calculation.element('selectCalcBrokerRewardCondition').getValue(), + async (rewardConditionId) => { + function fillAgents() { + const leadid = $calculation.element('selectLead').getValue(); + fillAgentsFromLead.fillIndAgent(store, apolloClient, leadid); + fillAgentsFromLead.fillCalcDoubleAgent(store, apolloClient, leadid); + fillAgentsFromLead.fillFinDepartment(store, apolloClient, leadid); + } + + if (!rewardConditionId) { + if (helper.enabled === true) { + helper.trigger(); + fillAgents(); + } + + return; + } + + const { + data: { evo_reward_condition }, + } = await apolloClient.query< + CRMTypes.GetRewardWithoutOtherAgentQuery, + CRMTypes.GetRewardWithoutOtherAgentQueryVariables + >({ + query: QUERY_GET_REWARD_WITHOUT_OTHER_AGENT, + variables: { + conditionId: rewardConditionId, + }, + }); + + if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) { + helper.trigger(); + + $calculation.element('selectDealerPerson').block(); + $calculation.element('selectDealerBroker').resetValue(); + $calculation.element('selectIndAgent').reset(); + $calculation.element('selectCalcDoubleAgent').reset(); + $calculation.element('selectCalcFinDepartment').reset(); + } else { + helper.trigger(); + + $calculation.element('selectDealerPerson').unblock(); + $calculation.element('selectDealerBroker').unblock(); + fillAgents(); + } } - - if (!rewardConditionId) { - fillAgents(); - - return; - } - - const { - data: { evo_reward_condition }, - } = await apolloClient.query< - CRMTypes.GetRewardWithoutOtherAgentQuery, - CRMTypes.GetRewardWithoutOtherAgentQueryVariables - >({ - query: QUERY_GET_REWARD_WITHOUT_OTHER_AGENT, - variables: { - conditionId: rewardConditionId, - }, - }); - - if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) { - $calculation.element('selectDealerPerson').block(); - $calculation.element('selectDealerBroker').reset(); - $calculation.element('selectIndAgent').reset(); - $calculation.element('selectCalcDoubleAgent').reset(); - $calculation.element('selectCalcFinDepartment').reset(); - } else { - $calculation.element('selectDealerPerson').unblock(); - $calculation.element('selectDealerBroker').unblock(); - fillAgents(); - } - } - ); + ); + } /** * Добавить реакцию на изменение списка в поле selectFinDepartmentRewardCondtion: @@ -436,47 +498,56 @@ export function commonReactions({ store, apolloClient }: ReactionsContext) { selectCalcBroker заполняется значением из Интереса */ - reaction( - () => $calculation.element('selectFinDepartmentRewardCondtion').getValue(), - async (rewardConditionId) => { - function fillAgents() { - const leadid = $calculation.element('selectLead').getValue(); - fillAgentsFromLead.fillIndAgent(store, apolloClient, leadid); - fillAgentsFromLead.fillCalcDoubleAgent(store, apolloClient, leadid); - fillAgentsFromLead.fillFinDepartment(store, apolloClient, leadid); + { + const helper = new Helper(); + reaction( + () => $calculation.element('selectFinDepartmentRewardCondtion').getValue(), + async (rewardConditionId) => { + function fillAgents() { + const leadid = $calculation.element('selectLead').getValue(); + fillAgentsFromLead.fillIndAgent(store, apolloClient, leadid); + fillAgentsFromLead.fillCalcDoubleAgent(store, apolloClient, leadid); + fillAgentsFromLead.fillFinDepartment(store, apolloClient, leadid); + } + + if (!rewardConditionId) { + if (helper.enabled === true) { + helper.trigger(); + fillAgents(); + } + + return; + } + const { + data: { evo_reward_condition }, + } = await apolloClient.query< + CRMTypes.GetRewardWithoutOtherAgentQuery, + CRMTypes.GetRewardWithoutOtherAgentQueryVariables + >({ + query: QUERY_GET_REWARD_WITHOUT_OTHER_AGENT, + variables: { + conditionId: rewardConditionId, + }, + }); + + if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) { + helper.trigger(); + + $calculation.element('selectDealerPerson').block(); + $calculation.element('selectDealerBroker').resetValue(); + $calculation.element('selectIndAgent').reset(); + $calculation.element('selectCalcDoubleAgent').reset(); + $calculation.element('selectCalcBroker').reset(); + } else { + helper.trigger(); + + $calculation.element('selectDealerPerson').unblock(); + $calculation.element('selectDealerBroker').unblock(); + fillAgents(); + } } - - if (!rewardConditionId) { - fillAgents(); - - return; - } - - const { - data: { evo_reward_condition }, - } = await apolloClient.query< - CRMTypes.GetRewardWithoutOtherAgentQuery, - CRMTypes.GetRewardWithoutOtherAgentQueryVariables - >({ - query: QUERY_GET_REWARD_WITHOUT_OTHER_AGENT, - variables: { - conditionId: rewardConditionId, - }, - }); - - if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) { - $calculation.element('selectDealerPerson').block(); - $calculation.element('selectDealerBroker').reset(); - $calculation.element('selectIndAgent').reset(); - $calculation.element('selectCalcDoubleAgent').reset(); - $calculation.element('selectCalcBroker').reset(); - } else { - $calculation.element('selectDealerPerson').unblock(); - $calculation.element('selectDealerBroker').unblock(); - fillAgents(); - } - } - ); + ); + } } export function validationReactions({ store, apolloClient }: ReactionsContext) {