bypass get param value
This commit is contained in:
parent
4d7444e92a
commit
16e0016b6b
@ -2,14 +2,16 @@ import { useStores } from '../useStores';
|
||||
|
||||
export const useStatus = elementName => {
|
||||
const { calculationStore } = useStores();
|
||||
const status = calculationStore.statuses[elementName];
|
||||
|
||||
const status = calculationStore.getStatus(elementName);
|
||||
return { status };
|
||||
};
|
||||
|
||||
export const useTableStatus = ({ tableName, rowIndex, propName }) => {
|
||||
const { calculationStore } = useStores();
|
||||
const status =
|
||||
calculationStore.tables[tableName].rows[rowIndex][propName].status;
|
||||
const status = calculationStore.getTableRowValues(
|
||||
tableName,
|
||||
rowIndex,
|
||||
'status',
|
||||
)[propName];
|
||||
return { status };
|
||||
};
|
||||
|
||||
@ -14,8 +14,17 @@ const tablesActions = {
|
||||
let values = {};
|
||||
const row = this.tables[tableName].rows[rowIndex];
|
||||
const keys = Object.keys(row);
|
||||
|
||||
let overridedValue;
|
||||
if (this.stores.calculationProcess.bypass[paramName]) {
|
||||
const { target, value } = this.stores.calculationProcess.bypass.status;
|
||||
if (target.indexOf(tableName) > -1) {
|
||||
overridedValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
for (let key of keys) {
|
||||
values[key] = row[key][paramName || 'value'];
|
||||
values[key] = overridedValue || row[key][paramName];
|
||||
}
|
||||
return values;
|
||||
},
|
||||
|
||||
@ -24,6 +24,12 @@ const valuesActions = {
|
||||
},
|
||||
|
||||
getStatus(elementName) {
|
||||
if (this.stores.calculationProcess.bypass.status) {
|
||||
const { target, value } = this.stores.calculationProcess.bypass.status;
|
||||
if (target.indexOf(elementName) > -1) {
|
||||
return value || undefined;
|
||||
}
|
||||
}
|
||||
return this.statuses[elementName];
|
||||
},
|
||||
setStatus(elementName, status) {
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
import { openNotification } from 'client/Elements/Notification';
|
||||
import valuesConstants from 'core/constants/values';
|
||||
import { IReactionEffect } from 'core/types/Calculation/Store/effect';
|
||||
import { ElementsNames } from 'core/types/Calculation/Store/elements';
|
||||
import { TableNames } from 'core/types/Calculation/Store/tables';
|
||||
import { ElementStatus } from 'core/types/statuses';
|
||||
import { convertPrice } from '../lib/tools';
|
||||
|
||||
@ -58,25 +60,6 @@ const reactionEffects: IReactionEffect[] = [
|
||||
},
|
||||
}),
|
||||
|
||||
calculationStore => ({
|
||||
expression: () => {
|
||||
const { recalcWithRevision } = calculationStore.values;
|
||||
return recalcWithRevision;
|
||||
},
|
||||
effect: recalcWithRevision => {
|
||||
if (recalcWithRevision === true) {
|
||||
calculationStore.setStatus('selectLead', ElementStatus.Disabled);
|
||||
calculationStore.setStatus('selectOpportunity', ElementStatus.Disabled);
|
||||
} else {
|
||||
calculationStore.setStatus('selectLead', ElementStatus.Default);
|
||||
calculationStore.setStatus('selectOpportunity', ElementStatus.Default);
|
||||
}
|
||||
},
|
||||
options: {
|
||||
fireImmediately: true,
|
||||
},
|
||||
}),
|
||||
|
||||
calculationStore => ({
|
||||
expression: () => {
|
||||
const { recalcWithRevision } = calculationStore.values;
|
||||
@ -366,6 +349,67 @@ const reactionEffects: IReactionEffect[] = [
|
||||
}
|
||||
},
|
||||
}),
|
||||
|
||||
(calculationStore, calculationProcess) => ({
|
||||
expression: () => {
|
||||
const { recalcWithRevision } = calculationStore.values;
|
||||
return recalcWithRevision;
|
||||
},
|
||||
effect: recalcWithRevision => {
|
||||
if (recalcWithRevision) {
|
||||
calculationProcess.setBypass({
|
||||
param: 'status',
|
||||
target: elementsToDisable,
|
||||
value: ElementStatus.Disabled,
|
||||
});
|
||||
} else {
|
||||
calculationProcess.clearBypass('status');
|
||||
}
|
||||
},
|
||||
}),
|
||||
];
|
||||
|
||||
const elementsToDisable: (ElementsNames | TableNames)[] = [
|
||||
'tablePayments',
|
||||
'selectLead',
|
||||
'selectOpportunity',
|
||||
'selectProduct',
|
||||
'selectClientRisk',
|
||||
'selectClientType',
|
||||
'tbxLeasingPeriod',
|
||||
'tbxLastPaymentPerc',
|
||||
'tbxLastPaymentRub',
|
||||
'radioLastPaymentRule',
|
||||
'radioGraphType',
|
||||
'tbxParmentsDecreasePercent',
|
||||
'radioSeasonType',
|
||||
'selectHighSeasonStart',
|
||||
'selectLeaseObjectType',
|
||||
'radioDeliveryTime',
|
||||
'cbxLeaseObjectUsed',
|
||||
'selectBrand',
|
||||
'selectModel',
|
||||
'selectConfiguration',
|
||||
'selectLeaseObjectCategory',
|
||||
'selectDealer',
|
||||
'selectDealerPerson',
|
||||
'selectIndAgent',
|
||||
'selectCalcBroker',
|
||||
'selectCalcFinDepartment',
|
||||
'selectRegionRegistration',
|
||||
'selectTownRegistration',
|
||||
'tbxInsKaskoPriceLeasePeriod',
|
||||
'selectTarif',
|
||||
'tbxCreditRate',
|
||||
'selectRate',
|
||||
'tbxMaxPriceChange',
|
||||
'tbxImporterRewardPerc',
|
||||
'tbxImporterRewardRub',
|
||||
'selectRegistration',
|
||||
'radioRequirementTelematic',
|
||||
'selectTelematic',
|
||||
'selectTracker',
|
||||
'tbxMileage',
|
||||
];
|
||||
|
||||
export default reactionEffects;
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
import { TableNames } from 'core/types/Calculation/Store/tables';
|
||||
import { ElementStatus } from 'core/types/statuses';
|
||||
import { ElementsNames } from 'core/types/Calculation/Store/elements';
|
||||
import { LinksNames } from 'core/types/Calculation/Store/links';
|
||||
import { ICalculationStore } from 'core/types/Calculation/Store';
|
||||
import { ICalculationStore, ElementParam } from 'core/types/Calculation/Store';
|
||||
import { Process } from 'core/types/Calculation/Store/process';
|
||||
import { isEqual } from 'lodash';
|
||||
import { autorun, makeAutoObservable, reaction } from 'mobx';
|
||||
@ -19,6 +22,24 @@ export const calculationProcess = makeAutoObservable({
|
||||
setProcess(process) {
|
||||
this.process = process;
|
||||
},
|
||||
|
||||
bypass: {
|
||||
status: undefined,
|
||||
},
|
||||
setBypass({
|
||||
param,
|
||||
target,
|
||||
value,
|
||||
}: {
|
||||
param: ElementParam;
|
||||
target: (ElementsNames | TableNames)[];
|
||||
value?: ElementStatus;
|
||||
}) {
|
||||
this.bypass[param] = { target, value };
|
||||
},
|
||||
clearBypass(prop) {
|
||||
this.bypass[prop] = undefined;
|
||||
},
|
||||
});
|
||||
|
||||
export const calculationUrls = makeAutoObservable({
|
||||
@ -37,6 +58,11 @@ const CalculationStore: ICalculationStore = makeAutoObservable(
|
||||
computedEffects,
|
||||
actionsEffects,
|
||||
modal,
|
||||
{
|
||||
stores: {
|
||||
calculationProcess,
|
||||
},
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
@ -15,6 +15,8 @@ import {
|
||||
} from './tables';
|
||||
import { TValue, TValues, ValuesNames, ResultValuesNames } from './values';
|
||||
|
||||
export type ElementParam = 'value' | 'status' | 'options' | 'filter' | 'validation';
|
||||
|
||||
interface ICalculationValues {
|
||||
staticData: TStaticData;
|
||||
getStaticData: (dataName: CRMEntityNames) => TCRMEntity[];
|
||||
@ -67,7 +69,7 @@ interface ICalculationTables {
|
||||
getTableRowValues: (
|
||||
tableName: TableNames,
|
||||
rowIndex: number,
|
||||
paramName: string,
|
||||
paramName: ElementParam,
|
||||
) => { values: TableProps<any> };
|
||||
|
||||
setTableRows: (
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
export enum Process {
|
||||
Default,
|
||||
LoadKp,
|
||||
RecalcWithoutRevision,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user