Compare commits
3 Commits
dev
...
release/dy
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
39dc4bfa9e | ||
|
|
ce0b6290f7 | ||
|
|
d916a180a2 |
@ -8,9 +8,10 @@ import { getCurrentISODate } from '@/utils/date';
|
||||
import { normalizeOptions } from '@/utils/entity';
|
||||
import { debouncedReaction } from '@/utils/mobx';
|
||||
import { reaction, toJS } from 'mobx';
|
||||
import { max } from 'radash';
|
||||
|
||||
export default function reactions({ store, apolloClient }: ProcessContext) {
|
||||
const { $calculation, $tables } = store;
|
||||
const { $calculation, $tables, $process } = store;
|
||||
|
||||
reaction(
|
||||
() => $calculation.$values.getValues(['leasingPeriod', 'leaseObjectType', 'maxMass']),
|
||||
@ -47,9 +48,9 @@ export default function reactions({ store, apolloClient }: ProcessContext) {
|
||||
)
|
||||
);
|
||||
|
||||
$calculation.element('selectTechnicalCard').setOptions(normalizeOptions(options));
|
||||
|
||||
const currentTechnicalCardId = $calculation.element('selectTechnicalCard').getValue();
|
||||
|
||||
$calculation.element('selectTechnicalCard').setOptions(normalizeOptions(options));
|
||||
if (currentTechnicalCardId) {
|
||||
const {
|
||||
data: { evo_addproduct_type },
|
||||
@ -74,6 +75,54 @@ export default function reactions({ store, apolloClient }: ProcessContext) {
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* Устанавливаем самую дорогую техническую карточку по умолчанию первый раз при формировании списка карт
|
||||
*/
|
||||
{
|
||||
const dispose = reaction(
|
||||
() => {
|
||||
const technicalCards = $calculation.element('selectTechnicalCard').getOptions();
|
||||
const isLoadKP = $process.has('LoadKP');
|
||||
|
||||
return { isLoadKP, technicalCards };
|
||||
},
|
||||
async ({ technicalCards, isLoadKP }) => {
|
||||
if (isLoadKP) {
|
||||
dispose();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const currentTechnicalCard = $calculation.element('selectTechnicalCard').getValue();
|
||||
|
||||
if (technicalCards.length && !currentTechnicalCard) {
|
||||
const evo_addproduct_types = await Promise.all(
|
||||
technicalCards.map(async (x) => {
|
||||
const {
|
||||
data: { evo_addproduct_type },
|
||||
} = await apolloClient.query({
|
||||
query: CRMTypes.GetAddProductTypeDocument,
|
||||
variables: { addproductTypeId: x.value },
|
||||
});
|
||||
|
||||
return evo_addproduct_type;
|
||||
})
|
||||
);
|
||||
|
||||
const maxPriceTechnicalCard = max(evo_addproduct_types, (x) => x?.evo_graph_price ?? 0);
|
||||
|
||||
if (maxPriceTechnicalCard) {
|
||||
$calculation
|
||||
.element('selectTechnicalCard')
|
||||
.setValue(maxPriceTechnicalCard?.evo_addproduct_typeid);
|
||||
}
|
||||
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
reaction(
|
||||
() => $calculation.$values.getValues(['leasingPeriod', 'leaseObjectType']),
|
||||
async ({ leasingPeriod, leaseObjectType }) => {
|
||||
|
||||
@ -1 +1,2 @@
|
||||
export { default as common } from './common';
|
||||
export { default as init } from './init';
|
||||
|
||||
34
apps/web/process/fingap/reactions/init.ts
Normal file
34
apps/web/process/fingap/reactions/init.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import type { ProcessContext } from '@/process/types';
|
||||
import { when } from 'mobx';
|
||||
|
||||
export default function reactions({ store }: ProcessContext) {
|
||||
const { $tables } = store;
|
||||
|
||||
/**
|
||||
* Устанавливаем СК фингап по умолчанию при загрузке страницы
|
||||
*/
|
||||
when(() => {
|
||||
const finGAPInsuranceCompanies = $tables.insurance.row('fingap').getOptions('insuranceCompany');
|
||||
if (finGAPInsuranceCompanies.length) {
|
||||
$tables.insurance
|
||||
.row('fingap')
|
||||
.setValue('insuranceCompany', finGAPInsuranceCompanies[0]?.value)
|
||||
.setValue('insured', 100_000_001);
|
||||
}
|
||||
|
||||
return Boolean(finGAPInsuranceCompanies.length);
|
||||
});
|
||||
|
||||
/**
|
||||
* Устанавливаем все риски ФинГАП по умолчанию при загрузке страницы
|
||||
*/
|
||||
when(() => {
|
||||
const { risks } = $tables.fingap;
|
||||
|
||||
if (risks.length) {
|
||||
$tables.fingap.setSelectedKeys(risks.map((x) => x.key));
|
||||
}
|
||||
|
||||
return Boolean(risks.length);
|
||||
});
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user