|
|
@@ -1,7 +1,7 @@
|
|
|
import React, { useState, useEffect } from 'react';
|
|
|
import { useQuery, useMutation } from '@tanstack/react-query';
|
|
|
import { toast } from 'sonner';
|
|
|
-import { Layers, Package, Plus, Trash2, Edit, X, Check, ChevronDown, ChevronRight } from 'lucide-react';
|
|
|
+import { Layers, Package, Plus, Edit } from 'lucide-react';
|
|
|
|
|
|
import { Button } from '@d8d/shared-ui-components/components/ui/button';
|
|
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@d8d/shared-ui-components/components/ui/card';
|
|
|
@@ -81,14 +81,13 @@ export const GoodsParentChildPanel: React.FC<GoodsParentChildPanelProps> = ({
|
|
|
disabled = false
|
|
|
}) => {
|
|
|
const [panelMode, setPanelMode] = useState<PanelMode>(PanelMode.VIEW);
|
|
|
- const [expandedParentId, setExpandedParentId] = useState<number | null>(null);
|
|
|
const [selectedChildren, setSelectedChildren] = useState<number[]>(childGoodsIds);
|
|
|
const [localBatchSpecs, setLocalBatchSpecs] = useState<BatchSpecTemplate[]>(batchSpecs);
|
|
|
const [isSetAsParentDialogOpen, setIsSetAsParentDialogOpen] = useState(false);
|
|
|
const [isRemoveParentDialogOpen, setIsRemoveParentDialogOpen] = useState(false);
|
|
|
|
|
|
// 获取子商品列表(编辑模式)
|
|
|
- const { data: childrenData, isLoading: isLoadingChildren, refetch: refetchChildren } = useQuery({
|
|
|
+ const { data: childrenData } = useQuery({
|
|
|
queryKey: ['goods-children', goodsId, tenantId],
|
|
|
queryFn: async () => {
|
|
|
if (!goodsId || mode !== 'edit') return { data: [], total: 0 };
|
|
|
@@ -116,7 +115,7 @@ export const GoodsParentChildPanel: React.FC<GoodsParentChildPanelProps> = ({
|
|
|
const setAsParentMutation = useMutation({
|
|
|
mutationFn: async () => {
|
|
|
if (!goodsId) throw new Error('商品ID不能为空');
|
|
|
- const res = await goodsClientManager.get()[':id'].setAsParent.$post({
|
|
|
+ const res = await goodsClientManager.get()[':id']['set-as-parent'].$post({
|
|
|
param: { id: goodsId }
|
|
|
});
|
|
|
if (res.status !== 200) throw new Error('设为父商品失败');
|
|
|
@@ -261,7 +260,7 @@ export const GoodsParentChildPanel: React.FC<GoodsParentChildPanelProps> = ({
|
|
|
// 判断当前商品状态
|
|
|
const isParent = spuId === 0;
|
|
|
const isChild = spuId > 0;
|
|
|
- const hasChildren = childrenData?.total > 0 || selectedChildren.length > 0;
|
|
|
+ const hasChildren = (childrenData?.total || 0) > 0 || selectedChildren.length > 0;
|
|
|
|
|
|
return (
|
|
|
<Card className="mt-6">
|
|
|
@@ -423,7 +422,7 @@ export const GoodsParentChildPanel: React.FC<GoodsParentChildPanelProps> = ({
|
|
|
});
|
|
|
}
|
|
|
}}
|
|
|
- onSaveTemplate={(templateName, specs) => {
|
|
|
+ onSaveTemplate={(templateName) => {
|
|
|
toast.success(`模板 "${templateName}" 已保存`);
|
|
|
// 在实际应用中,这里可以保存到本地存储或后端
|
|
|
}}
|