process/agents: fill calcDoubleAgent
This commit is contained in:
parent
a24b62739d
commit
efa9002c8b
22
process/agents/lib/__generated__/GetDoubleAgent.ts
generated
Normal file
22
process/agents/lib/__generated__/GetDoubleAgent.ts
generated
Normal file
@ -0,0 +1,22 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @generated
|
||||
// This file was automatically generated and should not be edited.
|
||||
|
||||
// ====================================================
|
||||
// GraphQL query operation: GetDoubleAgent
|
||||
// ====================================================
|
||||
|
||||
export interface GetDoubleAgent_doubleAgent {
|
||||
__typename: "account";
|
||||
label: string | null;
|
||||
value: any | null;
|
||||
}
|
||||
|
||||
export interface GetDoubleAgent {
|
||||
doubleAgent: GetDoubleAgent_doubleAgent | null;
|
||||
}
|
||||
|
||||
export interface GetDoubleAgentVariables {
|
||||
evo_double_agent_accountid: any;
|
||||
}
|
||||
24
process/agents/lib/__generated__/GetDoubleAgentAccountId.ts
generated
Normal file
24
process/agents/lib/__generated__/GetDoubleAgentAccountId.ts
generated
Normal file
@ -0,0 +1,24 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @generated
|
||||
// This file was automatically generated and should not be edited.
|
||||
|
||||
// ====================================================
|
||||
// GraphQL query operation: GetDoubleAgentAccountId
|
||||
// ====================================================
|
||||
|
||||
export interface GetDoubleAgentAccountId_lead {
|
||||
__typename: "lead";
|
||||
evo_double_agent_accountid: any | null;
|
||||
}
|
||||
|
||||
export interface GetDoubleAgentAccountId {
|
||||
/**
|
||||
* Лизинговые сделки. statecode по умолчанию 0, можно отфильтровать по ownerid и/или domainName
|
||||
*/
|
||||
lead: GetDoubleAgentAccountId_lead | null;
|
||||
}
|
||||
|
||||
export interface GetDoubleAgentAccountIdVariables {
|
||||
leadid: any;
|
||||
}
|
||||
@ -5,7 +5,15 @@ import type RootStore from 'stores/root';
|
||||
import { normalizeOptions } from 'tools/entity';
|
||||
import type { GetAgent } from './__generated__/GetAgent';
|
||||
import type { GetAgentAccountId } from './__generated__/GetAgentAccountId';
|
||||
import type { GetDoubleAgent } from './__generated__/GetDoubleAgent';
|
||||
import type { GetDoubleAgentAccountId } from './__generated__/GetDoubleAgentAccountId';
|
||||
|
||||
/**
|
||||
* Если lead содержит данные,
|
||||
* то indAgent заполняется ссылкой на карточку Контрагент (account),
|
||||
* записанную в поле Интереса "Агент" (lead.evo_agent_accountid → account),
|
||||
* иначе очищать поле калькулятора indAgent
|
||||
*/
|
||||
const QUERY_GET_AGENT_ACCOUNTID = gql`
|
||||
query GetAgentAccountId($leadid: Uuid!) {
|
||||
lead(leadid: $leadid) {
|
||||
@ -61,3 +69,68 @@ export async function fillIndAgent(
|
||||
$calculation.resetElement('selectIndAgent');
|
||||
}
|
||||
}
|
||||
|
||||
const QUERY_GET_DOUBLE_AGENT_ACCOUNTID = gql`
|
||||
query GetDoubleAgentAccountId($leadid: Uuid!) {
|
||||
lead(leadid: $leadid) {
|
||||
evo_double_agent_accountid
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const QUERY_GET_DOUBLE_AGENT = gql`
|
||||
query GetDoubleAgent($evo_double_agent_accountid: Uuid!) {
|
||||
doubleAgent: account(accountid: $evo_double_agent_accountid) {
|
||||
label: name
|
||||
value: accountid
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
/**
|
||||
* Если lead содержит данные,
|
||||
* то calcDoubleAgent заполняется ссылкой на карточку Контрагент (account),
|
||||
* записанную в поле Интереса "Двойной агент" (lead.evo_double_agent_accountid → account)
|
||||
* иначе очищать поле калькулятора calcDoubleAgent
|
||||
*/
|
||||
export async function fillCalcDoubleAgent(
|
||||
{ $calculation }: RootStore,
|
||||
apolloClient: ApolloClient<object>,
|
||||
leadid: string | null
|
||||
) {
|
||||
if (!leadid) {
|
||||
$calculation.resetElement('selectCalcDoubleAgent');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const {
|
||||
data: { lead },
|
||||
} = await apolloClient.query<GetDoubleAgentAccountId>({
|
||||
query: QUERY_GET_DOUBLE_AGENT_ACCOUNTID,
|
||||
variables: {
|
||||
leadid,
|
||||
},
|
||||
});
|
||||
|
||||
if (lead?.evo_double_agent_accountid) {
|
||||
const {
|
||||
data: { doubleAgent },
|
||||
} = await apolloClient.query<GetDoubleAgent>({
|
||||
query: QUERY_GET_DOUBLE_AGENT,
|
||||
variables: {
|
||||
evo_double_agent_accountid: lead.evo_double_agent_accountid,
|
||||
},
|
||||
});
|
||||
|
||||
if (doubleAgent) {
|
||||
$calculation.$options.setElementOptions(
|
||||
'selectCalcDoubleAgent',
|
||||
normalizeOptions([doubleAgent])
|
||||
);
|
||||
$calculation.setElementValue('selectCalcDoubleAgent', doubleAgent.value);
|
||||
}
|
||||
} else {
|
||||
$calculation.resetElement('selectCalcDoubleAgent');
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import type { ApolloClient } from '@apollo/client';
|
||||
import { reaction } from 'mobx';
|
||||
import type RootStore from 'stores/root';
|
||||
import { fillIndAgent } from '../lib/fill-agents-from-lead';
|
||||
import { fillCalcDoubleAgent, fillIndAgent } from '../lib/fill-agents-from-lead';
|
||||
|
||||
export default function commonReactions(store: RootStore, apolloClient: ApolloClient<object>) {
|
||||
const { $calculation } = store;
|
||||
@ -9,6 +9,7 @@ export default function commonReactions(store: RootStore, apolloClient: ApolloCl
|
||||
() => $calculation.getElementValue('selectLead'),
|
||||
(leadid) => {
|
||||
fillIndAgent(store, apolloClient, leadid);
|
||||
fillCalcDoubleAgent(store, apolloClient, leadid);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user