request: use tbxInsFranchise value reaction: reset kasko results on change tbxInsFranchise
103 lines
2.5 KiB
TypeScript
103 lines
2.5 KiB
TypeScript
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([
|
|
'leaseObjectType',
|
|
// osago
|
|
'townRegistration',
|
|
'legalClientTown',
|
|
'legalClientRegion',
|
|
'objectRegistration',
|
|
'townRegistration',
|
|
// kasko
|
|
'lead',
|
|
'opportunity',
|
|
'leaseObjectUseFor',
|
|
'leaseObjectCategory',
|
|
'insDecentral',
|
|
'leasingWithoutKasko',
|
|
'insAgeDrivers',
|
|
'insExpDrivers',
|
|
'vin',
|
|
'brand',
|
|
'model',
|
|
'leaseObjectMotorPower',
|
|
'leaseObjectPrice',
|
|
'supplierDiscountRub',
|
|
'leaseObjectYear',
|
|
'leasingPeriod',
|
|
]),
|
|
}),
|
|
async () => {
|
|
const initialValues = await init();
|
|
|
|
if (initialValues) {
|
|
$tables.elt.kasko.setRows(initialValues.kasko);
|
|
$tables.elt.osago.setRows(initialValues.osago);
|
|
}
|
|
},
|
|
{
|
|
delay: 10,
|
|
equals: comparer.shallow,
|
|
fireImmediately: true,
|
|
}
|
|
);
|
|
|
|
disposableReaction(
|
|
() => $process.has('ELT') || $process.has('LoadKP'),
|
|
() => $calculation.element('tbxInsFranchise').getValue(),
|
|
async () => {
|
|
const initialValues = await init();
|
|
|
|
$tables.elt.kasko.setRows(initialValues.kasko);
|
|
},
|
|
{
|
|
delay: 10,
|
|
}
|
|
);
|
|
|
|
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,
|
|
}
|
|
);
|
|
}
|