forked from yoone/WEB
Feature: 增加换货功能
This commit is contained in:
parent
b9449c3a8a
commit
fb79163721
|
|
@ -22,6 +22,7 @@ import {
|
|||
ordercontrollerRefundorder,
|
||||
ordercontrollerSyncorder,
|
||||
ordercontrollerSyncorderbyid,
|
||||
ordercontrollerUpdateOrderItems,
|
||||
} from '@/servers/api/order';
|
||||
import { productcontrollerSearchproducts } from '@/servers/api/product';
|
||||
import { sitecontrollerAll } from '@/servers/api/site';
|
||||
|
|
@ -66,6 +67,7 @@ import {
|
|||
Drawer,
|
||||
Dropdown,
|
||||
Empty,
|
||||
message,
|
||||
Popconfirm,
|
||||
Radio,
|
||||
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
|
||||
label="备注"
|
||||
span={3}
|
||||
|
|
@ -1133,11 +1147,11 @@ const Shipping: React.FC<{
|
|||
{
|
||||
measurements: {
|
||||
weight: {
|
||||
unit: 'KGS',
|
||||
unit: 'LBS',
|
||||
value: 1,
|
||||
},
|
||||
cuboid: {
|
||||
unit: 'CM',
|
||||
unit: 'IN',
|
||||
l: 6,
|
||||
w: 4,
|
||||
h: 4,
|
||||
|
|
@ -1682,7 +1696,6 @@ const Shipping: React.FC<{
|
|||
valueEnum={{
|
||||
CM: '厘米',
|
||||
IN: '英寸',
|
||||
FT: '英尺',
|
||||
}}
|
||||
placeholder="请输入单位"
|
||||
rules={[{ required: true, message: '请输入单位' }]}
|
||||
|
|
@ -1698,7 +1711,8 @@ const Shipping: React.FC<{
|
|||
<ProFormSelect
|
||||
label="单位"
|
||||
name={['measurements', 'weight', 'unit']}
|
||||
valueEnum={{ KGS: '千克', LBS: '磅', OZS: '盎司' }}
|
||||
valueEnum={{ KGS: '千克', LBS: '磅' }}
|
||||
// valueEnum={{ KGS: '千克', LBS: '磅', OZS: '盎司' }}
|
||||
placeholder="请输入单位"
|
||||
rules={[{ required: true, message: '请输入单位' }]}
|
||||
/>
|
||||
|
|
@ -1738,7 +1752,8 @@ const Shipping: React.FC<{
|
|||
<ProFormSelect
|
||||
label="单位"
|
||||
name={['weight', 'unit']}
|
||||
valueEnum={{ kg: '千克', lb: '磅', g: '克', oz: '盎司' }}
|
||||
valueEnum={{ kg: '千克', lb: '磅' }}
|
||||
// valueEnum={{ kg: '千克', lb: '磅', oz: '盎司' }}
|
||||
placeholder="请输入单位"
|
||||
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<{
|
||||
tableRef?: React.MutableRefObject<ActionType | undefined>;
|
||||
}> = ({ tableRef }) => {
|
||||
|
|
|
|||
|
|
@ -208,3 +208,19 @@ export async function ordercontrollerSyncorderbyid(
|
|||
...(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 || {}),
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -993,6 +993,10 @@ declare namespace API {
|
|||
orderIds?: number[];
|
||||
};
|
||||
|
||||
type ShipmentSkuDTO = {
|
||||
sales?: OrderSale[];
|
||||
}
|
||||
|
||||
type ShippingAddress = {
|
||||
id?: number;
|
||||
name?: string;
|
||||
|
|
|
|||
Loading…
Reference in New Issue