import type { ProcessContext } from '../../types'; import helper from '../lib/helper'; import { disposableReaction } from '@/utils/mobx'; import { comparer, toJS } from 'mobx'; export default function reactions(context: ProcessContext) { const { store } = context; const { $calculation, $tables, $process } = store; const { init } = helper(context); disposableReaction( () => $process.has('ELT') || $process.has('LoadKP'), () => ({ values: $calculation.$values.getValues([ 'objectRegistration', 'townRegistration', 'legalClientRegion', 'legalClientTown', 'brand', 'model', 'GPSBrand', 'GPSModel', 'leaseObjectYear', 'leaseObjectCategory', 'leaseObjectMotorPower', 'leaseObjectUseFor', 'maxMass', 'countSeats', 'withTrailer', 'lead', 'opportunity', 'insDecentral', 'leaseObjectType', 'insAgeDrivers', 'insExpDrivers', 'vin', 'leaseObjectUsed', 'leasingPeriod', 'leaseObjectPrice', 'quote', ]), }), async () => { const initialValues = await init(); if (initialValues) { $tables.elt.osago.setRows(initialValues.osago); } }, { delay: 10, equals: comparer.shallow, fireImmediately: true, } ); disposableReaction( () => $process.has('ELT') || $process.has('LoadKP'), () => ({ values: $calculation.$values.getValues([ 'legalClientRegion', 'legalClientTown', 'leaseObjectType', 'leaseObjectCategory', 'brand', 'model', 'leaseObjectUsed', 'product', 'leaseObjectYear', 'leaseObjectMotorPower', 'engineType', 'leasingPeriod', 'plPriceRub', 'discountRub', 'importProgramSum', 'addEquipmentPrice', 'insFranchise', 'GPSBrand', 'GPSModel', 'insAgeDrivers', 'insExpDrivers', 'insUnlimitDrivers', 'maxMass', 'mileage', 'vin', 'leaseObjectUseFor', 'countSeats', 'lead', 'opportunity', 'withTrailer', 'insDecentral', 'leasingWithoutKasko', 'quote', ]), }), async () => { const initialValues = await init(); if (initialValues) { $tables.elt.kasko.setRows(initialValues.kasko); } }, { delay: 10, equals: comparer.shallow, fireImmediately: true, } ); disposableReaction( () => $process.has('ELT') || $process.has('LoadKP'), () => { const { insCost, insuranceCompany } = toJS($tables.insurance.row('kasko').getValues()); const insFranchise = $calculation.element('tbxInsFranchise').getValue(); return { insCost, insFranchise, insuranceCompany }; }, () => { $tables.elt.kasko.resetSelectedKey(); }, { delay: 10, equals: comparer.shallow, } ); disposableReaction( () => $process.has('ELT') || $process.has('LoadKP'), () => { const { insCost, insuranceCompany } = toJS($tables.insurance.row('osago').getValues()); return { insCost, insuranceCompany }; }, () => { $tables.elt.osago.resetSelectedKey(); }, { delay: 10, equals: comparer.shallow, } ); }