Добавить реакцию:

Если Тип предмета лизингаselectLeaseObjectType  = Спецтехника (ID=9) и значение в поле tbxMaxSpeed< 20, то insuredOSAGO = Лизингополучатель (100000000), inscostOSAGO = 0, inscompanyOSAGO = ПРОЧИЕ и закрыты для редактирования
This commit is contained in:
vchikalkin 2024-07-04 16:43:00 +03:00
parent 0be3a575f7
commit 25723a1939

View File

@ -6,7 +6,7 @@ import { selectLeaseObjectUseFor } from '@/config/default-options';
import * as CRMTypes from '@/graphql/crm.types';
import { normalizeOptions } from '@/utils/entity';
import { debouncedReaction, disposableReaction } from '@/utils/mobx';
import { reaction } from 'mobx';
import { comparer, reaction } from 'mobx';
export function common({ store, apolloClient }: ProcessContext) {
const { $calculation, $tables, $process } = store;
@ -303,6 +303,59 @@ export function common({ store, apolloClient }: ProcessContext) {
}
}
);
debouncedReaction(
() => {
const values = $calculation.$values.getValues(['leaseObjectType', 'maxMass']);
const osago = $tables.insurance.row('osago').getValues();
return { ...values, osago };
},
async ({ leaseObjectType: leaseObjectTypeId, maxMass, osago }) => {
if (!leaseObjectTypeId) {
$tables.insurance.row('osago').column('insuranceCompany').resetOptions().unblock();
return;
}
const {
data: { evo_leasingobject_type },
} = await apolloClient.query({
query: CRMTypes.GetLeaseObjectTypeDocument,
variables: {
leaseObjectTypeId,
},
});
const {
data: { accounts },
} = await apolloClient.query({
query: CRMTypes.GetInsuranceCompaniesDocument,
});
if (evo_leasingobject_type?.evo_id === '9' && maxMass < 20 && osago.insured === 100_000_000) {
const otherInsuranceCompany = accounts?.find(
(x) => x?.evo_type_ins_policy === null && x.label?.includes('ПРОЧИЕ')
);
if (otherInsuranceCompany) {
$tables.insurance
.row('osago')
.column('insuranceCompany')
.setOptions(normalizeOptions([otherInsuranceCompany]))
.setValue(otherInsuranceCompany.value)
.block();
}
} else {
$tables.insurance.row('osago').column('insuranceCompany').resetOptions().unblock();
}
},
{
delay: 1,
equals: comparer.structural,
wait: 100,
}
);
}
export const validation = createValidationReaction(createValidationSchema);