90 lines
2.4 KiB
TypeScript
90 lines
2.4 KiB
TypeScript
import type { ReactionsContext } from '@/process/types';
|
|
import extend from '@/stores/tables/insurance/tools';
|
|
import { reaction } from 'mobx';
|
|
import { pick } from 'radash';
|
|
import message from 'ui/elements/message';
|
|
|
|
const key = 'KP_LOADING_INFO';
|
|
|
|
export default function loadKpReactions({ store, trpcClient }: ReactionsContext) {
|
|
const { $calculation, $process, $tables } = store;
|
|
|
|
reaction(
|
|
() => $calculation.element('selectQuote').getValue(),
|
|
(quoteId) => {
|
|
if (!quoteId) return;
|
|
|
|
$process.add('LoadKP');
|
|
|
|
const quoteName = $calculation.element('selectQuote').getOption()?.label;
|
|
|
|
message.loading({
|
|
content: `Загружаем КП ${quoteName}...`,
|
|
key,
|
|
});
|
|
|
|
const { recalcWithRevision } = $calculation.$values.values;
|
|
|
|
trpcClient.quote.getData
|
|
.query({
|
|
values: {
|
|
quote: quoteId,
|
|
recalcWithRevision,
|
|
},
|
|
})
|
|
.then(({ values, payments, insurance, fingap }) => {
|
|
const savedValues = pick($calculation.$values.values, [
|
|
'lead',
|
|
'opportunity',
|
|
'quote',
|
|
'leadUrl',
|
|
'opportunityUrl',
|
|
'quoteUrl',
|
|
]);
|
|
|
|
$calculation.$values.setValues({
|
|
values: {
|
|
...values,
|
|
...savedValues,
|
|
},
|
|
});
|
|
|
|
$tables.payments.setValues(payments.values);
|
|
|
|
if (insurance.values.osago) {
|
|
extend($tables.insurance).setRowValues(insurance.values.osago);
|
|
}
|
|
if (insurance.values.kasko) {
|
|
extend($tables.insurance).setRowValues(insurance.values.kasko);
|
|
}
|
|
if (insurance.values.fingap) {
|
|
extend($tables.insurance).setRowValues(insurance.values.fingap);
|
|
}
|
|
|
|
if (fingap) $tables.fingap.setSelectedKeys(fingap.keys);
|
|
|
|
message.success({
|
|
content: `КП ${quoteName} загружено`,
|
|
key,
|
|
});
|
|
})
|
|
.catch(() => {
|
|
message.error({
|
|
content: `Ошибка во время загрузки КП ${quoteName}`,
|
|
key,
|
|
});
|
|
})
|
|
.finally(() => {
|
|
$process.delete('LoadKP');
|
|
});
|
|
}
|
|
);
|
|
|
|
reaction(
|
|
() => $process.has('LoadKP'),
|
|
(isLoadKP) => {
|
|
$calculation.$status.setStatus('selectQuote', isLoadKP ? 'Disabled' : 'Default');
|
|
}
|
|
);
|
|
}
|