2023-01-18 15:44:15 +03:00

122 lines
4.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type * as CRMTypes from 'graphql/crm.types';
import { autorun, reaction } from 'mobx';
import type { ReactionsContext } from 'process/types';
import * as query from '../lib/query';
export default function leasebackReactions({ store, apolloClient }: ReactionsContext) {
const { $calculation, $tables } = store;
/**
* Дополнить реакцию на изменение поля Салон приобретения selectDealer:
если в поле selectDealer указан account, у которого evo_return_leasing_dealer = true, то
1) поле selectDealerPerson обнулять и закрывать для редактирования,
иначе формировать список связанных значений
2) в таблице страхования в столбце Плательщик
в строках ОСАГО и КАСКО указывать "Лизингополучатель" (100 000 000) и закрывать для редактирования ,
иначе открывать данные поля для редактирования
3) ПЛ БУ cbxLeaseObjectUsed = true
*/
reaction(
() => $calculation.element('selectDealer').getValue(),
async (dealerId) => {
if (!dealerId) return;
const {
data: { dealer },
} = await apolloClient.query<
CRMTypes.GetDealerReturnLeasingQuery,
CRMTypes.GetDealerReturnLeasingQueryVariables
>({
query: query.QUERY_GET_DEALER_RETURN_LEASING,
variables: {
dealerId,
},
});
if (dealer?.evo_return_leasing_dealer === true) {
$calculation.element('selectDealerPerson').block().resetValue();
$tables.insurance.row('kasko').setValue('insured', 100_000_000).block('insured');
$calculation.element('cbxLeaseObjectUsed').setValue(true);
} else {
$calculation.element('selectDealerPerson').unblock();
$tables.insurance.row('kasko').resetStatus('insured');
}
}
);
// объединили реакцию для прицепа и возвратного лизинга
reaction(
() => ({
dealerId: $calculation.element('selectDealer').getValue(),
leaseObjectCategory: $calculation.element('selectLeaseObjectCategory').getValue(),
}),
async ({ dealerId, leaseObjectCategory }) => {
const isTrailer = leaseObjectCategory === 100_000_004;
let returnLeasing = false;
if (dealerId) {
const {
data: { dealer },
} = await apolloClient.query<
CRMTypes.GetDealerReturnLeasingQuery,
CRMTypes.GetDealerReturnLeasingQueryVariables
>({
query: query.QUERY_GET_DEALER_RETURN_LEASING,
variables: {
dealerId,
},
});
returnLeasing = dealer?.evo_return_leasing_dealer === true;
}
if (isTrailer || returnLeasing) {
$tables.insurance.row('osago').setValue('insured', 100_000_000).block('insured');
} else {
$tables.insurance.row('osago').resetStatus('insured');
}
}
);
/* eslint-disable max-len */
/**
* В валидацию на кнопку Рассчитать внести изменение:
1) поле selectDealerPerson убрать из списка обязательных для расчета полей
2) добавить валидацию на поле selectDealerPerson :
Если в поле selectDealer указан account, у которого evo_return_leasing_dealer = False (или null)
и поле selectDealerPerson = null, то выводить ошибку и поле selectDealerPerson обводить красной рамкой,
иначе все ок
*/
/* eslint-enable */
autorun(async () => {
const dealerId = $calculation.element('selectDealer').getValue();
const dealerPersonId = $calculation.element('selectDealerPerson').getValue();
let returnLeasing: boolean | null | undefined;
if (dealerId) {
const {
data: { dealer },
} = await apolloClient.query<
CRMTypes.GetDealerReturnLeasingQuery,
CRMTypes.GetDealerReturnLeasingQueryVariables
>({
query: query.QUERY_GET_DEALER_RETURN_LEASING,
variables: {
dealerId,
},
});
returnLeasing = dealer?.evo_return_leasing_dealer;
}
$calculation.element('selectDealerPerson').validate({
invalid: !!dealerId && !dealerPersonId && !returnLeasing,
message: 'Не заполнено поле',
});
});
}