process/calculate: reset results on change form values

This commit is contained in:
vchikalkin 2023-05-24 12:55:53 +03:00
parent 4383bc54b3
commit 0246916fca
5 changed files with 48 additions and 5 deletions

View File

@ -7,7 +7,9 @@ const errorMessage = 'Ошибка во время расчета графика
const successMessage = 'Расчет графика завершен успешно!';
export async function action({ store, trpcClient }: ProcessContext) {
const { $calculation, $tables, $results } = store;
const { $calculation, $tables, $results, $process } = store;
$process.add('Calculate');
$calculation.$status.setStatus('btnCalculate', 'Loading');
$calculation.$status.setStatus('btnCreateKP', 'Loading');
@ -60,5 +62,7 @@ export async function action({ store, trpcClient }: ProcessContext) {
$calculation.$status.setStatus('btnCalculate', 'Default');
$calculation.$status.setStatus('btnCreateKP', 'Default');
$calculation.$status.setStatus('btnCreateKPMini', 'Default');
$process.delete('Calculate');
});
}

View File

@ -1,9 +1,10 @@
import helper from '../lib/helper';
import type { ProcessContext } from '@/process/types';
import { reaction } from 'mobx';
import { disposableReaction } from '@/utils/mobx';
import { comparer, reaction } from 'mobx';
export default function reactions({ store, apolloClient }: ProcessContext) {
const { $calculation } = store;
const { $calculation, $tables, $results, $process } = store;
reaction(
() => $calculation.element('radioCalcType').getValue(),
@ -37,4 +38,24 @@ export default function reactions({ store, apolloClient }: ProcessContext) {
$calculation.element('labelIrrInfo').setValue({ max, min });
}
);
disposableReaction(
() => $process.has('Calculate'),
() => ({
insurance: {
fingap: $tables.insurance.row('fingap').getValues(),
kasko: $tables.insurance.row('kasko').getValues(),
osago: $tables.insurance.row('osago').getValues(),
},
payments: $tables.payments.getValues,
values: $calculation.$values.getValues(),
}),
() => {
$results.clear();
},
{
delay: 10,
equals: comparer.structural,
}
);
}

View File

@ -1,7 +1,7 @@
import type { ObservableSet } from 'mobx';
import { observable } from 'mobx';
export type Process = 'ELT' | 'LoadKP' | 'Unlimited';
export type Process = 'Calculate' | 'ELT' | 'LoadKP' | 'Unlimited';
export type ProcessStore = ObservableSet<Process>;
export default function createProcessStore() {

View File

@ -3,6 +3,7 @@ import type { ResultPayment, ResultValues } from './types';
import type RootStore from '@/stores/root';
import type { IObservableArray } from 'mobx';
import { makeAutoObservable, observable } from 'mobx';
import { notification } from 'ui/elements';
export default class Results {
private root: RootStore;
@ -17,6 +18,10 @@ export default class Results {
this.root = rootStore;
}
private get clean() {
return !this.payments.length;
}
public setPayments = (payments: ResultPayment[]) => {
this.payments.replace(payments);
};
@ -26,7 +31,16 @@ export default class Results {
};
public clear = () => {
if (this.clean === true) return;
this.payments.clear();
this.values = defaultResultsValues;
notification.open({
description: 'Результаты расчета были сброшены',
key: 'ACTION_CALCULATE',
message: 'Внимание',
type: 'warning',
});
};
}

View File

@ -4,7 +4,7 @@ import type { Row } from './types';
import type { Status } from '@/stores/calculation/statuses/types';
import type RootStore from '@/stores/root';
import type { IObservableArray, IObservableValue } from 'mobx';
import { makeAutoObservable, observable, reaction } from 'mobx';
import { makeAutoObservable, observable, reaction, toJS } from 'mobx';
export default class PaymentsTable {
private root: RootStore;
@ -51,6 +51,10 @@ export default class PaymentsTable {
return this.values[index];
}
public get getValues() {
return toJS(this.values);
}
public setValue = (index: number, value: number) => {
this.values[index] = value;
};