From 52e982ba4244968fd4481b9d89a210b7d1cdd9c1 Mon Sep 17 00:00:00 2001 From: tikkhun Date: Mon, 1 Dec 2025 10:59:35 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=BB=9F=E4=B8=80=E5=B0=86=20produ?= =?UTF-8?q?ctSku=20=E5=AD=97=E6=AE=B5=E9=87=8D=E5=91=BD=E5=90=8D=E4=B8=BA?= =?UTF-8?q?=20sku?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 简化产品 SKU 字段命名,将 productSku 统一改为 sku,保持代码一致性 --- src/pages/Product/List/index.tsx | 225 +++++++++--------- .../Statistics/InventoryForecast/index.tsx | 12 +- src/pages/Statistics/Restocking/index.tsx | 10 +- src/pages/Stock/List/index.tsx | 4 +- src/pages/Stock/PurchaseOrder/index.tsx | 14 +- src/pages/Stock/Record/index.tsx | 2 +- src/pages/Stock/Transfer/index.tsx | 22 +- src/servers/api/typings.d.ts | 18 +- 8 files changed, 153 insertions(+), 154 deletions(-) diff --git a/src/pages/Product/List/index.tsx b/src/pages/Product/List/index.tsx index 87b9d04..4137825 100644 --- a/src/pages/Product/List/index.tsx +++ b/src/pages/Product/List/index.tsx @@ -1,5 +1,4 @@ import { - productcontrollerAutobindcomponents, productcontrollerCreateproduct, productcontrollerDeleteproduct, productcontrollerGetproductcomponents, @@ -32,12 +31,7 @@ import AttributeFormItem from '@/pages/Product/Attribute/components/AttributeFor import React, { useMemo, useRef, useState } from 'react'; const capitalize = (s: string) => s.charAt(0).toLocaleUpperCase() + s.slice(1); -// TODO -interface DictItem { - id: number; - name: string; - title: string; -} + const NameCn: React.FC<{ id: number; value: string | undefined; @@ -97,7 +91,7 @@ const ComponentsCell: React.FC<{ productId: number }> = ({ productId }) => { {components && components.length ? ( components.map((component: any) => ( - {component.productSku || `#${component.id}`} × {component.quantity} + {component.sku || `#${component.id}`} × {component.quantity} (库存: {component.stock ?.map((s: any) => `${s.name}:${s.quantity}`) @@ -160,6 +154,27 @@ const List: React.FC = () => { ); }, }, + { + title: '产品类型', + dataIndex: 'type', + valueType: 'select', + valueEnum: { + single: { text: '单品' }, + bundle: { text: '套装' }, + }, + render: (_, record) => { + // 如果类型不存在,则返回- + if (!record.type) return '-'; + // 判断是否为单品 + const isSingle = record.type === 'single'; + // 根据类型显示不同颜色的标签 + return ( + + {isSingle ? '单品' : '套装'} + + ); + }, + }, { title: '价格', dataIndex: 'price', @@ -429,24 +444,24 @@ const CreateForm: React.FC<{ if (sku) { // 获取库存信息 const { data } = await stockcontrollerGetstocks({ - productSku: sku, + sku: sku, } as any); // 如果库存信息存在且不为空 if (data && data.items && data.items.length > 0) { // 设置在库状态 setStockStatus('in-stock'); // 设置产品类型为单品 - formRef.current?.setFieldsValue({ productType: 'single' }); + formRef.current?.setFieldsValue({ type: 'single' }); } else { // 设置未在库状态 setStockStatus('out-of-stock'); // 设置产品类型为套装 - formRef.current?.setFieldsValue({ productType: 'bundle' }); + formRef.current?.setFieldsValue({ type: 'bundle' }); } } else { // 如果 sku 不存在,则重置状态 setStockStatus(null); - formRef.current?.setFieldsValue({ productType: null }); + formRef.current?.setFieldsValue({ type: null }); } } }} @@ -485,8 +500,8 @@ const CreateForm: React.FC<{ price: (values as any).price, promotionPrice: (values as any).promotionPrice, attributes, - components: - values.productType === 'bundle' ? values.components : undefined, + type: values.type, // 直接使用 type + components: values.components, }; const { success, message: errMsg } = await productcontrollerCreateproduct(payload); @@ -507,9 +522,6 @@ const CreateForm: React.FC<{ placeholder="请输入SKU" rules={[{ required: true, message: '请输入SKU' }]} /> - {stockStatus && ( - prevValues.productType !== curValues.productType + prevValues.type !== curValues.type } noStyle > {({ getFieldValue }: { getFieldValue: (name: string) => any }) => - getFieldValue('productType') === 'bundle' ? ( + getFieldValue('type') === 'bundle' ? ( (); const [components, setComponents] = useState< - { productSku: string; quantity: number }[] + { sku: string; quantity: number }[] >([]); - const [productType, setProductType] = useState<'single' | 'bundle' | null>( - null, - ); + const [type, setType] = useState<'single' | 'bundle' | null>(null); + const [stockStatus, setStockStatus] = useState< + 'in-stock' | 'out-of-stock' | null + >(null); React.useEffect(() => { (async () => { const { data: stockData } = await stockcontrollerGetstocks({ - productSku: record.sku, + sku: record.sku, } as any); if (stockData && stockData.items && stockData.items.length > 0) { - setProductType('single'); - formRef.current?.setFieldsValue({ productType: 'single' }); + // 如果有库存,则为单品 + setType('single'); + setStockStatus('in-stock'); + formRef.current?.setFieldsValue({ type: 'single' }); } else { - setProductType('bundle'); - formRef.current?.setFieldsValue({ productType: 'bundle' }); + // 如果没有库存,则为套装 + setType('bundle'); + setStockStatus('out-of-stock'); + formRef.current?.setFieldsValue({ type: 'bundle' }); } const { data: componentsData } = await productcontrollerGetproductcomponents({ id: record.id }); @@ -680,9 +697,9 @@ const EditForm: React.FC<{ return acc; }, {} as any), components: components, - productType: productType, + type: type, }; - }, [record, components, productType]); + }, [record, components, type]); return ( @@ -702,19 +719,19 @@ const EditForm: React.FC<{ if (sku) { // 获取库存信息 const { data } = await stockcontrollerGetstocks({ - productSku: sku, + sku: sku, } as any); // 如果库存信息存在且不为空 if (data && data.items && data.items.length > 0) { // 设置产品类型为单品 - formRef.current?.setFieldsValue({ productType: 'single' }); + formRef.current?.setFieldsValue({ type: 'single' }); } else { // 设置产品类型为套装 - formRef.current?.setFieldsValue({ productType: 'bundle' }); + formRef.current?.setFieldsValue({ type: 'bundle' }); } } else { // 如果 sku 不存在,则重置状态 - formRef.current?.setFieldsValue({ productType: null }); + formRef.current?.setFieldsValue({ type: null }); } } }} @@ -752,12 +769,13 @@ const EditForm: React.FC<{ price: (values as any).price, promotionPrice: (values as any).promotionPrice, attributes, + type: values.type, // 直接使用 type }; const { success, message: errMsg } = await productcontrollerUpdateproduct({ id: record.id }, payload); - if (values.productType === 'bundle') { + if (values.type === 'bundle') { const { success: success2, message: errMsg2 } = await productcontrollerSetproductcomponents( { id: record.id }, @@ -791,21 +809,14 @@ const EditForm: React.FC<{ placeholder="请输入SKU" rules={[{ required: true, message: '请输入SKU' }]} /> - - {() => { - const productType = formRef.current?.getFieldValue('productType'); - return ( - productType && ( - - {productType === 'single' ? '单品' : '套装'} - - ) - ); - }} - + {stockStatus && ( + + {stockStatus === 'in-stock' ? '在库' : '未在库'} + + )} + + prevValues.type !== curValues.type + } + noStyle + > + {({ getFieldValue }: { getFieldValue: (name: string) => any }) => + getFieldValue('type') === 'bundle' ? ( + ( +
+ {listDom} + {action} +
+ )} + > + + + + +
+ ) : null + } +
- - - - - prevValues.productType !== curValues.productType - } - noStyle - > - {({ getFieldValue }: { getFieldValue: (name: string) => any }) => - getFieldValue('productType') === 'bundle' ? ( - ( -
- {listDom} - {action} -
- )} - > - - - - -
- ) : null - } -
); }; diff --git a/src/pages/Statistics/InventoryForecast/index.tsx b/src/pages/Statistics/InventoryForecast/index.tsx index 401f5de..d40ec7f 100644 --- a/src/pages/Statistics/InventoryForecast/index.tsx +++ b/src/pages/Statistics/InventoryForecast/index.tsx @@ -29,7 +29,7 @@ const ListPage: React.FC = () => { }, { title: 'SKU', - dataIndex: 'productSku', + dataIndex: 'sku', hideInSearch: true, }, ...points @@ -88,13 +88,13 @@ const ListPage: React.FC = () => { render(_, record) { return ( { dataIndex: 'restockQuantityReal', hideInSearch: true, render(_, record) { - return ; + return ; }, }, { @@ -138,7 +138,7 @@ const ListPage: React.FC = () => { render(_, record) { if (!record.availableDays) return '-'; const availableDays = Number(record.availableDays); - const quantity = real?.[record.productSku] || 0; + const quantity = real?.[record.sku] || 0; const day = availableDays + Math.floor( @@ -154,7 +154,7 @@ const ListPage: React.FC = () => { render(_, record) { if (!record.availableDays) return '-'; const availableDays = Number(record.availableDays); - const quantity = real?.[record.productSku] || 0; + const quantity = real?.[record.sku] || 0; const day = availableDays + Math.floor( diff --git a/src/pages/Statistics/Restocking/index.tsx b/src/pages/Statistics/Restocking/index.tsx index 94d2e16..ed2f695 100644 --- a/src/pages/Statistics/Restocking/index.tsx +++ b/src/pages/Statistics/Restocking/index.tsx @@ -96,14 +96,14 @@ const ListPage: React.FC = () => { render(_, record) { return ( { hideInSearch: true, render(_, record) { const base = record.lastMonthSales; - return 3 * count * base + (savety[record.productSku] || 0); + return 3 * count * base + (savety[record.sku] || 0); }, }, { @@ -139,10 +139,10 @@ const ListPage: React.FC = () => { const base = record.lastMonthSales; return ( ); diff --git a/src/pages/Stock/List/index.tsx b/src/pages/Stock/List/index.tsx index 8d589bc..219805b 100644 --- a/src/pages/Stock/List/index.tsx +++ b/src/pages/Stock/List/index.tsx @@ -25,7 +25,7 @@ const ListPage: React.FC = () => { const columns: ProColumns[] = [ { title: 'SKU', - dataIndex: 'productSku', + dataIndex: 'sku', hideInSearch: true, sorter: true, }, @@ -130,7 +130,7 @@ const ListPage: React.FC = () => { ); return [ item.productName || '', - item.productSku || '', + item.sku || '', ...stockRow, ]; }); diff --git a/src/pages/Stock/PurchaseOrder/index.tsx b/src/pages/Stock/PurchaseOrder/index.tsx index 5a00cd1..addd481 100644 --- a/src/pages/Stock/PurchaseOrder/index.tsx +++ b/src/pages/Stock/PurchaseOrder/index.tsx @@ -285,7 +285,7 @@ const CreateForm: React.FC<{ return []; } }} - name="productSku" + name="sku" label={'产品' + (idx + 1)} width="lg" placeholder="请选择产品" @@ -347,9 +347,9 @@ const UpdateForm: React.FC<{ ...values, items: values?.items?.map((item: API.PurchaseOrderItem) => ({ ...item, - productSku: { + sku: { label: item.productName, - value: item.productSku, + value: item.sku, }, })), }; @@ -466,7 +466,7 @@ const UpdateForm: React.FC<{ return []; } }} - name="productSku" + name="sku" label="产品" width="lg" placeholder="请选择产品" @@ -530,9 +530,9 @@ const DetailForm: React.FC<{ ...values, items: values?.items?.map((item: API.PurchaseOrderItem) => ({ ...item, - productSku: { + sku: { label: item.productName, - value: item.productSku, + value: item.sku, }, })), }; @@ -631,7 +631,7 @@ const DetailForm: React.FC<{ return []; } }} - name="productSku" + name="sku" label="产品" width="lg" placeholder="请选择产品" diff --git a/src/pages/Stock/Record/index.tsx b/src/pages/Stock/Record/index.tsx index 5ece148..5f702da 100644 --- a/src/pages/Stock/Record/index.tsx +++ b/src/pages/Stock/Record/index.tsx @@ -23,7 +23,7 @@ const ListPage: React.FC = () => { }, { title: 'SKU', - dataIndex: 'productSku', + dataIndex: 'sku', hideInSearch: true, }, { diff --git a/src/pages/Stock/Transfer/index.tsx b/src/pages/Stock/Transfer/index.tsx index ee8b01b..3166e61 100644 --- a/src/pages/Stock/Transfer/index.tsx +++ b/src/pages/Stock/Transfer/index.tsx @@ -283,11 +283,11 @@ const CreateForm: React.FC<{ }); form.setFieldsValue({ items: data?.map( - (item: { productName: string; productSku: string }) => ({ + (item: { productName: string; sku: string }) => ({ ...item, - productSku: { + sku: { label: item.productName, - value: item.productSku, + value: item.sku, }, }), ), @@ -343,7 +343,7 @@ const CreateForm: React.FC<{ return []; } }} - name="productSku" + name="sku" label={'产品' + (idx + 1)} width="lg" placeholder="请选择产品" @@ -392,9 +392,9 @@ const UpdateForm: React.FC<{ ...values, items: values?.items?.map((item: API.PurchaseOrderItem) => ({ ...item, - productSku: { + sku: { label: item.productName, - value: item.productSku, + value: item.sku, }, })), }; @@ -519,7 +519,7 @@ const UpdateForm: React.FC<{ return []; } }} - name="productSku" + name="sku" label={'产品' + (idx + 1)} width="lg" placeholder="请选择产品" @@ -565,11 +565,11 @@ const DetailForm: React.FC<{ const initialValues = { ...values, items: values?.items?.map( - (item: { productName: string; productSku: string }) => ({ + (item: { productName: string; sku: string }) => ({ ...item, - productSku: { + sku: { label: item.productName, - value: item.productSku, + value: item.sku, }, }), ), @@ -676,7 +676,7 @@ const DetailForm: React.FC<{ return []; } }} - name="productSku" + name="sku" label="产品" width="lg" placeholder="请选择产品" diff --git a/src/servers/api/typings.d.ts b/src/servers/api/typings.d.ts index 0cdd0ac..ba3d620 100644 --- a/src/servers/api/typings.d.ts +++ b/src/servers/api/typings.d.ts @@ -898,7 +898,7 @@ declare namespace API { id?: number; productId?: number; /** 组件所关联的 SKU */ - productSku?: string; + sku?: string; /** 组成数量 */ quantity?: number; /** 创建时间 */ @@ -924,7 +924,7 @@ declare namespace API { type PurchaseOrderItem = { id?: number; - productSku?: string; + sku?: string; productName?: string; quantity?: number; price?: number; @@ -1076,7 +1076,7 @@ declare namespace API { productName?: string; /** 按库存点ID排序 */ sortPointId?: number; - /** 排序对象,格式如 { productName: "asc", productSku: "desc" } */ + /** 排序对象,格式如 { productName: "asc", sku: "desc" } */ order?: Record; }; @@ -1086,7 +1086,7 @@ declare namespace API { /** 每页大小 */ pageSize?: number; stockPointId?: number; - productSku?: string; + sku?: string; productName?: string; operationType?: string; startDate?: string; @@ -1328,7 +1328,7 @@ declare namespace API { /** 每页大小 */ pageSize?: number; stockPointId?: number; - productSku?: string; + sku?: string; productName?: string; operationType?: string; startDate?: string; @@ -1343,7 +1343,7 @@ declare namespace API { productName?: string; /** 按库存点ID排序 */ sortPointId?: number; - /** 排序对象,格式如 { productName: "asc", productSku: "desc" } */ + /** 排序对象,格式如 { productName: "asc", sku: "desc" } */ order?: Record; }; @@ -1378,7 +1378,7 @@ declare namespace API { type StockDTO = { id?: number; stockPointId?: number; - productSku?: string; + sku?: string; quantity?: number; /** 创建时间 */ createdAt: string; @@ -1461,7 +1461,7 @@ declare namespace API { type StockRecordDTO = { id?: number; stockPointId?: number; - productSku?: string; + sku?: string; operationType?: any; quantityChange?: number; operatorId?: number; @@ -1650,7 +1650,7 @@ declare namespace API { type UpdateStockDTO = { stockPointId?: number; - productSku?: string; + sku?: string; quantityChange?: number; operationType?: 'in' | 'out'; operatorId?: number;