process/lead-opportunity:

Если lead содержит данные, то в opportunity подгружается значение из поля Интереса
   * Лизинговая сделка (lead.evo_opportunityid → opportunity),
   * и в списке для выбора только эта ЛС указывается
   * Иначе  ничего не указывается
This commit is contained in:
vchikalkin 2022-07-12 17:29:30 +03:00
parent 5dacb4d526
commit df5037d873
4 changed files with 89 additions and 0 deletions

View File

@ -51,6 +51,7 @@ function Home() {
*/
setTimeout(() => {
leadOpportunityReactions.common(store, apolloClient);
leadOpportunityReactions.urls(store, apolloClient);
paymentsReactions(store, apolloClient);
calculateReactions.validation(store, apolloClient);

View File

@ -0,0 +1,30 @@
/* tslint:disable */
/* eslint-disable */
// @generated
// This file was automatically generated and should not be edited.
// ====================================================
// GraphQL query operation: GetOpportunityByLead
// ====================================================
export interface GetOpportunityByLead_lead_evo_opportunityidData {
__typename: "opportunity";
label: string | null;
value: any | null;
}
export interface GetOpportunityByLead_lead {
__typename: "lead";
evo_opportunityidData: GetOpportunityByLead_lead_evo_opportunityidData | null;
}
export interface GetOpportunityByLead {
/**
* Лизинговые сделки. statecode по умолчанию 0, можно отфильтровать по ownerid и/или domainName
*/
lead: GetOpportunityByLead_lead | null;
}
export interface GetOpportunityByLeadVariables {
leadid: any;
}

View File

@ -0,0 +1,57 @@
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 { GetOpportunityByLead } from './__generated__/GetOpportunityByLead';
export default function commonReactions(store: RootStore, apolloClient: ApolloClient<object>) {
const { $calculation } = store;
const QUERY_GET_OPPORTUNITY = gql`
query GetOpportunityByLead($leadid: Uuid!) {
lead(leadid: $leadid) {
evo_opportunityidData {
label: name
value: opportunityid
}
}
}
`;
/**
* Если lead содержит данные, то в opportunity подгружается значение из поля Интереса
* Лизинговая сделка (lead.evo_opportunityid opportunity),
* и в списке для выбора только эта ЛС указывается
* Иначе ничего не указывается
*/
reaction(
() => $calculation.getElementValue('selectLead'),
async (leadid) => {
if (!leadid) {
$calculation.resetElement('selectOpportunity');
return;
}
const {
data: { lead },
} = await apolloClient.query<GetOpportunityByLead>({
query: QUERY_GET_OPPORTUNITY,
variables: {
leadid,
},
});
if (lead?.evo_opportunityidData) {
$calculation.$options.setElementOptions(
'selectOpportunity',
normalizeOptions([lead.evo_opportunityidData])
);
$calculation.setElementValue('selectOpportunity', lead.evo_opportunityidData.value);
} else {
$calculation.resetElement('selectOpportunity');
}
}
);
}

View File

@ -1,2 +1,3 @@
/* eslint-disable import/prefer-default-export */
export { default as common } from './common';
export { default as urls } from './urls';