system-copyright-react/src/components/myOrder/MyOrder.tsx

367 lines
11 KiB
TypeScript
Raw Normal View History

2024-08-27 18:29:20 +08:00
import { Table, TableProps, Tooltip, Spin, Modal, Input } from "antd";
const { Search } = Input;
2024-08-12 14:43:58 +08:00
import { useEffect, useState } from "react";
import useMessage from "antd/es/message/useMessage";
import { get } from "../../util/AjaxUtils";
import './myorder.css'
type IListPage<T> = {
page: number;
total: number;
rows: T[]
}
type DetailDataType = {
productType: string;
quantity: number;
unitPrice: number;
notes: string;
productDescription: string;
}
type DataType = {
orderId: string;
orderNo: string;
totalAmount: number;
detail: DetailDataType;
orderStatus: string;
gmtCreate: string;
}
2024-08-27 18:29:20 +08:00
type DataTypeDetail = {
productName: string; //商品名称
productType: string; //商品类型
quantity: number; //购买数量
unitPrice: number; //单价
productDescription: string; //商品描述
notes: string; //备注
}
2024-08-12 14:43:58 +08:00
export default function MyOrder() {
const [messageApi, messageContext] = useMessage();
const [isLoading, setIsLoading] = useState(false)
const [page, setPage] = useState(1);
const [total, setTotal] = useState(0);
const [dataArray, setDataArray] = useState<DataType[]>([]);
2024-08-27 18:29:20 +08:00
const [detailData, setDetailData] = useState<DataTypeDetail[]>([])
const [orderDetailsModal, setOrderDetailsModal] = useState(false) //详情弹窗
const [keyWords, setKewWords] = useState('')
2024-08-12 14:43:58 +08:00
const getData = () => {
get<IListPage<DataType>>({
messageApi,
2024-08-27 18:29:20 +08:00
url: '/api/order/listpage/self',
2024-08-12 14:43:58 +08:00
config: {
params: {
page: page,
2024-08-27 18:29:20 +08:00
rows: 20,
keywords: keyWords,
2024-08-12 14:43:58 +08:00
}
},
onBefore() {
setIsLoading(true);
},
onSuccess({ data }) {
// console.log(data);
setPage(data.page);
setTotal(data.total);
setDataArray(data.rows);
},
onFinally() {
setIsLoading(false);
}
})
}
2024-08-27 18:29:20 +08:00
const getOrderDetails = (orderId: string) => {
get({
messageApi,
url: `/api/order-detail/list/order-id/${orderId}`,
config: {
},
onBefore() {
setIsLoading(true);
},
onSuccess(data: any) {
// console.log(data.data);
setDetailData(data.data)
},
onFinally() {
setIsLoading(false);
}
})
}
2024-08-12 14:43:58 +08:00
const columns: TableProps<DataType>['columns'] = [
{
title: '订单号',
dataIndex: 'orderNo',
align: 'center',
width: 250,
fixed: 'left'
},
{
title: '总金额',
dataIndex: 'totalAmount',
align: 'center',
width: 100,
fixed: 'left',
render: (value) => {
return (value / 100).toFixed(2)
}
},
{
title: '订单状态',
dataIndex: 'orderStatus',
align: 'center',
width: 100,
render: (value) => {
if (value === 'COMPLETE') {
return '完成';
}
2024-08-27 18:29:20 +08:00
if (value === ' FULL_REFUND') {
return '全额退款';
}
if (value === 'PENDING') {
return '等待';
}
if (value === 'CORRECTION1_REFUND') {
return '补正1次退款';
}
if (value === 'CORRECTION2_REFUND') {
return '补正2次退款';
2024-08-12 14:43:58 +08:00
}
}
},
{
title: '创建时间',
dataIndex: 'gmtCreate',
align: 'center',
width: 180
},
2024-08-27 18:29:20 +08:00
// {
// title: '产品类型',
// dataIndex: 'detail.productType',
// align: 'center',
// width: 100,
// render: (_value, record) => {
// if (record.detail.productType === 'PROJ') {
// return '项目创建'
// }
// if (record.detail.productType === 'AGENT') {
// return '项目代理'
// }
// return record.detail.productType
// }
// },
// {
// title: '数量',
// dataIndex: 'detail.quantity',
// align: 'center',
// width: 100,
// render: (_value, record) => {
// return record.detail.quantity
// }
// },
// {
// title: '单价',
// dataIndex: 'detail.unitPrice',
// align: 'center',
// width: 100,
// render: (_value, record) => {
// return (record.detail.unitPrice / 100).toFixed(2)
// }
// },
// {
// title: '订单备注',
// dataIndex: 'detail.notes',
// align: 'center',
// width: 120,
// render: (_value, record) => {
// return record.detail.notes
// }
// },
// {
// title: '描述',
// dataIndex: 'detail.productDescription',
// align: 'center',
// width: 200,
// ellipsis: {
// showTitle: false,
// },
// render: (_value, record) => {
// return <Tooltip placement="top" title={record.detail.productDescription}>{record.detail.productDescription}</Tooltip>
// }
// },
2024-08-12 14:43:58 +08:00
{
2024-08-27 18:29:20 +08:00
title: '订单详情',
2024-08-12 14:43:58 +08:00
align: 'center',
width: 100,
2024-08-27 18:29:20 +08:00
render: (_, record) => (
// {record.name}
<div className='refunBtn' onClick={() => {
// console.log(record.orderId); //id
// console.log(record.orderNo); //编号
// setOrderId(record.orderId)
setOrderDetailsModal(true)
getOrderDetails(record.orderId)
}}></div>
),
},
]
const detailColumns: TableProps<DataTypeDetail>['columns'] = [
{
title: '商品名称',
dataIndex: 'productName',
align: 'center',
// width: 250,
ellipsis: {
showTitle: false,
},
2024-08-12 14:43:58 +08:00
render: (_value, record) => {
2024-08-27 18:29:20 +08:00
return <Tooltip placement="top" title={record.productName}>{record.productName}</Tooltip>
}
},
{
title: '商品类型',
dataIndex: 'productType',
align: 'center',
render: (_value, record) => {
if (record.productType === 'PROJ') {
2024-08-12 14:43:58 +08:00
return '项目创建'
}
2024-08-27 18:29:20 +08:00
if (record.productType === 'AGENT') {
2024-08-12 14:43:58 +08:00
return '项目代理'
}
2024-08-27 18:29:20 +08:00
if (record.productType === 'FULL_REFUND') {
return '全额退款'
}
if (record.productType === 'CORRECTION1_REFUND') {
return '补正1次退款'
}
if (record.productType === 'CORRECTION2_REFUND') {
return '补正2次退款'
}
return record.productType
2024-08-12 14:43:58 +08:00
}
2024-08-27 18:29:20 +08:00
2024-08-12 14:43:58 +08:00
},
{
2024-08-27 18:29:20 +08:00
title: '购买数量',
dataIndex: 'quantity',
2024-08-12 14:43:58 +08:00
align: 'center',
width: 100,
2024-08-27 18:29:20 +08:00
2024-08-12 14:43:58 +08:00
},
{
title: '单价',
2024-08-27 18:29:20 +08:00
dataIndex: 'unitPrice',
2024-08-12 14:43:58 +08:00
align: 'center',
2024-08-27 18:29:20 +08:00
render: (value) => {
return (value / 100).toFixed(2)
2024-08-12 14:43:58 +08:00
}
2024-08-27 18:29:20 +08:00
2024-08-12 14:43:58 +08:00
},
2024-08-27 18:29:20 +08:00
2024-08-12 14:43:58 +08:00
{
title: '订单备注',
dataIndex: 'detail.notes',
align: 'center',
2024-08-27 18:29:20 +08:00
// width: 120,
2024-08-12 14:43:58 +08:00
render: (_value, record) => {
2024-08-27 18:29:20 +08:00
return <Tooltip placement="top" title={record.notes}>{record.notes}</Tooltip>
2024-08-12 14:43:58 +08:00
}
},
{
2024-08-27 18:29:20 +08:00
title: '商品描述',
dataIndex: 'productDescription',
2024-08-12 14:43:58 +08:00
align: 'center',
width: 200,
ellipsis: {
showTitle: false,
},
render: (_value, record) => {
2024-08-27 18:29:20 +08:00
return <Tooltip placement="top" title={record.productDescription}>{record.productDescription}</Tooltip>
2024-08-12 14:43:58 +08:00
}
2024-08-27 18:29:20 +08:00
}
2024-08-12 14:43:58 +08:00
]
// useEffect(() => {
// getData();
// }, []);
2024-08-27 18:29:20 +08:00
const handleSearch = (value: string) => {
// console.log(value);
setKewWords(value)
}
const handleChange = (e: any) => {
// console.log(e.target.value);
if (e.target.value == '') {
setKewWords('')
}
}
2024-08-12 14:43:58 +08:00
useEffect(() => {
getData();
2024-08-27 18:29:20 +08:00
}, [page, keyWords]);
2024-08-12 14:43:58 +08:00
return (
<div>
{messageContext}
2024-08-27 18:29:20 +08:00
<div style={{
marginBottom: 10,
marginTop: 10
}}>
<Search placeholder="输入订单号查询订单"
// value={nowKeyword}
onSearch={handleSearch}
onChange={handleChange}
style={{
width: '300px',
}}
/>
</div>
2024-08-12 14:43:58 +08:00
<Spin tip="加载中..." spinning={isLoading}>
<Table columns={columns} dataSource={dataArray}
pagination={
{
pageSize: 20,
total: total,
onChange: (currentPage) => {
setPage(currentPage);
},
2024-08-27 18:29:20 +08:00
showSizeChanger: false
2024-08-12 14:43:58 +08:00
}
}
2024-08-27 18:29:20 +08:00
scroll={{ y: 500 }} bordered key="dataTable" rowKey="orderId" />
2024-08-12 14:43:58 +08:00
</Spin>
2024-08-27 18:29:20 +08:00
<Modal
title="订单详情"
cancelText="取消"
destroyOnClose={true}
open={orderDetailsModal}
// onOk={() => {
// setOrderDetailsModal(false)
// }}
width={1300}
onCancel={() => {
setOrderDetailsModal(false)
}}
footer={null}
>
<Spin tip="加载中..." spinning={isLoading}>
<Table columns={detailColumns}
dataSource={detailData}
// pagination={
// {
// pageSize: 20,
// total: total,
// onChange: (currentPage) => {
// setPage(currentPage);
// },
// showSizeChanger: false
// }
// }
pagination={false}
// scroll={{ y: 500 }}
bordered key="dataTable" rowKey="orderId" />
</Spin>
</Modal>
2024-08-12 14:43:58 +08:00
</div>
)
}