process/agents: fill selectDealerPerson & selectDealerBroker
This commit is contained in:
parent
d4330b8edb
commit
0f23662df0
@ -5,6 +5,7 @@ import type { Elements } from 'Components/Calculation/config/map/values';
|
||||
import type RootStore from 'stores/root';
|
||||
import { normalizeOptions } from 'tools/entity';
|
||||
import QUERY_GET_AGENT from './query/get-agent';
|
||||
import QUERY_GET_BROKER_ACCOUNTID from './query/get-broker-accountid';
|
||||
import type { GetAgent } from './query/__generated__/GetAgent';
|
||||
|
||||
function makeFillAgent(
|
||||
@ -99,14 +100,6 @@ export const fillCalcDoubleAgent = makeFillAgent(
|
||||
* иначе очищать поле калькулятора calcBroker
|
||||
*/
|
||||
|
||||
const QUERY_GET_BROKER_ACCOUNTID = gql`
|
||||
query GetBrokerAccountId($leadid: Uuid!) {
|
||||
lead(leadid: $leadid) {
|
||||
agentid: evo_broker_accountid
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const fillCalcBroker = makeFillAgent(
|
||||
'selectCalcBroker',
|
||||
QUERY_GET_BROKER_ACCOUNTID,
|
||||
|
||||
11
process/agents/lib/query/get-broker-accountid.js
Normal file
11
process/agents/lib/query/get-broker-accountid.js
Normal file
@ -0,0 +1,11 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
const QUERY_GET_BROKER_ACCOUNTID = gql`
|
||||
query GetBrokerAccountId($leadid: Uuid!) {
|
||||
lead(leadid: $leadid) {
|
||||
agentid: evo_broker_accountid
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export default QUERY_GET_BROKER_ACCOUNTID;
|
||||
21
process/agents/reactions/__generated__/GetBrokerAccountIdFromDealer.ts
generated
Normal file
21
process/agents/reactions/__generated__/GetBrokerAccountIdFromDealer.ts
generated
Normal file
@ -0,0 +1,21 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @generated
|
||||
// This file was automatically generated and should not be edited.
|
||||
|
||||
// ====================================================
|
||||
// GraphQL query operation: GetBrokerAccountIdFromDealer
|
||||
// ====================================================
|
||||
|
||||
export interface GetBrokerAccountIdFromDealer_dealer {
|
||||
__typename: "account";
|
||||
evo_broker_accountid: any | null;
|
||||
}
|
||||
|
||||
export interface GetBrokerAccountIdFromDealer {
|
||||
dealer: GetBrokerAccountIdFromDealer_dealer | null;
|
||||
}
|
||||
|
||||
export interface GetBrokerAccountIdFromDealerVariables {
|
||||
dealerId: any;
|
||||
}
|
||||
25
process/agents/reactions/__generated__/GetDealerPerson.ts
generated
Normal file
25
process/agents/reactions/__generated__/GetDealerPerson.ts
generated
Normal file
@ -0,0 +1,25 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @generated
|
||||
// This file was automatically generated and should not be edited.
|
||||
|
||||
// ====================================================
|
||||
// GraphQL query operation: GetDealerPerson
|
||||
// ====================================================
|
||||
|
||||
export interface GetDealerPerson_salon_providers {
|
||||
__typename: "account";
|
||||
label: string | null;
|
||||
value: any | null;
|
||||
}
|
||||
|
||||
export interface GetDealerPerson {
|
||||
/**
|
||||
* Поставщики ЮЛ салона. statecode по умолчанию 0
|
||||
*/
|
||||
salon_providers: (GetDealerPerson_salon_providers | null)[] | null;
|
||||
}
|
||||
|
||||
export interface GetDealerPersonVariables {
|
||||
dealerId: any;
|
||||
}
|
||||
@ -1,10 +1,20 @@
|
||||
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 * as fillAgentsFromLead from '../lib/fill-agents-from-lead';
|
||||
import QUERY_GET_AGENT from '../lib/query/get-agent';
|
||||
import type { GetAgent } from '../lib/query/__generated__/GetAgent';
|
||||
import type { GetBrokerAccountIdFromDealer } from './__generated__/GetBrokerAccountIdFromDealer';
|
||||
import type { GetDealerPerson } from './__generated__/GetDealerPerson';
|
||||
|
||||
export default function commonReactions(store: RootStore, apolloClient: ApolloClient<object>) {
|
||||
const { $calculation } = store;
|
||||
|
||||
/**
|
||||
* Заполняем агентов из Интереса
|
||||
*/
|
||||
reaction(
|
||||
() => $calculation.getElementValue('selectLead'),
|
||||
(leadid) => {
|
||||
@ -14,4 +24,100 @@ export default function commonReactions(store: RootStore, apolloClient: ApolloCl
|
||||
fillAgentsFromLead.fillFinDepartment(store, apolloClient, leadid);
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* Заполняем selectDealerPerson
|
||||
* На изменение Салон приобретения формируем список в поле ЮЛ поставщика - записи Контрагент,
|
||||
* у которых статус = активный И Поставщик = Да И Тип поставщика = Юридическое лицо
|
||||
* И связаны с карточкой Контрагент из поля "Салон приобретения" по связи Салон-ЮЛ
|
||||
*/
|
||||
|
||||
const QUERY_GET_DEALER_PERSON = gql`
|
||||
query GetDealerPerson($dealerId: Uuid!) {
|
||||
salon_providers(statecode: 0, salonaccountid: $dealerId) {
|
||||
label: name
|
||||
value: accountid
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
reaction(
|
||||
() => $calculation.getElementValue('selectDealer'),
|
||||
async (dealerId) => {
|
||||
if (!dealerId) {
|
||||
$calculation.resetElement('selectDealerPerson');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const {
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
data: { salon_providers },
|
||||
} = await apolloClient.query<GetDealerPerson>({
|
||||
query: QUERY_GET_DEALER_PERSON,
|
||||
variables: {
|
||||
dealerId,
|
||||
},
|
||||
});
|
||||
|
||||
if (salon_providers?.length) {
|
||||
$calculation.setElementOptions('selectDealerPerson', normalizeOptions(salon_providers));
|
||||
$calculation.setElementValue('selectDealerPerson', salon_providers[0]?.value);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* Заполняем selectDealerBroker
|
||||
*/
|
||||
|
||||
const QUERY_GET_BROKER_ACCOUNTID = gql`
|
||||
query GetBrokerAccountIdFromDealer($dealerId: Uuid!) {
|
||||
dealer: account(accountid: $dealerId) {
|
||||
evo_broker_accountid
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
reaction(
|
||||
() => $calculation.getElementValue('selectDealerPerson'),
|
||||
async (dealerPersonId) => {
|
||||
if (!dealerPersonId) {
|
||||
$calculation.resetElement('selectDealerBroker');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// prettier-ignore
|
||||
const { data: { dealer } } = await apolloClient.query<GetBrokerAccountIdFromDealer>({
|
||||
query: QUERY_GET_BROKER_ACCOUNTID,
|
||||
variables: {
|
||||
dealerId: dealerPersonId,
|
||||
},
|
||||
});
|
||||
|
||||
if (dealer?.evo_broker_accountid) {
|
||||
// prettier-ignore
|
||||
const { data: { agent: dealerBroker } } = await apolloClient.query<GetAgent>({
|
||||
query: QUERY_GET_AGENT,
|
||||
variables: {
|
||||
agentid: dealer?.evo_broker_accountid,
|
||||
},
|
||||
});
|
||||
|
||||
if (dealerBroker) {
|
||||
$calculation.setElementOptions('selectDealerBroker', normalizeOptions([dealerBroker]));
|
||||
$calculation.setElementValue('selectDealerBroker', dealerBroker.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* Заполняем selectDealerRewardCondition
|
||||
*/
|
||||
|
||||
/**
|
||||
* Заполняем selectDealerBrokerRewardCondition
|
||||
*/
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ export default class CalculationStore {
|
||||
|
||||
resetElement = (elementName: Values.Elements) => {
|
||||
this.resetElementValue(elementName);
|
||||
this.$options.resetOption(elementName);
|
||||
this.$options.resetOptions(elementName);
|
||||
this.$status.resetStatus(elementName);
|
||||
this.$validation.clearErrors(elementName);
|
||||
};
|
||||
@ -60,6 +60,10 @@ export default class CalculationStore {
|
||||
this.$options.setOptions(elementName, options);
|
||||
};
|
||||
|
||||
resetElementOptions = <T extends Values.Elements>(elementName: T) => {
|
||||
this.$options.resetOptions(elementName);
|
||||
};
|
||||
|
||||
getElementOption<T extends Values.Elements>(elementName: T) {
|
||||
const value = this.getElementValue(elementName);
|
||||
|
||||
|
||||
@ -40,6 +40,20 @@ export default class OptionsStore {
|
||||
return options;
|
||||
}
|
||||
|
||||
private checkValueInOptions = (elementName: Elements) => {
|
||||
/**
|
||||
* Проверяем, что значение есть в новом списке, иначе сбрасываем значение
|
||||
*/
|
||||
const value = this.root.$calculation.getElementValue(elementName);
|
||||
if (
|
||||
// eslint-disable-next-line operator-linebreak
|
||||
!this.options[elementName]?.length ||
|
||||
this.options[elementName].some((x) => x.value === value)
|
||||
) {
|
||||
this.root.$calculation.resetElementValue(elementName);
|
||||
}
|
||||
};
|
||||
|
||||
setOptions = <T extends Elements>(elementName: T, options: BaseOption<ElementsTypes[T]>[]) => {
|
||||
/**
|
||||
* TODO: use T instead of any in BaseOption type
|
||||
@ -48,13 +62,7 @@ export default class OptionsStore {
|
||||
*/
|
||||
this.options[elementName] = options as BaseOption<any>[];
|
||||
|
||||
/**
|
||||
* Проверяем, что значение есть в новом списке, иначе сбрасываем значение
|
||||
*/
|
||||
const value = this.root.$calculation.getElementValue(elementName);
|
||||
if (!options?.length || options.some((x) => x.value === value)) {
|
||||
this.root.$calculation.resetElementValue(elementName);
|
||||
}
|
||||
this.checkValueInOptions(elementName);
|
||||
|
||||
/**
|
||||
* Если в новом списке одна запись, то указываем ее
|
||||
@ -69,8 +77,9 @@ export default class OptionsStore {
|
||||
}
|
||||
};
|
||||
|
||||
resetOption = <T extends Elements>(elementName: T) => {
|
||||
resetOptions = <T extends Elements>(elementName: T) => {
|
||||
this.options[elementName] = defaultOptions[elementName];
|
||||
this.checkValueInOptions(elementName);
|
||||
};
|
||||
|
||||
setManyOptions = (
|
||||
@ -81,7 +90,7 @@ export default class OptionsStore {
|
||||
(Object.keys(defaultOptions) as Elements[])
|
||||
.filter((elementName) => !settings?.exclude.includes(elementName))
|
||||
.forEach((elementName) => {
|
||||
this.resetOption(elementName);
|
||||
this.resetOptions(elementName);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user