|
@@ -1,5 +1,5 @@
|
|
|
-import React, { useState } from 'react';
|
|
|
|
|
-import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
|
|
|
|
|
|
+import React, { useState, useCallback } from 'react';
|
|
|
|
|
+import { useQuery, useMutation } from '@tanstack/react-query';
|
|
|
import { format } from 'date-fns';
|
|
import { format } from 'date-fns';
|
|
|
import { zhCN } from 'date-fns/locale';
|
|
import { zhCN } from 'date-fns/locale';
|
|
|
import { toast } from 'sonner';
|
|
import { toast } from 'sonner';
|
|
@@ -9,7 +9,6 @@ import type { InferRequestType, InferResponseType } from 'hono/client';
|
|
|
|
|
|
|
|
import { Button } from '@d8d/shared-ui-components/components/ui/button';
|
|
import { Button } from '@d8d/shared-ui-components/components/ui/button';
|
|
|
import { Input } from '@d8d/shared-ui-components/components/ui/input';
|
|
import { Input } from '@d8d/shared-ui-components/components/ui/input';
|
|
|
-import { Label } from '@d8d/shared-ui-components/components/ui/label';
|
|
|
|
|
import { Badge } from '@d8d/shared-ui-components/components/ui/badge';
|
|
import { Badge } from '@d8d/shared-ui-components/components/ui/badge';
|
|
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@d8d/shared-ui-components/components/ui/card';
|
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@d8d/shared-ui-components/components/ui/card';
|
|
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@d8d/shared-ui-components/components/ui/table';
|
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@d8d/shared-ui-components/components/ui/table';
|
|
@@ -25,8 +24,8 @@ import { FileSelector } from '@d8d/file-management-ui-mt';
|
|
|
import { GoodsCategoryCascadeSelector } from '@d8d/goods-category-management-ui-mt/components';
|
|
import { GoodsCategoryCascadeSelector } from '@d8d/goods-category-management-ui-mt/components';
|
|
|
import { SupplierSelector } from '@d8d/supplier-management-ui-mt/components';
|
|
import { SupplierSelector } from '@d8d/supplier-management-ui-mt/components';
|
|
|
import { MerchantSelector } from '@d8d/merchant-management-ui-mt/components';
|
|
import { MerchantSelector } from '@d8d/merchant-management-ui-mt/components';
|
|
|
-import { GoodsParentChildPanel } from './GoodsParentChildPanel';
|
|
|
|
|
-import { Search, Plus, Edit, Trash2, Package, Layers } from 'lucide-react';
|
|
|
|
|
|
|
+import { GoodsParentChildPanel, type ParentChildData, type BatchSpecTemplate } from './GoodsParentChildPanel';
|
|
|
|
|
+import { Search, Plus, Edit, Trash2, Package } from 'lucide-react';
|
|
|
|
|
|
|
|
type CreateRequest = InferRequestType<typeof goodsClient.index.$post>['json'];
|
|
type CreateRequest = InferRequestType<typeof goodsClient.index.$post>['json'];
|
|
|
type UpdateRequest = InferRequestType<typeof goodsClient[':id']['$put']>['json'];
|
|
type UpdateRequest = InferRequestType<typeof goodsClient[':id']['$put']>['json'];
|
|
@@ -36,7 +35,6 @@ const createFormSchema = AdminCreateGoodsDto;
|
|
|
const updateFormSchema = AdminUpdateGoodsDto;
|
|
const updateFormSchema = AdminUpdateGoodsDto;
|
|
|
|
|
|
|
|
export const GoodsManagement: React.FC = () => {
|
|
export const GoodsManagement: React.FC = () => {
|
|
|
- const queryClient = useQueryClient();
|
|
|
|
|
const [searchParams, setSearchParams] = useState({ page: 1, limit: 10, search: '' });
|
|
const [searchParams, setSearchParams] = useState({ page: 1, limit: 10, search: '' });
|
|
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
|
const [editingGoods, setEditingGoods] = useState<GoodsResponse | null>(null);
|
|
const [editingGoods, setEditingGoods] = useState<GoodsResponse | null>(null);
|
|
@@ -47,7 +45,7 @@ export const GoodsManagement: React.FC = () => {
|
|
|
spuId: 0,
|
|
spuId: 0,
|
|
|
spuName: null as string | null,
|
|
spuName: null as string | null,
|
|
|
childGoodsIds: [] as number[],
|
|
childGoodsIds: [] as number[],
|
|
|
- batchSpecs: [] as Array<{ name: string; price: number; costPrice: number; stock: number; sort: number }>
|
|
|
|
|
|
|
+ batchSpecs: [] as BatchSpecTemplate[]
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// 创建表单
|
|
// 创建表单
|
|
@@ -214,8 +212,8 @@ export const GoodsManagement: React.FC = () => {
|
|
|
// 更新父子商品数据
|
|
// 更新父子商品数据
|
|
|
setParentChildData({
|
|
setParentChildData({
|
|
|
spuId: goods.spuId,
|
|
spuId: goods.spuId,
|
|
|
- spuName: goods.spuName,
|
|
|
|
|
- childGoodsIds: goods.childGoods?.map(child => child.id) || [],
|
|
|
|
|
|
|
+ spuName: goods.spuName ?? null,
|
|
|
|
|
+ childGoodsIds: goods.childGoodsIds || [],
|
|
|
batchSpecs: []
|
|
batchSpecs: []
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -263,6 +261,16 @@ export const GoodsManagement: React.FC = () => {
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ // 处理父子商品数据变化,适配GoodsParentChildPanel的onDataChange类型
|
|
|
|
|
+ const handleParentChildDataChange = useCallback((data: ParentChildData) => {
|
|
|
|
|
+ setParentChildData({
|
|
|
|
|
+ spuId: data.spuId,
|
|
|
|
|
+ spuName: data.spuName ?? null,
|
|
|
|
|
+ childGoodsIds: data.childGoodsIds,
|
|
|
|
|
+ batchSpecs: data.batchSpecs || []
|
|
|
|
|
+ });
|
|
|
|
|
+ }, [setParentChildData]);
|
|
|
|
|
+
|
|
|
return (
|
|
return (
|
|
|
<div className="space-y-4">
|
|
<div className="space-y-4">
|
|
|
<div className="flex justify-between items-center">
|
|
<div className="flex justify-between items-center">
|
|
@@ -849,10 +857,10 @@ export const GoodsManagement: React.FC = () => {
|
|
|
goodsId={isCreateForm ? undefined : editingGoods?.id}
|
|
goodsId={isCreateForm ? undefined : editingGoods?.id}
|
|
|
goodsName={isCreateForm ? createForm.watch('name') : editingGoods?.name}
|
|
goodsName={isCreateForm ? createForm.watch('name') : editingGoods?.name}
|
|
|
spuId={parentChildData.spuId}
|
|
spuId={parentChildData.spuId}
|
|
|
- spuName={parentChildData.spuName}
|
|
|
|
|
|
|
+ spuName={parentChildData.spuName ?? undefined}
|
|
|
childGoodsIds={parentChildData.childGoodsIds}
|
|
childGoodsIds={parentChildData.childGoodsIds}
|
|
|
batchSpecs={isCreateForm ? parentChildData.batchSpecs : undefined}
|
|
batchSpecs={isCreateForm ? parentChildData.batchSpecs : undefined}
|
|
|
- onDataChange={setParentChildData}
|
|
|
|
|
|
|
+ onDataChange={handleParentChildDataChange}
|
|
|
onUpdate={refetch}
|
|
onUpdate={refetch}
|
|
|
disabled={isCreateForm ? createMutation.isPending : updateMutation.isPending}
|
|
disabled={isCreateForm ? createMutation.isPending : updateMutation.isPending}
|
|
|
/>
|
|
/>
|