48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { defaultResultsValues } from './default-values';
|
|
import type { ResultPayment, ResultValues } from './types';
|
|
import { notification } from '@/Components/Common/Notification';
|
|
import type RootStore from '@/stores/root';
|
|
import type { IObservableArray } from 'mobx';
|
|
import { makeAutoObservable, observable } from 'mobx';
|
|
|
|
export default class Results {
|
|
private root: RootStore;
|
|
public payments: IObservableArray<ResultPayment>;
|
|
public values: ResultValues;
|
|
|
|
constructor(rootStore: RootStore) {
|
|
this.payments = observable<ResultPayment>([]);
|
|
this.values = defaultResultsValues;
|
|
makeAutoObservable(this);
|
|
|
|
this.root = rootStore;
|
|
}
|
|
|
|
private get clean() {
|
|
return !this.payments.length;
|
|
}
|
|
|
|
public setPayments = (payments: ResultPayment[]) => {
|
|
this.payments.replace(payments);
|
|
};
|
|
|
|
public setValues = (values: ResultValues) => {
|
|
this.values = values;
|
|
};
|
|
|
|
public clear = () => {
|
|
if (this.clean === true) return;
|
|
|
|
this.payments.clear();
|
|
this.values = defaultResultsValues;
|
|
|
|
notification.open({
|
|
description: 'Результаты расчета были сброшены',
|
|
key: 'ACTION_CALCULATE',
|
|
message: 'Внимание',
|
|
placement: 'bottomRight',
|
|
type: 'warning',
|
|
});
|
|
};
|
|
}
|