This repository has been archived on 2025-05-09. You can view files and clone it, but cannot push or open issues or pull requests.
2021-06-09 09:32:29 +03:00

368 lines
8.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import InputNumber from 'client/Elements/InputNumber';
import Label from 'client/Elements/Label';
import { openNotification } from 'client/Elements/Notification';
import Select from 'client/Elements/Select';
import {
insuranceKaskoDefaultFilter,
insuranceOsagoDefaultFilter,
} from 'core/constants/stores/Calculation/filters';
import { formatNumber } from 'core/tools/format';
import {
ITable,
TableColumn,
TableColumnCallbacks,
TableColumnOptions,
TableRow,
} from 'core/types/Calculation/Store/tables';
import { ElementStatus } from 'core/types/statuses';
const columns: TableColumn[] = [
{
name: 'policyType',
title: 'Тип полиса',
Component: Label,
},
{
name: 'insuranceCompany',
title: 'Страховая компания',
Component: Select,
props: {
nameMiddleware: name => {
const targetName = name.match(/"(.+)"/);
if (targetName) {
return targetName[1].replaceAll('"', String.fromCharCode(160)).trim();
}
return name;
},
},
},
{
name: 'insured',
title: 'Плательщик',
Component: Select,
},
{
name: 'insCost',
title: 'Стоимость за первый период',
Component: InputNumber,
props: {
min: '0.00',
max: '2500000.00',
step: '1000.00',
precision: 2,
formatter: formatNumber,
},
},
{
name: 'insTerm',
title: 'Срок страхования',
Component: Select,
},
];
const rows: TableRow[] = [
{
policyType: {
value: 'ОСАГО',
},
insuranceCompany: {
value: null,
filter: insuranceOsagoDefaultFilter,
},
insured: {
value: 100000000,
},
insCost: {
value: 0,
},
insTerm: {
value: 100000000,
status: ElementStatus.Disabled,
},
},
{
policyType: {
value: 'КАСКО',
},
insuranceCompany: {
value: null,
filter: insuranceKaskoDefaultFilter,
},
insured: {
value: 100000000,
},
insCost: {
value: 0,
},
insTerm: {
value: null,
status: ElementStatus.Disabled,
},
},
{
policyType: {
value: 'ДГО',
},
insuranceCompany: {
value: null,
status: ElementStatus.Disabled,
filter: insuranceKaskoDefaultFilter,
},
insured: {
value: null,
status: ElementStatus.Disabled,
},
insCost: {
value: 0,
},
insTerm: {
value: null,
status: ElementStatus.Disabled,
},
},
{
policyType: {
value: 'НС',
},
insuranceCompany: {
value: null,
status: ElementStatus.Disabled,
filter: insuranceKaskoDefaultFilter,
},
insured: {
value: null,
status: ElementStatus.Disabled,
},
insCost: {
value: 0,
},
insTerm: {
value: null,
status: ElementStatus.Disabled,
},
},
];
const callbacks: TableColumnCallbacks = {
insCost: ({ calculationStore, tableName, rowIndex }) => {
if (
calculationStore.tables[tableName]?.rows[rowIndex]['insCost']?.value &&
calculationStore.tables[tableName]?.rows[rowIndex]['insCost']?.value >
0 &&
!calculationStore.tables[tableName]?.rows[rowIndex]['insuranceCompany']
?.value
) {
calculationStore.setTableRow(
'tableInsurance',
rowIndex,
)({
insuranceCompany: {
validation: false,
},
});
openNotification({
type: 'error',
title: 'Ошибка',
description: 'Не указана страховая компания по полису',
})();
} else {
calculationStore.setTableRow(
'tableInsurance',
rowIndex,
)({
insuranceCompany: {
validation: true,
},
});
}
if (
calculationStore.tables[tableName]?.rows[rowIndex]['insCost']?.value &&
calculationStore.tables[tableName]?.rows[rowIndex]['insCost']?.value >
0 &&
!calculationStore.tables[tableName]?.rows[rowIndex]['insTerm']?.value
) {
calculationStore.setTableRow(
'tableInsurance',
rowIndex,
)({
insTerm: {
validation: false,
},
});
openNotification({
type: 'error',
title: 'Ошибка',
description: 'Не указан срок страхования',
})();
} else {
calculationStore.setTableRow(
'tableInsurance',
rowIndex,
)({
insTerm: {
validation: true,
},
});
}
if (
calculationStore.tables[tableName]?.rows[rowIndex]['insCost']?.value &&
calculationStore.tables[tableName]?.rows[rowIndex]['insCost']?.value >
0 &&
!calculationStore.tables[tableName]?.rows[rowIndex]['insured']?.value
) {
calculationStore.setTableRow(
'tableInsurance',
rowIndex,
)({
insured: {
validation: false,
},
});
openNotification({
type: 'error',
title: 'Ошибка',
description: 'Не указан плательщик',
})();
} else {
calculationStore.setTableRow(
'tableInsurance',
rowIndex,
)({
insured: {
validation: true,
},
});
}
},
insured: ({ calculationStore, tableName, rowIndex }) => {
if (
calculationStore.tables[tableName]?.rows[rowIndex]['insCost']?.value &&
calculationStore.tables[tableName]?.rows[rowIndex]['insCost']?.value >
0 &&
!calculationStore.tables[tableName]?.rows[rowIndex]['insured']?.value
) {
calculationStore.setTableRow(
'tableInsurance',
rowIndex,
)({
insured: {
validation: false,
},
});
openNotification({
type: 'error',
title: 'Ошибка',
description: 'Не указан плательщик',
})();
} else {
calculationStore.setTableRow(
'tableInsurance',
rowIndex,
)({
insured: {
validation: true,
},
});
}
},
insTerm: ({ calculationStore, tableName, rowIndex }) => {
if (
calculationStore.tables[tableName]?.rows[rowIndex]['insCost']?.value &&
calculationStore.tables[tableName]?.rows[rowIndex]['insCost']?.value >
0 &&
!calculationStore.tables[tableName]?.rows[rowIndex]['insTerm']?.value
) {
calculationStore.setTableRow(
'tableInsurance',
rowIndex,
)({
insTerm: {
validation: false,
},
});
openNotification({
type: 'error',
title: 'Ошибка',
description: 'Не указан срок страхования',
})();
} else {
calculationStore.setTableRow(
'tableInsurance',
rowIndex,
)({
insTerm: {
validation: true,
},
});
}
},
insuranceCompany: ({ calculationStore, tableName, rowIndex }) => {
if (
calculationStore.tables[tableName]?.rows[rowIndex] &&
calculationStore.tables[tableName]?.rows[rowIndex]['insCost']?.value &&
calculationStore.tables[tableName]?.rows[rowIndex]['insCost']?.value >
0 &&
!calculationStore.tables[tableName]?.rows[rowIndex]['insuranceCompany']
?.value
) {
calculationStore.setTableRow(
'tableInsurance',
rowIndex,
)({
insuranceCompany: {
validation: false,
},
});
openNotification({
type: 'error',
title: 'Ошибка',
description: 'Не указана страховая компания по полису',
})();
} else {
calculationStore.setTableRow(
'tableInsurance',
rowIndex,
)({
insuranceCompany: {
validation: true,
},
});
}
},
};
const options: TableColumnOptions = {
insured: [
{
name: 'ЛП',
value: 100000000,
},
{
name: 'ЛД',
value: 100000001,
},
],
insTerm: [
{
name: '12 месяцев',
value: 100000000,
},
{
name: 'Срок ДЛ',
value: 100000001,
},
],
};
export default {
columns,
rows,
options,
callbacks,
params: {},
} as ITable;