更新操作按钮为菜单栏 & 调整页面表格顺序
This commit is contained in:
@@ -4,10 +4,8 @@ import { format } from "date-fns"
|
||||
import { CheckCircle, Clock, XCircle } from "lucide-react"
|
||||
import { Suspense, useCallback, useState } from "react"
|
||||
import { Controller, useForm } from "react-hook-form"
|
||||
import { toast } from "sonner"
|
||||
import { z } from "zod"
|
||||
import { getPageTrade, getTradeComplete } from "@/actions/trade"
|
||||
import { Auth } from "@/components/auth"
|
||||
import { getPageTrade } from "@/actions/trade"
|
||||
import { DataTable, useDataTable } from "@/components/data-table"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import {
|
||||
@@ -24,7 +22,6 @@ import {
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select"
|
||||
import { ScopeTradeWriteComplete } from "@/lib/scopes"
|
||||
import type { Trade } from "@/models/trade"
|
||||
|
||||
type FilterValues = {
|
||||
@@ -113,30 +110,8 @@ export default function TradePage() {
|
||||
table.pagination.onPageChange(1)
|
||||
})
|
||||
|
||||
const [completingId, setCompletingId] = useState<string | null>(null)
|
||||
|
||||
const handleComplete = async (trade: Trade) => {
|
||||
if (completingId) return
|
||||
setCompletingId(trade.inner_no)
|
||||
try {
|
||||
const result = await getTradeComplete({
|
||||
user_id: Number(trade.user_id),
|
||||
trade_no: trade.inner_no,
|
||||
method: trade.method,
|
||||
})
|
||||
if (result.success) {
|
||||
toast.success("订单已完成")
|
||||
} else {
|
||||
toast.error(result.message || "操作失败")
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("完成订单失败:", error)
|
||||
toast.error("网络错误,请稍后重试")
|
||||
}
|
||||
}
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
{/* 筛选表单 */}
|
||||
<form onSubmit={onFilter} className="bg-white p-4">
|
||||
<div className="flex flex-wrap items-end gap-4">
|
||||
<Controller
|
||||
@@ -268,7 +243,7 @@ export default function TradePage() {
|
||||
</div>
|
||||
|
||||
<FieldGroup className="flex-row justify-start mt-4 gap-2">
|
||||
<Button type="submit">筛选</Button>
|
||||
<Button type="submit">搜索</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
@@ -288,35 +263,14 @@ export default function TradePage() {
|
||||
{...table}
|
||||
columns={[
|
||||
{
|
||||
header: "会员号",
|
||||
accessorFn: row => row.user?.phone || "",
|
||||
},
|
||||
{
|
||||
header: "订单号",
|
||||
accessorKey: "inner_no",
|
||||
},
|
||||
{
|
||||
header: "渠道订单号",
|
||||
accessorKey: "outer_no",
|
||||
},
|
||||
{
|
||||
header: "支付渠道",
|
||||
accessorKey: "method",
|
||||
cell: ({ row }) => {
|
||||
const methodMap: Record<number, string> = {
|
||||
1: "支付宝",
|
||||
2: "微信",
|
||||
3: "商福通",
|
||||
4: "商福通渠道支付宝",
|
||||
5: "商福通渠道微信",
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
{methodMap[row.original.method as number] || "未知"}
|
||||
</div>
|
||||
)
|
||||
},
|
||||
header: "创建时间",
|
||||
accessorKey: "created_at",
|
||||
cell: ({ row }) =>
|
||||
format(new Date(row.original.created_at), "yyyy-MM-dd HH:mm"),
|
||||
},
|
||||
{ header: "会员号", accessorFn: row => row.user?.phone || "" },
|
||||
{ header: "订单号", accessorKey: "inner_no" },
|
||||
{ header: "购买套餐", accessorKey: "subject" },
|
||||
{
|
||||
header: "支付金额",
|
||||
accessorKey: "payment",
|
||||
@@ -338,25 +292,6 @@ export default function TradePage() {
|
||||
)
|
||||
},
|
||||
},
|
||||
{
|
||||
header: "支付平台",
|
||||
accessorKey: "platform",
|
||||
cell: ({ row }) => {
|
||||
const platform = row.original.platform
|
||||
if (!platform) return <span>-</span>
|
||||
return (
|
||||
<div className="flex items-center gap-2">
|
||||
{platform === 1 ? (
|
||||
<span>电脑网站</span>
|
||||
) : platform === 2 ? (
|
||||
<span>手机网站</span>
|
||||
) : (
|
||||
<span>-</span>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
},
|
||||
},
|
||||
{
|
||||
header: "支付状态",
|
||||
accessorKey: "status",
|
||||
@@ -390,37 +325,44 @@ export default function TradePage() {
|
||||
}
|
||||
},
|
||||
},
|
||||
{ header: "购买套餐", accessorKey: "subject" },
|
||||
{
|
||||
header: "创建时间",
|
||||
accessorKey: "created_at",
|
||||
cell: ({ row }) =>
|
||||
format(new Date(row.original.created_at), "yyyy-MM-dd HH:mm"),
|
||||
},
|
||||
{
|
||||
id: "action",
|
||||
meta: { pin: "right" },
|
||||
header: "操作",
|
||||
header: "支付平台",
|
||||
accessorKey: "platform",
|
||||
cell: ({ row }) => {
|
||||
const isPending = row.original.status === 0
|
||||
const isLoading = completingId === row.original.inner_no
|
||||
const platform = row.original.platform
|
||||
if (!platform) return <span>-</span>
|
||||
return (
|
||||
<div className="flex gap-2">
|
||||
<Auth scope={ScopeTradeWriteComplete}>
|
||||
{isPending && (
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={() => handleComplete(row.original)}
|
||||
disabled={isLoading}
|
||||
>
|
||||
{isLoading ? "处理中..." : "完成订单"}
|
||||
</Button>
|
||||
)}
|
||||
</Auth>
|
||||
<div className="flex items-center gap-2">
|
||||
{platform === 1 ? (
|
||||
<span>电脑网站</span>
|
||||
) : platform === 2 ? (
|
||||
<span>手机网站</span>
|
||||
) : (
|
||||
<span>-</span>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
},
|
||||
},
|
||||
{
|
||||
header: "支付渠道",
|
||||
accessorKey: "method",
|
||||
cell: ({ row }) => {
|
||||
const methodMap: Record<number, string> = {
|
||||
1: "支付宝",
|
||||
2: "微信",
|
||||
3: "商福通",
|
||||
4: "商福通渠道支付宝",
|
||||
5: "商福通渠道微信",
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
{methodMap[row.original.method as number] || "未知"}
|
||||
</div>
|
||||
)
|
||||
},
|
||||
},
|
||||
{ header: "渠道订单号", accessorKey: "outer_no" },
|
||||
]}
|
||||
/>
|
||||
</Suspense>
|
||||
|
||||
Reference in New Issue
Block a user