feat(报价单卡片): 选不到商品时当场新建——接入录单同款 QuickCreateProductModal(复用 createCatalogProductForOrderLine),建成即回填并刷新商品列表
This commit is contained in:
@@ -11,6 +11,8 @@ import { useListLoadState, type ListLoadOptions } from '../../hooks/useListLoadS
|
||||
import { CustomerSelector, type CustomerOption } from '../../components/order/CustomerSelector';
|
||||
import { type SkuNameOption } from '../../components/order/SkuNameSelector';
|
||||
import { SearchableSelect, type SearchableSelectOption } from '../../components/ui/SearchableSelect';
|
||||
import { QuickCreateProductModal, type QuickCreateProductConfirm } from '../../components/order/QuickCreateProductModal';
|
||||
import { createCatalogProductForOrderLine } from '../../utils/productCatalog';
|
||||
import { DecimalTextInput, parseDecimalText } from '../../components/ui/DecimalInput';
|
||||
import {
|
||||
createQuoteSheetApi,
|
||||
@@ -557,6 +559,11 @@ export const QuoteVersionManagement: React.FC = () => {
|
||||
const [inlineAddOpen, setInlineAddOpen] = useState(false);
|
||||
const [inlineSaving, setInlineSaving] = useState(false);
|
||||
const [inlineDraft, setInlineDraft] = useState({ sku_code: '', spec: '', unit: '', cost_price: '', sale_price: '', markup_ratio: '' });
|
||||
/** 录单同款「新建商品」弹窗(2026-10-20 开发者:选不到商品时当场建档,复用录单组件) */
|
||||
const [showCreateProductModal, setShowCreateProductModal] = useState(false);
|
||||
const [createProductInitialName, setCreateProductInitialName] = useState('');
|
||||
const [createProductError, setCreateProductError] = useState('');
|
||||
const [creatingProduct, setCreatingProduct] = useState(false);
|
||||
/**
|
||||
* 重复商品集合(2026-10-20 开发者需求:重复商品标红提示)。
|
||||
* 判定按 `sku_code`;出现 ≥2 次即标红 —— 提交时后端会按 SKU 去重只保留最后一行,
|
||||
@@ -591,6 +598,10 @@ export const QuoteVersionManagement: React.FC = () => {
|
||||
const [showExcelImportModal, setShowExcelImportModal] = useState(false);
|
||||
const { categoryRows } = useCategoryRows({ enabledOnly: false });
|
||||
const categoryLabelMap = useMemo(() => buildCategoryLabelMap(categoryRows), [categoryRows]);
|
||||
const createCategoryOptions = useMemo(
|
||||
() => categoryRows.map((c) => ({ category_code: c.category_code, label: c.category_name })),
|
||||
[categoryRows]
|
||||
);
|
||||
const skuMap = useMemo(() => new Map(skus.map((sku) => [sku.sku_code, sku])), [skus]);
|
||||
|
||||
const quoteSheetColumns = useMemo(
|
||||
@@ -1801,29 +1812,18 @@ export const QuoteVersionManagement: React.FC = () => {
|
||||
}}
|
||||
options={quoteSkuOptions}
|
||||
compact
|
||||
alwaysShowCreate
|
||||
onCreateFromQuery={(q) => {
|
||||
setCreateProductInitialName(q);
|
||||
setCreateProductError('');
|
||||
setShowCreateProductModal(true);
|
||||
}}
|
||||
/>
|
||||
{inlineDraft.sku_code ? (
|
||||
<button type="button" onClick={() => setInlineDraft((d) => ({ ...d, sku_code: '', spec: '', unit: '' }))} className="shrink-0 px-1 text-slate-400" title="清除">
|
||||
×
|
||||
</button>
|
||||
) : null}
|
||||
<a
|
||||
href="/products/skus?new=1"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="shrink-0 whitespace-nowrap text-xs text-emerald-600 hover:underline"
|
||||
title={t('quotes.form.newSku')}
|
||||
>
|
||||
+ {t('quotes.form.newSku')}
|
||||
</a>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void reloadSkus()}
|
||||
className="shrink-0 whitespace-nowrap text-xs text-slate-500 hover:underline"
|
||||
title={t('quotes.form.refreshSku')}
|
||||
>
|
||||
{t('quotes.form.refreshSku')}
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
@@ -1919,6 +1919,55 @@ export const QuoteVersionManagement: React.FC = () => {
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
<QuickCreateProductModal
|
||||
show={showCreateProductModal}
|
||||
isCreating={creatingProduct}
|
||||
error={createProductError}
|
||||
initialName={createProductInitialName}
|
||||
initialCategoryCode=""
|
||||
initialUnit="斤"
|
||||
initialSalePrice={0}
|
||||
initialCostPrice={0}
|
||||
categoryOptions={createCategoryOptions}
|
||||
onClose={() => {
|
||||
if (creatingProduct) return;
|
||||
setShowCreateProductModal(false);
|
||||
setCreateProductError('');
|
||||
}}
|
||||
onConfirm={(payload: QuickCreateProductConfirm) => {
|
||||
void (async () => {
|
||||
if (creatingProduct) return;
|
||||
if (!payload.name) { setCreateProductError(t('orders.enterSkuName')); return; }
|
||||
if (!payload.categoryCode) { setCreateProductError(t('orders.pickCategory')); return; }
|
||||
setCreatingProduct(true);
|
||||
setCreateProductError('');
|
||||
try {
|
||||
const created = await createCatalogProductForOrderLine({
|
||||
name: payload.name,
|
||||
categoryCode: payload.categoryCode,
|
||||
unit: payload.unit,
|
||||
salePrice: payload.salePrice,
|
||||
costPrice: payload.costPrice,
|
||||
spec: payload.spec,
|
||||
});
|
||||
setInlineDraft((d) => ({
|
||||
...d,
|
||||
sku_code: created.skuCode,
|
||||
unit: payload.unit || d.unit,
|
||||
cost_price: payload.costPrice ? String(payload.costPrice) : d.cost_price,
|
||||
sale_price: payload.salePrice ? String(payload.salePrice) : d.sale_price,
|
||||
}));
|
||||
await reloadSkus();
|
||||
setShowCreateProductModal(false);
|
||||
notify.success(t('quotes.toast.updated'));
|
||||
} catch (err: any) {
|
||||
setCreateProductError(err?.message || String(err));
|
||||
} finally {
|
||||
setCreatingProduct(false);
|
||||
}
|
||||
})();
|
||||
}}
|
||||
/>
|
||||
{(expandedDetail.enrichedItems || []).length === 0 ? (
|
||||
<div className="app-surface rounded-2xl border px-4 py-8 text-center text-sm text-slate-500">
|
||||
{t('quotes.detail.emptyItems')}
|
||||
|
||||
Reference in New Issue
Block a user