style(库存): 删除入口与全选删除沿用原交互
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s

去掉真实删除单独文案/按钮;单条与全选当前页统一走删除:有可用量先清空,已无可用量移除批次记录。
This commit is contained in:
Ubuntu
2026-11-02 16:00:24 +08:00
parent f1dee6e24d
commit b8d26123df
5 changed files with 32 additions and 117 deletions
+1 -1
View File
@@ -37,6 +37,6 @@ describe('库存批次真实删除(方案 A)', () => {
expect(route).toContain('/inventory/batches/:inventoryId/hard-delete');
expect(route).toContain("['inventory_adjust']");
expect(page).toContain('hardDeleteInventoryBatchApi');
expect(page).toContain('inventory.action.hardDelete');
expect(page).toContain('setVoidTargets([item])');
});
});
+2 -12
View File
@@ -71,8 +71,6 @@ export const inventory: MessageDict = {
inboundDate: 'In {date}',
'action.edit': 'Edit',
'action.editTitle': 'Adjust available stock',
'action.hardDeleteTitle': 'Permanently delete (no available stock)',
'action.hardDelete': 'Delete permanently',
'action.delete': 'Delete',
'action.deleteTitle': 'Zero this batch and hide it from the default list',
'pager.inventory': 'batches',
@@ -134,19 +132,11 @@ export const inventory: MessageDict = {
'holding.loading': 'Loading…',
'holding.empty': 'No holding cost',
'hardDelete.title': 'Permanently delete stock batch',
'hardDelete.body': 'Available stock is 0. This permanently deletes the inventory batch so it no longer blocks product deletion. Stock logs and report files are kept.',
'hardDelete.confirm': 'Delete permanently',
'hardDelete.processing': 'Deleting…',
'hardDelete.done': 'Stock batch permanently deleted',
'hardDelete.failed': 'Permanent delete failed',
'hardDelete.reason': 'Consumed cleanup',
'hardDelete.keepHint': 'Stock logs and report files are kept; this cannot be undone.',
'void.title': 'Void stock batch',
'void.bodyOne':
'Set this batch available to 0 and hide it from the default list. No hard delete; logs remain. Do not void batches that are still physically in stock.',
'Delete this batch: available stock is cleared first; batches with no available stock have their batch record removed. Stock logs and report files are kept. This cannot be undone.',
'void.bodyMany':
'Void {n} batches on this page (other pages untouched). Available set to 0 and hidden from the default list; logs remain.',
'Delete {n} batches on this page (other pages untouched): available stock is cleared first; batches with no available stock have their batch record removed. Logs and report files are kept.',
'void.product': 'Product',
'void.batch': 'Batch',
'void.currentAvailable': 'Current available {qty}',
+2 -12
View File
@@ -74,8 +74,6 @@ export const inventory: MessageDict = {
inboundDate: 'Masuk {date}',
'action.edit': 'Ubah',
'action.editTitle': 'Ubah stok tersedia',
'action.hardDeleteTitle': 'Hapus permanen (tidak ada stok tersedia)',
'action.hardDelete': 'Hapus permanen',
'action.delete': 'Hapus',
'action.deleteTitle':
'Nolkan batch ini dan sembunyikan dari daftar default',
@@ -138,19 +136,11 @@ export const inventory: MessageDict = {
'holding.loading': 'Memuat…',
'holding.empty': 'Tidak ada biaya holding',
'hardDelete.title': 'Hapus permanen batch stok',
'hardDelete.body': 'Stok tersedia 0. Batch inventaris akan dihapus permanen dan tidak lagi memblokir penghapusan produk. Log stok dan file laporan tetap disimpan.',
'hardDelete.confirm': 'Hapus permanen',
'hardDelete.processing': 'Menghapus…',
'hardDelete.done': 'Batch stok dihapus permanen',
'hardDelete.failed': 'Gagal menghapus permanen',
'hardDelete.reason': 'Pembersihan stok habis',
'hardDelete.keepHint': 'Log stok dan file laporan tetap disimpan; tidak dapat dibatalkan.',
'void.title': 'Hapus batch stok',
'void.bodyOne':
'Set tersedia batch ini ke 0 dan sembunyikan dari daftar default. Tidak hapus fisik; log tetap. Jangan void batch yang masih ada di gudang.',
'Hapus batch ini: stok tersedia dikosongkan lebih dulu; batch tanpa stok tersedia akan dihapus record-nya. Log stok dan file laporan tetap disimpan. Tidak dapat dibatalkan.',
'void.bodyMany':
'Hapus {n} batch di halaman ini (halaman lain tidak). Tersedia jadi 0 lalu disembunyikan; log tetap.',
'Hapus {n} batch di halaman ini (halaman lain tidak): stok tersedia dikosongkan lebih dulu; batch tanpa stok tersedia akan dihapus record-nya. Log dan file laporan tetap disimpan.',
'void.product': 'Produk',
'void.batch': 'Batch',
'void.currentAvailable': 'Tersedia sekarang {qty}',
+2 -12
View File
@@ -70,8 +70,6 @@ export const inventory: MessageDict = {
inboundDate: '入库 {date}',
'action.edit': '修改',
'action.editTitle': '修改可用库存',
'action.hardDeleteTitle': '可真实删除(已无可用库存)',
'action.hardDelete': '真实删除',
'action.delete': '删除',
'action.deleteTitle': '将本批次可用清零并从默认列表隐藏',
'pager.inventory': '条库存',
@@ -132,19 +130,11 @@ export const inventory: MessageDict = {
'holding.loading': '加载中…',
'holding.empty': '暂无在库存货(账外进仓台账)',
'hardDelete.title': '真实删除库存批次',
'hardDelete.body': '该批次可用库存已为 0。真实删除后会物理删除库存批次,商品不再被它引用;库存流水和报告文件保留。',
'hardDelete.confirm': '确认真实删除',
'hardDelete.processing': '删除中…',
'hardDelete.done': '库存批次已真实删除',
'hardDelete.failed': '真实删除失败',
'hardDelete.reason': '已用完清理',
'hardDelete.keepHint': '不会删除库存流水/报告文件,删除后不可恢复。',
'void.title': '删除库存批次',
'void.bodyOne':
'将本批次可用改为 0,默认列表不再显示。不物理删库,流水保留。请勿把真实在库批次一并删掉。',
'删除本批次:有可用量的先清空可用量;已无可用量的批次移除批次记录。库存流水和报告文件保留,删除后不可恢复。',
'void.bodyMany':
'将删除当前页 {n} 条批次(不含其它页)。可用改为 0 后默认列表不再显示,流水保留。',
'删除当前页 {n} 条批次(不含其它页):有可用量的先清空可用量;已无可用量的批次移除批次记录。流水和报告文件保留。',
'void.product': '商品',
'void.batch': '批次',
'void.currentAvailable': '当前可用 {qty}',
+25 -80
View File
@@ -413,8 +413,6 @@ export const InventoryManagement: React.FC = () => {
const [unitChoices, setUnitChoices] = useState<Array<{ value: string; label: string }>>([]);
const [voidTargets, setVoidTargets] = useState<InventoryItem[]>([]);
const [voidSaving, setVoidSaving] = useState(false);
const [hardDeleteTarget, setHardDeleteTarget] = useState<InventoryItem | null>(null);
const [hardDeleting, setHardDeleting] = useState(false);
const [voidProgress, setVoidProgress] = useState('');
const [stockCoverEnabled, setStockCoverEnabled] = useState(true);
const [stockImportOpen, setStockImportOpen] = useState(false);
@@ -596,25 +594,6 @@ export const InventoryManagement: React.FC = () => {
};
}, []);
const submitHardDeleteBatch = async () => {
if (!hardDeleteTarget || hardDeleting) return;
setHardDeleting(true);
try {
await hardDeleteInventoryBatchApi({
inventoryId: hardDeleteTarget.id,
reason: t('inventory.hardDelete.reason'),
operatingBranchCode: operatingBranchCode || readOperatingBranchCode(),
});
notify.success(t('inventory.hardDelete.done'));
setHardDeleteTarget(null);
await Promise.all([fetchInventory(), fetchInventoryLogs()]);
} catch (error: any) {
notify.error(error?.message || t('inventory.hardDelete.failed'));
} finally {
setHardDeleting(false);
}
};
const closeVoidModal = () => {
if (voidSaving) return;
setVoidTargets([]);
@@ -623,12 +602,7 @@ export const InventoryManagement: React.FC = () => {
const submitVoidBatch = async () => {
if (!voidTargets.length || voidSaving) return;
const targets = voidTargets.filter((item) => (Number(item.available_qty) || 0) > 0);
if (!targets.length) {
notify.error(t('inventory.toast.noVoidable'));
setVoidTargets([]);
return;
}
const targets = voidTargets;
setVoidSaving(true);
const branch = operatingBranchCode || readOperatingBranchCode();
let ok = 0;
@@ -638,12 +612,20 @@ export const InventoryManagement: React.FC = () => {
const item = targets[i];
setVoidProgress(`${i + 1}/${targets.length}`);
try {
await adjustInventoryAvailableApi({
inventoryId: item.id,
availableQty: 0,
remark: INVENTORY_VOID_REMARK,
operatingBranchCode: branch,
});
if (Number(item.available_qty) > 1e-9) {
await adjustInventoryAvailableApi({
inventoryId: item.id,
availableQty: 0,
remark: INVENTORY_VOID_REMARK,
operatingBranchCode: branch,
});
} else {
await hardDeleteInventoryBatchApi({
inventoryId: item.id,
reason: INVENTORY_VOID_REMARK,
operatingBranchCode: branch,
});
}
ok += 1;
} catch (err: unknown) {
const msg = err instanceof Error ? err.message : t('inventory.toast.deleteFail');
@@ -1413,12 +1395,11 @@ export const InventoryManagement: React.FC = () => {
type="button"
disabled={loading || voidSaving || sortedInventory.length === 0}
onClick={() => {
const rows = sortedInventory.filter((item) => (Number(item.available_qty) || 0) > 0);
if (!rows.length) {
if (!sortedInventory.length) {
notify.error(t('inventory.toast.pageNoVoidable'));
return;
}
setVoidTargets(rows);
setVoidTargets(sortedInventory);
}}
className="inline-flex items-center px-3 py-2 text-sm font-medium text-red-700 border border-red-200 rounded-md hover:bg-red-50 disabled:opacity-50 whitespace-nowrap"
title={t('inventory.bulkVoidTitle')}
@@ -1792,25 +1773,14 @@ export const InventoryManagement: React.FC = () => {
>
{t('inventory.action.edit')}
</button>
{Number(item.available_qty) <= 1e-9 ? (
<button
type="button"
onClick={() => setHardDeleteTarget(item)}
className="inline-flex items-center px-2.5 py-1.5 text-xs font-medium text-red-700 hover:bg-red-50 rounded-lg"
title={t('inventory.action.hardDeleteTitle')}
>
{t('inventory.action.hardDelete')}
</button>
) : (
<button
type="button"
onClick={() => setVoidTargets([item])}
className="inline-flex items-center px-2.5 py-1.5 text-xs font-medium text-red-600 hover:bg-red-50 rounded-lg"
title={t('inventory.action.deleteTitle')}
>
{t('inventory.action.delete')}
</button>
)}
<button
type="button"
onClick={() => setVoidTargets([item])}
className="inline-flex items-center px-2.5 py-1.5 text-xs font-medium text-red-600 hover:bg-red-50 rounded-lg"
title={t('inventory.action.deleteTitle')}
>
{t('inventory.action.delete')}
</button>
</div>
</td>
);
@@ -2215,31 +2185,6 @@ export const InventoryManagement: React.FC = () => {
</DialogOverlay>
)}
{hardDeleteTarget && (
<DialogOverlay onBackdropMouseDown={() => (hardDeleting ? undefined : setHardDeleteTarget(null))}>
<div className="app-surface rounded-xl shadow-xl w-full max-w-md p-5" onClick={(e) => e.stopPropagation()}>
<div className="flex items-center justify-between mb-4">
<h3 className="text-lg font-semibold text-black dark:text-slate-100">{t('inventory.hardDelete.title')}</h3>
<button type="button" onClick={() => setHardDeleteTarget(null)} disabled={hardDeleting} className="p-1.5 rounded-lg hover:bg-gray-100 disabled:opacity-50" aria-label={t('common.close')}>
<X className="w-4 h-4" />
</button>
</div>
<p className="text-sm text-gray-600 dark:text-slate-300">{t('inventory.hardDelete.body')}</p>
<div className="mt-3 space-y-2 text-sm">
<div><p className="text-gray-500 text-xs">{t('inventory.void.product')}</p><p className="font-medium">{hardDeleteTarget.sku_name || hardDeleteTarget.sku_code}</p></div>
<div><p className="text-gray-500 text-xs">{t('inventory.void.batch')}</p><p className="font-mono text-xs">{hardDeleteTarget.batch_no}</p></div>
<p className="text-xs text-gray-500">{t('inventory.hardDelete.keepHint')}</p>
</div>
<div className="mt-5 flex justify-end gap-2">
<button type="button" onClick={() => setHardDeleteTarget(null)} disabled={hardDeleting} className="px-3 py-2 text-sm rounded-lg border border-gray-200 hover:bg-gray-50 disabled:opacity-50">{t('common.cancel')}</button>
<button type="button" onClick={() => void submitHardDeleteBatch()} disabled={hardDeleting} className="px-3 py-2 text-sm rounded-lg bg-red-600 text-white hover:bg-red-700 disabled:opacity-50">
{hardDeleting ? t('inventory.hardDelete.processing') : t('inventory.hardDelete.confirm')}
</button>
</div>
</div>
</DialogOverlay>
)}
{adjustItem && (
<DialogOverlay onBackdropMouseDown={closeAdjustModal}>
<div