diff --git a/apps/web/graphql/crm.query.graphql b/apps/web/graphql/crm.query.graphql index 67792ac..98b3c72 100644 --- a/apps/web/graphql/crm.query.graphql +++ b/apps/web/graphql/crm.query.graphql @@ -214,6 +214,7 @@ query GetLeaseObjectType($leaseObjectTypeId: Uuid!) { evo_leasingobject_type(evo_leasingobject_typeid: $leaseObjectTypeId) { evo_vehicle_type evo_id + evo_category } } diff --git a/apps/web/graphql/crm.types.ts b/apps/web/graphql/crm.types.ts index af6ce49..926f326 100644 --- a/apps/web/graphql/crm.types.ts +++ b/apps/web/graphql/crm.types.ts @@ -246,7 +246,7 @@ export type GetLeaseObjectTypeQueryVariables = Exact<{ }>; -export type GetLeaseObjectTypeQuery = { __typename?: 'Query', evo_leasingobject_type: { __typename?: 'evo_leasingobject_type', evo_vehicle_type: Array | null, evo_id: string | null } | null }; +export type GetLeaseObjectTypeQuery = { __typename?: 'Query', evo_leasingobject_type: { __typename?: 'evo_leasingobject_type', evo_vehicle_type: Array | null, evo_id: string | null, evo_category: number | null } | null }; export type GetBrandsQueryVariables = Exact<{ [key: string]: never; }>; @@ -483,7 +483,7 @@ export const GetImportProgramDocument = {"kind":"Document","definitions":[{"kind export const GetRegionsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetRegions"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_regions"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"evo_name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"evo_regionid"}}]}}]}}]} as unknown as DocumentNode; export const GetGpsBrandsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetGPSBrands"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_gps_brands"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"evo_name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"evo_gps_brandid"}}]}}]}}]} as unknown as DocumentNode; export const GetLeaseObjectTypesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetLeaseObjectTypes"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_leasingobject_types"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"evo_name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"evo_leasingobject_typeid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_leasingobject_typeid"}}]}}]}}]} as unknown as DocumentNode; -export const GetLeaseObjectTypeDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetLeaseObjectType"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"leaseObjectTypeId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_leasingobject_type"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"evo_leasingobject_typeid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"leaseObjectTypeId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_vehicle_type"}},{"kind":"Field","name":{"kind":"Name","value":"evo_id"}}]}}]}}]} as unknown as DocumentNode; +export const GetLeaseObjectTypeDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetLeaseObjectType"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"leaseObjectTypeId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_leasingobject_type"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"evo_leasingobject_typeid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"leaseObjectTypeId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_vehicle_type"}},{"kind":"Field","name":{"kind":"Name","value":"evo_id"}},{"kind":"Field","name":{"kind":"Name","value":"evo_category"}}]}}]}}]} as unknown as DocumentNode; export const GetBrandsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetBrands"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_brands"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"evo_name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"evo_brandid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_brandid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_vehicle_type"}}]}}]}}]} as unknown as DocumentNode; export const GetBrandDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetBrand"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"brandId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_brand"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"evo_brandid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"brandId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_importer_reward_perc"}},{"kind":"Field","name":{"kind":"Name","value":"evo_importer_reward_rub"}}]}}]}}]} as unknown as DocumentNode; export const GetModelsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetModels"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"brandId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_models"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}},{"kind":"Argument","name":{"kind":"Name","value":"evo_brandid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"brandId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"evo_name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"evo_modelid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_modelid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_vehicle_type"}}]}}]}}]} as unknown as DocumentNode; diff --git a/apps/web/process/leasing-object/reactions/common.ts b/apps/web/process/leasing-object/reactions/common.ts index 57ce289..9bb4c17 100644 --- a/apps/web/process/leasing-object/reactions/common.ts +++ b/apps/web/process/leasing-object/reactions/common.ts @@ -377,4 +377,32 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex } } ); + + reaction( + () => $calculation.element('selectLeaseObjectType').getValue(), + async (leaseObjectTypeId) => { + if (!leaseObjectTypeId) { + $calculation.element('selectLeaseObjectCategory').resetValue(); + + return; + } + + const { + data: { evo_leasingobject_type }, + } = await apolloClient.query({ + query: CRMTypes.GetLeaseObjectTypeDocument, + variables: { + leaseObjectTypeId, + }, + }); + + if (evo_leasingobject_type?.evo_category) { + $calculation + .element('selectLeaseObjectCategory') + .setValue(evo_leasingobject_type?.evo_category); + } else { + $calculation.element('selectLeaseObjectCategory').resetValue(); + } + } + ); } diff --git a/apps/web/process/leasing-object/reactions/validation.ts b/apps/web/process/leasing-object/reactions/validation.ts index 8eb1c7b..49c9e61 100644 --- a/apps/web/process/leasing-object/reactions/validation.ts +++ b/apps/web/process/leasing-object/reactions/validation.ts @@ -83,45 +83,82 @@ export default function validationReactions({ store, apolloClient }: ReactionsCo } ); - const validationHelper = new ValidationHelper(); + { + const validationHelper = new ValidationHelper(); - reaction( - () => $calculation.$values.getValues(['leaseObjectType', 'countSeats', 'maxMass']), - async ({ countSeats, leaseObjectType: leaseObjectTypeId, maxMass }) => { - if (!leaseObjectTypeId) { - validationHelper.removeErrors(); + reaction( + () => $calculation.$values.getValues(['leaseObjectType', 'countSeats', 'maxMass']), + async ({ countSeats, leaseObjectType: leaseObjectTypeId, maxMass }) => { + if (!leaseObjectTypeId) { + validationHelper.removeErrors(); - return; + return; + } + + const { + data: { evo_leasingobject_type }, + } = await apolloClient.query({ + query: CRMTypes.GetLeaseObjectTypeDocument, + variables: { + leaseObjectTypeId, + }, + }); + + $calculation.element('tbxCountSeats').validate({ + helper: validationHelper, + invalid: evo_leasingobject_type?.evo_id === '1' && countSeats >= 9, + message: 'Количество мест должно быть меньше 9', + }); + + $calculation.element('tbxCountSeats').validate({ + helper: validationHelper, + invalid: + (evo_leasingobject_type?.evo_id === '4' || evo_leasingobject_type?.evo_id === '5') && + countSeats <= 8, + message: 'Количество мест должно быть больше 8', + }); + + $calculation.element('tbxMaxMass').validate({ + helper: validationHelper, + invalid: evo_leasingobject_type?.evo_id === '2' && maxMass <= 0, + message: 'Не заполнено поле', + }); } + ); + } - const { - data: { evo_leasingobject_type }, - } = await apolloClient.query({ - query: CRMTypes.GetLeaseObjectTypeDocument, - variables: { - leaseObjectTypeId, - }, - }); + { + const validationHelper = new ValidationHelper(); - $calculation.element('tbxCountSeats').validate({ - helper: validationHelper, - invalid: evo_leasingobject_type?.evo_id === '1' && countSeats >= 9, - message: 'Количество мест должно быть меньше 9', - }); + reaction( + () => $calculation.$values.getValues(['leaseObjectType', 'leaseObjectCategory']), + async ({ leaseObjectCategory, leaseObjectType: leaseObjectTypeId }) => { + if (!leaseObjectTypeId) { + validationHelper.removeErrors(); - $calculation.element('tbxCountSeats').validate({ - helper: validationHelper, - invalid: - (evo_leasingobject_type?.evo_id === '4' || evo_leasingobject_type?.evo_id === '5') && - countSeats <= 8, - message: 'Количество мест должно быть больше 8', - }); + return; + } - $calculation.element('tbxMaxMass').validate({ - helper: validationHelper, - invalid: evo_leasingobject_type?.evo_id === '2' && maxMass <= 0, - message: 'Не заполнено поле', - }); - } - ); + const { + data: { evo_leasingobject_type }, + } = await apolloClient.query({ + query: CRMTypes.GetLeaseObjectTypeDocument, + variables: { + leaseObjectTypeId, + }, + }); + + $calculation.element('selectLeaseObjectCategory').validate({ + helper: validationHelper, + invalid: + !leaseObjectCategory && + Boolean( + evo_leasingobject_type?.evo_id && + !['6', '9', '10'].includes(evo_leasingobject_type?.evo_id) + ), + message: 'Не заполнено поле', + }); + } + ); + } }