Feature: 增加换货功能

This commit is contained in:
黄珑 2025-08-21 15:38:53 +08:00
parent b9449c3a8a
commit fb79163721
3 changed files with 166 additions and 15 deletions

View File

@ -22,6 +22,7 @@ import {
ordercontrollerRefundorder, ordercontrollerRefundorder,
ordercontrollerSyncorder, ordercontrollerSyncorder,
ordercontrollerSyncorderbyid, ordercontrollerSyncorderbyid,
ordercontrollerUpdateOrderItems,
} from '@/servers/api/order'; } from '@/servers/api/order';
import { productcontrollerSearchproducts } from '@/servers/api/product'; import { productcontrollerSearchproducts } from '@/servers/api/product';
import { sitecontrollerAll } from '@/servers/api/site'; import { sitecontrollerAll } from '@/servers/api/site';
@ -66,6 +67,7 @@ import {
Drawer, Drawer,
Dropdown, Dropdown,
Empty, Empty,
message,
Popconfirm, Popconfirm,
Radio, Radio,
Row, Row,
@ -861,6 +863,18 @@ const Detail: React.FC<{
); );
}} }}
/> />
<ProDescriptions.Item
label="换货"
span={3}
render={(_, record) => {
return (
<SalesChange
detailRef={ref}
id={record.id as number}
/>
)
}}
/>
<ProDescriptions.Item <ProDescriptions.Item
label="备注" label="备注"
span={3} span={3}
@ -1133,11 +1147,11 @@ const Shipping: React.FC<{
{ {
measurements: { measurements: {
weight: { weight: {
unit: 'KGS', unit: 'LBS',
value: 1, value: 1,
}, },
cuboid: { cuboid: {
unit: 'CM', unit: 'IN',
l: 6, l: 6,
w: 4, w: 4,
h: 4, h: 4,
@ -1276,16 +1290,16 @@ const Shipping: React.FC<{
<ProFormList <ProFormList
label="发货产品" label="发货产品"
name="sales" name="sales"
// rules={[ // rules={[
// { // {
// required: true, // required: true,
// message: '至少需要一个商品', // message: '至少需要一个商品',
// validator: (_, value) => // validator: (_, value) =>
// value && value.length > 0 // value && value.length > 0
// ? Promise.resolve() // ? Promise.resolve()
// : Promise.reject('至少需要一个商品'), // : Promise.reject('至少需要一个商品'),
// }, // },
// ]} // ]}
> >
<ProForm.Group> <ProForm.Group>
<ProFormSelect <ProFormSelect
@ -1682,7 +1696,6 @@ const Shipping: React.FC<{
valueEnum={{ valueEnum={{
CM: '厘米', CM: '厘米',
IN: '英寸', IN: '英寸',
FT: '英尺',
}} }}
placeholder="请输入单位" placeholder="请输入单位"
rules={[{ required: true, message: '请输入单位' }]} rules={[{ required: true, message: '请输入单位' }]}
@ -1698,7 +1711,8 @@ const Shipping: React.FC<{
<ProFormSelect <ProFormSelect
label="单位" label="单位"
name={['measurements', 'weight', 'unit']} name={['measurements', 'weight', 'unit']}
valueEnum={{ KGS: '千克', LBS: '磅', OZS: '盎司' }} valueEnum={{ KGS: '千克', LBS: '磅' }}
// valueEnum={{ KGS: '千克', LBS: '磅', OZS: '盎司' }}
placeholder="请输入单位" placeholder="请输入单位"
rules={[{ required: true, message: '请输入单位' }]} rules={[{ required: true, message: '请输入单位' }]}
/> />
@ -1738,7 +1752,8 @@ const Shipping: React.FC<{
<ProFormSelect <ProFormSelect
label="单位" label="单位"
name={['weight', 'unit']} name={['weight', 'unit']}
valueEnum={{ kg: '千克', lb: '磅', g: '克', oz: '盎司' }} valueEnum={{ kg: '千克', lb: '磅' }}
// valueEnum={{ kg: '千克', lb: '磅', oz: '盎司' }}
placeholder="请输入单位" placeholder="请输入单位"
rules={[{ required: true, message: '请输入单位' }]} rules={[{ required: true, message: '请输入单位' }]}
/> />
@ -1803,6 +1818,122 @@ const Shipping: React.FC<{
); );
}; };
const SalesChange: React.FC<{
id: number;
detailRef?: React.MutableRefObject<ActionType | undefined>;
reShipping?: boolean;
}> = ({ id, detailRef }) => {
const [options, setOptions] = useState<any[]>([]);
const formRef = useRef<ProFormInstance>();
return (
<ModalForm
formRef={formRef}
title="换货"
size="large"
width="80vw"
modalProps={{
destroyOnHidden: true,
styles: {
body: { maxHeight: '65vh', overflowY: 'auto', overflowX: 'hidden' },
},
}}
trigger={
<Button type="primary">
<CodeSandboxOutlined />
</Button>
}
request={async () => {
const { data, success }: API.OrderDetailRes =
await ordercontrollerGetorderdetail({
orderId: id,
});
if (!success || !data) return {};
data.sales = data.sales?.reduce((acc: API.OrderSale[], cur: API.OrderSale) => {
let idx = acc.findIndex((v: any) => v.productId === cur.productId);
if (idx === -1) {
acc.push(cur);
} else {
acc[idx].quantity += cur.quantity;
}
return acc;
},
[],
);
// setOptions(
// data.sales?.map((item) => ({
// label: item.name,
// value: item.sku,
// })) || [],
// );
return { ...data };
}}
onFinish={async (formData: any) => {
const { sales } = formData;
const res = await ordercontrollerUpdateOrderItems(id, sales);
if (!res.success) {
message.error(`更新货物信息失败: ${res.message}`);
return false;
}
message.success('更新成功')
detailRef?.current?.reload();
return true;
}}
>
<ProFormList
label="换货产品"
name="sales"
>
<ProForm.Group>
<ProFormSelect
params={{ options }}
request={async ({ keyWords, options }) => {
if (!keyWords || keyWords.length < 2) return options;
try {
const { data } = await productcontrollerSearchproducts({
name: keyWords,
});
return (
data?.map((item) => {
return {
label: `${item.name} - ${item.nameCn}`,
value: item?.sku,
};
}) || options
);
} catch (error) {
return options;
}
}}
name="sku"
label="产品"
placeholder="请选择产品"
tooltip="至少输入3个字符"
fieldProps={{
showSearch: true,
filterOption: false,
}}
debounceTime={300} // 防抖,减少请求频率
rules={[{ required: true, message: '请选择产品' }]}
/>
<ProFormDigit
name="quantity"
colProps={{ span: 12 }}
label="数量"
placeholder="请输入数量"
rules={[{ required: true, message: '请输入数量' }]}
fieldProps={{
precision: 0,
}}
/>
</ProForm.Group>
</ProFormList>
</ModalForm>
);
}
const CreateOrder: React.FC<{ const CreateOrder: React.FC<{
tableRef?: React.MutableRefObject<ActionType | undefined>; tableRef?: React.MutableRefObject<ActionType | undefined>;
}> = ({ tableRef }) => { }> = ({ tableRef }) => {

View File

@ -208,3 +208,19 @@ export async function ordercontrollerSyncorderbyid(
...(options || {}), ...(options || {}),
}); });
} }
/** 此处后端没有提供注释 POST /order/updateOrderItems/${param0} */
export async function ordercontrollerUpdateOrderItems(
orderId: number,
body: API.ShipmentSkuDTO,
options?: { [key: string]: any },
) {
return request<API.BooleanRes>(`/order/updateOrderItems/${orderId}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
data: body,
...(options || {}),
});
}

View File

@ -993,6 +993,10 @@ declare namespace API {
orderIds?: number[]; orderIds?: number[];
}; };
type ShipmentSkuDTO = {
sales?: OrderSale[];
}
type ShippingAddress = { type ShippingAddress = {
id?: number; id?: number;
name?: string; name?: string;