diff --git a/process/lead-opportunity/reactions/__generated__/GetQuotesByLead.ts b/process/lead-opportunity/reactions/__generated__/GetQuotesByLead.ts new file mode 100644 index 0000000..8475ce0 --- /dev/null +++ b/process/lead-opportunity/reactions/__generated__/GetQuotesByLead.ts @@ -0,0 +1,25 @@ +/* tslint:disable */ +/* eslint-disable */ +// @generated +// This file was automatically generated and should not be edited. + +// ==================================================== +// GraphQL query operation: GetQuotesByLead +// ==================================================== + +export interface GetQuotesByLead_quotes { + __typename: "quote"; + label: string | null; + value: any | null; +} + +export interface GetQuotesByLead { + /** + * Предложения. statecode по умолчанию 0, можно отфильтровать по ownerid и/или domainName + */ + quotes: (GetQuotesByLead_quotes | null)[] | null; +} + +export interface GetQuotesByLeadVariables { + leadid: any; +} diff --git a/process/lead-opportunity/reactions/common.ts b/process/lead-opportunity/reactions/common.ts index fa998d6..5f634b2 100644 --- a/process/lead-opportunity/reactions/common.ts +++ b/process/lead-opportunity/reactions/common.ts @@ -2,8 +2,10 @@ import type { ApolloClient } from '@apollo/client'; import { gql } from '@apollo/client'; import { reaction } from 'mobx'; import type RootStore from 'stores/root'; +import { normalizeOptions } from 'tools/entity'; import type { GetLeadidByOpportunity } from './__generated__/GetLeadidByOpportunity'; import type { GetOpportunityByLead } from './__generated__/GetOpportunityByLead'; +import type { GetQuotesByLead } from './__generated__/GetQuotesByLead'; export default function commonReactions(store: RootStore, apolloClient: ApolloClient) { const { $calculation } = store; @@ -98,4 +100,40 @@ export default function commonReactions(store: RootStore, apolloClient: ApolloCl } } ); + + /** + * Если lead содержит данные, + То в quote подгружается список Предложений CRM (сущность quote), + у которых в поле Интерес (quote.evo_leadid) записана ссылка на выбранный интерес. + Иначе очищать поле калькулятора quote. + */ + + const QUERY_GET_QUOTES_BY_LEAD = gql` + query GetQuotesByLead($leadid: Uuid!) { + quotes(evo_leadid: $leadid) { + label: evo_quotename + value: quoteid + } + } + `; + + reaction( + () => $calculation.getElementValue('selectLead'), + async (leadid) => { + if (leadid) { + const { + data: { quotes }, + } = await apolloClient.query({ + query: QUERY_GET_QUOTES_BY_LEAD, + variables: { + leadid, + }, + }); + + $calculation.$options.setElementOptions('selectQuote', normalizeOptions(quotes)); + } else { + $calculation.resetElement('selectQuote'); + } + } + ); }