stores/calculation: support chain methods

This commit is contained in:
Chika 2022-10-26 15:21:01 +03:00
parent 31c70615af
commit 99f82ec2f9
18 changed files with 233 additions and 222 deletions

View File

@ -14,7 +14,7 @@ function PaymentsParams() {
const [selectSeasonType, tbxParmentsDecreasePercent, selectHighSeasonStart] = renderedElements;
const { $calculation } = useStore();
const graphType = $calculation.getElementValue('radioGraphType');
const graphType = $calculation.element('radioGraphType').getValue();
switch (graphType) {
case 100_000_000:

View File

@ -14,7 +14,7 @@ const QUERY_GET_CURRENCY_SYMBOL = gql`
const CurrencyAddon = observer(() => {
const { $calculation } = useStore();
const currencyid = $calculation.$values.getValue('supplierCurrency');
const currencyid = $calculation.element('selectSupplierCurrency').getValue();
const { data } = useQuery<
CRMTypes.GetCurrencySymbolQuery,

View File

@ -180,7 +180,7 @@ const overrideRender: Partial<Record<keyof typeof map, RenderProps>> = {
const Title = observer(() => {
const { $calculation } = useStore();
const graphType = $calculation.getElementValue('radioGraphType');
const graphType = $calculation.element('radioGraphType').getValue();
switch (graphType) {
case 100_000_001:

View File

@ -15,11 +15,11 @@ export default function validationReactions(store: RootStore, apolloClient: Apol
},
(hasErrors) => {
if (hasErrors) {
$calculation.blockElement('btnCalculate');
$calculation.blockElement('btnCreateKP');
$calculation.$status.setStatus('btnCalculate', 'Disabled');
$calculation.$status.setStatus('btnCreateKP', 'Disabled');
} else {
$calculation.unblockElement('btnCalculate');
$calculation.unblockElement('btnCreateKP');
$calculation.$status.setStatus('btnCalculate', 'Default');
$calculation.$status.setStatus('btnCreateKP', 'Default');
}
},
{

View File

@ -53,7 +53,7 @@ export default function commonReactions(
reaction(
() => {
const finGAPInsuranceCompany = $tables.insurance.getRowValue('fingap', 'insuranceCompany');
const leasingPeriod = $calculation.getElementValue('tbxLeasingPeriod');
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
return {
finGAPInsuranceCompany,
@ -127,8 +127,8 @@ export default function commonReactions(
const paymentsValues = toJS($tables.payments.values);
const plPriceRub = $calculation.$values.getValue('plPriceRub');
const discountRub = $calculation.$values.getValue('discountRub');
const firstPaymentRub = $calculation.getElementValue('tbxFirstPaymentRub');
const leasingPeriod = $calculation.getElementValue('tbxLeasingPeriod');
const firstPaymentRub = $calculation.element('tbxFirstPaymentRub').getValue();
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
return {
finGAPInsuranceCompany,

View File

@ -10,7 +10,7 @@ export default function getData(apolloClient, store) {
function setManyOptions(options) {
Object.keys(options).forEach((elementName) => {
const elementOptions = options[elementName];
$calculation.$options.setOptions(elementName, elementOptions);
$calculation.element(elementName).setOptions(elementOptions);
});
}

View File

@ -35,10 +35,9 @@ export default function setInitialValuesReactions(
(x) => x?.isocurrencycode === 'RUB'
);
$calculation.setElementValue(
'selectSupplierCurrency',
transactioncurrency_rub?.transactioncurrencyid
);
$calculation
.element('selectSupplierCurrency')
.setValue(transactioncurrency_rub?.transactioncurrencyid);
}
);
}

View File

@ -31,10 +31,10 @@ export default function commonReactions(store: RootStore, apolloClient: ApolloCl
makeDisposable(
() =>
reaction(
() => $calculation.getElementValue('selectLead'),
() => $calculation.element('selectLead').getValue(),
async (leadid) => {
if (!leadid) {
$calculation.resetElementValue('selectOpportunity');
$calculation.element('selectOpportunity').resetValue();
return;
}
@ -52,9 +52,9 @@ export default function commonReactions(store: RootStore, apolloClient: ApolloCl
});
if (lead?.evo_opportunityidData?.value) {
$calculation.setElementValue('selectOpportunity', lead?.evo_opportunityidData?.value);
$calculation.element('selectOpportunity').setValue(lead?.evo_opportunityidData?.value);
} else {
$calculation.resetElementValue('selectOpportunity');
$calculation.element('selectOpportunity').resetValue();
}
}
),
@ -76,9 +76,9 @@ export default function commonReactions(store: RootStore, apolloClient: ApolloCl
`;
reaction(
() => $calculation.getElementValue('selectOpportunity'),
() => $calculation.element('selectOpportunity').getValue(),
async (opportunityid) => {
const leadid = $calculation.getElementValue('selectLead');
const leadid = $calculation.element('selectLead').getValue();
if (leadid) {
const {
@ -94,7 +94,7 @@ export default function commonReactions(store: RootStore, apolloClient: ApolloCl
});
if (!opportunityid && lead?.evo_opportunityidData?.value) {
$calculation.resetElementValue('selectLead');
$calculation.element('selectLead').resetValue();
}
}
@ -109,7 +109,7 @@ export default function commonReactions(store: RootStore, apolloClient: ApolloCl
},
});
$calculation.setElementValue('selectLead', data.opportunity?.evo_leadid);
$calculation.element('selectLead').setValue(data.opportunity?.evo_leadid);
}
}
);
@ -131,7 +131,7 @@ export default function commonReactions(store: RootStore, apolloClient: ApolloCl
`;
reaction(
() => $calculation.getElementValue('selectLead'),
() => $calculation.element('selectLead').getValue(),
async (leadid) => {
if (leadid) {
const {
@ -146,9 +146,9 @@ export default function commonReactions(store: RootStore, apolloClient: ApolloCl
},
});
$calculation.setElementOptions('selectQuote', normalizeOptions(quotes));
$calculation.element('selectQuote').setOptions(normalizeOptions(quotes));
} else {
$calculation.resetElement('selectQuote');
$calculation.element('selectQuote').reset();
}
}
);

View File

@ -12,10 +12,10 @@ export default function urlsReactions(store: RootStore, apolloClient: ApolloClie
*/
function makeLinkReaction(elementName: Elements, linkElementName: Elements, query: DocumentNode) {
reaction(
() => $calculation.getElementValue(elementName),
() => $calculation.element(elementName).getValue(),
(id) => {
if (!id) {
$calculation.resetElementValue(linkElementName);
$calculation.element(linkElementName).resetValue();
return;
}
@ -34,22 +34,22 @@ export default function urlsReactions(store: RootStore, apolloClient: ApolloClie
.then(({ data }) => {
clearTimeout(timeoutId);
if (data.entity?.link) {
$calculation.setElementValue(linkElementName, data.entity?.link);
$calculation.element(linkElementName).setValue(data.entity?.link);
}
})
.catch(() => {
clearTimeout(timeoutId);
$calculation.resetElementValue(linkElementName);
$calculation.element(linkElementName).resetValue();
});
}
);
reaction(
() => $calculation.getElementValue(linkElementName),
() => $calculation.element(linkElementName).getValue(),
(url) => {
if (!url) {
$calculation.blockElement(linkElementName);
$calculation.element(linkElementName).block();
} else {
$calculation.unblockElement(linkElementName);
$calculation.element(linkElementName).unblock();
}
}
);

View File

@ -22,14 +22,14 @@ export default function paymentsReactions(
const { $calculation, $tables, $process } = store;
reaction(
() => $calculation.getElementValue('tbxFirstPaymentPerc'),
() => $calculation.element('tbxFirstPaymentPerc').getValue(),
(firstPaymentPerc) => {
$tables.payments.setValue(0, firstPaymentPerc);
}
);
reaction(
() => $calculation.getElementValue('tbxLastPaymentPerc'),
() => $calculation.element('tbxLastPaymentPerc').getValue(),
(lastPaymentPerc) => {
const paymentsLength = $tables.payments.values.length;
$tables.payments.setValue(paymentsLength - 1, lastPaymentPerc);
@ -43,8 +43,8 @@ export default function paymentsReactions(
() =>
reaction(
() => {
const graphType = $calculation.getElementValue('radioGraphType');
const leasingPeriod = $calculation.getElementValue('tbxLeasingPeriod');
const graphType = $calculation.element('radioGraphType').getValue();
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
return {
graphType,
@ -63,8 +63,8 @@ export default function paymentsReactions(
})
);
const firstPaymentPerc = $calculation.getElementValue('tbxFirstPaymentPerc');
const lastPaymentPerc = $calculation.getElementValue('tbxLastPaymentPerc');
const firstPaymentPerc = $calculation.element('tbxFirstPaymentPerc').getValue();
const lastPaymentPerc = $calculation.element('tbxLastPaymentPerc').getValue();
$tables.payments.setRows([
{
@ -93,11 +93,11 @@ export default function paymentsReactions(
() =>
reaction(
() => {
const graphType = $calculation.getElementValue('radioGraphType');
const leasingPeriod = $calculation.getElementValue('tbxLeasingPeriod');
const parmentsDecreasePercent = $calculation.getElementValue(
'tbxParmentsDecreasePercent'
);
const graphType = $calculation.element('radioGraphType').getValue();
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
const parmentsDecreasePercent = $calculation
.element('tbxParmentsDecreasePercent')
.getValue();
return {
graphType,
@ -121,8 +121,8 @@ export default function paymentsReactions(
}
);
const firstPaymentPerc = $calculation.getElementValue('tbxFirstPaymentPerc');
const lastPaymentPerc = $calculation.getElementValue('tbxLastPaymentPerc');
const firstPaymentPerc = $calculation.element('tbxFirstPaymentPerc').getValue();
const lastPaymentPerc = $calculation.element('tbxLastPaymentPerc').getValue();
$tables.payments.setRows([
{
@ -148,8 +148,8 @@ export default function paymentsReactions(
() =>
reaction(
() => {
const graphType = $calculation.getElementValue('radioGraphType');
const leasingPeriod = $calculation.getElementValue('tbxLeasingPeriod');
const graphType = $calculation.element('radioGraphType').getValue();
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
return {
graphType,
@ -183,8 +183,8 @@ export default function paymentsReactions(
})
);
const firstPaymentPerc = $calculation.getElementValue('tbxFirstPaymentPerc');
const lastPaymentPerc = $calculation.getElementValue('tbxLastPaymentPerc');
const firstPaymentPerc = $calculation.element('tbxFirstPaymentPerc').getValue();
const lastPaymentPerc = $calculation.element('tbxLastPaymentPerc').getValue();
$tables.payments.setRows([
{
@ -215,7 +215,7 @@ export default function paymentsReactions(
reaction(
() => {
const graphType = $calculation.getElementValue('radioGraphType');
const graphType = $calculation.element('radioGraphType').getValue();
return graphType;
},
@ -231,7 +231,7 @@ export default function paymentsReactions(
seasonSeasonTypes.has(option.value)
);
}
$calculation.setElementOptions('selectSeasonType', selectSeasonTypeOptions);
$calculation.element('selectSeasonType').setOptions(selectSeasonTypeOptions);
}
);
@ -246,9 +246,9 @@ export default function paymentsReactions(
() =>
reaction(
() => {
const degressionType = $calculation.getElementValue('selectSeasonType');
const leasingPeriod = $calculation.getElementValue('tbxLeasingPeriod');
const graphType = $calculation.getElementValue('radioGraphType');
const degressionType = $calculation.element('selectSeasonType').getValue();
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
const graphType = $calculation.element('radioGraphType').getValue();
return {
degressionType,
@ -317,8 +317,8 @@ export default function paymentsReactions(
}
}
const firstPaymentPerc = $calculation.getElementValue('tbxFirstPaymentPerc');
const lastPaymentPerc = $calculation.getElementValue('tbxLastPaymentPerc');
const firstPaymentPerc = $calculation.element('tbxFirstPaymentPerc').getValue();
const lastPaymentPerc = $calculation.element('tbxLastPaymentPerc').getValue();
$tables.payments.setRows([
{
@ -341,9 +341,9 @@ export default function paymentsReactions(
() =>
reaction(
() => {
const graphType = $calculation.getElementValue('radioGraphType');
const graphType = $calculation.element('radioGraphType').getValue();
const payments = toJS($tables.payments.values);
const degressionType = $calculation.getElementValue('selectSeasonType');
const degressionType = $calculation.element('selectSeasonType').getValue();
return {
graphType,
@ -365,8 +365,8 @@ export default function paymentsReactions(
return value;
});
const firstPaymentPerc = $calculation.getElementValue('tbxFirstPaymentPerc');
const lastPaymentPerc = $calculation.getElementValue('tbxLastPaymentPerc');
const firstPaymentPerc = $calculation.element('tbxFirstPaymentPerc').getValue();
const lastPaymentPerc = $calculation.element('tbxLastPaymentPerc').getValue();
$tables.payments.setValues([firstPaymentPerc, ...payments, lastPaymentPerc]);
}
@ -385,7 +385,7 @@ export default function paymentsReactions(
reaction(
() => {
const graphType = $calculation.getElementValue('radioGraphType');
const graphType = $calculation.element('radioGraphType').getValue();
return {
graphType,
@ -394,8 +394,8 @@ export default function paymentsReactions(
({ graphType }) => {
if (graphType !== 100_000_003) return;
const seasonType = $calculation.getElementValue('selectSeasonType');
const highSeasonStart = $calculation.getElementValue('selectHighSeasonStart');
const seasonType = $calculation.element('selectSeasonType').getValue();
const highSeasonStart = $calculation.element('selectHighSeasonStart').getValue();
if (!seasonType || !highSeasonStart) {
$tables.payments.setValues([]);
@ -405,16 +405,16 @@ export default function paymentsReactions(
reaction(
() => {
const seasonType = $calculation.getElementValue('selectSeasonType');
const seasonType = $calculation.element('selectSeasonType').getValue();
return seasonType;
},
(seasonType) => {
const graphType = $calculation.getElementValue('radioGraphType');
const graphType = $calculation.element('radioGraphType').getValue();
if (graphType !== 100_000_003) return;
if (!seasonType) {
$calculation.resetElement('selectHighSeasonStart');
$calculation.element('selectHighSeasonStart').reset();
return;
}
@ -423,7 +423,7 @@ export default function paymentsReactions(
(option) => !seasonsConstants.FORBIDDEN_HIGH_SEASON_START[seasonType].includes(option.label)
);
$calculation.setElementOptions('selectHighSeasonStart', highSeasonStartOptions);
$calculation.element('selectHighSeasonStart').setOptions(highSeasonStartOptions);
}
);
@ -445,9 +445,9 @@ export default function paymentsReactions(
() =>
reaction(
() => {
const seasonType = $calculation.getElementValue('selectSeasonType');
const highSeasonStartOption = $calculation.getElementOption('selectHighSeasonStart');
const leasingPeriod = $calculation.getElementValue('tbxLeasingPeriod');
const seasonType = $calculation.element('selectSeasonType').getValue();
const highSeasonStartOption = $calculation.element('selectHighSeasonStart').getOption();
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
return {
seasonType,
@ -456,7 +456,7 @@ export default function paymentsReactions(
};
},
({ seasonType, highSeasonStartOption, leasingPeriod }) => {
const graphType = $calculation.getElementValue('radioGraphType');
const graphType = $calculation.element('radioGraphType').getValue();
if (graphType !== 100_000_003) return;
if (!seasonType || !highSeasonStartOption) {
@ -475,8 +475,8 @@ export default function paymentsReactions(
shift(seasons, shiftNumber)
);
const rows: Row[] = generateSeasonPaymentsRows(seasonType, shiftNumber, payments);
const firstPaymentPerc = $calculation.getElementValue('tbxFirstPaymentPerc');
const lastPaymentPerc = $calculation.getElementValue('tbxLastPaymentPerc');
const firstPaymentPerc = $calculation.element('tbxFirstPaymentPerc').getValue();
const lastPaymentPerc = $calculation.element('tbxLastPaymentPerc').getValue();
$tables.payments.setRows([
{
@ -504,11 +504,11 @@ export default function paymentsReactions(
return seasons;
},
(nextSeasons, prevSeasons) => {
const graphType = $calculation.getElementValue('radioGraphType');
const graphType = $calculation.element('radioGraphType').getValue();
if (graphType !== 100_000_003) return;
const seasonType = $calculation.getElementValue('selectSeasonType');
const highSeasonStartOption = $calculation.getElementOption('selectHighSeasonStart');
const seasonType = $calculation.element('selectSeasonType').getValue();
const highSeasonStartOption = $calculation.element('selectHighSeasonStart').getOption();
if (!seasonType || !highSeasonStartOption) return;
const shiftNumber = Number.parseInt(highSeasonStartOption.label, 10) - 2;
@ -525,14 +525,14 @@ export default function paymentsReactions(
values[positionIndex] = unshiftedNextSeasons[changeIndex];
const seasons = seasonsTools.generateSeasons(seasonType, values);
const leasingPeriod = $calculation.getElementValue('tbxLeasingPeriod');
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
const payments = seasonsTools.generateSeasonsPayments(
leasingPeriod,
shift(seasons, shiftNumber)
);
const rows: Row[] = generateSeasonPaymentsRows(seasonType, shiftNumber, payments);
const firstPaymentPerc = $calculation.getElementValue('tbxFirstPaymentPerc');
const lastPaymentPerc = $calculation.getElementValue('tbxLastPaymentPerc');
const firstPaymentPerc = $calculation.element('tbxFirstPaymentPerc').getValue();
const lastPaymentPerc = $calculation.element('tbxLastPaymentPerc').getValue();
$tables.payments.setRows([
{
@ -562,10 +562,10 @@ export default function paymentsReactions(
reaction(
() => {
const payments = toJS($tables.payments.values);
const graphType = $calculation.getElementValue('radioGraphType');
const seasonType = $calculation.getElementValue('selectSeasonType');
const highSeasonStart = $calculation.getElementValue('selectHighSeasonStart');
const leasingPeriod = $calculation.getElementValue('tbxLeasingPeriod');
const graphType = $calculation.element('radioGraphType').getValue();
const seasonType = $calculation.element('selectSeasonType').getValue();
const highSeasonStart = $calculation.element('selectHighSeasonStart').getValue();
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
return {
payments,

View File

@ -7,10 +7,10 @@ import { areEqual, isSorted } from 'tools/array';
import { SEASONS_PERIODS, SEASONS_PERIOD_NUMBER } from './lib/seasons-constants';
export default function validatePaymentsTable({ $calculation, $tables }: RootStore) {
switch ($calculation.getElementValue('radioGraphType')) {
switch ($calculation.element('radioGraphType').getValue()) {
// Дегрессия
case 100_000_001:
if (!$calculation.getElementValue('selectSeasonType')) {
if (!$calculation.element('selectSeasonType').getValue()) {
return 'Не выбран тип дегрессии';
}
/**
@ -18,7 +18,7 @@ export default function validatePaymentsTable({ $calculation, $tables }: RootSto
*/
{
const MIN_PAYMENT = 3;
const leasingPeriod = $calculation.getElementValue('tbxLeasingPeriod');
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
const targetPayments = $tables.payments.values.slice(1, leasingPeriod - 1);
if (!targetPayments.every((payment) => payment >= MIN_PAYMENT)) {
@ -30,7 +30,7 @@ export default function validatePaymentsTable({ $calculation, $tables }: RootSto
* при Дегрессии все значения не должны быть равны друг другу + что при Легком старте 2,3 и 4 платежи не должны быть равны 100
*/
{
const leasingPeriod = $calculation.getElementValue('tbxLeasingPeriod');
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
const targetPayments = $tables.payments.values.slice(1, leasingPeriod - 1);
if (new Set(targetPayments).size === 1) {
@ -42,7 +42,7 @@ export default function validatePaymentsTable({ $calculation, $tables }: RootSto
* Проверка на возрастание
*/
{
const leasingPeriod = $calculation.getElementValue('tbxLeasingPeriod');
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
const targetPayments = $tables.payments.values.slice(1, leasingPeriod - 1);
for (let i = 2; i < targetPayments.length - 1; i += 1) {
@ -73,7 +73,7 @@ export default function validatePaymentsTable({ $calculation, $tables }: RootSto
* иначе не осуществлять Расчет графика и выводить ошибку "Нельзя осуществить расчет - указана очень жетская дегрессия. Не менее чем у 4х платежей "Соотношение платежа" должно не отличаться между самой",
*/
{
const leasingPeriod = $calculation.getElementValue('tbxLeasingPeriod');
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
const targetPayments = $tables.payments.values.slice(1, leasingPeriod - 1);
const counts = counting(targetPayments, (v) => v);
if (Object.values(counts).filter((count) => count > 1).length < 2) {
@ -84,17 +84,17 @@ export default function validatePaymentsTable({ $calculation, $tables }: RootSto
break;
case 100_000_003: {
const leasingPeriod = $calculation.getElementValue('tbxLeasingPeriod');
const leasingPeriod = $calculation.element('tbxLeasingPeriod').getValue();
if (leasingPeriod < 14) {
return 'При сезонном виде графика срок лизинга должен быть больше 14 месяцев';
}
const seasonType = $calculation.getElementValue('selectSeasonType');
const seasonType = $calculation.element('selectSeasonType').getValue();
if (!seasonType) {
return 'Не выбран тип сезонности';
}
const highSeasonStartOption = $calculation.getElementOption('selectHighSeasonStart');
const highSeasonStartOption = $calculation.element('selectHighSeasonStart').getOption();
if (!highSeasonStartOption) {
return 'Не выбрано смещение сезонности';
}

View File

@ -31,9 +31,9 @@ export default function computedReactions(store: RootStore, apolloClient: Apollo
autorun(
async () => {
const supplierCurrencyId = $calculation.getElementValue('selectSupplierCurrency');
const leaseObjectPrice = $calculation.getElementValue('tbxLeaseObjectPrice');
const supplierDiscountRub = $calculation.getElementValue('tbxSupplierDiscountRub');
const supplierCurrencyId = $calculation.element('selectSupplierCurrency').getValue();
const leaseObjectPrice = $calculation.element('tbxLeaseObjectPrice').getValue();
const supplierDiscountRub = $calculation.element('tbxSupplierDiscountRub').getValue();
if (!supplierCurrencyId) {
$calculation.$values.setValue('plPriceRub', leaseObjectPrice);

View File

@ -26,10 +26,10 @@ export function fillAgentRewardReaction(
makeDisposable(
() =>
reaction(
() => $calculation.getElementValue(agentField),
() => $calculation.element(agentField).getValue(),
async (agentId) => {
if (!agentId) {
$calculation.resetElement(rewardConditionField);
$calculation.element(rewardConditionField).reset();
return;
}
@ -47,10 +47,9 @@ export function fillAgentRewardReaction(
});
if (evo_reward_conditions?.length) {
$calculation.setElementOptions(
rewardConditionField,
normalizeOptions(evo_reward_conditions)
);
$calculation
.element(rewardConditionField)
.setOptions(normalizeOptions(evo_reward_conditions));
}
}
),
@ -72,10 +71,10 @@ export function fillAgentRewardSummReaction(
makeDisposable(
() =>
reaction(
() => $calculation.getElementValue(rewardConditionField),
() => $calculation.element(rewardConditionField).getValue(),
async (rewardConditionId) => {
if (!rewardConditionId) {
$calculation.resetElement(rewardSummField);
$calculation.element(rewardSummField).reset();
return;
}
@ -92,9 +91,9 @@ export function fillAgentRewardSummReaction(
},
});
$calculation.setElementValue(rewardSummField, evo_reward_condition?.evo_reward_summ);
$calculation.element(rewardSummField).setValue(evo_reward_condition?.evo_reward_summ);
$calculation.unblockElement(rewardSummField);
$calculation.element(rewardSummField).unblock();
}
),
() => $process.has('LoadKP')

View File

@ -18,7 +18,7 @@ function makeFillAgentFromLead(
leadid: string | null
) {
if (!leadid) {
$calculation.resetElement(elementName);
$calculation.element(elementName).reset();
return;
}
@ -43,11 +43,13 @@ function makeFillAgentFromLead(
});
if (agent) {
$calculation.setElementOptions(elementName, normalizeOptions([agent]));
$calculation.setElementValue(elementName, agent.value);
$calculation
.element(elementName)
.setOptions(normalizeOptions([agent]))
.setValue(agent.value);
}
} else {
$calculation.resetElement(elementName);
$calculation.element(elementName).reset();
}
};
}

View File

@ -22,7 +22,7 @@ export function fillReactions(store: RootStore, apolloClient: ApolloClient<objec
makeDisposable(
() =>
reaction(
() => $calculation.getElementValue('selectLead'),
() => $calculation.element('selectLead').getValue(),
(leadid) => {
fillAgentsFromLead.fillIndAgent(store, apolloClient, leadid);
fillAgentsFromLead.fillCalcDoubleAgent(store, apolloClient, leadid);
@ -122,10 +122,10 @@ export function commonReactions(store: RootStore, apolloClient: ApolloClient<obj
*/
reaction(
() => $calculation.getElementValue('selectDealerRewardCondition'),
() => $calculation.element('selectDealerRewardCondition').getValue(),
async (rewardConditionId) => {
function fillAgents() {
const leadid = $calculation.getElementValue('selectLead');
const leadid = $calculation.element('selectLead').getValue();
fillAgentsFromLead.fillIndAgent(store, apolloClient, leadid);
fillAgentsFromLead.fillCalcDoubleAgent(store, apolloClient, leadid);
fillAgentsFromLead.fillCalcBroker(store, apolloClient, leadid);
@ -151,11 +151,11 @@ export function commonReactions(store: RootStore, apolloClient: ApolloClient<obj
});
if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) {
$calculation.resetElement('selectDealerBroker');
$calculation.resetElement('selectIndAgent');
$calculation.resetElement('selectCalcDoubleAgent');
$calculation.resetElement('selectCalcBroker');
$calculation.resetElement('selectCalcFinDepartment');
$calculation.element('selectDealerBroker').reset();
$calculation.element('selectIndAgent').reset();
$calculation.element('selectCalcDoubleAgent').reset();
$calculation.element('selectCalcBroker').reset();
$calculation.element('selectCalcFinDepartment').reset();
} else {
fillAgents();
}
@ -184,10 +184,10 @@ export function commonReactions(store: RootStore, apolloClient: ApolloClient<obj
selectFinDepartmentRewardCondtion заполняется значением из Интереса
*/
reaction(
() => $calculation.getElementValue('selectDealerBrokerRewardCondition'),
() => $calculation.element('selectDealerBrokerRewardCondition').getValue(),
async (rewardConditionId) => {
function fillAgents() {
const leadid = $calculation.getElementValue('selectLead');
const leadid = $calculation.element('selectLead').getValue();
fillAgentsFromLead.fillIndAgent(store, apolloClient, leadid);
fillAgentsFromLead.fillCalcDoubleAgent(store, apolloClient, leadid);
fillAgentsFromLead.fillCalcBroker(store, apolloClient, leadid);
@ -213,14 +213,13 @@ export function commonReactions(store: RootStore, apolloClient: ApolloClient<obj
});
if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) {
$calculation.blockElement('selectDealerPerson');
$calculation.resetElement('selectIndAgent');
$calculation.resetElement('selectCalcDoubleAgent');
$calculation.resetElement('selectCalcBroker');
$calculation.resetElement('selectCalcFinDepartment');
$calculation.element('selectDealerPerson').block();
$calculation.element('selectIndAgent').reset();
$calculation.element('selectCalcDoubleAgent').reset();
$calculation.element('selectCalcBroker').reset();
$calculation.element('selectCalcFinDepartment').reset();
} else {
$calculation.unblockElement('selectDealerPerson');
$calculation.element('selectDealerPerson').unblock();
fillAgents();
}
}
@ -249,10 +248,10 @@ export function commonReactions(store: RootStore, apolloClient: ApolloClient<obj
*/
reaction(
() => $calculation.getElementValue('selectIndAgentRewardCondition'),
() => $calculation.element('selectIndAgentRewardCondition').getValue(),
async (rewardConditionId) => {
function fillAgents() {
const leadid = $calculation.getElementValue('selectLead');
const leadid = $calculation.element('selectLead').getValue();
fillAgentsFromLead.fillCalcDoubleAgent(store, apolloClient, leadid);
fillAgentsFromLead.fillCalcBroker(store, apolloClient, leadid);
fillAgentsFromLead.fillFinDepartment(store, apolloClient, leadid);
@ -277,14 +276,13 @@ export function commonReactions(store: RootStore, apolloClient: ApolloClient<obj
});
if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) {
$calculation.blockElement('selectDealerPerson');
$calculation.resetElement('selectDealerBroker');
$calculation.resetElement('selectCalcDoubleAgent');
$calculation.resetElement('selectCalcBroker');
$calculation.resetElement('selectCalcFinDepartment');
$calculation.element('selectDealerPerson').block();
$calculation.element('selectDealerBroker').reset();
$calculation.element('selectCalcDoubleAgent').reset();
$calculation.element('selectCalcBroker').reset();
$calculation.element('selectCalcFinDepartment').reset();
} else {
$calculation.unblockElement('selectDealerPerson');
$calculation.element('selectDealerPerson').unblock();
fillAgents();
}
}
@ -313,10 +311,10 @@ export function commonReactions(store: RootStore, apolloClient: ApolloClient<obj
*/
reaction(
() => $calculation.getElementValue('selectCalcDoubleAgentRewardCondition'),
() => $calculation.element('selectCalcDoubleAgentRewardCondition').getValue(),
async (rewardConditionId) => {
function fillAgents() {
const leadid = $calculation.getElementValue('selectLead');
const leadid = $calculation.element('selectLead').getValue();
fillAgentsFromLead.fillIndAgent(store, apolloClient, leadid);
fillAgentsFromLead.fillCalcBroker(store, apolloClient, leadid);
fillAgentsFromLead.fillFinDepartment(store, apolloClient, leadid);
@ -341,15 +339,14 @@ export function commonReactions(store: RootStore, apolloClient: ApolloClient<obj
});
if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) {
$calculation.blockElement('selectDealerPerson');
$calculation.resetElement('selectDealerBroker');
$calculation.resetElement('selectIndAgent');
$calculation.resetElement('selectCalcBroker');
$calculation.resetElement('selectCalcFinDepartment');
$calculation.element('selectDealerPerson').block();
$calculation.element('selectDealerBroker').reset();
$calculation.element('selectIndAgent').reset();
$calculation.element('selectCalcBroker').reset();
$calculation.element('selectCalcFinDepartment').reset();
} else {
$calculation.unblockElement('selectDealerPerson');
$calculation.unblockElement('selectDealerBroker');
$calculation.element('selectDealerPerson').unblock();
$calculation.element('selectDealerBroker').unblock();
fillAgents();
}
}
@ -378,10 +375,10 @@ export function commonReactions(store: RootStore, apolloClient: ApolloClient<obj
selectCalcFinDepartment заполняется значением из Интереса
*/
reaction(
() => $calculation.getElementValue('selectCalcBrokerRewardCondition'),
() => $calculation.element('selectCalcBrokerRewardCondition').getValue(),
async (rewardConditionId) => {
function fillAgents() {
const leadid = $calculation.getElementValue('selectLead');
const leadid = $calculation.element('selectLead').getValue();
fillAgentsFromLead.fillIndAgent(store, apolloClient, leadid);
fillAgentsFromLead.fillCalcDoubleAgent(store, apolloClient, leadid);
fillAgentsFromLead.fillFinDepartment(store, apolloClient, leadid);
@ -406,15 +403,14 @@ export function commonReactions(store: RootStore, apolloClient: ApolloClient<obj
});
if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) {
$calculation.blockElement('selectDealerPerson');
$calculation.resetElement('selectDealerBroker');
$calculation.resetElement('selectIndAgent');
$calculation.resetElement('selectCalcDoubleAgent');
$calculation.resetElement('selectCalcFinDepartment');
$calculation.element('selectDealerPerson').block();
$calculation.element('selectDealerBroker').reset();
$calculation.element('selectIndAgent').reset();
$calculation.element('selectCalcDoubleAgent').reset();
$calculation.element('selectCalcFinDepartment').reset();
} else {
$calculation.unblockElement('selectDealerPerson');
$calculation.unblockElement('selectDealerBroker');
$calculation.element('selectDealerPerson').unblock();
$calculation.element('selectDealerBroker').unblock();
fillAgents();
}
}
@ -443,10 +439,10 @@ export function commonReactions(store: RootStore, apolloClient: ApolloClient<obj
*/
reaction(
() => $calculation.getElementValue('selectFinDepartmentRewardCondtion'),
() => $calculation.element('selectFinDepartmentRewardCondtion').getValue(),
async (rewardConditionId) => {
function fillAgents() {
const leadid = $calculation.getElementValue('selectLead');
const leadid = $calculation.element('selectLead').getValue();
fillAgentsFromLead.fillIndAgent(store, apolloClient, leadid);
fillAgentsFromLead.fillCalcDoubleAgent(store, apolloClient, leadid);
fillAgentsFromLead.fillFinDepartment(store, apolloClient, leadid);
@ -471,15 +467,14 @@ export function commonReactions(store: RootStore, apolloClient: ApolloClient<obj
});
if (evo_reward_condition?.evo_agency_agreementidData?.evo_reward_without_other_agent) {
$calculation.blockElement('selectDealerPerson');
$calculation.resetElement('selectDealerBroker');
$calculation.resetElement('selectIndAgent');
$calculation.resetElement('selectCalcDoubleAgent');
$calculation.resetElement('selectCalcBroker');
$calculation.element('selectDealerPerson').block();
$calculation.element('selectDealerBroker').reset();
$calculation.element('selectIndAgent').reset();
$calculation.element('selectCalcDoubleAgent').reset();
$calculation.element('selectCalcBroker').reset();
} else {
$calculation.unblockElement('selectDealerPerson');
$calculation.unblockElement('selectDealerBroker');
$calculation.element('selectDealerPerson').unblock();
$calculation.element('selectDealerBroker').unblock();
fillAgents();
}
}

View File

@ -35,11 +35,11 @@ export function commonReactions(store: RootStore, apolloClient: ApolloClient<obj
makeDisposable(
() =>
reaction(
() => $calculation.getElementValue('selectDealer'),
() => $calculation.element('selectDealer').getValue(),
async (dealerId) => {
if (!dealerId) {
$calculation.resetElement('selectDealerPerson');
$calculation.resetElement('selectDealerBroker');
$calculation.element('selectDealerPerson').reset();
$calculation.element('selectDealerBroker').reset();
return;
}
@ -57,8 +57,10 @@ export function commonReactions(store: RootStore, apolloClient: ApolloClient<obj
});
if (salon_providers?.length) {
$calculation.setElementOptions('selectDealerPerson', normalizeOptions(salon_providers));
$calculation.setElementValue('selectDealerPerson', salon_providers[0]?.value);
$calculation
.element('selectDealerPerson')
.setOptions(normalizeOptions(salon_providers))
.setValue(salon_providers[0]?.value);
}
}
),
@ -80,7 +82,7 @@ export function commonReactions(store: RootStore, apolloClient: ApolloClient<obj
makeDisposable(
() =>
reaction(
() => $calculation.getElementValue('selectDealerPerson'),
() => $calculation.element('selectDealerPerson').getValue(),
async (dealerPersonId) => {
if (!dealerPersonId) {
return;
@ -109,14 +111,13 @@ export function commonReactions(store: RootStore, apolloClient: ApolloClient<obj
});
if (dealerBroker) {
$calculation.setElementOptions(
'selectDealerBroker',
normalizeOptions([dealerBroker])
);
$calculation.setElementValue('selectDealerBroker', dealerBroker.value);
$calculation
.element('selectDealerBroker')
.setOptions(normalizeOptions([dealerBroker]))
.setValue(dealerBroker.value);
}
} else {
$calculation.resetElement('selectDealerBroker');
$calculation.element('selectDealerBroker').reset();
}
}
),
@ -148,19 +149,19 @@ export function commonReactions(store: RootStore, apolloClient: ApolloClient<obj
});
reaction(
() => $calculation.getElementValue('selectDealerRewardCondition'),
() => $calculation.element('selectDealerRewardCondition').getValue(),
(dealerRewardConditionId) => {
if (dealerRewardConditionId) {
$calculation.resetElementValue('selectDealerBroker');
$calculation.element('selectDealerBroker').resetValue();
}
}
);
reaction(
() => $calculation.getElementValue('selectDealerBrokerRewardCondition'),
() => $calculation.element('selectDealerBrokerRewardCondition').getValue(),
(dealerBrokerRewardConditionId) => {
if (dealerBrokerRewardConditionId) {
$calculation.resetElementValue('selectDealerPerson');
$calculation.element('selectDealerPerson').resetValue();
}
}
);

View File

@ -1,5 +1,4 @@
/* eslint-disable import/no-cycle */
import type { Elements as ElementsActions } from 'Components/Calculation/config/map/actions';
import type * as Values from 'Components/Calculation/config/map/values';
import { getValueName } from 'Components/Calculation/config/map/values';
import type { BaseOption } from 'Elements/types';
@ -22,51 +21,67 @@ export default class CalculationStore {
this.$validation = new ValidationStore(rootStore);
}
resetElement = (elementName: Values.Elements) => {
this.resetElementValue(elementName);
this.$options.resetOptions(elementName);
this.$status.resetStatus(elementName);
this.$validation.clearErrors(elementName);
};
element = <E extends Values.Elements>(elementName: E) => ({
reset: () => {
const valueName = getValueName(elementName);
this.$values.resetValue(valueName);
blockElement = (elementName: Values.Elements | ElementsActions) => {
this.$status.setStatus(elementName, 'Disabled');
};
this.$options.resetOptions(elementName);
this.$status.resetStatus(elementName);
this.$validation.clearErrors(elementName);
unblockElement = (elementName: Values.Elements | ElementsActions) => {
this.$status.setStatus(elementName, 'Default');
};
return this.element(elementName);
},
getElementValue<E extends Values.Elements>(elementName: E) {
const valueName = getValueName(elementName);
block: () => {
this.$status.setStatus(elementName, 'Disabled');
return this.$values.getValue(valueName) as Values.ElementsTypes[E];
}
return this.element(elementName);
},
setElementValue = <E extends Values.Elements>(elementName: E, value: Values.ElementsTypes[E]) => {
const valueName = getValueName(elementName);
this.$values.setValue(valueName, value);
};
unblock: () => {
this.$status.setStatus(elementName, 'Default');
resetElementValue = (elementName: Values.Elements) => {
const valueName = getValueName(elementName);
this.$values.resetValue(valueName);
};
return this.element(elementName);
},
setElementOptions = <T extends Values.Elements>(
elementName: T,
options: BaseOption<Values.ElementsTypes[T]>[]
) => {
this.$options.setOptions(elementName, options);
};
getValue: () => {
const valueName = getValueName(elementName);
resetElementOptions = <T extends Values.Elements>(elementName: T) => {
this.$options.resetOptions(elementName);
};
return this.$values.getValue(valueName) as Values.ElementsTypes[E];
},
getElementOption<T extends Values.Elements>(elementName: T) {
const value = this.getElementValue(elementName);
setValue: (value: Values.ElementsTypes[E]) => {
const valueName = getValueName(elementName);
this.$values.setValue(valueName, value);
return this.$options.getOptions(elementName)?.find((x) => x.value === value);
}
return this.element(elementName);
},
resetValue: () => {
const valueName = getValueName(elementName);
this.$values.resetValue(valueName);
return this.element(elementName);
},
getOption: () => {
const valueName = getValueName(elementName);
const value = this.$values.getValue(valueName) as Values.ElementsTypes[E];
return this.$options.getOptions(elementName)?.find((x) => x.value === value);
},
setOptions: (options: BaseOption<Values.ElementsTypes[E]>[]) => {
this.$options.setOptions(elementName, options);
return this.element(elementName);
},
resetOptions: () => {
this.$options.resetOptions(elementName);
return this.element(elementName);
},
});
}

View File

@ -30,13 +30,13 @@ export default class OptionsStore {
/**
* Проверяем, что значение есть в новом списке, иначе сбрасываем значение
*/
const value = this.root.$calculation.getElementValue(elementName);
const value = this.root.$calculation.element(elementName).getValue();
if (
// eslint-disable-next-line operator-linebreak
!this.options[elementName]?.length ||
!this.options[elementName].some((x) => x.value === value)
) {
this.root.$calculation.resetElementValue(elementName);
this.root.$calculation.element(elementName).resetValue();
}
};