2021-10-06 13:57:04 +05:00
|
|
|
import { Empty, Form } from 'antd';
|
2021-09-03 09:26:43 +05:00
|
|
|
import {Grid, GridItem} from '../../components/Grid'
|
2021-10-06 13:57:04 +05:00
|
|
|
import '../../styles/index.css'
|
|
|
|
|
|
|
|
const renderSwitchableColumn = (column, itm) => {
|
|
|
|
if(column.render) {
|
|
|
|
return (
|
|
|
|
<Form.Item
|
2021-10-07 15:05:59 +05:00
|
|
|
key={column.dataIndex}
|
2021-10-06 13:57:04 +05:00
|
|
|
name={column.dataIndex}
|
|
|
|
style={{margin: 0}}
|
2021-10-08 11:25:21 +05:00
|
|
|
//rules={column.formItemRules}
|
2021-10-06 13:57:04 +05:00
|
|
|
>
|
|
|
|
{column.render(itm[column.dataIndex])}
|
|
|
|
</Form.Item>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-10-07 15:05:59 +05:00
|
|
|
return <p key={column.title} className='m-5px'>{itm[column.dataIndex]}</p>
|
2021-10-06 13:57:04 +05:00
|
|
|
}
|
2021-09-03 09:26:43 +05:00
|
|
|
|
|
|
|
export const View = ({columns, item}) => {
|
|
|
|
if (!item || !columns?.length)
|
2021-10-07 15:05:59 +05:00
|
|
|
return <Empty key='empty' image={Empty.PRESENTED_IMAGE_SIMPLE}/>
|
2021-09-03 09:26:43 +05:00
|
|
|
|
|
|
|
const colsCount = 3
|
|
|
|
const viewItems = columns.map( (column, i) => {
|
|
|
|
const row = Math.floor(i / colsCount) + 1
|
|
|
|
const colb = i % colsCount
|
2021-10-04 18:06:42 +05:00
|
|
|
|
2021-09-03 09:26:43 +05:00
|
|
|
return <>
|
2021-10-06 13:57:04 +05:00
|
|
|
<GridItem
|
2021-10-07 15:05:59 +05:00
|
|
|
key={column.dataIndex}
|
2021-10-06 13:57:04 +05:00
|
|
|
row={row}
|
|
|
|
col={colb*2 + 1}
|
2021-10-07 10:48:26 +05:00
|
|
|
style={{border:'1px solid lightgrey'}}
|
2021-10-06 13:57:04 +05:00
|
|
|
>
|
|
|
|
{column.title}
|
|
|
|
</GridItem>
|
|
|
|
|
|
|
|
<GridItem
|
2021-10-07 15:05:59 +05:00
|
|
|
key={column.title}
|
2021-10-06 13:57:04 +05:00
|
|
|
row={row}
|
|
|
|
col={colb*2 + 2}
|
2021-10-07 10:48:26 +05:00
|
|
|
style={{border:'1px solid lightgrey',
|
2021-10-06 13:57:04 +05:00
|
|
|
justifyContent:'right',
|
|
|
|
marginRight:'16px',
|
|
|
|
fontWeight:'bold',
|
2021-10-07 15:05:59 +05:00
|
|
|
textAlign:'right',
|
|
|
|
padding: 0}}
|
2021-10-06 13:57:04 +05:00
|
|
|
>
|
|
|
|
{renderSwitchableColumn(column, item)}
|
|
|
|
</GridItem>
|
2021-09-03 09:26:43 +05:00
|
|
|
</>
|
|
|
|
})
|
|
|
|
|
2021-10-04 18:06:42 +05:00
|
|
|
return <>
|
|
|
|
<Grid>
|
|
|
|
{viewItems}
|
|
|
|
</Grid>
|
|
|
|
</>
|
2021-09-03 09:26:43 +05:00
|
|
|
}
|