import React, { useEffect, useState } from "../../../recovery-preview/node_modules/react/index.js"; import { compactText, formatCurrencyFen, formatUnixSeconds, requestJson, } from "../../runtime/client.js"; const ORDER_PERIODS = [ "month_price", "quarter_price", "half_year_price", "year_price", "two_year_price", "three_year_price", "onetime_price", "reset_price", ]; function FinanceOrderPage() { const [loading, setLoading] = useState(true); const [refreshTick, setRefreshTick] = useState(0); const [searchInput, setSearchInput] = useState(""); const [keyword, setKeyword] = useState(""); const [status, setStatus] = useState(""); const [rows, setRows] = useState([]); const [pagination, setPagination] = useState({ current: 1, last_page: 1, per_page: 20, total: 0 }); const [plans, setPlans] = useState([]); const [modal, setModal] = useState(null); const [assignForm, setAssignForm] = useState({ email: "", plan_id: "", period: "", total_amount: "" }); const [detail, setDetail] = useState(null); const [notice, setNotice] = useState(""); const [error, setError] = useState(""); useEffect(() => { let active = true; (async () => { try { const payload = await requestJson("/plan/fetch"); if (!active) { return; } setPlans(Array.isArray(payload?.data) ? payload.data : payload?.list || payload || []); } catch (err) { if (active) { setNotice(err.message || "Plan list unavailable"); } } })(); return () => { active = false; }; }, []); useEffect(() => { let active = true; (async () => { setLoading(true); setError(""); try { const query = new URLSearchParams({ page: String(pagination.current || 1), per_page: String(pagination.per_page || 20), }); if (keyword) { query.set("keyword", keyword); } if (status !== "") { query.set("status", status); } const payload = await requestJson(`/order/fetch?${query.toString()}`); if (!active) { return; } setRows(Array.isArray(payload?.list) ? payload.list : []); setPagination(payload?.pagination || pagination); } catch (err) { if (active) { setError(err.message || "Failed to load orders"); setRows([]); } } finally { if (active) { setLoading(false); } } })(); return () => { active = false; }; }, [keyword, pagination.current, pagination.per_page, refreshTick, status]); const reload = () => setRefreshTick((value) => value + 1); const openDetail = async (order) => { setModal({ type: "detail", title: order.trade_no }); setDetail(null); try { const payload = await requestJson("/order/detail", { method: "POST", body: { trade_no: order.trade_no }, }); setDetail(payload?.data || payload); } catch (err) { setDetail({ error: err.message || "Failed to load detail" }); } }; const submitSearch = (event) => { event.preventDefault(); setPagination((current) => ({ ...current, current: 1 })); setKeyword(compactText(searchInput)); }; const markPaid = async (tradeNo) => { if (!window.confirm(`Mark ${tradeNo} as paid?`)) { return; } try { await requestJson("/order/paid", { method: "POST", body: { trade_no: tradeNo } }); reload(); } catch (err) { setError(err.message || "Failed to mark order paid"); } }; const cancelOrder = async (tradeNo) => { if (!window.confirm(`Cancel ${tradeNo}?`)) { return; } try { await requestJson("/order/cancel", { method: "POST", body: { trade_no: tradeNo } }); reload(); } catch (err) { setError(err.message || "Failed to cancel order"); } }; const saveAssign = async (event) => { event.preventDefault(); try { await requestJson("/order/assign", { method: "POST", body: { email: compactText(assignForm.email), plan_id: toNullableNumber(assignForm.plan_id), period: compactText(assignForm.period), total_amount: toNullableNumber(assignForm.total_amount), }, }); setModal(null); reload(); } catch (err) { setError(err.message || "Failed to assign order"); } }; const saveCommissionStatus = async (tradeNo, commissionStatus) => { try { await requestJson("/order/update", { method: "POST", body: { trade_no: tradeNo, commission_status: commissionStatus }, }); reload(); } catch (err) { setError(err.message || "Failed to update commission state"); } }; return (

Recovered React Page

Finance Order

Live order table with detail drill-down, manual payment actions, and commission state updates.

{pagination.total}orders
{pagination.current}page
{plans.length}plans
setSearchInput(event.target.value)} placeholder="Search by trade no or user ID" />
{notice ?
{notice}
: null} {error ?
{error}
: null}
{loading ? ( ) : rows.length === 0 ? ( ) : rows.map((order) => ( ))}
Trade No User Plan Period Amount Status Commission Created Actions
Loading...
No orders found
{order.user_email || `User ${order.user_id}`} UID: {order.user_id}
{order.plan?.name || order.plan_name || `Plan ${order.plan_id || "-"}`} {order.period || "-"} {formatCurrencyFen(order.total_amount)} {statusLabel(order.status)}
{commissionStatusLabel(order.commission_status)} {formatCurrencyFen(order.commission_balance)}
{formatUnixSeconds(order.created_at)}
{Number(order.status) === 0 ? ( <> ) : null}
Page {pagination.current} / {pagination.last_page}
{modal?.type === "assign" ? ( setModal(null)}>
) : null} {modal?.type === "detail" ? ( setModal(null)}> {detail?.error ?
{detail.error}
: null}
{JSON.stringify(detail, null, 2)}
) : null}
); } function Modal({ title, children, onClose }) { return (
event.stopPropagation()}>

{title}

{children}
); } function statusLabel(status) { switch (Number(status)) { case 0: return "Pending"; case 2: return "Cancelled"; case 3: return "Paid"; default: return String(status ?? "-"); } } function statusClass(status) { switch (Number(status)) { case 0: return "chip-warn"; case 2: return "chip-danger"; case 3: return "chip-ok"; default: return "chip-soft"; } } function commissionStatusLabel(status) { switch (Number(status)) { case 0: return "Pending"; case 1: return "Processing"; case 2: return "Valid"; case 3: return "Invalid"; default: return String(status ?? "-"); } } function toNullableNumber(value) { const trimmed = compactText(value); if (!trimmed) { return undefined; } const number = Number(trimmed); return Number.isNaN(number) ? undefined : number; } export default FinanceOrderPage;