确定订单页修改
This commit is contained in:
@@ -70,6 +70,7 @@ export default function OrderConfirmPage() {
|
|||||||
const [addresses, setAddresses] = useState<Address[]>([]);
|
const [addresses, setAddresses] = useState<Address[]>([]);
|
||||||
const [addressId, setAddressId] = useState(params.get('addressId') || '');
|
const [addressId, setAddressId] = useState(params.get('addressId') || '');
|
||||||
const [preview, setPreview] = useState<OrderPreview | null>(null);
|
const [preview, setPreview] = useState<OrderPreview | null>(null);
|
||||||
|
const [previewLoading, setPreviewLoading] = useState(false);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [msg, setMsg] = useState('');
|
const [msg, setMsg] = useState('');
|
||||||
|
|
||||||
@@ -104,13 +105,35 @@ export default function OrderConfirmPage() {
|
|||||||
}, [refreshProfile]);
|
}, [refreshProfile]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!productId || !addressId) return;
|
if (!productId) return;
|
||||||
|
let cancelled = false;
|
||||||
|
setPreviewLoading(true);
|
||||||
|
const body: { productId: string; quantity: number; addressId?: string } = {
|
||||||
|
productId,
|
||||||
|
quantity,
|
||||||
|
};
|
||||||
|
if (addressId) body.addressId = addressId;
|
||||||
|
|
||||||
request<OrderPreview>('USER_H5', '/trade/orders/preview', {
|
request<OrderPreview>('USER_H5', '/trade/orders/preview', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({ productId, quantity, addressId }),
|
body: JSON.stringify(body),
|
||||||
})
|
})
|
||||||
.then(setPreview)
|
.then((data) => {
|
||||||
.catch((e) => setMsg(e instanceof Error ? e.message : String(e)));
|
if (!cancelled) setPreview(data);
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
if (!cancelled) {
|
||||||
|
setPreview(null);
|
||||||
|
setMsg(e instanceof Error ? e.message : String(e));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
if (!cancelled) setPreviewLoading(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
};
|
||||||
}, [productId, quantity, addressId]);
|
}, [productId, quantity, addressId]);
|
||||||
|
|
||||||
function updateQuantity(next: number) {
|
function updateQuantity(next: number) {
|
||||||
@@ -331,9 +354,13 @@ export default function OrderConfirmPage() {
|
|||||||
<span className="order-confirm-row-label">配送方式</span>
|
<span className="order-confirm-row-label">配送方式</span>
|
||||||
<div className="order-confirm-delivery-value">
|
<div className="order-confirm-delivery-value">
|
||||||
<p className="order-confirm-row-value">
|
<p className="order-confirm-row-value">
|
||||||
{isCross ? '物流配送' : '小飞侠配送'}
|
{!addressId
|
||||||
|
? '选择地址后确认'
|
||||||
|
: isCross
|
||||||
|
? '物流配送'
|
||||||
|
: '小飞侠配送'}
|
||||||
</p>
|
</p>
|
||||||
{!isCross && (
|
{addressId && !isCross && (
|
||||||
<p className="order-confirm-delivery-hint">预计24小时内送达</p>
|
<p className="order-confirm-delivery-hint">预计24小时内送达</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
@@ -358,10 +385,14 @@ export default function OrderConfirmPage() {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!preview && productId && addressId && (
|
{previewLoading && !preview && productId && (
|
||||||
<div className="order-confirm-loading">加载订单信息...</div>
|
<div className="order-confirm-loading">加载订单信息...</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{!previewLoading && !preview && productId && (
|
||||||
|
<div className="order-confirm-loading">无法加载商品信息</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{msg && <p className="order-confirm-msg">{msg}</p>}
|
{msg && <p className="order-confirm-msg">{msg}</p>}
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
@@ -376,10 +407,10 @@ export default function OrderConfirmPage() {
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="order-confirm-pay-btn"
|
className="order-confirm-pay-btn"
|
||||||
disabled={loading || !preview}
|
disabled={loading || !preview || !addressId}
|
||||||
onClick={submit}
|
onClick={submit}
|
||||||
>
|
>
|
||||||
{loading ? '支付中...' : '微信支付'}
|
{loading ? '支付中...' : !addressId ? '请选择地址' : '微信支付'}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
|
|||||||
Reference in New Issue
Block a user