system-copyright-react/src/components/invoice/InvoiceList.tsx

308 lines
10 KiB
TypeScript
Raw Normal View History

2025-03-28 09:44:48 +08:00
import { Button, Dropdown, Flex, MenuProps, Modal, Popconfirm, Space, Table, TableProps, Tag } from "antd";
import { PlusOutlined } from "@ant-design/icons";
import {
useEffect,
// useRef,
useState
} from "react";
import { get, put } from "../../util/AjaxUtils.ts";
import { IListPage } from "../../interfaces/listpage/IListPage.ts";
2024-04-02 18:45:46 +08:00
import useMessage from "antd/es/message/useMessage";
import InvoiceSave from "./InvoiceSave.tsx";
2024-04-07 17:37:09 +08:00
import InvoiceEdit from "./InvoiceEdit.tsx";
import InvoiceShow from "./InvoiceShow.tsx";
2024-04-02 18:45:46 +08:00
enum InvoiceStatusEnum {
PENDING = 'PENDING',
COMPLETE = 'COMPLETE',
FAILED = 'FAILED',
CANCEL = 'CANCEL',
}
type DataType = {
examineOpinion: string;
examineUserId: string;
examineUserUsername: string;
gmtCreate: string;
gmtExamine: string;
invoiceAccount: string;
invoiceAddress: string;
invoiceAmount: number;
invoiceBank: string;
invoiceFileList: string[];
invoiceFiles: string;
invoiceId: string;
invoiceNo: string;
invoiceNote: string;
invoicePhone: string;
invoiceStatus: InvoiceStatusEnum;
invoiceTitle: string;
orderIds: string[];
}
export default function InvoiceList() {
const [messageApi, messageContext] = useMessage();
const [page, setPage] = useState(1);
const [total, setTotal] = useState(0);
const [dataArray, setDataArray] = useState<DataType[]>([]);
2024-04-07 17:37:09 +08:00
const [isSaveModalOpen, setIsSaveModalOpen] = useState(false);
const [isEditModalOpen, setIsEditModalOpen] = useState(false);
const [isShowModalOpen, setIsShowModalOpen] = useState(false);
2025-03-28 09:44:48 +08:00
// const invoiceId = useRef('');
const [invoiceId, setInvoiceId] = useState('');
// const [invdataArray,setInvDataArray] = useState<any[]>([]);
2024-04-02 18:45:46 +08:00
const columns: TableProps<DataType>['columns'] = [
{
title: '名称',
dataIndex: 'invoiceTitle',
align: 'center',
width: 180
},
{
title: '纳税人识别号',
dataIndex: 'invoiceNo',
align: 'center',
width: 180
},
{
title: '地址',
dataIndex: 'invoiceAddress',
align: 'center',
width: 180
},
{
title: '电话',
dataIndex: 'invoicePhone',
align: 'center',
width: 180
},
{
title: '开户行',
dataIndex: 'invoiceBank',
align: 'center',
width: 180
},
{
title: '开户行账号',
dataIndex: 'invoiceAccount',
align: 'center',
width: 180
},
{
title: '金额',
dataIndex: 'invoiceAmount',
align: 'center',
width: 160,
render: (value) => {
return (value / 100).toFixed(2)
}
},
{
title: '备注',
dataIndex: 'invoiceNote',
align: 'center',
width: 180
},
{
title: '创建时间',
dataIndex: 'gmtCreate',
align: 'center',
width: 180
},
{
title: '状态',
dataIndex: 'invoiceStatus',
align: 'center',
width: 100,
fixed: 'right',
render: (value) => {
2025-03-28 09:44:48 +08:00
if (value === InvoiceStatusEnum.PENDING) {
2024-04-02 18:45:46 +08:00
return <Tag color="magenta"></Tag>
}
2025-03-28 09:44:48 +08:00
if (value === InvoiceStatusEnum.COMPLETE) {
2024-04-02 18:45:46 +08:00
return <Tag color="green"></Tag>
}
2025-03-28 09:44:48 +08:00
if (value === InvoiceStatusEnum.FAILED) {
2024-04-02 18:45:46 +08:00
return <Tag color="red"></Tag>
}
2025-03-28 09:44:48 +08:00
if (value === InvoiceStatusEnum.CANCEL) {
2024-04-02 18:45:46 +08:00
return <Tag color="cyan"></Tag>
}
}
},
{
title: '操作',
dataIndex: 'operate',
align: 'center',
width: 120,
fixed: 'right',
2024-04-07 17:37:09 +08:00
render: (_value, record) => {
2025-03-28 09:44:48 +08:00
if (record.invoiceStatus === InvoiceStatusEnum.PENDING) {
2024-04-07 17:37:09 +08:00
return <Flex justify="center">
<Space>
<Button type="link" style={{
color: 'var(--color-dark)',
padding: '0'
}} onClick={() => {
2025-03-28 09:44:48 +08:00
// invoiceId.current = record.invoiceId;
// console.log(record.invoiceId);
setInvoiceId(record.invoiceId);
2024-04-07 17:37:09 +08:00
setIsShowModalOpen(true);
}}></Button>
<Popconfirm
title={false}
placement="right"
description="确定取消吗?"
okText="确定"
cancelText="取消"
okButtonProps={{
style: {
backgroundColor: 'var(--color-primary)'
}
}}
onConfirm={() => {
put<any>({
messageApi,
url: `/api/invoice/update-cancel/${record.invoiceId}`,
onSuccess() {
messageApi.success('取消成功');
getData();
}
})
}}
>
<Button type="link" danger style={{
padding: '0'
}}></Button>
</Popconfirm>
</Space>
</Flex>
}
2025-03-28 09:44:48 +08:00
if (record.invoiceStatus === InvoiceStatusEnum.CANCEL) {
2024-04-07 17:37:09 +08:00
return <Button type="link" style={{
padding: '0'
}} onClick={() => {
2025-03-28 09:44:48 +08:00
// invoiceId.current = record.invoiceId;
console.log(record.invoiceId);
setInvoiceId(record.invoiceId);
2024-04-07 17:37:09 +08:00
setIsEditModalOpen(true);
}}></Button>
}
2025-03-28 09:44:48 +08:00
if (record.invoiceStatus == InvoiceStatusEnum.COMPLETE) {
2024-04-02 18:45:46 +08:00
const items: MenuProps['items'] = [];
record.invoiceFileList.forEach((item, index) => {
items.push({
key: index,
label: (
<a href={item} download target="_blank">{index + 1}</a>
)
});
})
return (
<Dropdown menu={{ items }} placement="bottom" arrow>
<Button type="link"></Button>
</Dropdown>
)
}
}
},
]
2024-04-07 17:37:09 +08:00
const getData = () => {
2024-04-02 18:45:46 +08:00
get<IListPage<DataType>>({
messageApi,
url: '/api/invoice/listpage/self',
config: {
params: {
page: page,
rows: 20
}
},
2025-03-28 09:44:48 +08:00
onSuccess({ data }) {
2024-04-02 18:45:46 +08:00
setPage(data.page);
setTotal(data.total);
setDataArray(data.rows);
}
})
2024-04-07 17:37:09 +08:00
}
useEffect(() => {
getData();
2024-04-02 18:45:46 +08:00
}, [page]);
return (
<>
<div className="invoice-list-container">
<div className="mod-list">
2025-03-28 09:44:48 +08:00
<div className="table-btn-group" style={{ marginBottom: '15px' }}>
2024-04-02 18:45:46 +08:00
<Button value="small" onClick={() => {
2024-04-07 17:37:09 +08:00
setIsSaveModalOpen(true);
2025-03-28 09:44:48 +08:00
}}><PlusOutlined /> </Button>
2024-04-02 18:45:46 +08:00
</div>
<Table columns={columns} dataSource={dataArray} pagination={
{
pageSize: 20,
2024-04-07 17:37:09 +08:00
total: total,
2024-04-02 18:45:46 +08:00
onChange: (currentPage) => {
2025-03-28 09:44:48 +08:00
setPage(currentPage);
2024-04-07 17:37:09 +08:00
},
2024-04-02 18:45:46 +08:00
}
2025-03-28 09:44:48 +08:00
} scroll={{ y: 500 }} bordered key="dataTable" rowKey="invoiceId" />
2024-04-02 18:45:46 +08:00
</div>
</div>
2024-04-07 17:37:09 +08:00
<Modal open={isSaveModalOpen}
2025-03-28 09:44:48 +08:00
centered
title="申请开票"
footer={false}
onCancel={() => setIsSaveModalOpen(false)}
width={1000}
destroyOnClose
2024-04-07 17:37:09 +08:00
>
<InvoiceSave
handleOk={() => {
getData();
setIsSaveModalOpen(false);
}}
handleCancel={() => {
setIsSaveModalOpen(false);
}}
/>
</Modal>
<Modal open={isEditModalOpen}
2025-03-28 09:44:48 +08:00
centered
width={1000}
title="修改开票信息"
footer={false}
onCancel={() => setIsEditModalOpen(false)}
destroyOnClose
2024-04-07 17:37:09 +08:00
>
<InvoiceEdit
2025-03-28 09:44:48 +08:00
invoiceId={invoiceId}
// invdataArray={invdataArray}
2024-04-07 17:37:09 +08:00
handleOk={() => {
getData();
setIsEditModalOpen(false);
}}
handleCancel={() => {
setIsEditModalOpen(false);
}}
/>
</Modal>
<Modal open={isShowModalOpen}
2025-03-28 09:44:48 +08:00
destroyOnClose
title="查看开票信息"
footer={false}
onCancel={() => setIsShowModalOpen(false)}
centered
2024-04-02 18:45:46 +08:00
>
2025-03-28 09:44:48 +08:00
{/* {invoiceId.current} */}
2024-04-07 17:37:09 +08:00
<InvoiceShow
2025-03-28 09:44:48 +08:00
invoiceId={invoiceId}
2024-04-07 17:37:09 +08:00
/>
2024-04-02 18:45:46 +08:00
</Modal>
{messageContext}
</>
)
}