套餐编码可视化改造
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
getPageProductSku,
|
||||
} from "@/actions/product"
|
||||
import { DataTable, useDataTable } from "@/components/data-table"
|
||||
import { SkuCodeBadge } from "@/components/products/format"
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
@@ -22,15 +23,19 @@ import {
|
||||
} from "@/components/ui/alert-dialog"
|
||||
import { Badge } from "@/components/ui/badge"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import type { ProductCode } from "@/lib/base"
|
||||
import { cn } from "@/lib/utils"
|
||||
import type { Product } from "@/models/product"
|
||||
import type { ProductSku } from "@/models/product_sku"
|
||||
import { BatchUpdateDiscount } from "./batch-discount"
|
||||
import { CreateProductSku } from "./create"
|
||||
import type { SelectedProduct } from "./type"
|
||||
import { UpdateProductSku } from "./update"
|
||||
|
||||
export default function ProductPage() {
|
||||
const [selected, setSelected] = useState<number | undefined>(undefined)
|
||||
const [selected, setSelected] = useState<SelectedProduct | undefined>(
|
||||
undefined,
|
||||
)
|
||||
|
||||
return (
|
||||
<div className="size-full flex gap-6 items-stretch">
|
||||
@@ -41,8 +46,8 @@ export default function ProductPage() {
|
||||
}
|
||||
|
||||
function Products(props: {
|
||||
selected?: number
|
||||
onSelect?: (id: number) => void
|
||||
selected?: SelectedProduct
|
||||
onSelect?: (id: SelectedProduct) => void
|
||||
}) {
|
||||
const [list, setList] = useState<Product[]>([])
|
||||
|
||||
@@ -54,7 +59,7 @@ function Products(props: {
|
||||
}, [])
|
||||
|
||||
const selected = useMemo(() => {
|
||||
return list.find(item => item.id === props.selected)
|
||||
return list.find(item => item.id === props.selected?.id)
|
||||
}, [list, props.selected])
|
||||
|
||||
useEffect(() => {
|
||||
@@ -75,7 +80,7 @@ function Products(props: {
|
||||
"size-full box-border p-2 rounded-md flex justify-between items-center select-none",
|
||||
selected?.id === item.id && "bg-primary/20",
|
||||
)}
|
||||
onClick={() => props.onSelect?.(item.id)}
|
||||
onClick={() => props.onSelect?.({ id: item.id, code: item.code })}
|
||||
>
|
||||
<div>
|
||||
<p>{item.name}</p>
|
||||
@@ -90,10 +95,15 @@ function Products(props: {
|
||||
)
|
||||
}
|
||||
|
||||
function ProductSkus(props: { selected?: number }) {
|
||||
function ProductSkus(props: {
|
||||
selected?: {
|
||||
id: number
|
||||
code: ProductCode
|
||||
}
|
||||
}) {
|
||||
const action = useCallback(
|
||||
(page: number, size: number) =>
|
||||
getPageProductSku({ page, size, product_id: props.selected }),
|
||||
getPageProductSku({ page, size, product_id: props.selected?.id }),
|
||||
[props.selected],
|
||||
)
|
||||
|
||||
@@ -102,12 +112,9 @@ function ProductSkus(props: { selected?: number }) {
|
||||
return (
|
||||
<div className="flex-auto overflow-hidden flex flex-col items-stretch gap-3">
|
||||
<div className="flex gap-3">
|
||||
<CreateProductSku
|
||||
productId={props.selected ?? 0}
|
||||
onSuccess={table.refresh}
|
||||
/>
|
||||
<CreateProductSku product={props.selected} onSuccess={table.refresh} />
|
||||
<BatchUpdateDiscount
|
||||
productId={props.selected ?? 0}
|
||||
productId={props.selected?.id ?? 0}
|
||||
onSuccess={table.refresh}
|
||||
/>
|
||||
</div>
|
||||
@@ -118,7 +125,18 @@ function ProductSkus(props: { selected?: number }) {
|
||||
}}
|
||||
{...table}
|
||||
columns={[
|
||||
{ header: "套餐编码", accessorKey: "code" },
|
||||
{
|
||||
header: "套餐编码",
|
||||
cell: ({ row }) =>
|
||||
row.original.product ? (
|
||||
<SkuCodeBadge
|
||||
productCode={row.original.product.code}
|
||||
skuCode={row.original.code}
|
||||
/>
|
||||
) : (
|
||||
row.original.code
|
||||
),
|
||||
},
|
||||
{ header: "套餐名称", accessorKey: "name" },
|
||||
{ header: "单价", accessorFn: row => Number(row.price).toFixed(2) },
|
||||
{ header: "折扣", accessorFn: row => row.discount?.name ?? "—" },
|
||||
|
||||
Reference in New Issue
Block a user