selectBrand: загрузка списка и фильтрация
This commit is contained in:
parent
b8539c4cc5
commit
ce4a8ad2c1
@ -231,33 +231,45 @@ export type GetQuoteUrlQueryVariables = Exact<{
|
||||
|
||||
export type GetQuoteUrlQuery = { __typename?: 'Query', entity: { __typename?: 'quote', link: string | null } | null };
|
||||
|
||||
export type GetModelsQueryVariables = Exact<{
|
||||
export type GetModels_ProcessLeasingObjectQueryVariables = Exact<{
|
||||
brandid: Scalars['Uuid'];
|
||||
}>;
|
||||
|
||||
|
||||
export type GetModelsQuery = { __typename?: 'Query', evo_models: Array<{ __typename?: 'evo_model', evo_modelid: string | null, evo_vehicle_type: number | null, label: string | null, value: string | null } | null> | null };
|
||||
export type GetModels_ProcessLeasingObjectQuery = { __typename?: 'Query', evo_models: Array<{ __typename?: 'evo_model', evo_modelid: string | null, evo_vehicle_type: number | null, label: string | null, value: string | null } | null> | null };
|
||||
|
||||
export type GetModelsFilterDataLeaseObjectTypeQueryVariables = Exact<{
|
||||
export type GetLeaseObjectType_ProcessLeasingObjectQueryVariables = Exact<{
|
||||
leaseObjectTypeId: Scalars['Uuid'];
|
||||
}>;
|
||||
|
||||
|
||||
export type GetModelsFilterDataLeaseObjectTypeQuery = { __typename?: 'Query', leaseObjectType: { __typename?: 'evo_leasingobject_type', evo_vehicle_type: Array<number> | null } | null };
|
||||
export type GetLeaseObjectType_ProcessLeasingObjectQuery = { __typename?: 'Query', leaseObjectType: { __typename?: 'evo_leasingobject_type', evo_vehicle_type: Array<number> | null } | null };
|
||||
|
||||
export type GetModelsFilterDataSubsidyQueryVariables = Exact<{
|
||||
export type GetSubsidy_ProcessLeasingObjectQueryVariables = Exact<{
|
||||
subsidyId: Scalars['Uuid'];
|
||||
}>;
|
||||
|
||||
|
||||
export type GetModelsFilterDataSubsidyQuery = { __typename?: 'Query', subsidy: { __typename?: 'evo_subsidy', evo_models: Array<{ __typename?: 'evo_model', evo_modelid: string | null } | null> | null } | null };
|
||||
export type GetSubsidy_ProcessLeasingObjectQuery = { __typename?: 'Query', subsidy: { __typename?: 'evo_subsidy', evo_brands: Array<{ __typename?: 'evo_brand', evo_brandid: string | null } | null> | null, evo_models: Array<{ __typename?: 'evo_model', evo_modelid: string | null } | null> | null } | null };
|
||||
|
||||
export type GetModelsFilterDataImportProgramQueryVariables = Exact<{
|
||||
export type GetImportProgram_ProcessLeasingObjectQueryVariables = Exact<{
|
||||
importProgramId: Scalars['Uuid'];
|
||||
}>;
|
||||
|
||||
|
||||
export type GetModelsFilterDataImportProgramQuery = { __typename?: 'Query', importProgram: { __typename?: 'evo_subsidy', evo_models: Array<{ __typename?: 'evo_model', evo_modelid: string | null } | null> | null } | null };
|
||||
export type GetImportProgram_ProcessLeasingObjectQuery = { __typename?: 'Query', importProgram: { __typename?: 'evo_subsidy', evo_brands: Array<{ __typename?: 'evo_brand', evo_brandid: string | null } | null> | null, evo_models: Array<{ __typename?: 'evo_model', evo_modelid: string | null } | null> | null } | null };
|
||||
|
||||
export type GetBrands_ProcessLeasingObjectQueryVariables = Exact<{ [key: string]: never; }>;
|
||||
|
||||
|
||||
export type GetBrands_ProcessLeasingObjectQuery = { __typename?: 'Query', evo_brands: Array<{ __typename?: 'evo_brand', evo_brandid: string | null, evo_vehicle_type: Array<number> | null, label: string | null, value: string | null } | null> | null };
|
||||
|
||||
export type GetProduct_ProcessLeasingObjectQueryVariables = Exact<{
|
||||
productId: Scalars['Uuid'];
|
||||
}>;
|
||||
|
||||
|
||||
export type GetProduct_ProcessLeasingObjectQuery = { __typename?: 'Query', evo_baseproduct: { __typename?: 'evo_baseproduct', evo_brands: Array<{ __typename?: 'evo_brand', evo_brandid: string | null } | null> | null } | null };
|
||||
|
||||
export type GetLeasingWithoutKaskoOptionsQueryVariables = Exact<{ [key: string]: never; }>;
|
||||
|
||||
|
||||
@ -3,10 +3,11 @@ import { gql } from '@apollo/client';
|
||||
import type * as CRMTypes from 'graphql/crm.types';
|
||||
import { autorun } from 'mobx';
|
||||
import type { ReactionsContext } from 'process/types';
|
||||
import { intersects } from 'radash';
|
||||
import { normalizeOptions } from 'tools';
|
||||
|
||||
const QUERY_GET_MODELS = gql`
|
||||
query GetModels($brandid: Uuid!) {
|
||||
query GetModels_ProcessLeasingObject($brandid: Uuid!) {
|
||||
evo_models(statecode: 0, evo_brandid: $brandid) {
|
||||
label: evo_name
|
||||
value: evo_modelid
|
||||
@ -17,7 +18,7 @@ const QUERY_GET_MODELS = gql`
|
||||
`;
|
||||
|
||||
const QUERY_GET_LEASE_OBJECT_TYPE = gql`
|
||||
query GetModelsFilterDataLeaseObjectType($leaseObjectTypeId: Uuid!) {
|
||||
query GetLeaseObjectType_ProcessLeasingObject($leaseObjectTypeId: Uuid!) {
|
||||
leaseObjectType: evo_leasingobject_type(evo_leasingobject_typeid: $leaseObjectTypeId) {
|
||||
evo_vehicle_type
|
||||
}
|
||||
@ -25,8 +26,11 @@ const QUERY_GET_LEASE_OBJECT_TYPE = gql`
|
||||
`;
|
||||
|
||||
const QUERY_GET_SUBSIDY = gql`
|
||||
query GetModelsFilterDataSubsidy($subsidyId: Uuid!) {
|
||||
query GetSubsidy_ProcessLeasingObject($subsidyId: Uuid!) {
|
||||
subsidy: evo_subsidy(evo_subsidyid: $subsidyId) {
|
||||
evo_brands {
|
||||
evo_brandid
|
||||
}
|
||||
evo_models {
|
||||
evo_modelid
|
||||
}
|
||||
@ -35,8 +39,11 @@ const QUERY_GET_SUBSIDY = gql`
|
||||
`;
|
||||
|
||||
const QUERY_GET_IMPORT_PROGRAM = gql`
|
||||
query GetModelsFilterDataImportProgram($importProgramId: Uuid!) {
|
||||
query GetImportProgram_ProcessLeasingObject($importProgramId: Uuid!) {
|
||||
importProgram: evo_subsidy(evo_subsidyid: $importProgramId) {
|
||||
evo_brands {
|
||||
evo_brandid
|
||||
}
|
||||
evo_models {
|
||||
evo_modelid
|
||||
}
|
||||
@ -44,6 +51,27 @@ const QUERY_GET_IMPORT_PROGRAM = gql`
|
||||
}
|
||||
`;
|
||||
|
||||
const QUERY_GET_BRANDS = gql`
|
||||
query GetBrands_ProcessLeasingObject {
|
||||
evo_brands(statecode: 0) {
|
||||
label: evo_name
|
||||
value: evo_brandid
|
||||
evo_brandid
|
||||
evo_vehicle_type
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const QUERY_GET_PRODUCT = gql`
|
||||
query GetProduct_ProcessLeasingObject($productId: Uuid!) {
|
||||
evo_baseproduct(evo_baseproductid: $productId) {
|
||||
evo_brands {
|
||||
evo_brandid
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export default function commonReactions({ store, apolloClient }: ReactionsContext) {
|
||||
const { $calculation } = store;
|
||||
|
||||
@ -63,7 +91,10 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex
|
||||
|
||||
const {
|
||||
data: { evo_models },
|
||||
} = await apolloClient.query<CRMTypes.GetModelsQuery, CRMTypes.GetModelsQueryVariables>({
|
||||
} = await apolloClient.query<
|
||||
CRMTypes.GetModels_ProcessLeasingObjectQuery,
|
||||
CRMTypes.GetModels_ProcessLeasingObjectQueryVariables
|
||||
>({
|
||||
query: QUERY_GET_MODELS,
|
||||
variables: {
|
||||
brandid: brandId,
|
||||
@ -82,8 +113,8 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex
|
||||
const {
|
||||
data: { leaseObjectType },
|
||||
} = await apolloClient.query<
|
||||
CRMTypes.GetModelsFilterDataLeaseObjectTypeQuery,
|
||||
CRMTypes.GetModelsFilterDataLeaseObjectTypeQueryVariables
|
||||
CRMTypes.GetLeaseObjectType_ProcessLeasingObjectQuery,
|
||||
CRMTypes.GetLeaseObjectType_ProcessLeasingObjectQueryVariables
|
||||
>({
|
||||
query: QUERY_GET_LEASE_OBJECT_TYPE,
|
||||
variables: {
|
||||
@ -107,8 +138,8 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex
|
||||
const {
|
||||
data: { subsidy },
|
||||
} = await apolloClient.query<
|
||||
CRMTypes.GetModelsFilterDataSubsidyQuery,
|
||||
CRMTypes.GetModelsFilterDataSubsidyQueryVariables
|
||||
CRMTypes.GetSubsidy_ProcessLeasingObjectQuery,
|
||||
CRMTypes.GetSubsidy_ProcessLeasingObjectQueryVariables
|
||||
>({
|
||||
query: QUERY_GET_SUBSIDY,
|
||||
variables: {
|
||||
@ -135,8 +166,8 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex
|
||||
const {
|
||||
data: { importProgram },
|
||||
} = await apolloClient.query<
|
||||
CRMTypes.GetModelsFilterDataImportProgramQuery,
|
||||
CRMTypes.GetModelsFilterDataImportProgramQueryVariables
|
||||
CRMTypes.GetImportProgram_ProcessLeasingObjectQuery,
|
||||
CRMTypes.GetImportProgram_ProcessLeasingObjectQueryVariables
|
||||
>({
|
||||
query: QUERY_GET_IMPORT_PROGRAM,
|
||||
variables: {
|
||||
@ -166,4 +197,148 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex
|
||||
delay: 10,
|
||||
}
|
||||
);
|
||||
|
||||
autorun(
|
||||
async () => {
|
||||
const {
|
||||
product: productId,
|
||||
subsidy: subsidyId,
|
||||
importProgram: importProgramId,
|
||||
leaseObjectType: leaseObjectTypeId,
|
||||
} = $calculation.$values.values;
|
||||
|
||||
const {
|
||||
data: { evo_brands },
|
||||
} = await apolloClient.query<
|
||||
CRMTypes.GetBrands_ProcessLeasingObjectQuery,
|
||||
CRMTypes.GetBrands_ProcessLeasingObjectQueryVariables
|
||||
>({
|
||||
query: QUERY_GET_BRANDS,
|
||||
});
|
||||
|
||||
let brands = evo_brands;
|
||||
|
||||
if (!brands) {
|
||||
$calculation.element('selectBrand').reset();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (productId) {
|
||||
const {
|
||||
data: { evo_baseproduct },
|
||||
} = await apolloClient.query<
|
||||
CRMTypes.GetProduct_ProcessLeasingObjectQuery,
|
||||
CRMTypes.GetProduct_ProcessLeasingObjectQueryVariables
|
||||
>({
|
||||
query: QUERY_GET_PRODUCT,
|
||||
variables: {
|
||||
productId,
|
||||
},
|
||||
});
|
||||
|
||||
brands = brands?.filter((brand) => {
|
||||
if (
|
||||
!evo_baseproduct?.evo_brands?.length ||
|
||||
evo_baseproduct.evo_brands.filter(
|
||||
(baseproduct_evo_brand) => baseproduct_evo_brand?.evo_brandid === brand?.evo_brandid
|
||||
)?.length
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
if (leaseObjectTypeId) {
|
||||
const {
|
||||
data: { leaseObjectType },
|
||||
} = await apolloClient.query<
|
||||
CRMTypes.GetLeaseObjectType_ProcessLeasingObjectQuery,
|
||||
CRMTypes.GetLeaseObjectType_ProcessLeasingObjectQueryVariables
|
||||
>({
|
||||
query: QUERY_GET_LEASE_OBJECT_TYPE,
|
||||
variables: {
|
||||
leaseObjectTypeId,
|
||||
},
|
||||
});
|
||||
|
||||
brands = brands?.filter((brand) => {
|
||||
if (
|
||||
brand?.evo_vehicle_type?.length &&
|
||||
leaseObjectType?.evo_vehicle_type &&
|
||||
intersects(
|
||||
brand.evo_vehicle_type?.filter((x) => x > 0),
|
||||
leaseObjectType?.evo_vehicle_type
|
||||
)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
if (subsidyId) {
|
||||
const {
|
||||
data: { subsidy },
|
||||
} = await apolloClient.query<
|
||||
CRMTypes.GetSubsidy_ProcessLeasingObjectQuery,
|
||||
CRMTypes.GetSubsidy_ProcessLeasingObjectQueryVariables
|
||||
>({
|
||||
query: QUERY_GET_SUBSIDY,
|
||||
variables: {
|
||||
subsidyId,
|
||||
},
|
||||
});
|
||||
|
||||
brands = brands?.filter((brand) => {
|
||||
if (
|
||||
!subsidy?.evo_brands?.length ||
|
||||
subsidy?.evo_brands?.filter(
|
||||
(subsidy_evo_brand) => subsidy_evo_brand?.evo_brandid === brand?.evo_brandid
|
||||
)?.length
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
if (importProgramId) {
|
||||
const {
|
||||
data: { importProgram },
|
||||
} = await apolloClient.query<
|
||||
CRMTypes.GetImportProgram_ProcessLeasingObjectQuery,
|
||||
CRMTypes.GetImportProgram_ProcessLeasingObjectQueryVariables
|
||||
>({
|
||||
query: QUERY_GET_IMPORT_PROGRAM,
|
||||
variables: {
|
||||
importProgramId,
|
||||
},
|
||||
});
|
||||
|
||||
brands = brands?.filter((brand) => {
|
||||
if (
|
||||
!importProgram?.evo_brands?.length ||
|
||||
importProgram?.evo_brands?.filter(
|
||||
(importProgram_evo_brand) =>
|
||||
importProgram_evo_brand?.evo_brandid === brand?.evo_brandid
|
||||
)?.length
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
$calculation.element('selectBrand').setOptions(normalizeOptions(brands));
|
||||
},
|
||||
{
|
||||
delay: 10,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user