From c5cefd66db261adf4e25a6e6926827a741b9fd9e Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 21 Oct 2026 09:06:56 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8A=A5=E4=BB=B7=E5=8D=95):=20=E5=8D=A1?= =?UTF-8?q?=E7=89=87=E8=A7=86=E5=9B=BE=E5=86=85=E8=81=94=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=95=86=E5=93=81=EF=BC=88=E5=A4=8D=E7=94=A8=20append-items=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=EF=BC=8C=E5=90=AB=E6=88=90=E6=9C=AC=E4=BB=B7?= =?UTF-8?q?/=E9=94=80=E5=94=AE=E4=BB=B7/=E5=8D=95=E4=BD=8D=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=EF=BC=89=EF=BC=8C=E5=88=A4=E9=87=8D=E5=8F=A3=E5=BE=84?= =?UTF-8?q?=E4=BB=8D=E4=B8=BA=E5=90=8C=20SKU?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../customers/QuoteVersionManagement.tsx | 978 +++++++++++------- 1 file changed, 624 insertions(+), 354 deletions(-) diff --git a/src/pages/customers/QuoteVersionManagement.tsx b/src/pages/customers/QuoteVersionManagement.tsx index 22d8365..11eb6e0 100644 --- a/src/pages/customers/QuoteVersionManagement.tsx +++ b/src/pages/customers/QuoteVersionManagement.tsx @@ -4,6 +4,7 @@ import { motion, AnimatePresence } from 'framer-motion'; import { useNavigate, useSearchParams } from 'react-router-dom'; import { supabase } from '../../supabase/client'; import { notify } from '../../utils/notify'; +import { confirmDialog } from '../../utils/confirmDialog'; import { useAuth } from '../../hooks/useAuth'; import { useOperatingBranch } from '../../hooks/useOperatingBranch'; import { useListLoadState, type ListLoadOptions } from '../../hooks/useListLoadState'; @@ -21,6 +22,7 @@ import { syncSkuDictionaryApi, getSheetMappingStatsApi, deleteQuoteSheetApi, + appendQuoteSheetItemsApi, } from '../../utils/workflowApi'; import { DocumentExportButton } from '../../components/export/DocumentExportButton'; import { BulkImportModal } from '../../components/BulkImportModal'; @@ -39,7 +41,6 @@ import { import { buildQuoteExportRows } from '../../utils/exportDataBuilders'; import { useCategoryRows } from '../../hooks/useCategoryRows'; import { buildCategoryLabelMap, getCategoryDisplayLabelFromMap } from '../../utils/categories'; -import { formatTaxRateLabel } from '../../utils/branchTaxLevel'; import { type TableColumnDef } from '../../hooks/useTableColumnOrder'; import { useReorderableTableColumns } from '../../hooks/useReorderableTableColumns'; import { useClientTableSort } from '../../hooks/useClientTableSort'; @@ -53,6 +54,7 @@ import { PageFilterToolbar } from '../../components/ui/PagePrimitives'; import { useT } from '../../i18n'; import { markupRatioFromQuoteSaleRatio, + quoteSaleRatio, quoteSaleRatioTextFromMarkup, salePriceFromQuoteRatio, } from '../../utils/quotePriceRatio'; @@ -110,44 +112,6 @@ function buildQuoteSheetColumns( return cols; } -type QuoteSheetItemColumnId = - | 'seq' - | 'sku_name' - | 'category' - | 'tax_code' - | 'tax_rate' - | 'brand' - | 'loss_threshold' - | 'status' - | 'cost_price' - | 'sale_price' - | 'markup_ratio' - | 'unit'; - -const QUOTE_SHEET_ITEM_COLUMNS: Array> = [ - { id: 'seq', label: 'itemCol.seq', fixedStart: true }, - { id: 'sku_name', label: 'itemCol.skuName' }, - { id: 'category', label: 'itemCol.category' }, - { id: 'tax_code', label: 'itemCol.taxCode' }, - { id: 'tax_rate', label: 'itemCol.taxRate' }, - { id: 'brand', label: 'itemCol.brand' }, - { id: 'loss_threshold', label: 'itemCol.lossThreshold' }, - { id: 'status', label: 'itemCol.status' }, - { id: 'cost_price', label: 'itemCol.costPrice' }, - { id: 'sale_price', label: 'itemCol.salePrice' }, - { id: 'markup_ratio', label: 'itemCol.markupRatio' }, - { id: 'unit', label: 'itemCol.unit' }, -]; - -const QUOTE_SHEET_ITEM_COLUMN_ORDER_KEY = 'table_column_order:quote-sheet-items:v1'; - -function quoteSheetItemHeaderClass(id: QuoteSheetItemColumnId) { - const base = 'px-3 py-2.5 text-left text-xs font-semibold text-slate-500'; - if (id === 'cost_price' || id === 'sale_price' || id === 'markup_ratio') return `${base} text-right`; - if (id === 'seq') return `${base} w-12`; - return base; -} - interface SkuOption extends SkuNameOption { cost_price?: number; category_code?: string; @@ -330,6 +294,177 @@ const QuoteLineEditorRow = React.memo(({ )); +const moneyText = (value: unknown) => (Number(value) || 0).toFixed(2); + +interface QuoteItemCardProps { + item: QuoteExpandedItem; + index: number; + editable: boolean; + saving: boolean; + duplicate: boolean; + duplicateLabel: string; + labels: { + cost: string; + sale: string; + ratio: string; + spec: string; + unit: string; + enabled: string; + disabled: string; + delete: string; + emDash: string; + }; + onSavePrice: (item: QuoteExpandedItem, index: number, costPrice: number, salePrice: number) => void; + onDelete: (item: QuoteExpandedItem, index: number) => void; +} + +/** + * 报价明细卡片(2026-10-20 卡片化)。 + * 本地 draft,失焦/Enter 才提交;父级保存中/只读时禁用;保存失败由父级重读服务端值,effect 自动回滚。 + */ +const QuoteItemCard = React.memo(({ + item, + index, + editable, + saving, + duplicate, + duplicateLabel, + labels, + onSavePrice, + onDelete, +}) => { + const [costDraft, setCostDraft] = React.useState(moneyText(item.cost_price)); + const [saleDraft, setSaleDraft] = React.useState(moneyText(item.sale_price)); + const wasSavingRef = React.useRef(saving); + React.useEffect(() => { + setCostDraft(moneyText(item.cost_price)); + setSaleDraft(moneyText(item.sale_price)); + }, [item.sku_code, item.cost_price, item.sale_price]); + React.useEffect(() => { + // 保存结束(无论成功/失败)都以服务端最新值收口:失败时 item 没变 ⇒ 恢复原值, + // 不能把未落库的草稿继续显示成“已保存”。 + if (wasSavingRef.current && !saving) { + setCostDraft(moneyText(item.cost_price)); + setSaleDraft(moneyText(item.sale_price)); + } + wasSavingRef.current = saving; + }, [saving, item.cost_price, item.sale_price]); + + const cost = parseDecimalText(costDraft, NaN); + const sale = parseDecimalText(saleDraft, NaN); + const ratio = quoteSaleRatio(cost, sale); + const dirty = + Number.isFinite(cost) && Number.isFinite(sale) + ? Math.abs(cost - Number(item.cost_price || 0)) > 1e-9 || + Math.abs(sale - Number(item.sale_price || 0)) > 1e-9 + : false; + + const commit = () => { + if (!editable || saving || !Number.isFinite(cost) || !Number.isFinite(sale)) { + // 非法/空值不落库,恢复服务端值,避免卡片停在空态 + setCostDraft(moneyText(item.cost_price)); + setSaleDraft(moneyText(item.sale_price)); + return; + } + if (!dirty) return; + onSavePrice(item, index, Math.max(0, cost), Math.max(0, sale)); + }; + + return ( +
+
+
+

{item.sku_name}

+ {item.category_name || labels.emDash} + + {item.status === 1 ? labels.enabled : labels.disabled} + +
+ {editable ? ( + + ) : null} +
+ +
+ {labels.spec}: {item.spec || labels.emDash} + {labels.unit}: {item.unit || labels.emDash} +
+ +
+
+ + +
+
+ {labels.ratio} +
+ {ratio == null ? labels.emDash : ratio.toFixed(2).replace(/\.?0+$/, '')} +
+ % +
+
+ + {duplicate ?

{duplicateLabel}

: null} +
+ ); +}); + function parsePrice(raw: string): number { return parseDecimalText(raw, NaN); } @@ -397,8 +532,17 @@ export const QuoteVersionManagement: React.FC = () => { const [customerFilter, setCustomerFilter] = useState(''); const [expandedCode, setExpandedCode] = useState(null); const [expandedDetail, setExpandedDetail] = useState(null); + const [detailLoading, setDetailLoading] = useState(false); const [detailProductFilter, setDetailProductFilter] = useState(''); const [detailCategoryFilter, setDetailCategoryFilter] = useState(''); + /** 控制区名称/周期/生效日的本地草稿(服务端重读后回填) */ + const [detailDraft, setDetailDraft] = useState({ title: '', quote_cycle: 'month', effective_at: '' }); + /** 正在保存的价格卡片 key(保存中禁用所有价格输入,防连点) */ + const [priceSavingKey, setPriceSavingKey] = useState(null); + const detailLoadSeq = useRef(0); + const headerSaveSeq = useRef(0); + const priceSaveSeq = useRef(0); + const expandedCodeRef = useRef(null); const [showFormModal, setShowFormModal] = useState(false); const [editingCode, setEditingCode] = useState(null); @@ -409,6 +553,10 @@ export const QuoteVersionManagement: React.FC = () => { const [selectedCustomers, setSelectedCustomers] = useState([]); const [form, setForm] = useState(initialForm); const [lines, setLines] = useState([emptyLine()]); + /** 卡片视图内联"新增商品"(2026-10-20 开发者:修改弹窗已整合进卡片视图,需就地新增) */ + const [inlineAddOpen, setInlineAddOpen] = useState(false); + const [inlineSaving, setInlineSaving] = useState(false); + const [inlineDraft, setInlineDraft] = useState({ sku_code: '', unit: '', cost_price: '', sale_price: '', markup_ratio: '' }); /** * 重复商品集合(2026-10-20 开发者需求:重复商品标红提示)。 * 判定按 `sku_code`;出现 ≥2 次即标红 —— 提交时后端会按 SKU 去重只保留最后一行, @@ -454,15 +602,8 @@ export const QuoteVersionManagement: React.FC = () => { columnCount: sheetColumnCount, getHeaderProps: getSheetHeaderProps, } = useReorderableTableColumns(QUOTE_SHEET_COLUMN_ORDER_KEY, quoteSheetColumns); - const { - orderedColumns: sheetItemOrderedColumns, - columnCount: sheetItemColumnCount, - getHeaderProps: getSheetItemHeaderProps, - } = useReorderableTableColumns(QUOTE_SHEET_ITEM_COLUMN_ORDER_KEY, QUOTE_SHEET_ITEM_COLUMNS); type SheetSortKey = 'item_count'; - type SheetItemSortKey = 'tax_rate' | 'loss_threshold' | 'cost_price' | 'sale_price'; const sheetSort = useClientTableSort(); - const sheetItemSort = useClientTableSort(); const enrichQuoteItems = async ( items: QuoteSheetRow['items'] | undefined @@ -505,6 +646,222 @@ export const QuoteVersionManagement: React.FC = () => { }); }; + const buildSheetItemsPayload = ( + items: QuoteExpandedItem[], + override?: { index: number; costPrice: number; salePrice: number } + ) => + items.map((it, idx) => { + const cost = override && override.index === idx ? override.costPrice : Number(it.cost_price) || 0; + const sale = override && override.index === idx ? override.salePrice : Number(it.sale_price) || 0; + const saleRatio = quoteSaleRatio(cost, sale); + return { + sku_code: it.sku_code, + sku_name: it.sku_name, + unit: it.unit, + cost_price: Math.max(0, cost), + sale_price: Math.max(0, sale), + price: Math.max(0, sale), + markup_ratio: + override && override.index === idx + ? saleRatio == null + ? null + : markupRatioFromQuoteSaleRatio(saleRatio) + : it.markup_ratio ?? null, + }; + }); + + const loadExpandedDetail = async (code: string, options?: { silent?: boolean }) => { + // 切换展开单时让旧单的在途保存失效,避免旧响应把新单详情覆盖回去。 + if (expandedCodeRef.current !== code) { + expandedCodeRef.current = code; + headerSaveSeq.current++; + priceSaveSeq.current++; + setPriceSavingKey(null); + } + const seq = ++detailLoadSeq.current; + if (!options?.silent) setDetailLoading(true); + try { + const { data } = await getQuoteSheetApi(code); + const detail = data as QuoteSheetRow; + const enrichedItems = await enrichQuoteItems(detail.items); + if (seq !== detailLoadSeq.current) return; + setExpandedDetail({ ...detail, enrichedItems }); + setDetailDraft({ + title: detail.title || '', + quote_cycle: detail.quote_cycle || 'month', + effective_at: detail.effective_at ? new Date(detail.effective_at).toISOString().slice(0, 10) : '', + }); + } catch (error: any) { + if (seq !== detailLoadSeq.current) return; + notify.error(error?.message || t('quotes.toast.loadSheetsFail')); + } finally { + if (seq === detailLoadSeq.current) setDetailLoading(false); + } + }; + + const expandedEditable = + !!expandedDetail && canManageQuotes && isActiveSheet(expandedDetail); + + const saveHeaderField = async (field: 'title' | 'quote_cycle' | 'effective_at', value: string) => { + if (!expandedCode || !expandedDetail || !expandedEditable) return; + const normalized = field === 'title' ? value.trim() : value; + const current = + field === 'title' + ? String(expandedDetail.title || '').trim() + : field === 'quote_cycle' + ? String(expandedDetail.quote_cycle || 'month') + : expandedDetail.effective_at + ? new Date(expandedDetail.effective_at).toISOString().slice(0, 10) + : ''; + if (normalized === current) return; + if (field === 'effective_at' && !normalized) { + setDetailDraft((draft) => ({ ...draft, effective_at: current })); + return; + } + const scope = expandedCode; + const loadSeqAtStart = detailLoadSeq.current; + const seq = ++headerSaveSeq.current; + try { + // AC-11:自动保存只传单个字段,绝不带 items(否则会触发配送商价格确认) + await updateQuoteSheetApi(scope, { [field]: normalized } as Record); + if ( + seq !== headerSaveSeq.current || + expandedCodeRef.current !== scope || + loadSeqAtStart !== detailLoadSeq.current + ) { + return; + } + await loadSheets({ silent: true }); + if (expandedCodeRef.current !== scope || loadSeqAtStart !== detailLoadSeq.current) return; + await loadExpandedDetail(scope, { silent: true }); + if (seq === headerSaveSeq.current) notify.success(t('quotes.detail.headerSaved')); + } catch (error: any) { + if ( + seq !== headerSaveSeq.current || + expandedCodeRef.current !== scope || + loadSeqAtStart !== detailLoadSeq.current + ) { + return; + } + setDetailDraft((draft) => ({ + ...draft, + [field]: + field === 'title' + ? String(expandedDetail.title || '') + : field === 'quote_cycle' + ? String(expandedDetail.quote_cycle || 'month') + : current, + })); + notify.error(error?.message || t('quotes.toast.updateFail')); + } + }; + + const saveItemPrice = async ( + item: QuoteExpandedItem, + index: number, + costPrice: number, + salePrice: number + ) => { + if (!expandedCode || !expandedDetail || !expandedEditable) return; + const seq = ++priceSaveSeq.current; + const key = `${item.sku_code}-${index}`; + setPriceSavingKey(key); + try { + // AC-15:后端整表删后重插 ⇒ 必须提交当前明细全集 + const items = buildSheetItemsPayload(expandedDetail.enrichedItems || [], { + index, + costPrice, + salePrice, + }); + const response = await updateQuoteSheetApi(expandedCode, { items }); + if (seq !== priceSaveSeq.current) return; + if (response.delivery_handoff && response.delivery_handoff.ok === false) { + notify.error(response.delivery_handoff.message || t('quotes.toast.updateFail')); + } else { + notify.success(t('quotes.toast.updated')); + } + await loadSheets({ silent: true }); + await loadExpandedDetail(expandedCode, { silent: true }); + } catch (error: any) { + if (seq !== priceSaveSeq.current) return; + notify.error(error?.message || t('quotes.toast.updateFail')); + // 失败重读服务端值,卡片 effect 会把本地草稿恢复 + await loadExpandedDetail(expandedCode, { silent: true }); + } finally { + if (seq === priceSaveSeq.current) setPriceSavingKey(null); + } + }; + + const deleteExpandedItem = async (item: QuoteExpandedItem, index: number) => { + if (!expandedCode || !expandedDetail || !expandedEditable) return; + if ((expandedDetail.enrichedItems || []).length <= 1) { + notify(t('quotes.toast.needValidLine')); + return; + } + const ok = await confirmDialog({ + message: t('quotes.detail.deleteItemConfirm', { name: item.sku_name }), + danger: true, + }); + if (!ok) return; + const seq = ++priceSaveSeq.current; + setPriceSavingKey('delete'); + try { + const items = buildSheetItemsPayload( + (expandedDetail.enrichedItems || []).filter((_, idx) => idx !== index) + ); + await updateQuoteSheetApi(expandedCode, { items }); + if (seq !== priceSaveSeq.current) return; + notify.success(t('quotes.toast.updated')); + await loadSheets({ silent: true }); + await loadExpandedDetail(expandedCode, { silent: true }); + } catch (error: any) { + if (seq !== priceSaveSeq.current) return; + notify.error(error?.message || t('quotes.toast.updateFail')); + await loadExpandedDetail(expandedCode, { silent: true }); + } finally { + if (seq === priceSaveSeq.current) setPriceSavingKey(null); + } + }; + + const currentCustomer = expandedDetail?.customers?.[0] || null; + const currentCustomerCode = currentCustomer?.customer_code || ''; + + const switchExpandedCustomer = async (nextCustomerCode: string) => { + if (!expandedCode || !expandedDetail || !expandedEditable) return; + if (!nextCustomerCode || nextCustomerCode === currentCustomerCode) return; + const target = customers.find((c) => c.customer_code === nextCustomerCode); + const ok = await confirmDialog({ + message: t('quotes.detail.switchCustomerConfirm', { + customer: target?.company_name || nextCustomerCode, + }), + danger: false, + }); + if (!ok) return; + const scope = expandedCode; + const loadSeqAtStart = detailLoadSeq.current; + try { + const currentCodes = (expandedDetail.customers || []).map((c) => c.customer_code); + // 编辑阶段追加客户:后端只给新客户复制一张,本单客户不变;绝不带 items/title/周期/生效日 + const response = (await updateQuoteSheetApi(scope, { + customer_codes: [...currentCodes, nextCustomerCode], + })) as { sheets?: Array<{ quote_sheet_code?: string }> }; + if (expandedCodeRef.current !== scope || loadSeqAtStart !== detailLoadSeq.current) return; + const nextCode = String(response.sheets?.[0]?.quote_sheet_code || ''); + notify.success(t('quotes.toast.created')); + // 新单可能在「执行中」列表,清客户筛选并确保当前页签能看到 + setCustomerFilter(''); + setViewFilter('active'); + await loadSheets(); + if (nextCode) { + setExpandedCode(nextCode); + await loadExpandedDetail(nextCode); + } + } catch (error: any) { + // 目标客户已有报价单时后端 400 customer_already_quoted,这里只提示,不新建 + notify.error(error?.message || t('quotes.toast.createFail')); + } + }; + useEffect(() => { Promise.all([ supabase.from('customers').select('customer_code, company_name').in('status', [10, 20]).order('company_name'), @@ -615,64 +972,6 @@ export const QuoteVersionManagement: React.FC = () => { resetCreateForm(); }; - const openEditModal = async ( - row: QuoteSheetRow, - options?: { focusSkuCode?: string } - ) => { - if (!isActiveSheet(row)) { - notify(t('quotes.toast.editOnlyActive')); - return; - } - if (!canManageQuotes) { - notify(t('quotes.toast.noEditPermission')); - return; - } - setSaving(true); - try { - const { data } = await getQuoteSheetApi(row.quote_sheet_code); - const detail = data as QuoteSheetRow; - const customerCodes = (detail.customers || []).map((c) => c.customer_code); - setForm({ - title: detail.title || '', - customer_codes: customerCodes, - quote_cycle: detail.quote_cycle || 'month', - effective_at: detail.effective_at - ? new Date(detail.effective_at).toISOString().slice(0, 10) - : new Date().toISOString().slice(0, 10), - }); - setSelectedCustomers(customers.filter((c) => customerCodes.includes(c.customer_code))); - const mappedLines = - (detail.items || []).length - ? (detail.items || []).map((item, idx) => ({ - key: `${row.quote_sheet_code}-${item.sku_code}-${idx}`, - sku_code: item.sku_code, - sku_name: item.sku_name || '', - unit: item.unit || '', - cost_price: String(item.cost_price ?? 0), - sale_price: String(item.sale_price ?? item.price), - markup_ratio: - item.markup_ratio == null ? '' : quoteSaleRatioTextFromMarkup(item.markup_ratio), - })) - : [emptyLine()]; - const focusCode = options?.focusSkuCode?.trim() || ''; - const orderedLines = - focusCode && mappedLines.length > 1 - ? [ - ...mappedLines.filter((line) => line.sku_code === focusCode), - ...mappedLines.filter((line) => line.sku_code !== focusCode), - ] - : mappedLines; - setLines(orderedLines.length ? orderedLines : [emptyLine()]); - setFocusSkuCode(focusCode || null); - setEditingCode(row.quote_sheet_code); - setShowFormModal(true); - } catch (error: any) { - notify(error?.message || t('quotes.toast.loadSheetsFail')); - } finally { - setSaving(false); - } - }; - const handleDelete = async () => { if (!deleteTarget) return; setDeleting(true); @@ -1049,19 +1348,17 @@ export const QuoteVersionManagement: React.FC = () => { setExpandedDetail(null); setDetailProductFilter(''); setDetailCategoryFilter(''); + expandedCodeRef.current = null; + headerSaveSeq.current++; + priceSaveSeq.current++; + setPriceSavingKey(null); return; } setExpandedCode(code); + setExpandedDetail(null); setDetailProductFilter(''); setDetailCategoryFilter(''); - try { - const { data } = await getQuoteSheetApi(code); - const detail = data as QuoteSheetRow; - const enrichedItems = await enrichQuoteItems(detail.items); - setExpandedDetail({ ...detail, enrichedItems }); - } catch { - setExpandedDetail(null); - } + await loadExpandedDetail(code); }; const filteredExpandedItems = useMemo(() => { @@ -1096,27 +1393,23 @@ export const QuoteVersionManagement: React.FC = () => { }); }, [expandedDetail?.enrichedItems, detailProductFilter, detailCategoryFilter]); + /** 展开明细内重复 SKU(按 sku_code 计;重复行都标红) */ + const expandedDuplicateSkuSet = useMemo(() => { + const seen = new Set(); + const dup = new Set(); + for (const item of expandedDetail?.enrichedItems || []) { + const code = String(item.sku_code || '').trim(); + if (!code) continue; + if (seen.has(code)) dup.add(code); + else seen.add(code); + } + return dup; + }, [expandedDetail?.enrichedItems]); + const sortedSheets = sheetSort.sortRows(sheets, (row) => row.item_count); const sheetPage = useClientTablePagination(sortedSheets, { resetKey: `${viewFilter}|${customerFilter}|${sheetSort.sortKey}|${sheetSort.sortDir}`, }); - const sortedExpandedItems = sheetItemSort.sortRows(filteredExpandedItems, (item, key) => { - if (key === 'tax_rate') return item.tax_rate; - if (key === 'loss_threshold') return item.default_loss_threshold; - if (key === 'cost_price') return item.cost_price; - return item.sale_price; - }); - - const handleProductRowDoubleClick = (skuCode: string) => { - if (!expandedCode) return; - const sheet = sheets.find((row) => row.quote_sheet_code === expandedCode); - if (!sheet) { - notify(t('quotes.toast.sheetNotFound')); - return; - } - void openEditModal(sheet, { focusSkuCode: skuCode }); - }; - const focusSaleDoneRef = useRef(false); useEffect(() => { @@ -1337,15 +1630,6 @@ export const QuoteVersionManagement: React.FC = () => { : t('quotes.action.enableAutoSalePrice')} )} - {isActiveSheet(row) && ( - - )} {isActiveSheet(row) && canManageQuotes && ( ) : null} -
+
{ className="app-input app-focus-ring w-full pl-8 pr-8 py-1.5 text-sm rounded-lg border border-slate-200 dark:border-slate-600" /> {detailCategoryFilter ? ( - ) : null}
+ + + +
-
- - - - {sheetItemOrderedColumns.map((col) => { - const sortable = - col.id === 'tax_rate' || - col.id === 'loss_threshold' || - col.id === 'cost_price' || - col.id === 'sale_price'; - return ( - - ); - })} - - - - {(expandedDetail.enrichedItems || []).length === 0 ? ( - - - - ) : filteredExpandedItems.length === 0 ? ( - - - - ) : ( - sortedExpandedItems.map((item, idx) => { - const canDblEdit = - canManageQuotes && - !!expandedDetail && - isActiveSheet(expandedDetail); - return ( - handleProductRowDoubleClick(item.sku_code) - : undefined - } - > - {sheetItemOrderedColumns.map((col) => { - switch (col.id) { - case 'seq': - return ( - - ); - case 'sku_name': - return ( - - ); - case 'category': - return ( - - ); - case 'tax_code': - return ( - - ); - case 'tax_rate': - return ( - - ); - case 'brand': - return ( - - ); - case 'loss_threshold': - return ( - - ); - case 'status': - return ( - - ); - case 'cost_price': - return ( - - ); - case 'sale_price': - return ( - - ); - case 'markup_ratio': - return ( - - ); - case 'unit': - return ( - - ); - default: - return null; - } - })} - - ); - }) - )} - -
- sheetItemSort.toggle(col.id as SheetItemSortKey) - : undefined - } - > - {sortable ? ( - - ) : ( - t(`quotes.${col.label}`) - )} -
- {t('quotes.detail.emptyItems')} -
- {t('quotes.detail.noMatch')} -
{idx + 1} -

{item.sku_name}

- {item.spec && item.spec !== t('quotes.emDash') ? ( -

{t('quotes.detail.specPrefix', { spec: item.spec })}

- ) : null} -
- {item.category_name || t('quotes.detail.uncategorized')} - - {item.tax_code || t('quotes.emDash')} - - {formatTaxRateLabel(item.tax_rate)} - - {item.brand || t('quotes.emDash')} - - {item.default_loss_threshold != null - ? `${item.default_loss_threshold}%` - : t('quotes.detail.lossDisabled')} - - - {item.status === 1 ? t('quotes.detail.skuEnabled') : t('quotes.detail.skuDisabled')} - - - ¥{Number(item.cost_price || 0).toFixed(2)} - - ¥{Number(item.sale_price || 0).toFixed(2)} - - {item.markup_ratio == null - ? t('quotes.emDash') - : `${quoteSaleRatioTextFromMarkup(item.markup_ratio)}%`} - - {item.unit || t('quotes.emDash')} -
-
- -
-

{t('quotes.detail.customersTitle')}

- {(expandedDetail.customers || []).length === 0 ? ( -

{t('quotes.detail.noCustomers')}

- ) : ( -
- {(expandedDetail.customers || []).map((c) => ( - + +
+ ) : null} + {inlineAddOpen && expandedEditable ? ( +
+
+ + + + +
+
+ + +
+
+ ) : null} + {(expandedDetail.enrichedItems || []).length === 0 ? ( +
+ {t('quotes.detail.emptyItems')} +
+ ) : filteredExpandedItems.length === 0 ? ( +
+ {t('quotes.detail.noMatch')} +
+ ) : ( +
+ {filteredExpandedItems.map((item) => { + const originalIndex = (expandedDetail.enrichedItems || []).findIndex((rowItem) => rowItem === item); + const cardIndex = originalIndex >= 0 ? originalIndex : 0; + return ( + void saveItemPrice(rowItem, index, costPrice, salePrice)} + onDelete={(rowItem, index) => void deleteExpandedItem(rowItem, index)} + /> + ); + })}
)}
- + )} )}