fix(mini-user): show real receiver fields on order detail
CI / verify (pull_request) Has been cancelled
CI / verify (pull_request) Has been cancelled
Order detail used non-existent addressSnapshot; API returns receiverName/phone/address. Render those and fix product qty from items/quantity.
This commit is contained in:
@@ -7,22 +7,36 @@ import ShareNavButton from '../../components/ShareNavButton';
|
|||||||
import WechatShareReady from '../../components/WechatShareReady';
|
import WechatShareReady from '../../components/WechatShareReady';
|
||||||
import { request, toast } from '../../lib/api';
|
import { request, toast } from '../../lib/api';
|
||||||
import { buildPayUrl } from '../../lib/checkout-nav';
|
import { buildPayUrl } from '../../lib/checkout-nav';
|
||||||
|
import { maskPhone } from '../../lib/phone';
|
||||||
import {
|
import {
|
||||||
DEFAULT_SHARE_DESC,
|
DEFAULT_SHARE_DESC,
|
||||||
DEFAULT_SHARE_TITLE,
|
DEFAULT_SHARE_TITLE,
|
||||||
toWeappShareMessage,
|
toWeappShareMessage,
|
||||||
} from '../../lib/wechat-share';
|
} from '../../lib/wechat-share';
|
||||||
|
|
||||||
|
type OrderItem = {
|
||||||
|
productName?: string;
|
||||||
|
productSpec?: string;
|
||||||
|
quantity?: number;
|
||||||
|
};
|
||||||
|
|
||||||
type OrderDetail = {
|
type OrderDetail = {
|
||||||
id: string;
|
id: string;
|
||||||
orderNo?: string;
|
orderNo?: string;
|
||||||
status?: string;
|
status?: string;
|
||||||
payAmount?: number;
|
payAmount?: number;
|
||||||
productName?: string;
|
productName?: string;
|
||||||
|
quantity?: number;
|
||||||
qty?: number;
|
qty?: number;
|
||||||
addressSnapshot?: string;
|
receiverName?: string;
|
||||||
|
receiverPhone?: string;
|
||||||
|
receiverProvince?: string;
|
||||||
|
receiverCity?: string;
|
||||||
|
receiverDistrict?: string;
|
||||||
|
receiverAddress?: string;
|
||||||
createdAt?: string;
|
createdAt?: string;
|
||||||
originOrderId?: string | null;
|
originOrderId?: string | null;
|
||||||
|
items?: OrderItem[];
|
||||||
};
|
};
|
||||||
|
|
||||||
const STATUS_LABELS: Record<string, string> = {
|
const STATUS_LABELS: Record<string, string> = {
|
||||||
@@ -37,6 +51,16 @@ const STATUS_LABELS: Record<string, string> = {
|
|||||||
REFUNDED: '已退款',
|
REFUNDED: '已退款',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function fullReceiverAddress(order: OrderDetail) {
|
||||||
|
const detail = (order.receiverAddress || '').trim();
|
||||||
|
const region = [order.receiverProvince, order.receiverCity, order.receiverDistrict]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join('');
|
||||||
|
if (!region && !detail) return '';
|
||||||
|
if (region && detail.startsWith(region)) return detail;
|
||||||
|
return `${region}${detail}`;
|
||||||
|
}
|
||||||
|
|
||||||
export default function OrderDetailPage() {
|
export default function OrderDetailPage() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const orderId = router.params.id ?? '';
|
const orderId = router.params.id ?? '';
|
||||||
@@ -50,16 +74,23 @@ export default function OrderDetailPage() {
|
|||||||
}, [orderId]);
|
}, [orderId]);
|
||||||
|
|
||||||
const canPay = !!order && order.status === 'PENDING_PAY' && !order.originOrderId;
|
const canPay = !!order && order.status === 'PENDING_PAY' && !order.originOrderId;
|
||||||
|
const item = order?.items?.[0];
|
||||||
|
const productName = item?.productName || order?.productName || '杜康商品';
|
||||||
|
const quantity = item?.quantity ?? order?.quantity ?? order?.qty ?? 1;
|
||||||
|
const addressText = order ? fullReceiverAddress(order) : '';
|
||||||
|
const receiverLine = order
|
||||||
|
? [order.receiverName, order.receiverPhone ? maskPhone(String(order.receiverPhone)) : '']
|
||||||
|
.filter(Boolean)
|
||||||
|
.join(' ')
|
||||||
|
: '';
|
||||||
|
|
||||||
const sharePayload = useMemo(
|
const sharePayload = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
title: order?.productName
|
title: productName !== '杜康商品' ? `我买了${productName} · 杜康好客` : DEFAULT_SHARE_TITLE,
|
||||||
? `我买了${order.productName} · 杜康好客`
|
|
||||||
: DEFAULT_SHARE_TITLE,
|
|
||||||
desc: DEFAULT_SHARE_DESC,
|
desc: DEFAULT_SHARE_DESC,
|
||||||
path: orderId ? `/pages/order-detail/index?id=${orderId}` : '/pages/home/index',
|
path: orderId ? `/pages/order-detail/index?id=${orderId}` : '/pages/home/index',
|
||||||
}),
|
}),
|
||||||
[order, orderId],
|
[productName, orderId],
|
||||||
);
|
);
|
||||||
|
|
||||||
useShareAppMessage(() => toWeappShareMessage(sharePayload));
|
useShareAppMessage(() => toWeappShareMessage(sharePayload));
|
||||||
@@ -94,8 +125,8 @@ export default function OrderDetailPage() {
|
|||||||
<View className="order-card">
|
<View className="order-card">
|
||||||
<Text className="order-card-title">商品信息</Text>
|
<Text className="order-card-title">商品信息</Text>
|
||||||
<View className="order-row">
|
<View className="order-row">
|
||||||
<Text className="order-row-label">{order.productName || '杜康商品'}</Text>
|
<Text className="order-row-label">{productName}</Text>
|
||||||
<Text className="order-row-value">x{order.qty ?? 1}</Text>
|
<Text className="order-row-value">x{quantity}</Text>
|
||||||
</View>
|
</View>
|
||||||
<View className="order-row">
|
<View className="order-row">
|
||||||
<Text className="order-row-label">实付金额</Text>
|
<Text className="order-row-label">实付金额</Text>
|
||||||
@@ -106,9 +137,24 @@ export default function OrderDetailPage() {
|
|||||||
</View>
|
</View>
|
||||||
<View className="order-card">
|
<View className="order-card">
|
||||||
<Text className="order-card-title">收货信息</Text>
|
<Text className="order-card-title">收货信息</Text>
|
||||||
<Text className="u-muted">
|
{receiverLine || addressText ? (
|
||||||
{order.addressSnapshot || '地址信息待完善'}
|
<>
|
||||||
</Text>
|
{receiverLine ? (
|
||||||
|
<View className="order-row">
|
||||||
|
<Text className="order-row-label">收货人</Text>
|
||||||
|
<Text className="order-row-value">{receiverLine}</Text>
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
{addressText ? (
|
||||||
|
<View className="order-row order-row--address">
|
||||||
|
<Text className="order-row-label">收货地址</Text>
|
||||||
|
<Text className="order-row-value order-row-value--wrap">{addressText}</Text>
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<Text className="u-muted">地址信息待完善</Text>
|
||||||
|
)}
|
||||||
</View>
|
</View>
|
||||||
<View className="order-card">
|
<View className="order-card">
|
||||||
<Text className="order-card-title">订单信息</Text>
|
<Text className="order-card-title">订单信息</Text>
|
||||||
|
|||||||
@@ -118,6 +118,18 @@
|
|||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.order-row--address {
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-row-value--wrap {
|
||||||
|
flex: 1;
|
||||||
|
text-align: right;
|
||||||
|
white-space: normal;
|
||||||
|
word-break: break-all;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
.order-row-value--price {
|
.order-row-value--price {
|
||||||
color: var(--color-heritage-red);
|
color: var(--color-heritage-red);
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
|
|||||||
Reference in New Issue
Block a user