PolicyTable: add onSelectRow
InsuranceTable: add elt indicator
This commit is contained in:
parent
038a46ed66
commit
539ddf52b9
@ -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',
|
||||
|
||||
@ -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 (
|
||||
<Flex flexDirection="column">
|
||||
<Validation storeSelector={storeSelector} />
|
||||
<PolicyTable storeSelector={storeSelector} columns={osagoColumns} />
|
||||
<PolicyTable
|
||||
storeSelector={storeSelector}
|
||||
columns={osagoColumns}
|
||||
onSelectRow={(row) => handleOnSelectRow(row)}
|
||||
/>
|
||||
</Flex>
|
||||
);
|
||||
}
|
||||
|
||||
@ -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<Insurance.RowValues> = [
|
||||
{
|
||||
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 <CheckOutlined />;
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
return <Check />;
|
||||
},
|
||||
title: 'ЭЛТ',
|
||||
width: '1%',
|
||||
},
|
||||
{
|
||||
key: 'policyType',
|
||||
dataIndex: 'policyType',
|
||||
|
||||
@ -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()),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user