Compare commits
13 Commits
c8064f20e3
...
db5486ffab
| Author | SHA1 | Date |
|---|---|---|
|
|
db5486ffab | |
|
|
aa5f6bcb48 | |
|
|
7c0fa5796d | |
|
|
fcbf0a4833 | |
|
|
236d0a85bf | |
|
|
ec57d7c476 | |
|
|
bd6a2a1509 | |
|
|
8d3c3ff71c | |
|
|
5f1c6eeb44 | |
|
|
0abe06d9df | |
|
|
860b7970c8 | |
|
|
67aa625785 | |
|
|
1d9838f72e |
|
|
@ -393,6 +393,14 @@ const UpdateForm: React.FC<{
|
|||
}));
|
||||
}}
|
||||
/>
|
||||
<ProFormText
|
||||
name={['email']}
|
||||
label="邮箱"
|
||||
width="lg"
|
||||
placeholder="请输入邮箱"
|
||||
required
|
||||
rules={[{ required: true, message: '请输入邮箱' }]}
|
||||
/>
|
||||
<ProForm.Group title="地址">
|
||||
<ProFormText
|
||||
name={['address', 'country']}
|
||||
|
|
@ -431,6 +439,8 @@ const UpdateForm: React.FC<{
|
|||
required
|
||||
rules={[{ required: true, message: '请输入详细地址' }]}
|
||||
/>
|
||||
|
||||
|
||||
</ProForm.Group>
|
||||
<ProFormItem
|
||||
name="contact"
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import styles from '../../../style/order-list.css';
|
|||
import InternationalPhoneInput from '@/components/InternationalPhoneInput';
|
||||
import SyncForm from '@/components/SyncForm';
|
||||
import { showSyncResult, SyncResultData } from '@/components/SyncResultMessage';
|
||||
import { UploadOutlined } from '@ant-design/icons';
|
||||
import { ORDER_STATUS_ENUM } from '@/constants';
|
||||
import { HistoryOrder } from '@/pages/Statistics/Order';
|
||||
import {
|
||||
|
|
@ -24,6 +25,7 @@ import {
|
|||
ordercontrollerSyncorderbyid,
|
||||
ordercontrollerSyncorders,
|
||||
ordercontrollerUpdateorderitems,
|
||||
ordercontrollerImportwintopay,
|
||||
} from '@/servers/api/order';
|
||||
import { productcontrollerSearchproducts } from '@/servers/api/product';
|
||||
import { sitecontrollerAll } from '@/servers/api/site';
|
||||
|
|
@ -74,11 +76,16 @@ import {
|
|||
Tabs,
|
||||
TabsProps,
|
||||
Tag,
|
||||
Upload,
|
||||
} from 'antd';
|
||||
import React, { useMemo, useRef, useState } from 'react';
|
||||
import RelatedOrders from '../../Subscription/Orders/RelatedOrders';
|
||||
|
||||
import dayjs from 'dayjs';
|
||||
import * as XLSX from 'xlsx';
|
||||
const ListPage: React.FC = () => {
|
||||
const [file, setFile] = useState<File | null>(null);
|
||||
const [csvData, setCsvData] = useState<any[]>([]);
|
||||
const [processedData, setProcessedData] = useState<any[]>([]);
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [activeKey, setActiveKey] = useState<string>('all');
|
||||
const [count, setCount] = useState<any[]>([]);
|
||||
|
|
@ -468,6 +475,64 @@ const ListPage: React.FC = () => {
|
|||
];
|
||||
const [selectedRowKeys, setSelectedRowKeys] = useState([]);
|
||||
|
||||
|
||||
/**
|
||||
* @description 处理文件上传
|
||||
*/
|
||||
const handleFileUpload = (uploadedFile: File) => {
|
||||
// 检查文件类型
|
||||
if (!uploadedFile.name.match(/\.(xlsx)$/)) {
|
||||
message.error('请上传 xlsx 格式的文件!');
|
||||
return false;
|
||||
}
|
||||
setFile(uploadedFile);
|
||||
|
||||
const reader = new FileReader();
|
||||
// 对于Excel文件,继续使用readAsArrayBuffer
|
||||
reader.onload = (e) => {
|
||||
try {
|
||||
const data = e.target?.result;
|
||||
// 如果是ArrayBuffer,使用type: 'array'来处理
|
||||
const workbook = XLSX.read(data, { type: 'array' });
|
||||
const sheetName = workbook.SheetNames[0];
|
||||
const worksheet = workbook.Sheets[sheetName];
|
||||
const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1 });
|
||||
|
||||
if (jsonData.length < 2) {
|
||||
message.error('文件为空或缺少表头!');
|
||||
setCsvData([]);
|
||||
return;
|
||||
}
|
||||
// 将数组转换为对象数组
|
||||
const headers = jsonData[0] as string[];
|
||||
const rows = jsonData.slice(1).map((rowArray: any) => {
|
||||
const rowData: { [key: string]: any } = {};
|
||||
headers.forEach((header, index) => {
|
||||
rowData[header] = rowArray[index];
|
||||
});
|
||||
return rowData;
|
||||
});
|
||||
|
||||
message.success(`成功解析 ${rows.length} 条数据.`);
|
||||
setCsvData(rows);
|
||||
setProcessedData([]); // 清空旧的处理结果
|
||||
} catch (error) {
|
||||
message.error('Excel文件解析失败,请检查文件格式!');
|
||||
console.error('Excel Parse Error:', error);
|
||||
setCsvData([]);
|
||||
}
|
||||
};
|
||||
reader.readAsArrayBuffer(uploadedFile);
|
||||
|
||||
|
||||
reader.onerror = (error) => {
|
||||
message.error('文件读取失败!');
|
||||
console.error('File Read Error:', error);
|
||||
};
|
||||
|
||||
return false; // 阻止antd Upload组件的默认上传行为
|
||||
};
|
||||
|
||||
return (
|
||||
<PageContainer ghost>
|
||||
<Tabs items={tabs} activeKey={activeKey} onChange={setActiveKey} />
|
||||
|
|
@ -495,6 +560,55 @@ const ListPage: React.FC = () => {
|
|||
}}
|
||||
toolBarRender={() => [
|
||||
// <CreateOrder tableRef={actionRef} />,
|
||||
<Upload
|
||||
// beforeUpload={handleFileUpload}
|
||||
name="file"
|
||||
accept=".xlsx"
|
||||
showUploadList={false}
|
||||
maxCount={1}
|
||||
customRequest={async (options) => {
|
||||
const { file, onSuccess, onError } = options;
|
||||
console.log(file);
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
try {
|
||||
const res = await request('/order/import', {
|
||||
method: 'POST',
|
||||
data: formData,
|
||||
requestType: 'form',
|
||||
});
|
||||
|
||||
if (res?.success && res.data) {
|
||||
// 使用xlsx将JSON数据转换为Excel
|
||||
const XLSX = require('xlsx');
|
||||
const worksheet = XLSX.utils.json_to_sheet(res.data);
|
||||
const workbook = XLSX.utils.book_new();
|
||||
XLSX.utils.book_append_sheet(workbook, worksheet, 'Orders');
|
||||
const excelBuffer = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' });
|
||||
// 否则按原逻辑处理二进制数据
|
||||
const blob = new Blob([excelBuffer], {
|
||||
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
});
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = 'orders.xlsx';
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
|
||||
} else {
|
||||
message.error(res.message || '导出失败');
|
||||
}
|
||||
actionRef.current?.reload();
|
||||
setSelectedRowKeys([]);
|
||||
} catch (error: any) {
|
||||
message.error('导入失败: ' + (error.message || '未知错误'));
|
||||
onError?.(error);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Button icon={<UploadOutlined />}>选择文件</Button>
|
||||
</Upload>,
|
||||
<SyncForm
|
||||
onFinish={async (values: any) => {
|
||||
try {
|
||||
|
|
@ -1267,7 +1381,10 @@ const Shipping: React.FC<{
|
|||
const [rates, setRates] = useState<API.RateDTO[]>([]);
|
||||
const [ratesLoading, setRatesLoading] = useState(false);
|
||||
const { message } = App.useApp();
|
||||
|
||||
const [shipmentPlatforms, setShipmentPlatforms] = useState([
|
||||
{ label: 'uniuni', value: 'uniuni' },
|
||||
{ label: 'tms.freightwaves', value: 'freightwaves' },
|
||||
]);
|
||||
return (
|
||||
<ModalForm
|
||||
formRef={formRef}
|
||||
|
|
@ -1296,6 +1413,7 @@ const Shipping: React.FC<{
|
|||
await ordercontrollerGetorderdetail({
|
||||
orderId: id,
|
||||
});
|
||||
console.log('success data',success,data)
|
||||
if (!success || !data) return {};
|
||||
data.sales = data.sales?.reduce(
|
||||
(acc: API.OrderSale[], cur: API.OrderSale) => {
|
||||
|
|
@ -1318,7 +1436,8 @@ const Shipping: React.FC<{
|
|||
if (reShipping) data.sales = [{}];
|
||||
let shipmentInfo = localStorage.getItem('shipmentInfo');
|
||||
if (shipmentInfo) shipmentInfo = JSON.parse(shipmentInfo);
|
||||
return {
|
||||
const a = {
|
||||
shipmentPlatform: 'uniuni',
|
||||
...data,
|
||||
// payment_method_id: shipmentInfo?.payment_method_id,
|
||||
stockPointId: shipmentInfo?.stockPointId,
|
||||
|
|
@ -1378,6 +1497,7 @@ const Shipping: React.FC<{
|
|||
},
|
||||
},
|
||||
};
|
||||
return a
|
||||
}}
|
||||
onFinish={async ({
|
||||
customer_note,
|
||||
|
|
@ -1441,7 +1561,18 @@ const Shipping: React.FC<{
|
|||
}
|
||||
}}
|
||||
>
|
||||
<ProFormText label="订单号" readonly name={'externalOrderId'} />
|
||||
<Row gutter={16}>
|
||||
<Col span={8}>
|
||||
<ProFormSelect
|
||||
name="shipmentPlatform"
|
||||
label="发货平台"
|
||||
options={shipmentPlatforms}
|
||||
placeholder="请选择发货平台"
|
||||
rules={[{ required: true, message: '请选择一个选项' }]}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
<ProFormText label="订单号" readonly name='externalOrderId' />
|
||||
<ProFormText label="客户备注" readonly name="customer_note" />
|
||||
<ProFormList
|
||||
label="后台备注"
|
||||
|
|
@ -1573,16 +1704,21 @@ const Shipping: React.FC<{
|
|||
title="发货信息"
|
||||
extra={
|
||||
<AddressPicker
|
||||
onChange={({
|
||||
onChange={(row) => {
|
||||
console.log(row);
|
||||
const {
|
||||
address,
|
||||
phone_number,
|
||||
phone_number_extension,
|
||||
stockPointId,
|
||||
}) => {
|
||||
email,
|
||||
} = row;
|
||||
formRef?.current?.setFieldsValue({
|
||||
stockPointId,
|
||||
// address_id: row.id,
|
||||
details: {
|
||||
origin: {
|
||||
email_addresses:email,
|
||||
address,
|
||||
phone_number: {
|
||||
phone: phone_number,
|
||||
|
|
@ -1595,6 +1731,11 @@ const Shipping: React.FC<{
|
|||
/>
|
||||
}
|
||||
>
|
||||
{/* <ProFormText
|
||||
label="address_id"
|
||||
name={'address_id'}
|
||||
rules={[{ required: true, message: '请输入ID' }]}
|
||||
/> */}
|
||||
<ProFormSelect
|
||||
name="stockPointId"
|
||||
width="md"
|
||||
|
|
@ -1687,7 +1828,6 @@ const Shipping: React.FC<{
|
|||
<ProFormText
|
||||
label="公司名称"
|
||||
name={['details', 'destination', 'name']}
|
||||
rules={[{ required: true, message: '请输入公司名称' }]}
|
||||
/>
|
||||
<ProFormItem
|
||||
name={['details', 'destination', 'address', 'country']}
|
||||
|
|
@ -2017,6 +2157,7 @@ const Shipping: React.FC<{
|
|||
details.origin.phone_number.number =
|
||||
details.origin.phone_number.phone;
|
||||
const res = await logisticscontrollerGetshipmentfee({
|
||||
shipmentPlatform: data.shipmentPlatform,
|
||||
stockPointId: data.stockPointId,
|
||||
|
||||
sender: details.origin.contact_name,
|
||||
|
|
@ -2343,7 +2484,7 @@ const CreateOrder: React.FC<{
|
|||
<ProFormText
|
||||
label="公司名称"
|
||||
name={['billing', 'company']}
|
||||
rules={[{ required: true, message: '请输入公司名称' }]}
|
||||
rules={[{ message: '请输入公司名称' }]}
|
||||
/>
|
||||
<ProFormItem
|
||||
name={['billing', 'country']}
|
||||
|
|
@ -2429,6 +2570,11 @@ const AddressPicker: React.FC<{
|
|||
value: item.id,
|
||||
}));
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'id',
|
||||
dataIndex: ['id'],
|
||||
hideInSearch: true,
|
||||
},
|
||||
{
|
||||
title: '地区',
|
||||
|
|
@ -2456,6 +2602,11 @@ const AddressPicker: React.FC<{
|
|||
`+${record.phone_number_extension} ${record.phone_number}`,
|
||||
hideInSearch: true,
|
||||
},
|
||||
{
|
||||
title: '邮箱',
|
||||
dataIndex: [ 'email'],
|
||||
hideInSearch: true,
|
||||
},
|
||||
];
|
||||
return (
|
||||
<ModalForm
|
||||
|
|
|
|||
|
|
@ -149,6 +149,45 @@ export async function ordercontrollerGetordersales(
|
|||
});
|
||||
}
|
||||
|
||||
/** 此处后端没有提供注释 POST /order/import */
|
||||
export async function ordercontrollerImportwintopay(
|
||||
body: {},
|
||||
files?: File[],
|
||||
options?: { [key: string]: any },
|
||||
) {
|
||||
const formData = new FormData();
|
||||
|
||||
if (files) {
|
||||
files.forEach((f) => formData.append('files', f || ''));
|
||||
}
|
||||
|
||||
Object.keys(body).forEach((ele) => {
|
||||
const item = (body as any)[ele];
|
||||
|
||||
if (item !== undefined && item !== null) {
|
||||
if (typeof item === 'object' && !(item instanceof File)) {
|
||||
if (item instanceof Array) {
|
||||
item.forEach((f) => formData.append(ele, f || ''));
|
||||
} else {
|
||||
formData.append(
|
||||
ele,
|
||||
new Blob([JSON.stringify(item)], { type: 'application/json' }),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
formData.append(ele, item);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return request<any>('/order/import', {
|
||||
method: 'POST',
|
||||
data: formData,
|
||||
requestType: 'form',
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** 此处后端没有提供注释 POST /order/order/cancel/${param0} */
|
||||
export async function ordercontrollerCancelorder(
|
||||
// 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
|
||||
|
|
|
|||
|
|
@ -460,6 +460,8 @@ declare namespace API {
|
|||
tracking_id?: string;
|
||||
/** 物流单号 */
|
||||
tracking_number?: string;
|
||||
/** 物流产品代码 */
|
||||
tracking_product_code?: string;
|
||||
/** 物流公司 */
|
||||
shipping_provider?: string;
|
||||
/** 发货方式 */
|
||||
|
|
@ -621,7 +623,7 @@ declare namespace API {
|
|||
shipping_total?: number;
|
||||
shipping_tax?: number;
|
||||
cart_tax?: number;
|
||||
total?: number;
|
||||
total?: any;
|
||||
total_tax?: number;
|
||||
customer_id?: number;
|
||||
customer_email?: string;
|
||||
|
|
@ -820,7 +822,7 @@ declare namespace API {
|
|||
shipping_total?: number;
|
||||
shipping_tax?: number;
|
||||
cart_tax?: number;
|
||||
total?: number;
|
||||
total?: any;
|
||||
total_tax?: number;
|
||||
customer_id?: number;
|
||||
customer_email?: string;
|
||||
|
|
@ -1634,7 +1636,7 @@ declare namespace API {
|
|||
shipmentPlatform?: string;
|
||||
stockPointId?: number;
|
||||
sender?: string;
|
||||
startPhone?: string;
|
||||
startPhone?: Record<string, any>;
|
||||
startPostalCode?: string;
|
||||
pickupAddress?: string;
|
||||
shipperCountryCode?: string;
|
||||
|
|
@ -1663,6 +1665,7 @@ declare namespace API {
|
|||
phone_number?: string;
|
||||
phone_number_extension?: string;
|
||||
phone_number_country?: string;
|
||||
email?: string;
|
||||
/** 创建时间 */
|
||||
createdAt: string;
|
||||
/** 更新时间 */
|
||||
|
|
|
|||
Loading…
Reference in New Issue