diff --git a/apps/web/Components/Calculation/Form/ELT/Components/PolicyTable.tsx b/apps/web/Components/Calculation/Form/ELT/Components/PolicyTable.tsx index f40fa5c..05c137d 100644 --- a/apps/web/Components/Calculation/Form/ELT/Components/PolicyTable.tsx +++ b/apps/web/Components/Calculation/Form/ELT/Components/PolicyTable.tsx @@ -1,12 +1,20 @@ import type { columns } from '../lib/config'; -import type { StoreSelector } from '../types'; +import type { Row, StoreSelector } from '../types'; import { useStore } from '@/stores/hooks'; import { observer } from 'mobx-react-lite'; -import { Table } from 'ui/antd'; +import { message, Table } from 'ui/antd'; export const PolicyTable = observer( - ({ storeSelector, ...props }: { columns: typeof columns; storeSelector: StoreSelector }) => { - const { $tables } = useStore(); + ({ + storeSelector, + onSelectRow, + ...props + }: { + columns: typeof columns; + onSelectRow: (row: Row) => void; + storeSelector: StoreSelector; + }) => { + const { $tables, $process } = useStore(); const { getRows, setSelectedKey, getSelectedRow } = storeSelector($tables.elt); return ( @@ -21,7 +29,13 @@ export const PolicyTable = observer( getCheckboxProps: (record) => ({ disabled: !record.sum || record.status !== null }), hideSelectAll: true, onSelect: (record) => { - if (record.sum > 0) setSelectedKey(record.key); + if (record.sum > 0) { + $process.add('ELT'); + setSelectedKey(record.key); + onSelectRow(record); + message.success({ content: 'Выбранный расчет ЭЛТ применен', key: record.key }); + $process.delete('ELT'); + } }, selectedRowKeys: getSelectedRow ? [getSelectedRow.key] : [], type: 'radio', diff --git a/apps/web/Components/Calculation/Form/ELT/Osago.tsx b/apps/web/Components/Calculation/Form/ELT/Osago.tsx index 096efac..4135e04 100644 --- a/apps/web/Components/Calculation/Form/ELT/Osago.tsx +++ b/apps/web/Components/Calculation/Form/ELT/Osago.tsx @@ -1,7 +1,7 @@ import { PolicyTable, ReloadButton, Validation } from './Components'; import { columns } from './lib/config'; import { makeEltOsagoRequest } from './lib/make-request'; -import type { StoreSelector } from './types'; +import type { Row, StoreSelector } from './types'; import { getEltOsago } from '@/api/elt/query'; import { STALE_TIME } from '@/constants/request'; import { useStore } from '@/stores/hooks'; @@ -57,6 +57,11 @@ export function Osago() { }); } + function handleOnSelectRow(row: Row) { + $tables.insurance.row('osago').column('insuranceCompany').setValue(row.key); + $tables.insurance.row('osago').column('insCost').setValue(row.sum); + } + const osagoColumns = clone(columns); osagoColumns[0].title = 'Страховая компания ОСАГО'; osagoColumns[3].title = ( @@ -66,7 +71,11 @@ export function Osago() { return ( - + handleOnSelectRow(row)} + /> ); } diff --git a/apps/web/Components/Calculation/Form/Insurance/InsuranceTable/config.tsx b/apps/web/Components/Calculation/Form/Insurance/InsuranceTable/config.tsx index fbff922..614ed18 100644 --- a/apps/web/Components/Calculation/Form/Insurance/InsuranceTable/config.tsx +++ b/apps/web/Components/Calculation/Form/Insurance/InsuranceTable/config.tsx @@ -3,12 +3,36 @@ import { buildOptionComponent, buildValueComponent } from './builders'; import type * as Insurance from './types'; import { MAX_INSURANCE } from '@/constants/values'; +import { useStore } from '@/stores/hooks'; +import { observer } from 'mobx-react-lite'; import { parser } from 'tools/number'; import { InputNumber, Select } from 'ui/elements'; +import { CheckOutlined } from 'ui/elements/icons'; import { createFormatter } from 'ui/elements/InputNumber'; import type { ColumnsType } from 'ui/elements/Table'; export const columns: ColumnsType = [ + { + key: 'elt', + dataIndex: 'elt', + render: (_, record) => { + const Check = observer(() => { + const { $tables } = useStore(); + if ( + (record.key === 'osago' && $tables.elt.osago.getSelectedRow?.key) || + (record.key === 'kasko' && $tables.elt.kasko.getSelectedRow?.key) + ) { + return ; + } + + return null; + }); + + return ; + }, + title: 'ЭЛТ', + width: '1%', + }, { key: 'policyType', dataIndex: 'policyType', diff --git a/apps/web/process/elt/reactions/common.ts b/apps/web/process/elt/reactions/common.ts index c9c0f3f..8147c77 100644 --- a/apps/web/process/elt/reactions/common.ts +++ b/apps/web/process/elt/reactions/common.ts @@ -1,14 +1,16 @@ import type { ProcessContext } from '../../types'; import helper from '../lib/helper'; -import { reaction, toJS } from 'mobx'; +import { disposableReaction } from '@/utils/mobx'; +import { toJS } from 'mobx'; export default function reactions(context: ProcessContext) { const { store } = context; - const { $calculation, $tables } = store; + const { $calculation, $tables, $process } = store; const { init } = helper(context); - reaction( + disposableReaction( + () => $process.has('ELT'), () => ({ kasko: toJS($tables.insurance.row('kasko').getValues()), osago: toJS($tables.insurance.row('osago').getValues()),