process/recalc: блокировка полей
This commit is contained in:
parent
64c1d72196
commit
1f2983a7ec
@ -14,7 +14,7 @@ import { uid } from 'radash';
|
||||
dayjs.extend(utc);
|
||||
|
||||
export function common({ store, apolloClient }: ProcessContext) {
|
||||
const { $calculation } = store;
|
||||
const { $calculation, $tables } = store;
|
||||
|
||||
reaction(
|
||||
() => $calculation.element('cbxRecalcWithRevision').getValue(),
|
||||
@ -131,6 +131,94 @@ export function common({ store, apolloClient }: ProcessContext) {
|
||||
$calculation.element('selectTelematic').setOptions(normalizeOptions(filteredTelematicTypes));
|
||||
}
|
||||
);
|
||||
|
||||
{
|
||||
const elements: Elements[] = [
|
||||
'cbxLeaseObjectUsed',
|
||||
'radioGraphType',
|
||||
'selectBrand',
|
||||
'selectCalcBroker',
|
||||
'selectCalcFinDepartment',
|
||||
'selectClientRisk',
|
||||
'selectClientType',
|
||||
'selectConfiguration',
|
||||
'selectDealer',
|
||||
'selectDealerPerson',
|
||||
'selectHighSeasonStart',
|
||||
'selectImportProgram',
|
||||
'selectIndAgent',
|
||||
'selectLead',
|
||||
'selectLeaseObjectCategory',
|
||||
'selectLeaseObjectType',
|
||||
'selectModel',
|
||||
'selectOpportunity',
|
||||
'selectRate',
|
||||
'selectRequirementTelematic',
|
||||
'selectSeasonType',
|
||||
'selectSubsidy',
|
||||
'selectTarif',
|
||||
'selectTelematic',
|
||||
'selectTracker',
|
||||
'tbxAddEquipmentPrice',
|
||||
'tbxCreditRate',
|
||||
'tbxEngineHours',
|
||||
'tbxImporterRewardPerc',
|
||||
'tbxImporterRewardRub',
|
||||
'tbxLeasingPeriod',
|
||||
'tbxMaxPriceChange',
|
||||
'tbxMileage',
|
||||
'tbxParmentsDecreasePercent',
|
||||
'tbxVIN',
|
||||
];
|
||||
reaction(
|
||||
() => $calculation.element('cbxRecalcWithRevision').getValue(),
|
||||
(recalcWithRevision) => {
|
||||
if (recalcWithRevision) {
|
||||
elements.forEach((elementName) =>
|
||||
$calculation.$status.overrideStatus(elementName, 'Disabled')
|
||||
);
|
||||
$tables.payments.overrideStatuses('Disabled');
|
||||
} else {
|
||||
elements.forEach((elementName) => $calculation.$status.clearOverridedStatus(elementName));
|
||||
$tables.payments.clearOverridedStatuses();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const agents: Elements[] = [
|
||||
'selectCalcBroker',
|
||||
'selectCalcBrokerRewardCondition',
|
||||
'selectCalcDoubleAgent',
|
||||
'selectCalcDoubleAgentRewardCondition',
|
||||
'selectCalcFinDepartment',
|
||||
'selectDealerBroker',
|
||||
'selectDealerBrokerRewardCondition',
|
||||
'selectDealerPerson',
|
||||
'selectDealerRewardCondition',
|
||||
'selectFinDepartmentRewardCondtion',
|
||||
'selectIndAgent',
|
||||
'selectIndAgentRewardCondition',
|
||||
'tbxCalcBrokerRewardSum',
|
||||
'tbxCalcDoubleAgentRewardSumm',
|
||||
'tbxDealerBrokerRewardSumm',
|
||||
'tbxDealerRewardSumm',
|
||||
'tbxFinDepartmentRewardSumm',
|
||||
'tbxIndAgentRewardSumm',
|
||||
];
|
||||
|
||||
reaction(
|
||||
() => $calculation.$values.getValues(['firstPaymentPerc', 'recalcWithRevision']),
|
||||
({ firstPaymentPerc, recalcWithRevision }) => {
|
||||
if (firstPaymentPerc === 0 && recalcWithRevision === true) {
|
||||
agents.forEach((elementName) =>
|
||||
$calculation.$status.overrideStatus(elementName, 'Disabled')
|
||||
);
|
||||
} else {
|
||||
agents.forEach((elementName) => $calculation.$status.clearOverridedStatus(elementName));
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const key = uid(7);
|
||||
|
||||
@ -9,6 +9,7 @@ import type { Status } from 'ui/elements/types';
|
||||
export default class StatusStore {
|
||||
private root: RootStore;
|
||||
private statuses: CalculationStatuses = defaultStatuses;
|
||||
private overrided: Partial<CalculationStatuses> = {};
|
||||
|
||||
constructor(rootStore: RootStore) {
|
||||
makeAutoObservable(this);
|
||||
@ -20,7 +21,7 @@ export default class StatusStore {
|
||||
};
|
||||
|
||||
public getStatus(elementName: ElementsActions | ElementsValues) {
|
||||
return this.statuses[elementName];
|
||||
return this.overrided[elementName] || this.statuses[elementName];
|
||||
}
|
||||
|
||||
public setStatus = (elementName: ElementsActions | ElementsValues, status: Status) => {
|
||||
@ -30,4 +31,12 @@ export default class StatusStore {
|
||||
public resetStatus = (elementName: ElementsActions | ElementsValues) => {
|
||||
this.statuses[elementName] = defaultStatuses[elementName];
|
||||
};
|
||||
|
||||
public overrideStatus = (elementName: ElementsActions | ElementsValues, status: Status) => {
|
||||
this.overrided[elementName] = status;
|
||||
};
|
||||
|
||||
public clearOverridedStatus = (elementName: ElementsActions | ElementsValues) => {
|
||||
this.overrided[elementName] = undefined;
|
||||
};
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ export default class PaymentsTable {
|
||||
public validation: Validation;
|
||||
public values: IObservableArray<number>;
|
||||
private statuses: IObservableArray<Status>;
|
||||
private overridedStatuses: IObservableArray<Status>;
|
||||
|
||||
constructor(rootStore: RootStore) {
|
||||
this.validation = new Validation({
|
||||
@ -20,6 +21,7 @@ export default class PaymentsTable {
|
||||
|
||||
this.values = observable<number>([]);
|
||||
this.statuses = observable<Status>([]);
|
||||
this.overridedStatuses = observable<Status>([]);
|
||||
|
||||
makeAutoObservable(this);
|
||||
this.root = rootStore;
|
||||
@ -48,13 +50,23 @@ export default class PaymentsTable {
|
||||
};
|
||||
|
||||
public getStatus(index: number) {
|
||||
return this.statuses[index];
|
||||
return this.overridedStatuses?.length ? this.overridedStatuses?.[index] : this.statuses[index];
|
||||
}
|
||||
|
||||
public setStatus = (index: number, status: Status) => {
|
||||
this.statuses[index] = status;
|
||||
};
|
||||
|
||||
public overrideStatuses = (status: Status) => {
|
||||
for (let index = 0; index < this.statuses.length; index++) {
|
||||
this.overridedStatuses[index] = status;
|
||||
}
|
||||
};
|
||||
|
||||
public clearOverridedStatuses = () => {
|
||||
this.overridedStatuses?.clear();
|
||||
};
|
||||
|
||||
public setStatuses = (statuses: Status[]) => {
|
||||
this.statuses.replace(statuses);
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user