|
|
|
@ -1,17 +1,16 @@
|
|
|
|
|
import { useCallback, useEffect, useState } from 'react'
|
|
|
|
|
import { ReloadOutlined, ReadOutlined, CheckSquareOutlined, StarOutlined, RightOutlined, LeftOutlined, ExpandOutlined, AppstoreOutlined } from '@ant-design/icons'
|
|
|
|
|
import { Flex, Button, Tooltip, List, Form, Row, Col, Drawer, Dropdown, Input, Checkbox, DatePicker, Switch, Breadcrumb } from 'antd'
|
|
|
|
|
import { useEffect, useState } from 'react'
|
|
|
|
|
import { ReloadOutlined, ReadOutlined, CheckSquareOutlined, RightOutlined, LeftOutlined, ExpandOutlined } from '@ant-design/icons'
|
|
|
|
|
import { Flex, Button, Tooltip, List, Form, Row, Col, Dropdown, Input, Checkbox, DatePicker, Switch, Breadcrumb, Skeleton } from 'antd'
|
|
|
|
|
import dayjs from 'dayjs'
|
|
|
|
|
import { useEmailList } from '@/hooks/useEmail';
|
|
|
|
|
import { isEmpty } from '@/utils/commons';
|
|
|
|
|
import { useEmailList } from '@/hooks/useEmail'
|
|
|
|
|
import { isEmpty } from '@/utils/commons'
|
|
|
|
|
import { MailboxDirIcon } from './MailboxDirIcon'
|
|
|
|
|
import { endWith } from 'rxjs';
|
|
|
|
|
|
|
|
|
|
const { RangePicker } = DatePicker
|
|
|
|
|
|
|
|
|
|
const PAGE_SIZE = 50; // 每页显示条数
|
|
|
|
|
const PAGE_SIZE = 50 // 每页显示条数
|
|
|
|
|
|
|
|
|
|
const MailBox = ({ mailboxDir, onMailItemClick, ...props}) => {
|
|
|
|
|
const MailBox = ({ mailboxDir, onMailItemClick, ...props }) => {
|
|
|
|
|
const DATE_RANGE_PRESETS = [
|
|
|
|
|
{
|
|
|
|
|
label: '本周',
|
|
|
|
@ -42,75 +41,77 @@ const MailBox = ({ mailboxDir, onMailItemClick, ...props}) => {
|
|
|
|
|
|
|
|
|
|
const { mailList, loading, error, refresh } = useEmailList(mailboxDir);
|
|
|
|
|
|
|
|
|
|
const [pagination, setPagination] = useState({
|
|
|
|
|
const [pagination, setPagination] = useState({
|
|
|
|
|
current: 1,
|
|
|
|
|
pageSize: PAGE_SIZE,
|
|
|
|
|
total: 0,
|
|
|
|
|
pagedList: []
|
|
|
|
|
});
|
|
|
|
|
pagedList: [],
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (mailList) {
|
|
|
|
|
const total = mailList.length;
|
|
|
|
|
const pageCount = Math.ceil(total / PAGE_SIZE);
|
|
|
|
|
const total = mailList.length
|
|
|
|
|
const pageCount = Math.ceil(total / PAGE_SIZE)
|
|
|
|
|
|
|
|
|
|
setPagination(prev => ({
|
|
|
|
|
setPagination((prev) => ({
|
|
|
|
|
...prev,
|
|
|
|
|
total,
|
|
|
|
|
pageCount,
|
|
|
|
|
current: 1, // 重置到第一页
|
|
|
|
|
pagedList: getPagedData(mailList, 1)
|
|
|
|
|
}));
|
|
|
|
|
pagedList: getPagedData(mailList, 1),
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
}, [mailList]);
|
|
|
|
|
}, [mailList])
|
|
|
|
|
|
|
|
|
|
const getPagedData = (data, currentPage) => {
|
|
|
|
|
const startIndex = (currentPage - 1) * PAGE_SIZE;
|
|
|
|
|
const endIndex = Math.min(startIndex + PAGE_SIZE, data.length);
|
|
|
|
|
return data.slice(startIndex, endIndex);
|
|
|
|
|
};
|
|
|
|
|
const startIndex = (currentPage - 1) * PAGE_SIZE
|
|
|
|
|
const endIndex = Math.min(startIndex + PAGE_SIZE, data.length)
|
|
|
|
|
return data.slice(startIndex, endIndex)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const prePage = () => {
|
|
|
|
|
if (pagination.current > 1) {
|
|
|
|
|
const newCurrent = pagination.current - 1;
|
|
|
|
|
setPagination(prev => ({
|
|
|
|
|
const newCurrent = pagination.current - 1
|
|
|
|
|
setPagination((prev) => ({
|
|
|
|
|
...prev,
|
|
|
|
|
current: newCurrent,
|
|
|
|
|
pagedList: getPagedData(mailList, newCurrent)
|
|
|
|
|
}));
|
|
|
|
|
pagedList: getPagedData(mailList, newCurrent),
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const nextPage = () => {
|
|
|
|
|
if (pagination.current < Math.ceil(pagination.total / PAGE_SIZE)) {
|
|
|
|
|
const newCurrent = pagination.current + 1;
|
|
|
|
|
setPagination(prev => ({
|
|
|
|
|
const newCurrent = pagination.current + 1
|
|
|
|
|
setPagination((prev) => ({
|
|
|
|
|
...prev,
|
|
|
|
|
current: newCurrent,
|
|
|
|
|
pagedList: getPagedData(mailList, newCurrent)
|
|
|
|
|
}));
|
|
|
|
|
pagedList: getPagedData(mailList, newCurrent),
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
console.info('props.breadcrumb: ', props.breadcrumb)
|
|
|
|
|
console.info('props.mailboxDir: ', mailboxDir)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mailItemRender = (item) => {
|
|
|
|
|
const isOrderNode = mailboxDir.COLI_SN > 0
|
|
|
|
|
const orderNumber = (isEmpty(item.MAI_COLI_ID) || isOrderNode) ? '' : (item.MAI_COLI_ID + ' - ')
|
|
|
|
|
const countryName = isEmpty(item.CountryCN) ? '' : ('[' + (item.CountryCN === null ? 'USA' : item.CountryCN) + '] ')
|
|
|
|
|
const orderNumber = isEmpty(item.MAI_COLI_ID) || isOrderNode ? '' : item.MAI_COLI_ID + ' - '
|
|
|
|
|
const countryName = isEmpty(item.CountryCN) ? '' : '[' + item.CountryCN + '] '
|
|
|
|
|
const mailStateClass = item.MOI_ReadState === 0 ? 'font-bold' : ''
|
|
|
|
|
return (
|
|
|
|
|
<li className='flex border border-solid border-t-0 border-x-0 border-gray-200 hover:bg-neutral-50 p-2' onClick={() => {
|
|
|
|
|
console.info('item: ', item)
|
|
|
|
|
onMailItemClick(item)
|
|
|
|
|
}}>
|
|
|
|
|
<li
|
|
|
|
|
className='flex border border-solid border-t-0 border-x-0 border-gray-200 hover:bg-neutral-50 p-2'>
|
|
|
|
|
<div className=''>
|
|
|
|
|
<Checkbox></Checkbox>
|
|
|
|
|
</div>
|
|
|
|
|
<div className='flex-1 pl-2'>
|
|
|
|
|
<div className='flex-1 pl-2'
|
|
|
|
|
onClick={() => {
|
|
|
|
|
console.info('item: ', item)
|
|
|
|
|
onMailItemClick(item)
|
|
|
|
|
}}>
|
|
|
|
|
<Flex gap='small' vertical={true} justify='space-between' className='cursor-pointer'>
|
|
|
|
|
<div>{orderNumber}<span className={mailStateClass}>{item.MAI_Subject}</span></div>
|
|
|
|
|
<div>
|
|
|
|
|
{orderNumber}
|
|
|
|
|
<span className={mailStateClass}>{item.MAI_Subject}</span>
|
|
|
|
|
</div>
|
|
|
|
|
<span className='text-neutral-500 text-wrap break-words break-all '>{countryName + item.SenderReceiver + ' ' + item.SRDate}</span>
|
|
|
|
|
</Flex>
|
|
|
|
|
</div>
|
|
|
|
@ -187,10 +188,9 @@ const MailBox = ({ mailboxDir, onMailItemClick, ...props}) => {
|
|
|
|
|
}}
|
|
|
|
|
placeholder={`邮件主题`}
|
|
|
|
|
/>
|
|
|
|
|
<Tooltip title='高级搜索'>
|
|
|
|
|
<Switch checkedChildren={<ExpandOutlined />}
|
|
|
|
|
unCheckedChildren={<ExpandOutlined />} defaultChecked={false} />
|
|
|
|
|
</Tooltip>
|
|
|
|
|
<Tooltip title='高级搜索'>
|
|
|
|
|
<Switch checkedChildren={<ExpandOutlined />} unCheckedChildren={<ExpandOutlined />} defaultChecked={false} />
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</div>
|
|
|
|
|
<div className='bg-white h-auto p-1 flex gap-1 items-center hidden'>
|
|
|
|
|
<Form
|
|
|
|
@ -219,41 +219,50 @@ const MailBox = ({ mailboxDir, onMailItemClick, ...props}) => {
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className='bg-white overflow-y-auto' style={{ height: 'calc(100vh - 198px)' }}>
|
|
|
|
|
<List loading={loading}
|
|
|
|
|
<Skeleton active loading={loading}>
|
|
|
|
|
<List
|
|
|
|
|
loading={loading}
|
|
|
|
|
header={
|
|
|
|
|
<Flex align='center' justify="space-between">
|
|
|
|
|
<Breadcrumb
|
|
|
|
|
items={
|
|
|
|
|
props.breadcrumb.map(bc => {
|
|
|
|
|
<Flex align='center' justify='space-between'>
|
|
|
|
|
<Breadcrumb
|
|
|
|
|
items={props.breadcrumb.map((bc) => {
|
|
|
|
|
return {
|
|
|
|
|
title: (
|
|
|
|
|
<>
|
|
|
|
|
<MailboxDirIcon type={bc?.iconIndex} />
|
|
|
|
|
<MailboxDirIcon type={bc?.iconIndex} />
|
|
|
|
|
<span>{bc.title}</span>
|
|
|
|
|
</>
|
|
|
|
|
),
|
|
|
|
|
}
|
|
|
|
|
})}
|
|
|
|
|
/>
|
|
|
|
|
<Flex align="center" justify="space-between">
|
|
|
|
|
<span>
|
|
|
|
|
{((pagination.current - 1) * PAGE_SIZE + 1)}-{Math.min(pagination.current * PAGE_SIZE, pagination.total)} of {pagination.total}
|
|
|
|
|
</span>
|
|
|
|
|
<Button icon={<LeftOutlined />} type="text" onClick={() => {
|
|
|
|
|
prePage()
|
|
|
|
|
}} iconPosition={'end'}></Button>
|
|
|
|
|
<Button icon={<RightOutlined />} type="text" onClick={() => {
|
|
|
|
|
nextPage()
|
|
|
|
|
}} iconPosition={'end'}></Button>
|
|
|
|
|
/>
|
|
|
|
|
<Flex align='center' justify='space-between'>
|
|
|
|
|
<span>
|
|
|
|
|
{(pagination.current - 1) * PAGE_SIZE + 1}-{Math.min(pagination.current * PAGE_SIZE, pagination.total)} of {pagination.total}
|
|
|
|
|
</span>
|
|
|
|
|
<Button
|
|
|
|
|
icon={<LeftOutlined />}
|
|
|
|
|
type='text'
|
|
|
|
|
onClick={() => {
|
|
|
|
|
prePage()
|
|
|
|
|
}}
|
|
|
|
|
iconPosition={'end'}></Button>
|
|
|
|
|
<Button
|
|
|
|
|
icon={<RightOutlined />}
|
|
|
|
|
type='text'
|
|
|
|
|
onClick={() => {
|
|
|
|
|
nextPage()
|
|
|
|
|
}}
|
|
|
|
|
iconPosition={'end'}></Button>
|
|
|
|
|
</Flex>
|
|
|
|
|
</Flex>
|
|
|
|
|
|
|
|
|
|
</Flex>
|
|
|
|
|
}
|
|
|
|
|
itemLayout='vertical'
|
|
|
|
|
pagination={false}
|
|
|
|
|
dataSource={pagination.pagedList}
|
|
|
|
|
renderItem={mailItemRender}
|
|
|
|
|
/>
|
|
|
|
|
</Skeleton>
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
)
|
|
|
|
|