diff --git a/src/client/stores/CalculationStore/Effects/autorun.ts b/src/client/stores/CalculationStore/Effects/autorun.ts index 4bbab2e..7108dfe 100644 --- a/src/client/stores/CalculationStore/Effects/autorun.ts +++ b/src/client/stores/CalculationStore/Effects/autorun.ts @@ -1,4 +1,8 @@ +import { openNotification } from 'client/Elements/Notification'; import { IAutorunEffect } from 'core/types/Calculation/Store/effect'; +import { Process } from 'core/types/Calculation/Store/process'; +import { ElementStatus } from 'core/types/statuses'; +import { calculationProcess } from '..'; const autorunEffects: IAutorunEffect[] = [ calculationStore => () => { @@ -76,35 +80,35 @@ const autorunEffects: IAutorunEffect[] = [ } } }, - calculationStore => () => { - const { - leaseObjectCategory, - maxMass, - withTrailer, - } = calculationStore.values; - if (leaseObjectCategory === 100000002) { - if (!maxMass) { - calculationStore.setValidation('tbxMaxMass', false); - } else { - calculationStore.setValidation('tbxMaxMass', true); - } - } else { - calculationStore.setValidation('tbxMaxMass', true); - calculationStore.setValidation('cbxWithTrailer', true); - } - }, - calculationStore => () => { - const { leaseObjectCategory, countSeats } = calculationStore.values; - if (leaseObjectCategory === 100000003) { - if (!countSeats) { - calculationStore.setValidation('tbxCountSeats', false); - } else { - calculationStore.setValidation('tbxCountSeats', true); - } - } else { - calculationStore.setValidation('tbxCountSeats', true); - } - }, + // calculationStore => () => { + // const { + // leaseObjectCategory, + // maxMass, + // withTrailer, + // } = calculationStore.values; + // if (leaseObjectCategory === 100000002) { + // if (!maxMass) { + // calculationStore.setValidation('tbxMaxMass', false); + // } else { + // calculationStore.setValidation('tbxMaxMass', true); + // } + // } else { + // calculationStore.setValidation('tbxMaxMass', true); + // calculationStore.setValidation('cbxWithTrailer', true); + // } + // }, + // calculationStore => () => { + // const { leaseObjectCategory, countSeats } = calculationStore.values; + // if (leaseObjectCategory === 100000003) { + // if (!countSeats) { + // calculationStore.setValidation('tbxCountSeats', false); + // } else { + // calculationStore.setValidation('tbxCountSeats', true); + // } + // } else { + // calculationStore.setValidation('tbxCountSeats', true); + // } + // }, calculationStore => () => { const { requirementTelematic } = calculationStore.values; if (requirementTelematic) { @@ -115,6 +119,210 @@ const autorunEffects: IAutorunEffect[] = [ calculationStore.setValue('tracker', tracker.evo_addproduct_typeid); } }, + + calculationStore => () => { + if (calculationProcess.process !== Process.Default) { + return; + } + + calculationStore.setFilter('selectLeaseObjectCategory', undefined); + + const { leaseObjectType: leaseObjectTypeId } = calculationStore.values; + if (!leaseObjectTypeId) { + calculationStore.setStatus( + 'selectLeaseObjectCategory', + ElementStatus.Default, + ); + calculationStore.setValidation('tbxCountSeats', undefined); + calculationStore.setValidation('tbxMaxMass', undefined); + return; + } + + const leaseObjectType = calculationStore.options.selectLeaseObjectType?.find( + x => x.evo_leasingobject_typeid === leaseObjectTypeId, + ); + + if (leaseObjectType) { + if (leaseObjectType.evo_id !== '8') { + calculationStore.setStatus( + 'selectLeaseObjectCategory', + ElementStatus.Default, + ); + calculationStore.setStatus('selectEngineType', ElementStatus.Default); + calculationStore.setStatus('tbxEngineVolume', ElementStatus.Default); + calculationStore.setStatus( + 'tbxLeaseObjectMotorPower', + ElementStatus.Default, + ); + + const { + engineVolume, + engineType, + leaseObjectMotorPower, + } = calculationStore.values; + + if (engineVolume <= 0) { + calculationStore.setValidation('tbxEngineVolume', false); + openNotification({ + type: 'error', + title: 'Ошибка', + description: 'Объем двигателя должен быть больше 0', + })(); + } else { + calculationStore.setValidation('tbxEngineVolume', undefined); + } + + if (!engineType) { + calculationStore.setValidation('selectEngineType', false); + openNotification({ + type: 'error', + title: 'Ошибка', + description: 'Тип двигателя должен содержать данные', + })(); + } else { + calculationStore.setValidation('selectEngineType', undefined); + } + + if (leaseObjectMotorPower <= 0) { + calculationStore.setValidation('tbxLeaseObjectMotorPower', false); + openNotification({ + type: 'error', + title: 'Ошибка', + description: 'Мощность двигателя должна быть больше 0', + })(); + } else { + calculationStore.setValidation('tbxLeaseObjectMotorPower', undefined); + } + } else { + calculationStore.setValue('leaseObjectMotorPower', 0); + calculationStore.setStatus( + 'tbxLeaseObjectMotorPower', + ElementStatus.Disabled, + ); + calculationStore.setValidation('tbxLeaseObjectMotorPower', undefined); + + calculationStore.setValue('engineType', null); + calculationStore.setStatus('selectEngineType', ElementStatus.Disabled); + calculationStore.setValidation('selectEngineType', undefined); + + calculationStore.setValue('engineVolume', 0); + calculationStore.setStatus('tbxEngineVolume', ElementStatus.Disabled); + calculationStore.setValidation('tbxEngineVolume', undefined); + } + } + }, + + calculationStore => () => { + if (calculationProcess.process !== Process.Default) { + return; + } + + const { leaseObjectType: leaseObjectTypeId } = calculationStore.values; + if (!leaseObjectTypeId) { + return; + } + + calculationStore.setValidation('tbxCountSeats', undefined); + calculationStore.setValidation('tbxMaxMass', undefined); + + const leaseObjectType = calculationStore.options.selectLeaseObjectType?.find( + x => x.evo_leasingobject_typeid === leaseObjectTypeId, + ); + + if (leaseObjectType) { + switch (leaseObjectType.evo_id) { + case '1': { + calculationStore.setValue('leaseObjectCategory', 100000001); + calculationStore.setStatus( + 'selectLeaseObjectCategory', + ElementStatus.Disabled, + ); + + const { countSeats } = calculationStore.values; + if (countSeats && countSeats >= 9) { + calculationStore.setValidation('tbxCountSeats', false); + openNotification({ + type: 'error', + title: 'Ошибка', + description: 'Количество мест должно быть меньше 9', + })(); + } + break; + } + + case '2': { + calculationStore.setStatus( + 'selectLeaseObjectCategory', + ElementStatus.Default, + ); + calculationStore.setFilter('selectLeaseObjectCategory', options => + options.filter(x => x.value === 100000001 || x.value === 100000002), + ); + + const { maxMass } = calculationStore.values; + if (!maxMass) { + calculationStore.setValidation('tbxMaxMass', false); + openNotification({ + type: 'error', + title: 'Ошибка', + description: + 'Разрешенная максимальная масса должна быть больше 0', + })(); + } + break; + } + + case '4': + case '5': { + calculationStore.setStatus( + 'selectLeaseObjectCategory', + ElementStatus.Default, + ); + calculationStore.setFilter('selectLeaseObjectCategory', options => + options.filter(x => x.value === 100000001 || x.value === 100000003), + ); + + const { countSeats } = calculationStore.values; + if (countSeats <= 8) { + calculationStore.setValidation('tbxCountSeats', false); + openNotification({ + type: 'error', + title: 'Ошибка', + description: 'Кол-во мест должно быть больше 8', + })(); + } + break; + } + + case '3': + case '7': { + calculationStore.setValue('leaseObjectCategory', 100000002); + calculationStore.setStatus( + 'selectLeaseObjectCategory', + ElementStatus.Disabled, + ); + break; + } + + case '8': { + calculationStore.setValue('leaseObjectCategory', 100000004); + calculationStore.setStatus( + 'selectLeaseObjectCategory', + ElementStatus.Disabled, + ); + break; + } + + default: { + calculationStore.setStatus( + 'selectLeaseObjectCategory', + ElementStatus.Default, + ); + break; + } + } + } + }, ]; export default autorunEffects; diff --git a/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts index 55481ea..64ec2be 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts @@ -1323,7 +1323,7 @@ const reactionEffects: IReactionEffect[] = [ effect: leaseObjectCategory => { if ( leaseObjectCategory === 100000001 || - leaseObjectCategory === 100000001 + leaseObjectCategory === 100000003 ) { calculationStore.setValue('withTrailer', false); calculationStore.setStatus('cbxWithTrailer', ElementStatus.Disabled); @@ -1643,6 +1643,23 @@ const reactionEffects: IReactionEffect[] = [ } }, }), + + calculationStore => ({ + expression: () => { + const { selectLeaseObjectCategory } = calculationStore.filters; + return selectLeaseObjectCategory; + }, + effect: selectLeaseObjectCategoryFilter => { + const { leaseObjectCategory } = calculationStore.values; + if ( + !selectLeaseObjectCategoryFilter( + calculationStore.options.selectLeaseObjectCategory, + ).some(x => x.value === leaseObjectCategory) + ) { + calculationStore.setValue('leaseObjectCategory', null); + } + }, + }), ]; export default reactionEffects;