feat(client): 新建出入库单默认填充默认仓库(两端,原型同步)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-07-14 10:51:03 +08:00
parent d4c5964932
commit f555b99565
15 changed files with 48 additions and 6 deletions
@@ -75,9 +75,26 @@ class _StockInFormScreenState extends ConsumerState<StockInFormScreen> {
} else {
_items.add(_ItemRow());
_initDefaults();
_initWarehouseDefault();
}
}
/// 新建单默认填充默认仓库(2026-07-14):仓库列表加载完成后,
/// `isDefault` 的仓 优先;无默认时仅剩 1 个仓才取它;否则保持 null。
/// 编辑模式不受影响(`_loadEditOrder` 已从单据自身仓库回填)。
Future<void> _initWarehouseDefault() async {
try {
final warehouses = await ref.read(warehouseListProvider.future);
if (!mounted || _warehouseId != null) return;
final defaultWh = warehouses.where((w) => w.isDefault).firstOrNull;
final picked = defaultWh?.id ??
(warehouses.length == 1 ? warehouses.first.id : null);
if (picked != null) {
setState(() => _warehouseId = picked);
}
} catch (_) {}
}
Future<void> _initDefaults() async {
try {
final shop = await ref.read(shopInfoProvider.future);
@@ -173,8 +173,29 @@ class _StockOutFormScreenState extends ConsumerState<StockOutFormScreen> {
@override
void initState() {
super.initState();
if (_isEdit) _loadEditOrder();
// 新单起始为空,用户通过「从库存选择」添加明细
if (_isEdit) {
_loadEditOrder();
} else {
// 新单起始为空,用户通过「从库存选择」添加明细
_initWarehouseDefault();
}
}
/// 新建单默认填充默认仓库(2026-07-14):仓库列表加载完成后,
/// `isDefault` 的仓 优先;无默认时仅剩 1 个仓才取它;否则保持 null。
/// 编辑模式不受影响(`_loadEditOrder` 已从单据自身仓库回填)。
Future<void> _initWarehouseDefault() async {
try {
final warehouses = await ref.read(warehouseListProvider.future);
if (!mounted || _warehouseId != null) return;
final defaultWh = warehouses.where((w) => w.isDefault).firstOrNull;
final picked = defaultWh?.id ??
(warehouses.length == 1 ? warehouses.first.id : null);
if (picked != null) {
setState(() => _warehouseId = picked);
await _loadInventory(picked);
}
} catch (_) {}
}
Future<void> _loadEditOrder() async {
Binary file not shown.

Before

Width:  |  Height:  |  Size: 159 KiB

After

Width:  |  Height:  |  Size: 160 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 156 KiB

After

Width:  |  Height:  |  Size: 156 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 160 KiB

After

Width:  |  Height:  |  Size: 160 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 133 KiB

After

Width:  |  Height:  |  Size: 132 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 132 KiB

After

Width:  |  Height:  |  Size: 130 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 134 KiB

After

Width:  |  Height:  |  Size: 132 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 126 KiB

After

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 123 KiB

After

Width:  |  Height:  |  Size: 123 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 127 KiB

After

Width:  |  Height:  |  Size: 127 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 84 KiB

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 82 KiB

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 85 KiB

After

Width:  |  Height:  |  Size: 83 KiB