feat(client): 名称/系列/规格可搜索下拉 + 修复打印状态提示

- 新增 SearchableOptionField 组件:点击弹出带搜索框的对话框,支持实时过滤
- 入库/出库表单名称、系列、规格列全部替换为可搜索选择器
- 打印按钮加步骤状态提示(正在准备字体→生成PDF→打开打印)+ catch 错误展示

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-04-30 20:13:07 +08:00
parent 66dbc4829c
commit cdf273da76
4 changed files with 232 additions and 79 deletions
@@ -512,6 +512,7 @@ class _QRCodeDialogState extends ConsumerState<_QRCodeDialog> {
late Future<Uint8List> _future;
Uint8List? _bytes;
bool _printing = false;
String _printStatus = '';
@override
void initState() {
@@ -526,9 +527,10 @@ class _QRCodeDialogState extends ConsumerState<_QRCodeDialog> {
Future<void> _print() async {
if (_bytes == null || _printing) return;
setState(() => _printing = true);
setState(() { _printing = true; _printStatus = '正在准备字体...'; });
try {
final fontData = await rootBundle.load('assets/fonts/NotoSansSC-Regular.ttf');
if (mounted) setState(() => _printStatus = '正在生成 PDF...');
final font = pw.Font.ttf(fontData);
final p = widget.product;
final doc = pw.Document();
@@ -553,9 +555,16 @@ class _QRCodeDialogState extends ConsumerState<_QRCodeDialog> {
),
),
));
if (mounted) setState(() => _printStatus = '正在打开打印...');
await Printing.layoutPdf(onLayout: (_) async => doc.save());
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('打印失败:$e'), backgroundColor: Colors.red),
);
}
} finally {
if (mounted) setState(() => _printing = false);
if (mounted) setState(() { _printing = false; _printStatus = ''; });
}
}
@@ -591,7 +600,9 @@ class _QRCodeDialogState extends ConsumerState<_QRCodeDialog> {
width: 14, height: 14,
child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white))
: const Icon(Icons.print, size: 16),
label: const Text('打印'),
label: Text(_printing
? (_printStatus.isNotEmpty ? _printStatus : '准备中...')
: '打印'),
),
],
);
@@ -10,6 +10,7 @@ import '../../providers/product_provider.dart';
import '../../providers/inventory_provider.dart';
import '../../providers/stock_in_provider.dart';
import '../../providers/warehouse_provider.dart';
import '../../widgets/searchable_option_field.dart';
class StockInFormScreen extends ConsumerStatefulWidget {
final int? editOrderId;
@@ -515,24 +516,18 @@ class _StockInFormScreenState extends ConsumerState<StockInFormScreen> {
child: asyncNames.when(
loading: () => const LinearProgressIndicator(),
error: (_, __) => const Text('加载失败'),
data: (names) => DropdownButtonFormField<int>(
value: item.selectedNameId,
hint: const Text('选择名称', style: TextStyle(fontSize: 12)),
isExpanded: true,
items: names
.map((o) => DropdownMenuItem(
value: o.id,
child: Text(o.name,
style: const TextStyle(fontSize: 12),
overflow: TextOverflow.ellipsis)))
data: (names) => SearchableOptionField(
options: names
.map((o) => OptionItem(id: o.id, name: o.name, code: o.code))
.toList(),
selectedId: item.selectedNameId,
hint: '选择名称',
dialogTitle: '选择商品名称',
isRequired: true,
onChanged: (v) => setState(() {
item.selectedNameId = v;
item.productId = null;
}),
validator: (v) => v == null ? '请选择' : null,
decoration: const InputDecoration(isDense: true),
style: const TextStyle(fontSize: 12, color: Colors.black87),
),
),
),
@@ -542,23 +537,17 @@ class _StockInFormScreenState extends ConsumerState<StockInFormScreen> {
child: asyncSeries.when(
loading: () => const LinearProgressIndicator(),
error: (_, __) => const Text('加载失败'),
data: (series) => DropdownButtonFormField<int>(
value: item.selectedSeriesId,
hint: const Text('选择系列', style: TextStyle(fontSize: 12)),
isExpanded: true,
items: series
.map((o) => DropdownMenuItem(
value: o.id,
child: Text(o.name,
style: const TextStyle(fontSize: 12),
overflow: TextOverflow.ellipsis)))
data: (series) => SearchableOptionField(
options: series
.map((o) => OptionItem(id: o.id, name: o.name, code: o.code))
.toList(),
selectedId: item.selectedSeriesId,
hint: '选择系列',
dialogTitle: '选择系列',
onChanged: (v) => setState(() {
item.selectedSeriesId = v;
item.productId = null;
}),
decoration: const InputDecoration(isDense: true),
style: const TextStyle(fontSize: 12, color: Colors.black87),
),
),
),
@@ -568,24 +557,18 @@ class _StockInFormScreenState extends ConsumerState<StockInFormScreen> {
child: asyncSpecs.when(
loading: () => const LinearProgressIndicator(),
error: (_, __) => const Text('加载失败'),
data: (specs) => DropdownButtonFormField<int>(
value: item.selectedSpecId,
hint: const Text('选择规格', style: TextStyle(fontSize: 12)),
isExpanded: true,
items: specs
.map((o) => DropdownMenuItem(
value: o.id,
child: Text(o.name,
style: const TextStyle(fontSize: 12),
overflow: TextOverflow.ellipsis)))
data: (specs) => SearchableOptionField(
options: specs
.map((o) => OptionItem(id: o.id, name: o.name, code: o.code))
.toList(),
selectedId: item.selectedSpecId,
hint: '选择规格',
dialogTitle: '选择规格',
isRequired: true,
onChanged: (v) => setState(() {
item.selectedSpecId = v;
item.productId = null;
}),
validator: (v) => v == null ? '请选择' : null,
decoration: const InputDecoration(isDense: true),
style: const TextStyle(fontSize: 12, color: Colors.black87),
),
),
),
@@ -10,6 +10,7 @@ import '../../providers/product_option_provider.dart';
import '../../providers/product_provider.dart';
import '../../providers/stock_out_provider.dart';
import '../../providers/warehouse_provider.dart';
import '../../widgets/searchable_option_field.dart';
class StockOutFormScreen extends ConsumerStatefulWidget {
final int? editOrderId;
@@ -515,24 +516,18 @@ class _StockOutFormScreenState extends ConsumerState<StockOutFormScreen> {
child: asyncNames.when(
loading: () => const LinearProgressIndicator(),
error: (_, __) => const Text('加载失败'),
data: (names) => DropdownButtonFormField<int>(
value: item.selectedNameId,
hint: const Text('选择名称', style: TextStyle(fontSize: 12)),
isExpanded: true,
items: names
.map((o) => DropdownMenuItem(
value: o.id,
child: Text(o.name,
style: const TextStyle(fontSize: 12),
overflow: TextOverflow.ellipsis)))
data: (names) => SearchableOptionField(
options: names
.map((o) => OptionItem(id: o.id, name: o.name, code: o.code))
.toList(),
selectedId: item.selectedNameId,
hint: '选择名称',
dialogTitle: '选择商品名称',
isRequired: true,
onChanged: (v) => setState(() {
item.selectedNameId = v;
item.productId = null;
}),
validator: (v) => v == null ? '请选择' : null,
decoration: const InputDecoration(isDense: true),
style: const TextStyle(fontSize: 12, color: Colors.black87),
),
),
),
@@ -542,23 +537,17 @@ class _StockOutFormScreenState extends ConsumerState<StockOutFormScreen> {
child: asyncSeries.when(
loading: () => const LinearProgressIndicator(),
error: (_, __) => const Text('加载失败'),
data: (series) => DropdownButtonFormField<int>(
value: item.selectedSeriesId,
hint: const Text('选择系列', style: TextStyle(fontSize: 12)),
isExpanded: true,
items: series
.map((o) => DropdownMenuItem(
value: o.id,
child: Text(o.name,
style: const TextStyle(fontSize: 12),
overflow: TextOverflow.ellipsis)))
data: (series) => SearchableOptionField(
options: series
.map((o) => OptionItem(id: o.id, name: o.name, code: o.code))
.toList(),
selectedId: item.selectedSeriesId,
hint: '选择系列',
dialogTitle: '选择系列',
onChanged: (v) => setState(() {
item.selectedSeriesId = v;
item.productId = null;
}),
decoration: const InputDecoration(isDense: true),
style: const TextStyle(fontSize: 12, color: Colors.black87),
),
),
),
@@ -568,24 +557,18 @@ class _StockOutFormScreenState extends ConsumerState<StockOutFormScreen> {
child: asyncSpecs.when(
loading: () => const LinearProgressIndicator(),
error: (_, __) => const Text('加载失败'),
data: (specs) => DropdownButtonFormField<int>(
value: item.selectedSpecId,
hint: const Text('选择规格', style: TextStyle(fontSize: 12)),
isExpanded: true,
items: specs
.map((o) => DropdownMenuItem(
value: o.id,
child: Text(o.name,
style: const TextStyle(fontSize: 12),
overflow: TextOverflow.ellipsis)))
data: (specs) => SearchableOptionField(
options: specs
.map((o) => OptionItem(id: o.id, name: o.name, code: o.code))
.toList(),
selectedId: item.selectedSpecId,
hint: '选择规格',
dialogTitle: '选择规格',
isRequired: true,
onChanged: (v) => setState(() {
item.selectedSpecId = v;
item.productId = null;
}),
validator: (v) => v == null ? '请选择' : null,
decoration: const InputDecoration(isDense: true),
style: const TextStyle(fontSize: 12, color: Colors.black87),
),
),
),