Добавить фильтр для поля selectProduct (работает на загрузку КП)

* если  recalcWithRevision=True, то в списке поля selectProduct должны отображаться
   * записи quote.evo_baseproductid из поля Предложение selectQuote + дать возможность выбирать продукт,
   * связанный с оquote.evo_baseproductid из поля Предложение selectQuote по связи evo_evo_baseproduct_evo_baseproduct
This commit is contained in:
vchikalkin 2023-01-30 13:38:49 +03:00
parent aa711a3e37
commit fd116f89bb
3 changed files with 147 additions and 14 deletions

View File

@ -139,7 +139,7 @@ export type GetProduct_ProcessConfiguratorQueryVariables = Exact<{
}>;
export type GetProduct_ProcessConfiguratorQuery = { __typename?: 'Query', evo_baseproduct: { __typename?: 'evo_baseproduct', evo_calculation_method: Array<number> | null, evo_leasingobject_types: Array<{ __typename?: 'evo_leasingobject_type', evo_leasingobject_typeid: string | null } | null> | null } | null };
export type GetProduct_ProcessConfiguratorQuery = { __typename?: 'Query', evo_baseproduct: { __typename?: 'evo_baseproduct', evo_calculation_method: Array<number> | null, evo_leasingobject_types: Array<{ __typename?: 'evo_leasingobject_type', evo_leasingobject_typeid: string | null } | null> | null, evo_baseproducts: Array<{ __typename?: 'evo_baseproduct', evo_baseproductid: string | null } | null> | null } | null };
export type GetSubsidy_ProcessConfiguratorQueryVariables = Exact<{
subsidyId: Scalars['Uuid'];
@ -167,6 +167,20 @@ export type GetDealerPersons_ProcessConfiguratorQueryVariables = Exact<{
export type GetDealerPersons_ProcessConfiguratorQuery = { __typename?: 'Query', dealerPersons: Array<{ __typename?: 'account', accountid: string | null, label: string | null, value: string | null } | null> | null };
export type GetQuote_ProcessConfiguratorQueryVariables = Exact<{
quoteId: Scalars['Uuid'];
}>;
export type GetQuote_ProcessConfiguratorQuery = { __typename?: 'Query', quote: { __typename?: 'quote', evo_baseproductid: string | null } | null };
export type GetProducts_ProcessConfiguratorQueryVariables = Exact<{
currentDate: InputMaybe<Scalars['DateTime']>;
}>;
export type GetProducts_ProcessConfiguratorQuery = { __typename?: 'Query', evo_baseproducts: Array<{ __typename?: 'evo_baseproduct', evo_baseproductid: string | null } | null> | null };
export type GetTarifs_ProcessConfiguratorQueryVariables = Exact<{
currentDate: InputMaybe<Scalars['DateTime']>;
}>;
@ -195,12 +209,17 @@ export type GetInsuranceDataQueryVariables = Exact<{
export type GetInsuranceDataQuery = { __typename?: 'Query', osago: Array<{ __typename?: 'account', value: string | null, label: string | null } | null> | null, kasko: Array<{ __typename?: 'account', value: string | null, label: string | null } | null> | null, fingap: Array<{ __typename?: 'account', value: string | null, label: string | null } | null> | null };
export type GetMainOptionsQueryVariables = Exact<{
export type GetMainOptionsQueryVariables = Exact<{ [key: string]: never; }>;
export type GetMainOptionsQuery = { __typename?: 'Query', selectSupplierCurrency: Array<{ __typename?: 'transactioncurrency', currencysymbol: string | null, label: string | null, value: string | null } | null> | null, selectLeaseObjectType: Array<{ __typename?: 'evo_leasingobject_type', label: string | null, value: string | null } | null> | null, selectGPSBrand: Array<{ __typename?: 'evo_gps_brand', label: string | null, value: string | null } | null> | null };
export type GetProductsQueryVariables = Exact<{
currentDate: InputMaybe<Scalars['DateTime']>;
}>;
export type GetMainOptionsQuery = { __typename?: 'Query', selectSupplierCurrency: Array<{ __typename?: 'transactioncurrency', currencysymbol: string | null, label: string | null, value: string | null } | null> | null, selectProduct: Array<{ __typename?: 'evo_baseproduct', label: string | null, value: string | null } | null> | null, selectLeaseObjectType: Array<{ __typename?: 'evo_leasingobject_type', label: string | null, value: string | null } | null> | null, selectGPSBrand: Array<{ __typename?: 'evo_gps_brand', label: string | null, value: string | null } | null> | null };
export type GetProductsQuery = { __typename?: 'Query', selectProduct: Array<{ __typename?: 'evo_baseproduct', label: string | null, value: string | null } | null> | null };
export type GetSubsidiesQueryVariables = Exact<{
currentDate: InputMaybe<Scalars['DateTime']>;

View File

@ -1,5 +1,7 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { gql } from '@apollo/client';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import type * as CRMTypes from 'graphql/crm.types';
import { reaction } from 'mobx';
import { SEASON_TYPES } from 'process/payments/lib/seasons-constants';
@ -8,6 +10,8 @@ import { diff } from 'radash';
import { normalizeOptions } from 'tools';
import { QUERY_GET_TARIF } from '../lib/query';
dayjs.extend(utc);
const QUERY_GET_LEASE_OBJECT_TYPES = gql`
query GetLeaseObjectTypes_ProcessConfigurator {
evo_leasingobject_types(statecode: 0) {
@ -25,6 +29,9 @@ const QUERY_GET_PRODUCT = gql`
evo_leasingobject_typeid
}
evo_calculation_method
evo_baseproducts {
evo_baseproductid
}
}
}
`;
@ -75,6 +82,27 @@ const QUERY_GET_DEALER_PERSONS = gql`
}
`;
const QUERY_GET_QUOTE = gql`
query GetQuote_ProcessConfigurator($quoteId: Uuid!) {
quote(quoteId: $quoteId) {
evo_baseproductid
}
}
`;
const QUERY_GET_PRODUCTS = gql`
query GetProducts_ProcessConfigurator($currentDate: DateTime) {
evo_baseproducts(
statecode: 0
evo_relation: [100000000]
evo_datefrom_param: { lte: $currentDate }
evo_dateto_param: { gte: $currentDate }
) {
evo_baseproductid
}
}
`;
export default function commonReactions({ store, apolloClient }: ReactionsContext) {
const { $calculation } = store;
@ -388,4 +416,80 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex
}
}
);
/* eslint-disable max-len */
/**
* Добавить фильтр для поля selectProduct (работает на загрузку КП)
* если recalcWithRevision=True, то в списке поля selectProduct должны отображаться
* записи quote.evo_baseproductid из поля Предложение selectQuote + дать возможность выбирать продукт,
* связанный с оquote.evo_baseproductid из поля Предложение selectQuote по связи evo_evo_baseproduct_evo_baseproduct
/* eslint-enable */
reaction(
() => $calculation.element('selectQuote').getValue(),
async (quoteId) => {
const currentDate = dayjs().utc(false).toISOString();
const {
data: { evo_baseproducts },
} = await apolloClient.query<
CRMTypes.GetProducts_ProcessConfiguratorQuery,
CRMTypes.GetProducts_ProcessConfiguratorQueryVariables
>({
query: QUERY_GET_PRODUCTS,
variables: {
currentDate,
},
});
if (!$calculation.element('cbxRecalcWithRevision').getValue()) {
$calculation.element('selectProduct').setOptions(normalizeOptions(evo_baseproducts));
return;
}
let quote: CRMTypes.GetQuote_ProcessConfiguratorQuery['quote'] = null;
if (quoteId) {
const { data } = await apolloClient.query<
CRMTypes.GetQuote_ProcessConfiguratorQuery,
CRMTypes.GetQuote_ProcessConfiguratorQueryVariables
>({
query: QUERY_GET_QUOTE,
variables: {
quoteId,
},
});
({ quote } = data);
}
if (quote?.evo_baseproductid) {
const {
data: { evo_baseproduct },
} = await apolloClient.query<
CRMTypes.GetProduct_ProcessConfiguratorQuery,
CRMTypes.GetProduct_ProcessConfiguratorQueryVariables
>({
query: QUERY_GET_PRODUCT,
variables: {
productId: quote?.evo_baseproductid,
},
});
const allowedProducts = evo_baseproduct?.evo_baseproducts?.map(
(product) => product?.evo_baseproductid
);
const filteredSelectProductOptions = normalizeOptions(
evo_baseproducts?.filter((product) =>
allowedProducts?.includes(product?.evo_baseproductid)
)
);
$calculation.element('selectProduct').setOptions(filteredSelectProductOptions);
} else {
$calculation.element('selectProduct').setOptions(normalizeOptions(evo_baseproducts));
}
}
);
}

View File

@ -8,23 +8,13 @@ import { useStore } from 'stores/hooks';
dayjs.extend(utc);
const QUERY_GET_MAIN_OPTIONS = gql`
query GetMainOptions($currentDate: DateTime) {
query GetMainOptions {
selectSupplierCurrency: transactioncurrencies {
label: currencyname
currencysymbol
value: transactioncurrencyid
}
selectProduct: evo_baseproducts(
statecode: 0
evo_relation: [100000000]
evo_datefrom_param: { lte: $currentDate }
evo_dateto_param: { gte: $currentDate }
) {
label: evo_name
value: evo_baseproductid
}
selectLeaseObjectType: evo_leasingobject_types(statecode: 0) {
label: evo_name
value: evo_leasingobject_typeid
@ -37,6 +27,20 @@ const QUERY_GET_MAIN_OPTIONS = gql`
}
`;
const QUERY_GET_PRODUCTS = gql`
query GetProducts($currentDate: DateTime) {
selectProduct: evo_baseproducts(
statecode: 0
evo_relation: [100000000]
evo_datefrom_param: { lte: $currentDate }
evo_dateto_param: { gte: $currentDate }
) {
label: evo_name
value: evo_baseproductid
}
}
`;
const QUERY_GET_SUBSIDIES = gql`
query GetSubsidies($currentDate: DateTime) {
evo_subsidies(
@ -107,6 +111,12 @@ const currentDate = dayjs().utc(false).toISOString();
function getMainData(query, onCompleted) {
query({
query: QUERY_GET_MAIN_OPTIONS,
}).then(({ data }) => {
onCompleted(data);
});
query({
query: QUERY_GET_PRODUCTS,
variables: {
currentDate,
},