effects: table && calculate button
This commit is contained in:
parent
a37ab0b37b
commit
839f1fe62a
@ -1,7 +1,9 @@
|
||||
import Button from 'client/Elements/Button';
|
||||
import Label from 'client/Elements/Label';
|
||||
import Select from 'client/Elements/Select';
|
||||
import Switch from 'client/Elements/Switch';
|
||||
import { IGroup } from 'core/types/Calculation/components';
|
||||
import { ElementType } from 'core/types/elements';
|
||||
|
||||
const resultsList: IGroup[] = [
|
||||
{
|
||||
@ -24,6 +26,16 @@ const resultsList: IGroup[] = [
|
||||
computedValue: 'opportunityName',
|
||||
},
|
||||
},
|
||||
{
|
||||
type: ElementType.Button,
|
||||
Component: Button,
|
||||
props: {
|
||||
name: 'btnCalculate',
|
||||
actionName: 'calculate',
|
||||
text: 'Рассчитать график',
|
||||
type: 'primary',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
@ -1338,11 +1338,8 @@ const sections: ISections[] = [
|
||||
title: 'Стоимость страховки КАСКО на весь срок',
|
||||
Component: InputNumber,
|
||||
props: {
|
||||
min: '10000',
|
||||
max: '1000000000',
|
||||
step: '10000.00',
|
||||
name: 'tbxInsKaskoPriceLeasePeriod',
|
||||
valueName: 'insKaskoPriceLeasePeriod',
|
||||
computedValue: 'insKaskoPriceLeasePeriod',
|
||||
},
|
||||
},
|
||||
],
|
||||
@ -1377,6 +1374,11 @@ const sections: ISections[] = [
|
||||
name: 'insCost',
|
||||
title: 'Стоимость полиса',
|
||||
Component: InputNumber,
|
||||
props: {
|
||||
min: '0.00',
|
||||
max: '1500000.00',
|
||||
step: '1000.00',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'insTerm',
|
||||
|
||||
@ -89,6 +89,7 @@ const Table = ({ name: tableName, columns, values, features, actions }) => {
|
||||
tableName,
|
||||
rowIndex: ri,
|
||||
propName: key,
|
||||
...columns[columnIndex].props,
|
||||
});
|
||||
return (
|
||||
<td key={ki}>
|
||||
|
||||
@ -65,7 +65,7 @@ export const useTableValue = ({ tableName, rowIndex, propName }) => {
|
||||
: undefined;
|
||||
useEffect(() => {
|
||||
if (cellCallback) {
|
||||
cellCallback(calculationStore, rowIndex, propName);
|
||||
cellCallback(calculationStore, tableName, rowIndex, propName);
|
||||
}
|
||||
}, [cellCallback, debouncedValue]);
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { openNotification } from 'client/Elements/Notification';
|
||||
import CalculationStore from 'client/stores/CalculationStore';
|
||||
import { TAction } from 'core/types/effect';
|
||||
import { Status } from 'core/types/statuses';
|
||||
|
||||
const actions: TAction = {
|
||||
createLead: () => {
|
||||
@ -144,6 +145,34 @@ const actions: TAction = {
|
||||
}
|
||||
}
|
||||
},
|
||||
calculate: () => {
|
||||
const { values: tableValues } = CalculationStore.tables.tableInsurance;
|
||||
const kaskoRow = tableValues.find(x => x.policyType === 'КАСКО');
|
||||
const DGORow = tableValues.find(x => x.policyType === 'ДГО');
|
||||
const NSRow = tableValues.find(x => x.policyType === 'НС');
|
||||
|
||||
if (
|
||||
kaskoRow &&
|
||||
kaskoRow.insCost === 0 &&
|
||||
((DGORow && DGORow.insCost > 0) || (NSRow && NSRow.insCost > 0))
|
||||
) {
|
||||
openNotification({
|
||||
type: 'error',
|
||||
title: 'Ошибка во время расчета графика',
|
||||
description: 'Укажите стоимость КАСКО',
|
||||
})();
|
||||
return;
|
||||
}
|
||||
|
||||
if (kaskoRow && kaskoRow.insured === 100000001 && kaskoRow.insCost === 0) {
|
||||
openNotification({
|
||||
type: 'error',
|
||||
title: 'Ошибка во время расчета графика',
|
||||
description: 'Укажите стоимость КАСКО, включаемую в график',
|
||||
})();
|
||||
return;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default { actions };
|
||||
|
||||
@ -41,7 +41,7 @@ const computedEffects = {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const modelId = this.values.model;
|
||||
if (modelId) {
|
||||
const model = this.options.selectModel?.find(
|
||||
@ -53,6 +53,21 @@ const computedEffects = {
|
||||
}
|
||||
}
|
||||
},
|
||||
insKaskoPriceLeasePeriod() {
|
||||
const { leasingPeriod } = this.values;
|
||||
const { values: tableValues } = this.tables.tableInsurance;
|
||||
const kaskoRow = tableValues[1];
|
||||
const dgo = tableValues[2];
|
||||
const ns = tableValues[3];
|
||||
|
||||
if (leasingPeriod && leasingPeriod > 15 && kaskoRow.insTerm === 100000001) {
|
||||
return (
|
||||
(leasingPeriod / 12) *
|
||||
(kaskoRow.insCost + dgo.insCost + ns.insCost)
|
||||
).toFixed(2);
|
||||
}
|
||||
return 0;
|
||||
},
|
||||
};
|
||||
|
||||
export default computedEffects;
|
||||
|
||||
@ -2032,10 +2032,10 @@ const reactionEffects: IReactionEffect[] = [
|
||||
);
|
||||
const kaskoRow = tableValues[kaskoRowIndex];
|
||||
if (kaskoRow) {
|
||||
return kaskoRow.insTerm;
|
||||
return { ...kaskoRow };
|
||||
}
|
||||
},
|
||||
effect: insTerm => {
|
||||
effect: ({ insuranceCompany, insTerm, insured }) => {
|
||||
if (insTerm) {
|
||||
const { values: tableValues } = calculationStore.tables.tableInsurance;
|
||||
const dgoRowIndex = tableValues.findIndex(x => x.policyType === 'ДГО');
|
||||
@ -2046,9 +2046,7 @@ const reactionEffects: IReactionEffect[] = [
|
||||
rowIndex: dgoRowIndex,
|
||||
},
|
||||
{
|
||||
values: {
|
||||
insTerm,
|
||||
},
|
||||
values: { insuranceCompany, insTerm, insured },
|
||||
},
|
||||
);
|
||||
const nsRowIndex = tableValues.findIndex(x => x.policyType === 'НС');
|
||||
@ -2060,18 +2058,30 @@ const reactionEffects: IReactionEffect[] = [
|
||||
},
|
||||
{
|
||||
values: {
|
||||
insuranceCompany,
|
||||
insTerm,
|
||||
insured,
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
}),
|
||||
|
||||
calculationStore => ({
|
||||
expression: () => {
|
||||
const { values: tableValues } = calculationStore.tables.tableInsurance;
|
||||
const kaskoRowIndex = tableValues.findIndex(
|
||||
x => x.policyType === 'КАСКО',
|
||||
);
|
||||
|
||||
if (insTerm === 'dl_period' && kaskoRowIndex) {
|
||||
const kaskoRow = tableValues[kaskoRowIndex];
|
||||
const { leasingPeriod } = calculationStore.values;
|
||||
if (kaskoRow) {
|
||||
return { insTerm: kaskoRow.insTerm, kaskoRowIndex, leasingPeriod };
|
||||
}
|
||||
},
|
||||
effect: ({ insTerm, kaskoRowIndex, leasingPeriod }) => {
|
||||
if (insTerm === 100000001 && leasingPeriod > 15 && kaskoRowIndex) {
|
||||
if (kaskoRowIndex >= 0)
|
||||
calculationStore.setTableRow(
|
||||
{
|
||||
@ -2080,7 +2090,7 @@ const reactionEffects: IReactionEffect[] = [
|
||||
},
|
||||
{
|
||||
values: {
|
||||
insured: 'evo',
|
||||
insured: 100000001,
|
||||
},
|
||||
statuses: {
|
||||
insured: Status.Disabled,
|
||||
@ -2114,8 +2124,12 @@ const reactionEffects: IReactionEffect[] = [
|
||||
const kaskoRowIndex = tableValues.findIndex(
|
||||
x => x.policyType === 'КАСКО',
|
||||
);
|
||||
if (leasingPeriod)
|
||||
if (leasingPeriod < 13) {
|
||||
const osagoRowIndex = tableValues.findIndex(
|
||||
x => x.policyType === 'ОСАГО',
|
||||
);
|
||||
|
||||
if (leasingPeriod) {
|
||||
if (leasingPeriod < 12) {
|
||||
if (kaskoRowIndex >= 0)
|
||||
calculationStore.setTableRow(
|
||||
{
|
||||
@ -2124,29 +2138,29 @@ const reactionEffects: IReactionEffect[] = [
|
||||
},
|
||||
{
|
||||
values: {
|
||||
insTerm: 'year_period',
|
||||
insured: 100000000,
|
||||
},
|
||||
statuses: {
|
||||
insTerm: Status.Disabled,
|
||||
insured: Status.Disabled,
|
||||
},
|
||||
},
|
||||
);
|
||||
} else if (leasingPeriod > 12 && leasingPeriod < 16) {
|
||||
if (kaskoRowIndex >= 0)
|
||||
if (osagoRowIndex >= 0) {
|
||||
calculationStore.setTableRow(
|
||||
{
|
||||
tableName: 'tableInsurance',
|
||||
rowIndex: kaskoRowIndex,
|
||||
rowIndex: osagoRowIndex,
|
||||
},
|
||||
{
|
||||
values: {
|
||||
insTerm: 'dl_period',
|
||||
insured: 100000000,
|
||||
},
|
||||
statuses: {
|
||||
insTerm: Status.Disabled,
|
||||
insured: Status.Disabled,
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (kaskoRowIndex >= 0)
|
||||
calculationStore.setTableRow(
|
||||
@ -2156,11 +2170,76 @@ const reactionEffects: IReactionEffect[] = [
|
||||
},
|
||||
{
|
||||
statuses: {
|
||||
insured: Status.Default,
|
||||
},
|
||||
},
|
||||
);
|
||||
if (osagoRowIndex >= 0) {
|
||||
calculationStore.setTableRow(
|
||||
{
|
||||
tableName: 'tableInsurance',
|
||||
rowIndex: osagoRowIndex,
|
||||
},
|
||||
{
|
||||
statuses: {
|
||||
insured: Status.Default,
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (leasingPeriod < 13) {
|
||||
if (kaskoRowIndex >= 0)
|
||||
calculationStore.setTableRow(
|
||||
{
|
||||
tableName: 'tableInsurance',
|
||||
rowIndex: kaskoRowIndex,
|
||||
},
|
||||
{
|
||||
values: {
|
||||
insTerm: 100000000,
|
||||
},
|
||||
statuses: {
|
||||
insTerm: Status.Disabled,
|
||||
},
|
||||
},
|
||||
);
|
||||
return;
|
||||
} else if (leasingPeriod > 12 && leasingPeriod < 16) {
|
||||
if (kaskoRowIndex >= 0)
|
||||
calculationStore.setTableRow(
|
||||
{
|
||||
tableName: 'tableInsurance',
|
||||
rowIndex: kaskoRowIndex,
|
||||
},
|
||||
{
|
||||
values: {
|
||||
insTerm: 100000001,
|
||||
},
|
||||
statuses: {
|
||||
insTerm: Status.Disabled,
|
||||
},
|
||||
},
|
||||
);
|
||||
return;
|
||||
} else {
|
||||
if (kaskoRowIndex >= 0) {
|
||||
calculationStore.setTableRow(
|
||||
{
|
||||
tableName: 'tableInsurance',
|
||||
rowIndex: kaskoRowIndex,
|
||||
},
|
||||
{
|
||||
statuses: {
|
||||
insured: Status.Default,
|
||||
insTerm: Status.Default,
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
options: {
|
||||
fireImmediately: true,
|
||||
|
||||
@ -6,6 +6,7 @@ const initialStatuses: TStatuses = {
|
||||
selectCalcFinDepartment: Status.Disabled,
|
||||
selectDoubleAgent: Status.Disabled,
|
||||
selectCalcDoubleAgent: Status.Disabled,
|
||||
tbxInsKaskoPriceLeasePeriod: Status.Disabled,
|
||||
};
|
||||
|
||||
export default initialStatuses;
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { openNotification } from 'client/Elements/Notification';
|
||||
import { Status } from 'core/types/statuses';
|
||||
import { IStoreTable } from './../types/tables';
|
||||
const initialTables: IStoreTable = {
|
||||
@ -8,7 +9,7 @@ const initialTables: IStoreTable = {
|
||||
insuranceCompany: null,
|
||||
insured: null,
|
||||
insCost: 0,
|
||||
insTerm: null,
|
||||
insTerm: 100000000,
|
||||
},
|
||||
{
|
||||
policyType: 'КАСКО',
|
||||
@ -54,31 +55,105 @@ const initialTables: IStoreTable = {
|
||||
insured: [
|
||||
{
|
||||
name: 'Лизингополучатель',
|
||||
value: 'client',
|
||||
value: 100000000,
|
||||
},
|
||||
{
|
||||
name: 'Лизингодатель',
|
||||
value: 'evo',
|
||||
value: 100000001,
|
||||
},
|
||||
],
|
||||
insTerm: [
|
||||
{
|
||||
name: '12 месяцев',
|
||||
value: 'year_period',
|
||||
value: 100000000,
|
||||
},
|
||||
{
|
||||
name: 'Срок ДЛ',
|
||||
value: 'dl_period',
|
||||
value: 100000001,
|
||||
},
|
||||
],
|
||||
},
|
||||
filters: [],
|
||||
callbacks: {
|
||||
policyType: (calculationStore, rowIndex, propName) => {
|
||||
//action
|
||||
insCost: (calculationStore, tableName, rowIndex, propName) => {
|
||||
if (
|
||||
calculationStore.tables[tableName].values[rowIndex]['insCost'] &&
|
||||
calculationStore.tables[tableName].values[rowIndex]['insCost'] > 0 &&
|
||||
!calculationStore.tables[tableName].values[rowIndex][
|
||||
'insuranceCompany'
|
||||
]
|
||||
) {
|
||||
openNotification({
|
||||
type: 'error',
|
||||
title: 'Ошибка',
|
||||
description: 'Не указана страховая компания по полису',
|
||||
})();
|
||||
}
|
||||
if (
|
||||
calculationStore.tables[tableName].values[rowIndex]['insCost'] &&
|
||||
calculationStore.tables[tableName].values[rowIndex]['insCost'] > 0 &&
|
||||
!calculationStore.tables[tableName].values[rowIndex]['insTerm']
|
||||
) {
|
||||
openNotification({
|
||||
type: 'error',
|
||||
title: 'Ошибка',
|
||||
description: 'Не указан срок страхования',
|
||||
})();
|
||||
}
|
||||
if (
|
||||
calculationStore.tables[tableName].values[rowIndex]['insCost'] &&
|
||||
calculationStore.tables[tableName].values[rowIndex]['insCost'] > 0 &&
|
||||
!calculationStore.tables[tableName].values[rowIndex]['insured']
|
||||
) {
|
||||
openNotification({
|
||||
type: 'error',
|
||||
title: 'Ошибка',
|
||||
description: 'Не указан плательщик',
|
||||
})();
|
||||
}
|
||||
},
|
||||
insuranceCompany: (calculationStore, rowIndex, propName) => {
|
||||
//action
|
||||
|
||||
insured: (calculationStore, tableName, rowIndex, propName) => {
|
||||
if (
|
||||
calculationStore.tables[tableName].values[rowIndex]['insCost'] &&
|
||||
calculationStore.tables[tableName].values[rowIndex]['insCost'] > 0 &&
|
||||
!calculationStore.tables[tableName].values[rowIndex]['insured']
|
||||
) {
|
||||
openNotification({
|
||||
type: 'error',
|
||||
title: 'Ошибка',
|
||||
description: 'Не указан плательщик',
|
||||
})();
|
||||
}
|
||||
},
|
||||
|
||||
insTerm: (calculationStore, tableName, rowIndex, propName) => {
|
||||
if (
|
||||
calculationStore.tables[tableName].values[rowIndex]['insCost'] &&
|
||||
calculationStore.tables[tableName].values[rowIndex]['insCost'] > 0 &&
|
||||
!calculationStore.tables[tableName].values[rowIndex]['insTerm']
|
||||
) {
|
||||
openNotification({
|
||||
type: 'error',
|
||||
title: 'Ошибка',
|
||||
description: 'Не указан срок страхования',
|
||||
})();
|
||||
}
|
||||
},
|
||||
insuranceCompany: (calculationStore, tableName, rowIndex, propName) => {
|
||||
if (
|
||||
calculationStore.tables[tableName].values[rowIndex]['insCost'] &&
|
||||
calculationStore.tables[tableName].values[rowIndex]['insCost'] > 0 &&
|
||||
!calculationStore.tables[tableName].values[rowIndex][
|
||||
'insuranceCompany'
|
||||
]
|
||||
) {
|
||||
openNotification({
|
||||
type: 'error',
|
||||
title: 'Ошибка',
|
||||
description: 'Не указана страховая компания по полису',
|
||||
})();
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import CommonStore from 'client/stores/CommonStore';
|
||||
import { IReactionOptions, IReactionPublic, Lambda, reaction } from 'mobx';
|
||||
import { IReactionOptions, IReactionPublic, Lambda } from 'mobx';
|
||||
import { ICalculationStore } from './stores';
|
||||
|
||||
type TCommonStore = typeof CommonStore;
|
||||
|
||||
export type ActionsNames = 'createLead';
|
||||
export type ActionsNames = 'createLead' | 'calculate';
|
||||
|
||||
export type TAction = {
|
||||
[actionName in ActionsNames]?: () => void;
|
||||
|
||||
@ -134,7 +134,8 @@ export type ElementsNames =
|
||||
| 'radioInsuranceOPF'
|
||||
| 'tableInsurance'
|
||||
| 'lblLead'
|
||||
| 'lblOpportunity';
|
||||
| 'lblOpportunity'
|
||||
| 'btnCalculate';
|
||||
|
||||
export enum ElementType {
|
||||
Default,
|
||||
|
||||
@ -16,6 +16,7 @@ export type TTableValues<T> = {
|
||||
|
||||
export type TCellCallback = (
|
||||
calculationStore: ICalculationStore,
|
||||
tableName: TableNames,
|
||||
rowIndex: number,
|
||||
propName: TableValuesNames,
|
||||
) => void;
|
||||
|
||||
@ -150,7 +150,8 @@ export type ValuesNames =
|
||||
export type ComputedValuesNames =
|
||||
| 'leadName'
|
||||
| 'opportunityName'
|
||||
| 'leaseObjectRiskName';
|
||||
| 'leaseObjectRiskName'
|
||||
| 'insKaskoPriceLeasePeriod';
|
||||
|
||||
export type TValues<T> = {
|
||||
[valueName in ValuesNames]?: T;
|
||||
|
||||
Reference in New Issue
Block a user