+ 已选择{lockedPayMethod === 'NATIVE' ? '收款码' : '微信代付'},切换方式请先取消支付
+
+ ) : (
+
@@ -338,6 +379,16 @@ export default function ProxyOrderDetailPage() {
{payMsg}
) : null}
+
+
) : null}
diff --git a/apps/h5-partner/src/pages/ProxyOrderPage.tsx b/apps/h5-partner/src/pages/ProxyOrderPage.tsx
index 70364f8..a1fe290 100644
--- a/apps/h5-partner/src/pages/ProxyOrderPage.tsx
+++ b/apps/h5-partner/src/pages/ProxyOrderPage.tsx
@@ -24,6 +24,7 @@ import type {
ProxyOrderPayResponse,
ProxyPayMethod,
} from '@dukang/shared-types';
+import { usePartnerPageView } from '../lib/usePageView';
function fmtMoney(n: number) {
return n.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
@@ -46,6 +47,7 @@ function initialDraft(): ProxyOrderDraft {
}
export default function ProxyOrderPage() {
+ usePartnerPageView('partner_proxy_order_view');
const navigate = useNavigate();
const [searchParams] = useSearchParams();
const draft0 = useMemo(() => initialDraft(), []);
@@ -70,6 +72,8 @@ export default function ProxyOrderPage() {
const [codeUrl, setCodeUrl] = useState
(null);
const [qrDataUrl, setQrDataUrl] = useState(null);
const [paying, setPaying] = useState(false);
+ const [cancelling, setCancelling] = useState(false);
+ const [lockedPayMethod, setLockedPayMethod] = useState(null);
const pollRef = useRef(null);
const region = useMemo(() => parseRegionCodes(regionCodes), [regionCodes]);
@@ -234,8 +238,17 @@ export default function ProxyOrderPage() {
}
async function startPay(orderId: string, method: ProxyPayMethod) {
+ if (lockedPayMethod && lockedPayMethod !== method) {
+ setMsg(
+ lockedPayMethod === 'JSAPI'
+ ? '该订单已发起微信代付,请先取消支付后重新下单'
+ : '该订单已生成收款码,请先取消支付后重新下单',
+ );
+ return;
+ }
setPaying(true);
setMsg('');
+ setPayMethod(method);
try {
if (method === 'JSAPI') {
if (!isWechatEnv()) {
@@ -266,11 +279,14 @@ export default function ProxyOrderPage() {
if (pay.mode === 'native' && pay.codeUrl) {
setCodeUrl(pay.codeUrl);
+ setLockedPayMethod(method);
startPoll(orderId);
return;
}
if (pay.mode === 'jsapi' && pay.prepay) {
+ setCodeUrl(null);
+ setLockedPayMethod(method);
await invokeWechatPay(pay.prepay, {
apiBase: '/api/v1',
clientApp: 'PARTNER_H5',
@@ -289,6 +305,40 @@ export default function ProxyOrderPage() {
}
}
+ async function cancelPay(orderId: string) {
+ setCancelling(true);
+ setMsg('');
+ stopPoll();
+ try {
+ await request('PARTNER_H5', `/partner/proxy-orders/${orderId}/cancel-pay`, {
+ method: 'POST',
+ body: '{}',
+ });
+ toastSuccess('已取消支付,可重新下单并选择其他支付方式');
+ setStep('form');
+ setCreated(null);
+ setCodeUrl(null);
+ setLockedPayMethod(null);
+ } catch (e) {
+ setMsg(e instanceof Error ? e.message : '取消失败');
+ } finally {
+ setCancelling(false);
+ }
+ }
+
+ function switchPayMethod(method: ProxyPayMethod) {
+ if (lockedPayMethod && lockedPayMethod !== method) {
+ setMsg(
+ lockedPayMethod === 'JSAPI'
+ ? '该订单已发起微信代付,请先取消支付后重新下单'
+ : '该订单已生成收款码,请先取消支付后重新下单',
+ );
+ return;
+ }
+ setPayMethod(method);
+ setMsg('');
+ }
+
async function submit() {
setMsg('');
const err = validateForm();
@@ -322,6 +372,7 @@ export default function ProxyOrderPage() {
setCreated(order);
setStep('pay');
setCodeUrl(null);
+ setLockedPayMethod(null);
await startPay(order.id, payMethod);
} catch (e) {
setMsg(e instanceof Error ? e.message : '下单失败');
@@ -359,24 +410,25 @@ export default function ProxyOrderPage() {
+ {lockedPayMethod ? (
+
+ 已选择{lockedPayMethod === 'NATIVE' ? '收款码' : '微信代付'},切换方式请先取消支付
+
+ ) : null}
{payMethod === 'NATIVE' ? (
@@ -419,6 +471,16 @@ export default function ProxyOrderPage() {
{msg}
) : null}
+
+