将账本业务页面、表单与审批迁移到 React,并加入旧版对照验收
This commit is contained in:
1 parent
f1a4e69f0d
commit
00dd683116
107 files changed
+31755
-191
No files matched your search
@@ -0,0 +1,42 @@
|
||||
import { Model, type LedgerState } from '../../shared';
|
||||
import { countValue, kinds, type Values } from './data';
|
||||
export function stockInput(form: HTMLFormElement, state: LedgerState, original?: Values) {
|
||||
const f = new FormData(form),
|
||||
text = (key: string) => String(f.get(key) || '');
|
||||
const kind = text('kind'),
|
||||
pocket = text('pocket'),
|
||||
grams = text('grams').trim(),
|
||||
to = text('to'),
|
||||
adjust = kind === 'adjustment',
|
||||
active = Model.activePocketKeys(state);
|
||||
if (!Object.hasOwn(kinds, kind) || (!active.includes(pocket) && pocket !== original?.pocket))
|
||||
throw new Error('请选择库存动作和货盘。');
|
||||
if (adjust && state.user.role !== 'owner') throw new Error('对数调整由店主操作。');
|
||||
if (
|
||||
!(original && adjust ? /^-?\d+(?:\.\d{1,3})?$/ : /^\d+(?:\.\d{1,3})?$/).test(grams) ||
|
||||
(!adjust && Number(grams) <= 0)
|
||||
)
|
||||
throw new Error(original ? '克重请填写有效数字,最多保留3位小数。' : '数量请填写大于0的数字,最多保留3位小数。');
|
||||
if (kind === 'transfer' && (to === pocket || (!active.includes(to) && to !== original?.to)))
|
||||
throw new Error('平移请选择两个不同的货盘。');
|
||||
if (adjust && original?.kind !== 'adjustment' && (!Model.pocketCountsEnabled(state, pocket) || Number(grams) !== 0))
|
||||
throw new Error('只调整对数请选择已启用对数的货盘,克重保留0。');
|
||||
const counted =
|
||||
Model.pocketCountsEnabled(state, pocket) || (kind === 'transfer' && Model.pocketCountsEnabled(state, to));
|
||||
const optional =
|
||||
!!original &&
|
||||
original.stockCount == null &&
|
||||
pocket === original.pocket &&
|
||||
(kind !== 'transfer' || to === original.to) &&
|
||||
Number(grams) !== 0;
|
||||
return {
|
||||
kind,
|
||||
date: text('date'),
|
||||
pocket,
|
||||
grams,
|
||||
note: original ? text('note').trim() : text('note'),
|
||||
...(original ? { reason: text('reason').trim() } : {}),
|
||||
...(kind === 'transfer' ? { to } : {}),
|
||||
...(counted ? { stockCount: countValue(text('stockCount'), adjust, optional) } : {}),
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user