From 39dc4bfa9e51a4cca761ffa5fe0657ff306f790c Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Fri, 19 Apr 2024 13:30:15 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=20=D1=80=D0=B5=D0=B0=D0=BA=D1=86=D0=B8?= =?UTF-8?q?=D1=8E=20=D0=B3=D0=B4=D0=B5=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D1=8F=D0=B5=D1=82=D1=81=D1=8F/=D1=84=D0=BE=D1=80=D0=BC?= =?UTF-8?q?=D0=B8=D1=80=D1=83=D0=B5=D1=82=D1=81=D1=8F=20=D1=81=D0=BF=D0=B8?= =?UTF-8?q?=D1=81=D0=BE=D0=BA=20=D0=B2=20=D0=BF=D0=BE=D0=BB=D0=B5=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D1=82=D0=B0=20=D1=82=D0=B5=D1=85=D0=BF=D0=BE=D0=BC?= =?UTF-8?q?=D0=BE=D1=89=D0=B8=20=D0=BD=D0=B5=D0=BE=D0=B1=D1=85=D0=BE=D0=B4?= =?UTF-8?q?=D0=B8=D0=BC=D0=BE=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C:=20=D0=B5=D1=81=D0=BB=D0=B8=20=D1=80=D0=B0=D0=BD=D0=B5?= =?UTF-8?q?=D0=B5=20=D0=B7=D0=BD=D0=B0=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=B2=20=D0=BF=D0=BE=D0=BB=D0=B5=20=D0=B1=D1=8B=D0=BB=D0=BE=20?= =?UTF-8?q?=D0=BF=D1=83=D1=81=D1=82=D0=BE,=20=D1=82=D0=BE=20=D1=83=D0=BA?= =?UTF-8?q?=D0=B0=D0=B7=D1=8B=D0=B2=D0=B0=D0=B5=D1=82=D1=81=D1=8F=20=D0=B7?= =?UTF-8?q?=D0=BD=D0=B0=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B8=D0=B7=20?= =?UTF-8?q?=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B0=20=D1=81=20=D0=BC=D0=B0?= =?UTF-8?q?=D0=BA=D1=81=D0=B8=D0=BC=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE=D0=B9=20?= =?UTF-8?q?=D1=81=D1=82=D0=BE=D0=B8=D0=BC=D0=BE=D1=81=D1=82=D1=8C=D1=8E,?= =?UTF-8?q?=20=D0=B8=D0=BD=D0=B0=D1=87=D0=B5=20=D0=BA=D0=B0=D0=BA=20=D1=81?= =?UTF-8?q?=D0=B5=D0=B9=D1=87=D0=B0=D1=81=20=D0=BF=D0=BE=D0=B4=D0=B1=D0=B8?= =?UTF-8?q?=D1=80=D0=B0=D0=B5=D1=82=D1=81=D1=8F=20=D0=BF=D0=BE=20=D1=81?= =?UTF-8?q?=D0=BE=D0=BE=D1=82=D0=B2=D0=B5=D1=82=D1=81=D1=82=D0=B2=D0=B8?= =?UTF-8?q?=D1=8E=20=D0=A2=D0=B8=D0=BF=D0=B0=20=D0=BA=D0=B0=D1=80=D1=82?= =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web/process/add-product/reactions.ts | 55 +++++++++++++++++++++-- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/apps/web/process/add-product/reactions.ts b/apps/web/process/add-product/reactions.ts index 3e4b48b..60bc810 100644 --- a/apps/web/process/add-product/reactions.ts +++ b/apps/web/process/add-product/reactions.ts @@ -8,9 +8,10 @@ import { getCurrentISODate } from '@/utils/date'; import { normalizeOptions } from '@/utils/entity'; import { debouncedReaction } from '@/utils/mobx'; import { reaction, toJS } from 'mobx'; +import { max } from 'radash'; export default function reactions({ store, apolloClient }: ProcessContext) { - const { $calculation, $tables } = store; + const { $calculation, $tables, $process } = store; reaction( () => $calculation.$values.getValues(['leasingPeriod', 'leaseObjectType', 'maxMass']), @@ -47,9 +48,9 @@ export default function reactions({ store, apolloClient }: ProcessContext) { ) ); - $calculation.element('selectTechnicalCard').setOptions(normalizeOptions(options)); - const currentTechnicalCardId = $calculation.element('selectTechnicalCard').getValue(); + + $calculation.element('selectTechnicalCard').setOptions(normalizeOptions(options)); if (currentTechnicalCardId) { const { data: { evo_addproduct_type }, @@ -74,6 +75,54 @@ export default function reactions({ store, apolloClient }: ProcessContext) { } ); + /** + * Устанавливаем самую дорогую техническую карточку по умолчанию первый раз при формировании списка карт + */ + { + const dispose = reaction( + () => { + const technicalCards = $calculation.element('selectTechnicalCard').getOptions(); + const isLoadKP = $process.has('LoadKP'); + + return { isLoadKP, technicalCards }; + }, + async ({ technicalCards, isLoadKP }) => { + if (isLoadKP) { + dispose(); + + return; + } + + const currentTechnicalCard = $calculation.element('selectTechnicalCard').getValue(); + + if (technicalCards.length && !currentTechnicalCard) { + const evo_addproduct_types = await Promise.all( + technicalCards.map(async (x) => { + const { + data: { evo_addproduct_type }, + } = await apolloClient.query({ + query: CRMTypes.GetAddProductTypeDocument, + variables: { addproductTypeId: x.value }, + }); + + return evo_addproduct_type; + }) + ); + + const maxPriceTechnicalCard = max(evo_addproduct_types, (x) => x?.evo_graph_price ?? 0); + + if (maxPriceTechnicalCard) { + $calculation + .element('selectTechnicalCard') + .setValue(maxPriceTechnicalCard?.evo_addproduct_typeid); + } + + dispose(); + } + } + ); + } + reaction( () => $calculation.$values.getValues(['leasingPeriod', 'leaseObjectType']), async ({ leasingPeriod, leaseObjectType }) => {