feat: handle off-shelf registration results
This commit is contained in:
@@ -49,8 +49,7 @@ class _RegistrationPageState extends State<RegistrationPage> {
|
||||
}
|
||||
|
||||
void _onKeyEvent(KeyEvent event) {
|
||||
if (event is KeyDownEvent &&
|
||||
event.logicalKey == LogicalKeyboardKey.enter) {
|
||||
if (event is KeyDownEvent && event.logicalKey == LogicalKeyboardKey.enter) {
|
||||
_submit();
|
||||
}
|
||||
}
|
||||
@@ -195,11 +194,24 @@ class _RegistrationPageState extends State<RegistrationPage> {
|
||||
_locationType = null;
|
||||
}
|
||||
});
|
||||
final msg = _isLocked ? '货位已锁定,请扫描下一张执行卡' : '上架成功';
|
||||
_showStatusOverride(msg, StatusDotColor.green, const Duration(milliseconds: 1500));
|
||||
final msg = result.isOffShelfSuccess
|
||||
? '下架成功'
|
||||
: (_isLocked ? '货位已锁定,请扫描下一张执行卡' : '上架成功');
|
||||
_showStatusOverride(
|
||||
msg,
|
||||
StatusDotColor.green,
|
||||
const Duration(milliseconds: 1500),
|
||||
);
|
||||
} else if (result.isDuplicate) {
|
||||
_feedbackService.trigger(FeedbackEvent.duplicateError);
|
||||
_showDuplicateDialog(zongpaiNo, result.duplicateInfo);
|
||||
} else if (result.isAlreadyOffShelf) {
|
||||
_feedbackService.trigger(FeedbackEvent.submitFailure);
|
||||
_showStatusOverride(
|
||||
result.errorMessage ?? '该总排号已下架至转运区域,不可重新上架',
|
||||
StatusDotColor.red,
|
||||
const Duration(seconds: 2),
|
||||
);
|
||||
} else {
|
||||
final isNetwork = result.errorMessage == '网络异常,请检查网络连接';
|
||||
_feedbackService.trigger(
|
||||
@@ -215,6 +227,7 @@ class _RegistrationPageState extends State<RegistrationPage> {
|
||||
|
||||
Future<void> _submitBatch(String baseUrl) async {
|
||||
int successCount = 0;
|
||||
int offShelfCount = 0;
|
||||
final failed = <String>[];
|
||||
final toRemove = <String>[];
|
||||
|
||||
@@ -226,6 +239,9 @@ class _RegistrationPageState extends State<RegistrationPage> {
|
||||
);
|
||||
if (result.success) {
|
||||
successCount++;
|
||||
if (result.isOffShelfSuccess) {
|
||||
offShelfCount++;
|
||||
}
|
||||
toRemove.add(zp);
|
||||
} else {
|
||||
failed.add(zp);
|
||||
@@ -238,6 +254,19 @@ class _RegistrationPageState extends State<RegistrationPage> {
|
||||
_showDuplicateDialog(zp, result.duplicateInfo);
|
||||
return;
|
||||
}
|
||||
if (result.isAlreadyOffShelf) {
|
||||
setState(() {
|
||||
_zongpaiNos.removeWhere((e) => toRemove.contains(e));
|
||||
_isSubmitting = false;
|
||||
});
|
||||
_feedbackService.trigger(FeedbackEvent.submitFailure);
|
||||
_showStatusOverride(
|
||||
result.errorMessage ?? '该总排号已下架至转运区域,不可重新上架',
|
||||
StatusDotColor.red,
|
||||
const Duration(seconds: 2),
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,8 +279,11 @@ class _RegistrationPageState extends State<RegistrationPage> {
|
||||
|
||||
if (failed.isEmpty) {
|
||||
_feedbackService.trigger(FeedbackEvent.submitSuccess);
|
||||
final msg = offShelfCount == successCount
|
||||
? '批量下架成功($successCount 条)'
|
||||
: '批量上架成功($successCount 条)';
|
||||
_showStatusOverride(
|
||||
'批量上架成功($successCount 条)',
|
||||
msg,
|
||||
StatusDotColor.green,
|
||||
const Duration(milliseconds: 1500),
|
||||
);
|
||||
@@ -492,7 +524,9 @@ class _RegistrationPageState extends State<RegistrationPage> {
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(14),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.grey.shade400),
|
||||
border: Border.all(
|
||||
color: Colors.grey.shade400,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: const Text(
|
||||
@@ -509,7 +543,9 @@ class _RegistrationPageState extends State<RegistrationPage> {
|
||||
const SizedBox(height: 6),
|
||||
itemBuilder: (context, index) {
|
||||
return Dismissible(
|
||||
key: ValueKey('${_zongpaiNos[index]}-$index'),
|
||||
key: ValueKey(
|
||||
'${_zongpaiNos[index]}-$index',
|
||||
),
|
||||
direction: DismissDirection.endToStart,
|
||||
onDismissed: (_) => _removeZongpai(index),
|
||||
background: Container(
|
||||
|
||||
@@ -5,23 +5,41 @@ import 'package:http/http.dart' as http;
|
||||
class RegistrationResult {
|
||||
final bool success;
|
||||
final bool isDuplicate;
|
||||
final bool isAlreadyOffShelf;
|
||||
final bool isOffShelfSuccess;
|
||||
final String? errorMessage;
|
||||
final Map<String, dynamic>? duplicateInfo;
|
||||
final Map<String, dynamic>? conflictInfo;
|
||||
|
||||
RegistrationResult({
|
||||
required this.success,
|
||||
this.isDuplicate = false,
|
||||
this.isAlreadyOffShelf = false,
|
||||
this.isOffShelfSuccess = false,
|
||||
this.errorMessage,
|
||||
this.duplicateInfo,
|
||||
this.conflictInfo,
|
||||
});
|
||||
|
||||
factory RegistrationResult.ok() => RegistrationResult(success: true);
|
||||
|
||||
factory RegistrationResult.offShelfSuccess() =>
|
||||
RegistrationResult(success: true, isOffShelfSuccess: true);
|
||||
|
||||
factory RegistrationResult.duplicate(Map<String, dynamic> info) =>
|
||||
RegistrationResult(
|
||||
success: false,
|
||||
isDuplicate: true,
|
||||
duplicateInfo: info,
|
||||
conflictInfo: info,
|
||||
);
|
||||
|
||||
factory RegistrationResult.alreadyOffShelf(Map<String, dynamic> info) =>
|
||||
RegistrationResult(
|
||||
success: false,
|
||||
isAlreadyOffShelf: true,
|
||||
errorMessage: info['message']?.toString() ?? '该总排号已下架至转运区域,不可重新上架',
|
||||
conflictInfo: info,
|
||||
);
|
||||
|
||||
factory RegistrationResult.error(String message) =>
|
||||
@@ -228,6 +246,10 @@ class ApiService {
|
||||
|
||||
switch (response.statusCode) {
|
||||
case 200:
|
||||
final body = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
if (body['previous_location'] != null) {
|
||||
return RegistrationResult.offShelfSuccess();
|
||||
}
|
||||
return RegistrationResult.ok();
|
||||
case 400:
|
||||
final body = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
@@ -235,7 +257,15 @@ class ApiService {
|
||||
return RegistrationResult.error(msg);
|
||||
case 409:
|
||||
final body = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
return RegistrationResult.duplicate(body);
|
||||
final errorCode = body['error_code']?.toString();
|
||||
if (errorCode == 'DUPLICATE_LOCATION') {
|
||||
return RegistrationResult.duplicate(body);
|
||||
}
|
||||
if (errorCode == 'ALREADY_OFF_SHELF') {
|
||||
return RegistrationResult.alreadyOffShelf(body);
|
||||
}
|
||||
final msg = body['message']?.toString() ?? '提交失败';
|
||||
return RegistrationResult.error(msg);
|
||||
default:
|
||||
final body = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
final msg =
|
||||
|
||||
Reference in New Issue
Block a user