diff --git a/furniture-3d-system/src/app/api/intake/non-integrated/[id]/abandon/route.ts b/furniture-3d-system/src/app/api/intake/non-integrated/[id]/abandon/route.ts new file mode 100644 index 00000000..b557cbe8 --- /dev/null +++ b/furniture-3d-system/src/app/api/intake/non-integrated/[id]/abandon/route.ts @@ -0,0 +1,32 @@ +import { NextRequest } from 'next/server' +import { AppError, ErrorCode } from '@/server/core/errors' +import { handleRequest, jsonError, jsonSuccess } from '@/server/core/response' +import { intakeNonIntegratedProductService } from '@/server/services/intake-non-integrated-product.service' + +type RouteContext = { + params: Promise<{ id: string }> +} + +export async function POST(request: NextRequest, context: RouteContext) { + return handleRequest( + request, + async (ctx) => { + const { id } = await context.params + const decodedId = decodeURIComponent(id) + + try { + const result = await intakeNonIntegratedProductService.abandonProduct( + decodedId, + ctx.user, + ) + return jsonSuccess(result, 200, ctx.requestId) + } catch (error) { + if (error instanceof AppError) { + return jsonError(error.code, error.message, error.statusCode, ctx.requestId) + } + throw error + } + }, + { requireAuth: true }, + ) +} diff --git a/furniture-3d-system/src/app/intake/product-development/NonIntegratedPendingDetail.tsx b/furniture-3d-system/src/app/intake/product-development/NonIntegratedPendingDetail.tsx index df00a8de..059f45c4 100644 --- a/furniture-3d-system/src/app/intake/product-development/NonIntegratedPendingDetail.tsx +++ b/furniture-3d-system/src/app/intake/product-development/NonIntegratedPendingDetail.tsx @@ -2,7 +2,7 @@ import { useRouter } from "next/navigation"; import { type ReactNode, useEffect, useMemo, useRef, useState } from "react"; -import { Copy, Pencil, Plus, RotateCcw, Trash2 } from "lucide-react"; +import { Ban, Copy, Pencil, Plus, RotateCcw, Trash2 } from "lucide-react"; import Button from "@/components/ui/Button"; import { CopyProductDialog, @@ -62,8 +62,11 @@ import { getDocumentWorkspaceCountByCategory } from "@/app/intake/product-develo import { ProductDevelopmentCategoryFilterField } from "@/app/intake/product-development/ProductDevelopmentCategoryFilterField"; import { displayPerson, + getCurrentUserResponsibleOwnerValues, getNonIntegratedListPeople, + isAdminUser, isCurrentUserResponsibleForNonIntegratedProduct, + matchesCurrentUserName, productMatchesText, type NonIntegratedListPermissionUser, } from "@/app/intake/product-development/nonIntegratedProductListLogic"; @@ -113,9 +116,23 @@ function createRestoredNonIntegratedProduct( }; } +function createAbandonedNonIntegratedProduct( + product: NonIntegratedProductRecord, +): NonIntegratedProductRecord { + return { + ...product, + projectStatus: "rejected", + openingReference: { + ...product.openingReference, + currentStage: "废弃不开", + }, + updatedAt: new Date().toISOString(), + }; +} + const PENDING_PAGE_SIZE = 50; const TABLE_ACTION_BUTTON_BASE = - "!h-8 !min-h-8 !w-8 !rounded-apple-md !px-0 !py-0 !shadow-none max-md:!h-7 max-md:!min-h-7 max-md:!w-7 max-md:!min-w-7"; + "!h-7 !min-h-7 !w-7 !min-w-7 !rounded-apple-md !px-0 !py-0 !shadow-none max-md:!h-6 max-md:!min-h-6 max-md:!w-6 max-md:!min-w-6"; const TABLE_ACTION_BUTTON_SECONDARY = `${TABLE_ACTION_BUTTON_BASE} !border-zinc-200 !bg-white !text-zinc-500 hover:!border-zinc-300 hover:!bg-zinc-50 hover:!text-zinc-950 focus:!border-zinc-400 disabled:!border-zinc-100 disabled:!bg-zinc-50 disabled:!text-zinc-300`; const TABLE_ACTION_BUTTON_PRIMARY = `${TABLE_ACTION_BUTTON_BASE} !border-zinc-950 !bg-zinc-950 !text-white hover:!border-zinc-800 hover:!bg-zinc-800 focus:!border-zinc-600 disabled:!border-zinc-200 disabled:!bg-zinc-200 disabled:!text-zinc-400`; const INTAKE_PRIMARY_BUTTON_CLASS = @@ -622,6 +639,50 @@ export function NonIntegratedPendingDetail({ } } + async function handleAbandon(product: NonIntegratedProductRecord) { + const productLabel = product.spu?.trim() || "当前产品"; + + if ( + !window.confirm( + `确认废弃「${productLabel}」吗?\n废弃后资料将变为只读,不能继续编辑,且不再触发每日推送提醒。`, + ) + ) { + return; + } + + try { + if (shouldUseSharedNonIntegratedApi) { + const response = await fetch( + `/api/intake/non-integrated/${encodeURIComponent(product.id)}/abandon`, + { method: "POST", credentials: "same-origin" }, + ); + const payload = (await response.json().catch(() => null)) as { + success?: boolean; + error?: { message?: string }; + } | null; + if (!response.ok || !payload?.success) { + throw new Error(payload?.error?.message || "废弃失败,请稍后再试"); + } + } else { + saveNonIntegratedProduct( + createAbandonedNonIntegratedProduct(product), + ); + } + + const nextProducts = products.map((currentProduct) => + currentProduct.id === product.id + ? { ...currentProduct, projectStatus: "rejected" } + : currentProduct, + ) as NonIntegratedProductRecord[]; + setProducts(nextProducts); + onProductsChange?.(nextProducts); + } catch (error) { + window.alert( + error instanceof Error ? error.message : "废弃失败,请稍后再试", + ); + } + } + function getAvailableCopyBrands(product: NonIntegratedProductRecord) { const configuredBrands = Array.from( new Set([ @@ -1439,18 +1500,18 @@ export function NonIntegratedPendingDetail({ > - + 序号 - + 成品预览图 {isSeriesDevelopmentList ? ( - + 系列名称 ) : null} - + {showOpeningProductName ? ( @@ -1525,6 +1586,15 @@ export function NonIntegratedPendingDetail({ getDocumentWorkspaceCountByCategory(product); const isFlowAbandoned = product.projectStatus === "rejected"; + const canAbandonCurrentRow = ( + row: NonIntegratedProductRecord, + ) => + row.projectStatus !== "rejected" && + (isAdminUser(currentUser) || + isCurrentUserResponsibleForNonIntegratedProduct( + row, + currentUser, + )); const people = getNonIntegratedListPeople(product); const canEditProduct = canEditNonIntegratedProduct( product, @@ -1553,12 +1623,12 @@ export function NonIntegratedPendingDetail({ key={product.id} className="border-b border-apple-separator" > - + {pageInfo?.sequenceById?.[product.id] ?? orderedFilteredProducts.sequenceById[product.id] ?? (safeCurrentPage - 1) * PENDING_PAGE_SIZE + index + 1} - + {productPreviewImage ? ( {isSeriesDevelopmentList ? ( - + {seriesDisplayName} ) : null} - + ) : null} + {!isFlowAbandoned && + canEditProduct && + canAbandonCurrentRow(product) ? ( + + ) : null} {isFlowAbandoned && canEditProduct ? (