- Add BoxInfoResult/BoxSaveResult data classes and API methods to ApiService - Create BoxingPage with mode switching, auto-fill rules, duplicate detection - Create BoxingDetailPage for read-only box detail view - Activate boxing module in HomePage navigation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
847 lines
24 KiB
Dart
847 lines
24 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:pad_scanner/services/app_config_service.dart';
|
|
import 'package:pad_scanner/services/scanner_service.dart';
|
|
import 'package:pad_scanner/services/code_parser.dart';
|
|
import 'package:pad_scanner/services/api_service.dart';
|
|
import 'package:pad_scanner/pages/boxing_detail_page.dart';
|
|
|
|
// === 装箱模式 ===
|
|
|
|
enum BoxingMode {
|
|
one2one, // 一码一箱
|
|
one2many, // 一码多箱
|
|
many2one, // 多码一箱
|
|
}
|
|
|
|
// === 页面阶段 ===
|
|
|
|
enum _Phase {
|
|
waiting, // 等待扫码
|
|
scanned, // 已扫码,显示信息
|
|
submitted, // 已提交成功
|
|
}
|
|
|
|
// === 主页面 ===
|
|
|
|
class BoxingPage extends StatefulWidget {
|
|
const BoxingPage({super.key});
|
|
|
|
@override
|
|
State<BoxingPage> createState() => _BoxingPageState();
|
|
}
|
|
|
|
class _BoxingPageState extends State<BoxingPage> {
|
|
final _scannerService = ScannerService();
|
|
final _apiService = ApiService();
|
|
|
|
// 模式
|
|
BoxingMode _mode = BoxingMode.one2one;
|
|
|
|
// 阶段
|
|
_Phase _phase = _Phase.waiting;
|
|
|
|
// 当前总排号
|
|
String? _zongpaiNo;
|
|
|
|
// 排产号信息(来自后端查询)
|
|
String? _paichanNo;
|
|
int? _erpQuantity;
|
|
List<BoxDetailData> _existingBoxes = [];
|
|
int _maxBoxNo = 0;
|
|
|
|
// 输入
|
|
final _boxNoController = TextEditingController();
|
|
final _quantityController = TextEditingController();
|
|
final _boxNoFocusNode = FocusNode();
|
|
final _quantityFocusNode = FocusNode();
|
|
|
|
// 多码一箱:已扫描过的总排号列表(用于显示)
|
|
final _scannedZongpais = <String>[];
|
|
|
|
// 箱号锁定(多码一箱模式)
|
|
bool _boxNoLocked = false;
|
|
|
|
// 提交中
|
|
bool _isSubmitting = false;
|
|
|
|
// 一码多箱:上次提交的值(用于继续添加预填)
|
|
int? _lastBoxNo;
|
|
int? _lastQuantity;
|
|
|
|
// 重复箱号
|
|
bool _isDuplicateBoxNo = false;
|
|
|
|
// 反馈
|
|
String? _feedbackMessage;
|
|
Color? _feedbackColor;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_scannerService.scanResults.listen(_onScan);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_boxNoController.dispose();
|
|
_quantityController.dispose();
|
|
_boxNoFocusNode.dispose();
|
|
_quantityFocusNode.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
// === 模式切换 ===
|
|
|
|
String get _modeLabel {
|
|
switch (_mode) {
|
|
case BoxingMode.one2one:
|
|
return '一码一箱';
|
|
case BoxingMode.one2many:
|
|
return '一码多箱';
|
|
case BoxingMode.many2one:
|
|
return '多码一箱';
|
|
}
|
|
}
|
|
|
|
void _cycleMode() {
|
|
setState(() {
|
|
switch (_mode) {
|
|
case BoxingMode.one2one:
|
|
_mode = BoxingMode.one2many;
|
|
case BoxingMode.one2many:
|
|
_mode = BoxingMode.many2one;
|
|
case BoxingMode.many2one:
|
|
_mode = BoxingMode.one2one;
|
|
}
|
|
_resetState();
|
|
});
|
|
}
|
|
|
|
void _resetState() {
|
|
_phase = _Phase.waiting;
|
|
_zongpaiNo = null;
|
|
_paichanNo = null;
|
|
_erpQuantity = null;
|
|
_existingBoxes = [];
|
|
_maxBoxNo = 0;
|
|
_boxNoController.clear();
|
|
_quantityController.clear();
|
|
_scannedZongpais.clear();
|
|
_boxNoLocked = false;
|
|
_isSubmitting = false;
|
|
_lastBoxNo = null;
|
|
_lastQuantity = null;
|
|
_isDuplicateBoxNo = false;
|
|
_feedbackMessage = null;
|
|
_feedbackColor = null;
|
|
}
|
|
|
|
// === 扫码处理 ===
|
|
|
|
void _onScan(ScanResult result) {
|
|
final parsed = CodeParser.parse(result.barcode);
|
|
|
|
if (parsed.type != CodeType.zongpaiNo) {
|
|
_showFeedback('无效码,请重新扫描', isError: true);
|
|
return;
|
|
}
|
|
|
|
final zongpai = parsed.value;
|
|
|
|
// 多码一箱已提交后:等待下一个扫码
|
|
if (_mode == BoxingMode.many2one && _phase == _Phase.submitted) {
|
|
_handleNextScanMany2One(zongpai);
|
|
return;
|
|
}
|
|
|
|
// 其他模式:等待扫码阶段才处理
|
|
if (_phase != _Phase.waiting) return;
|
|
|
|
_queryBoxInfo(zongpai);
|
|
}
|
|
|
|
void _handleNextScanMany2One(String zongpai) {
|
|
setState(() {
|
|
_phase = _Phase.waiting;
|
|
_zongpaiNo = null;
|
|
_feedbackMessage = null;
|
|
});
|
|
_queryBoxInfo(zongpai);
|
|
}
|
|
|
|
Future<void> _queryBoxInfo(String zongpai) async {
|
|
final configService = AppConfigService();
|
|
final baseUrl = await configService.getString('api_url') ?? '';
|
|
if (baseUrl.isEmpty) {
|
|
_showFeedback('未配置 API 地址,请前往设置', isError: true);
|
|
return;
|
|
}
|
|
|
|
final result = await _apiService.fetchBoxInfo(
|
|
baseUrl: baseUrl,
|
|
zongpaiNo: zongpai,
|
|
);
|
|
|
|
if (!mounted) return;
|
|
|
|
if (!result.success) {
|
|
_showFeedback(result.errorMessage ?? '查询失败', isError: true);
|
|
return;
|
|
}
|
|
|
|
setState(() {
|
|
_zongpaiNo = zongpai;
|
|
_paichanNo = result.paichanNo;
|
|
_erpQuantity = result.quantity;
|
|
_existingBoxes = result.existingBoxes;
|
|
_maxBoxNo = result.maxBoxNo;
|
|
_phase = _Phase.scanned;
|
|
_isDuplicateBoxNo = false;
|
|
_feedbackMessage = null;
|
|
|
|
// 多码一箱:记录已扫描列表
|
|
if (_mode == BoxingMode.many2one && !_scannedZongpais.contains(zongpai)) {
|
|
_scannedZongpais.add(zongpai);
|
|
}
|
|
|
|
// 根据模式自动填充
|
|
_applyAutoFill();
|
|
});
|
|
}
|
|
|
|
void _applyAutoFill() {
|
|
switch (_mode) {
|
|
case BoxingMode.one2one:
|
|
// 箱号 = max+1, 数量 = ERP 数量
|
|
_boxNoController.text = (_maxBoxNo + 1).toString();
|
|
_quantityController.text = (_erpQuantity ?? 0).toString();
|
|
case BoxingMode.one2many:
|
|
if (_lastBoxNo != null) {
|
|
// 继续添加:箱号 = 上次+1, 数量 = 上次值
|
|
_boxNoController.text = (_lastBoxNo! + 1).toString();
|
|
_quantityController.text = _lastQuantity?.toString() ?? '';
|
|
} else {
|
|
// 首次:箱号 = max+1, 数量不填
|
|
_boxNoController.text = (_maxBoxNo + 1).toString();
|
|
_quantityController.clear();
|
|
}
|
|
case BoxingMode.many2one:
|
|
// 箱号 = max+1 (首次) 或锁定, 数量 = ERP 数量
|
|
if (!_boxNoLocked) {
|
|
_boxNoController.text = (_maxBoxNo + 1).toString();
|
|
_boxNoLocked = true;
|
|
}
|
|
_quantityController.text = (_erpQuantity ?? 0).toString();
|
|
}
|
|
_checkDuplicateBoxNo();
|
|
}
|
|
|
|
// === 重复箱号检测 ===
|
|
|
|
void _checkDuplicateBoxNo() {
|
|
final boxNo = int.tryParse(_boxNoController.text);
|
|
if (boxNo == null) {
|
|
setState(() => _isDuplicateBoxNo = false);
|
|
return;
|
|
}
|
|
final exists = _existingBoxes.any((b) => b.boxNo == boxNo);
|
|
setState(() => _isDuplicateBoxNo = exists);
|
|
}
|
|
|
|
// === 提交 ===
|
|
|
|
bool get _canSubmit {
|
|
if (_isSubmitting || _phase != _Phase.scanned) return false;
|
|
if (_zongpaiNo == null) return false;
|
|
final boxNo = int.tryParse(_boxNoController.text);
|
|
final qty = int.tryParse(_quantityController.text);
|
|
if (boxNo == null || qty == null || qty <= 0) return false;
|
|
if (_isDuplicateBoxNo) return false;
|
|
return true;
|
|
}
|
|
|
|
Future<void> _submit() async {
|
|
if (!_canSubmit) return;
|
|
|
|
final configService = AppConfigService();
|
|
final baseUrl = await configService.getString('api_url') ?? '';
|
|
if (baseUrl.isEmpty) {
|
|
_showFeedback('未配置 API 地址,请前往设置', isError: true);
|
|
return;
|
|
}
|
|
|
|
final boxNo = int.parse(_boxNoController.text);
|
|
final quantity = int.parse(_quantityController.text);
|
|
|
|
setState(() => _isSubmitting = true);
|
|
|
|
final result = await _apiService.saveBoxRecord(
|
|
baseUrl: baseUrl,
|
|
zongpaiNo: _zongpaiNo!,
|
|
boxNo: boxNo,
|
|
quantity: quantity,
|
|
);
|
|
|
|
if (!mounted) return;
|
|
|
|
setState(() => _isSubmitting = false);
|
|
|
|
if (result.success) {
|
|
_onSubmitSuccess(boxNo, quantity);
|
|
} else if (result.isDuplicate) {
|
|
_showFeedback(
|
|
'排产号 ${result.paichanNo ?? ""} 下箱号 ${result.boxNo ?? ""} 已存在',
|
|
isError: true,
|
|
);
|
|
} else {
|
|
_showFeedback(result.errorMessage ?? '提交失败', isError: true);
|
|
}
|
|
}
|
|
|
|
void _onSubmitSuccess(int boxNo, int quantity) {
|
|
setState(() {
|
|
_lastBoxNo = boxNo;
|
|
_lastQuantity = quantity;
|
|
// 刷新已有箱号列表(将新记录加入本地列表)
|
|
_existingBoxes = List.from(_existingBoxes)
|
|
..add(BoxDetailData(
|
|
boxNo: boxNo,
|
|
items: [BoxItemData(zongpaiNo: _zongpaiNo!, quantity: quantity)],
|
|
));
|
|
_maxBoxNo = _maxBoxNo > boxNo ? _maxBoxNo : boxNo;
|
|
});
|
|
|
|
switch (_mode) {
|
|
case BoxingMode.one2one:
|
|
// 显示成功 1.5s → 重置
|
|
_showFeedback('装箱成功', isError: false);
|
|
Future.delayed(const Duration(milliseconds: 1500), () {
|
|
if (mounted) setState(() => _resetState());
|
|
});
|
|
|
|
case BoxingMode.one2many:
|
|
// 进入已提交状态,等待"继续添加"或"返回"
|
|
setState(() {
|
|
_phase = _Phase.submitted;
|
|
_zongpaiNo = null;
|
|
});
|
|
_showFeedback('装箱成功', isError: false);
|
|
|
|
case BoxingMode.many2one:
|
|
// 进入已提交状态,自动等待下一个扫码
|
|
setState(() {
|
|
_phase = _Phase.submitted;
|
|
_zongpaiNo = null;
|
|
});
|
|
_showFeedback('装箱成功,请扫描下一个总排号', isError: false);
|
|
}
|
|
}
|
|
|
|
// === 操作按钮 ===
|
|
|
|
void _onContinueAdding() {
|
|
// 一码多箱的继续添加
|
|
setState(() {
|
|
_phase = _Phase.waiting;
|
|
_feedbackMessage = null;
|
|
});
|
|
// 预填值会在下次扫码后的 _applyAutoFill 中处理
|
|
// 但这里需要手动触发,因为不重新扫码
|
|
// 用户需要扫描同一个总排号(或其他总排号)
|
|
}
|
|
|
|
void _onGoBack() {
|
|
setState(() => _resetState());
|
|
}
|
|
|
|
// === 反馈 ===
|
|
|
|
void _showFeedback(String message, {bool isError = false}) {
|
|
setState(() {
|
|
_feedbackMessage = message;
|
|
_feedbackColor = isError ? Colors.red.shade700 : Colors.green.shade700;
|
|
});
|
|
Future.delayed(const Duration(seconds: 2), () {
|
|
if (mounted) setState(() => _feedbackMessage = null);
|
|
});
|
|
}
|
|
|
|
// === 导航到详情页 ===
|
|
|
|
void _openDetail() {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (_) => BoxingDetailPage(
|
|
paichanNo: _paichanNo ?? '',
|
|
existingBoxes: _existingBoxes,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
// === 状态文字 ===
|
|
|
|
String get _statusText {
|
|
if (_isSubmitting) return '正在提交…';
|
|
if (_feedbackMessage != null) return _feedbackMessage!;
|
|
switch (_phase) {
|
|
case _Phase.waiting:
|
|
if (_mode == BoxingMode.many2one && _boxNoLocked) {
|
|
return '请扫描下一个总排号';
|
|
}
|
|
return '等待扫码';
|
|
case _Phase.scanned:
|
|
return '请确认信息并提交';
|
|
case _Phase.submitted:
|
|
switch (_mode) {
|
|
case BoxingMode.one2many:
|
|
return '装箱成功,可继续添加或返回';
|
|
case BoxingMode.many2one:
|
|
return '请扫描下一个总排号';
|
|
case BoxingMode.one2one:
|
|
return '';
|
|
}
|
|
}
|
|
}
|
|
|
|
Color get _statusDotColor {
|
|
if (_isSubmitting) return Colors.orange;
|
|
if (_feedbackMessage != null) {
|
|
return _feedbackColor == Colors.red.shade700 ? Colors.red : Colors.green;
|
|
}
|
|
switch (_phase) {
|
|
case _Phase.waiting:
|
|
return Colors.blue;
|
|
case _Phase.scanned:
|
|
return Colors.green;
|
|
case _Phase.submitted:
|
|
return Colors.green;
|
|
}
|
|
}
|
|
|
|
// === Build ===
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final colorScheme = Theme.of(context).colorScheme;
|
|
final isWaiting = _phase == _Phase.waiting && _zongpaiNo == null;
|
|
final showActionButtons =
|
|
_phase == _Phase.submitted && _mode != BoxingMode.one2one;
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('装箱编号'),
|
|
actions: [
|
|
// 模式切换按钮
|
|
Padding(
|
|
padding: const EdgeInsets.only(right: 4),
|
|
child: TextButton.icon(
|
|
onPressed: _cycleMode,
|
|
icon: const Icon(Icons.swap_horiz, size: 18),
|
|
label: Text(
|
|
_modeLabel,
|
|
style: const TextStyle(fontSize: 13),
|
|
),
|
|
style: TextButton.styleFrom(
|
|
foregroundColor: _mode == BoxingMode.many2one
|
|
? Colors.orange
|
|
: colorScheme.primary,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
body: Column(
|
|
children: [
|
|
// 反馈提示条
|
|
if (_feedbackMessage != null)
|
|
Container(
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 16),
|
|
color: _feedbackColor,
|
|
child: Text(
|
|
_feedbackMessage!,
|
|
style: const TextStyle(color: Colors.white, fontSize: 14),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
),
|
|
|
|
// 重复箱号警告条
|
|
if (_isDuplicateBoxNo && _phase == _Phase.scanned)
|
|
Container(
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
|
|
color: Colors.amber.shade100,
|
|
child: Text(
|
|
'箱号 ${_boxNoController.text} 已存在,请重新输入',
|
|
style: TextStyle(color: Colors.amber.shade900, fontSize: 13),
|
|
),
|
|
),
|
|
|
|
// 主内容区
|
|
Expanded(
|
|
child: SingleChildScrollView(
|
|
padding: const EdgeInsets.all(12),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// === 扫码区 ===
|
|
_buildScanArea(isWaiting),
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
// === 信息区 ===
|
|
_buildInfoArea(isWaiting, colorScheme),
|
|
|
|
const Divider(height: 24),
|
|
|
|
// === 输入区 ===
|
|
_buildInputArea(isWaiting),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
|
|
// 操作按钮(一码多箱 / 多码一箱)
|
|
if (showActionButtons)
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: OutlinedButton(
|
|
onPressed: _onGoBack,
|
|
style: OutlinedButton.styleFrom(
|
|
minimumSize: const Size.fromHeight(40),
|
|
),
|
|
child: const Text('返回'),
|
|
),
|
|
),
|
|
if (_mode == BoxingMode.one2many) ...[
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: ElevatedButton(
|
|
onPressed: _onContinueAdding,
|
|
style: ElevatedButton.styleFrom(
|
|
minimumSize: const Size.fromHeight(40),
|
|
),
|
|
child: const Text('继续添加'),
|
|
),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
|
|
// 底部状态栏
|
|
Container(
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
|
|
color: colorScheme.surfaceContainerHighest,
|
|
child: Row(
|
|
children: [
|
|
Container(
|
|
width: 8,
|
|
height: 8,
|
|
decoration: BoxDecoration(
|
|
color: _statusDotColor,
|
|
shape: BoxShape.circle,
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
Expanded(
|
|
child: Text(
|
|
_statusText,
|
|
style: const TextStyle(fontSize: 14),
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
// === 扫码区 Widget ===
|
|
|
|
Widget _buildScanArea(bool isWaiting) {
|
|
if (isWaiting) {
|
|
// 等待扫码:置灰提示
|
|
return Container(
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.all(16),
|
|
decoration: BoxDecoration(
|
|
color: Colors.grey.shade100,
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: const Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(Icons.qr_code_scanner, color: Colors.grey, size: 20),
|
|
SizedBox(width: 8),
|
|
Text(
|
|
'请扫描执行卡二维码',
|
|
style: TextStyle(color: Colors.grey, fontSize: 14),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
// 已扫码:显示总排号
|
|
if (_mode == BoxingMode.many2one && _scannedZongpais.isNotEmpty) {
|
|
// 多码一箱:显示已扫描列表
|
|
return Wrap(
|
|
spacing: 6,
|
|
runSpacing: 4,
|
|
children: _scannedZongpais.map((zp) {
|
|
final isCurrent = zp == _zongpaiNo;
|
|
return Chip(
|
|
avatar: Icon(
|
|
Icons.check_circle,
|
|
size: 16,
|
|
color: isCurrent ? Colors.green : Colors.grey,
|
|
),
|
|
label: Text(zp, style: const TextStyle(fontSize: 13)),
|
|
visualDensity: VisualDensity.compact,
|
|
);
|
|
}).toList(),
|
|
);
|
|
}
|
|
|
|
// 单个总排号
|
|
return Container(
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
|
|
decoration: BoxDecoration(
|
|
border: Border.all(color: Colors.green, width: 2),
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
const Icon(Icons.check_circle, color: Colors.green, size: 18),
|
|
const SizedBox(width: 8),
|
|
Text(
|
|
_zongpaiNo ?? '',
|
|
style: const TextStyle(
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.black87,
|
|
),
|
|
),
|
|
const Spacer(),
|
|
const Text(
|
|
'已识别',
|
|
style: TextStyle(fontSize: 12, color: Colors.green),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
// === 信息区 Widget ===
|
|
|
|
Widget _buildInfoArea(bool isWaiting, ColorScheme colorScheme) {
|
|
final grey = isWaiting;
|
|
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// 排产号
|
|
Text(
|
|
'排产号:',
|
|
style: TextStyle(
|
|
fontSize: 13,
|
|
color: grey ? Colors.grey : Colors.black54,
|
|
),
|
|
),
|
|
const SizedBox(height: 2),
|
|
Text(
|
|
_paichanNo ?? '--',
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
color: grey ? Colors.grey : Colors.black87,
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
|
|
// 已有箱数 + 最大箱号 + 详情按钮
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Row(
|
|
children: [
|
|
Text(
|
|
'已有箱数:',
|
|
style: TextStyle(
|
|
fontSize: 13,
|
|
color: grey ? Colors.grey : Colors.black54,
|
|
),
|
|
),
|
|
Text(
|
|
grey ? '--' : '${_existingBoxes.length}箱',
|
|
style: TextStyle(
|
|
fontSize: 13,
|
|
fontWeight: FontWeight.w600,
|
|
color: grey ? Colors.grey : Colors.black87,
|
|
),
|
|
),
|
|
const SizedBox(width: 16),
|
|
Text(
|
|
'最大箱号:',
|
|
style: TextStyle(
|
|
fontSize: 13,
|
|
color: grey ? Colors.grey : Colors.black54,
|
|
),
|
|
),
|
|
Text(
|
|
grey ? '--' : '$_maxBoxNo',
|
|
style: TextStyle(
|
|
fontSize: 13,
|
|
fontWeight: FontWeight.w600,
|
|
color: _maxBoxNo > 0 ? Colors.amber.shade800 : Colors.grey,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
TextButton(
|
|
onPressed: grey || _existingBoxes.isEmpty ? null : _openDetail,
|
|
style: TextButton.styleFrom(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
|
minimumSize: Size.zero,
|
|
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
),
|
|
child: Text(
|
|
'详情 →',
|
|
style: TextStyle(
|
|
fontSize: 13,
|
|
color: grey || _existingBoxes.isEmpty
|
|
? Colors.grey.shade400
|
|
: colorScheme.primary,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
// === 输入区 Widget ===
|
|
|
|
Widget _buildInputArea(bool isWaiting) {
|
|
final enabled = !isWaiting && _phase == _Phase.scanned;
|
|
|
|
return Row(
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
// 箱号输入
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'箱号',
|
|
style: TextStyle(
|
|
fontSize: 13,
|
|
color: enabled ? Colors.black54 : Colors.grey,
|
|
),
|
|
),
|
|
const SizedBox(height: 4),
|
|
SizedBox(
|
|
height: 40,
|
|
child: TextField(
|
|
controller: _boxNoController,
|
|
focusNode: _boxNoFocusNode,
|
|
enabled: enabled && !_boxNoLocked,
|
|
keyboardType: TextInputType.number,
|
|
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
|
|
onChanged: (_) => _checkDuplicateBoxNo(),
|
|
decoration: InputDecoration(
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 10),
|
|
border: const OutlineInputBorder(),
|
|
enabledBorder: OutlineInputBorder(
|
|
borderSide: BorderSide(
|
|
color: _isDuplicateBoxNo
|
|
? Colors.amber
|
|
: Colors.grey.shade400,
|
|
),
|
|
),
|
|
suffixIcon: _boxNoLocked
|
|
? const Icon(Icons.lock, size: 18, color: Colors.orange)
|
|
: null,
|
|
),
|
|
style: const TextStyle(fontSize: 16),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
|
|
// 数量输入
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'数量',
|
|
style: TextStyle(
|
|
fontSize: 13,
|
|
color: enabled ? Colors.black54 : Colors.grey,
|
|
),
|
|
),
|
|
const SizedBox(height: 4),
|
|
SizedBox(
|
|
height: 40,
|
|
child: TextField(
|
|
controller: _quantityController,
|
|
focusNode: _quantityFocusNode,
|
|
enabled: enabled,
|
|
keyboardType: TextInputType.number,
|
|
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
|
|
decoration: const InputDecoration(
|
|
contentPadding: EdgeInsets.symmetric(horizontal: 10),
|
|
border: OutlineInputBorder(),
|
|
),
|
|
style: const TextStyle(fontSize: 16),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
|
|
// 确认按钮
|
|
SizedBox(
|
|
height: 40,
|
|
child: ElevatedButton(
|
|
onPressed: _canSubmit ? _submit : null,
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor:
|
|
_canSubmit ? Theme.of(context).colorScheme.primary : Colors.grey.shade300,
|
|
foregroundColor: _canSubmit ? Colors.white : Colors.grey.shade600,
|
|
),
|
|
child: _isSubmitting
|
|
? const SizedBox(
|
|
width: 18,
|
|
height: 18,
|
|
child: CircularProgressIndicator(
|
|
strokeWidth: 2,
|
|
color: Colors.white,
|
|
),
|
|
)
|
|
: const Text('确认', style: TextStyle(fontSize: 15)),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|