Extract large methods from _BoxingPageState into 6 part files: - boxing_scan_part.dart: scan handling and auto-scan processing - boxing_submit_part.dart: submit/update/delete API calls - boxing_box_mutation_part.dart: box item mutations - boxing_single_ops_part.dart: single-code boxing operations - boxing_multi_ops_part.dart: multi-code boxing operations - boxing_status_part.dart: status bar management Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
162 lines
4.8 KiB
Dart
162 lines
4.8 KiB
Dart
// ignore_for_file: invalid_use_of_protected_member, unnecessary_this
|
|
|
|
part of '../../boxing_page.dart';
|
|
|
|
extension _BoxingSubmitPart on _BoxingPageState {
|
|
Future<bool> _submit() async {
|
|
if (!_canSubmit) return false;
|
|
|
|
final boxNo = int.parse(_boxNoController.text);
|
|
final quantity = int.parse(_quantityController.text);
|
|
|
|
setState(() => _isSubmitting = true);
|
|
|
|
final editing = _editingBox;
|
|
final action = editing == null
|
|
? await _apiActions.saveBoxRecord(
|
|
zongpaiNo: _zongpaiNo!,
|
|
boxNo: boxNo,
|
|
quantity: quantity,
|
|
)
|
|
: await _apiActions.updateBoxRecord(
|
|
boxItemId: editing.boxItemId,
|
|
boxNo: boxNo,
|
|
quantity: quantity,
|
|
);
|
|
|
|
if (!mounted) return false;
|
|
|
|
setState(() => _isSubmitting = false);
|
|
|
|
if (action.success) {
|
|
if (editing == null) {
|
|
this._onSubmitSuccess(boxNo, quantity, action.data!.boxItemId);
|
|
} else {
|
|
this._onUpdateSuccess(editing, boxNo, quantity);
|
|
}
|
|
return true;
|
|
} else if (action.errorKind == BoxingActionErrorKind.duplicate) {
|
|
_feedbackService.trigger(FeedbackEvent.duplicateBoxNo);
|
|
this._showStatusOverride(
|
|
'该总排号在箱号 ${action.boxNo ?? ""} 已存在,请重新输入',
|
|
StatusDotColor.amber,
|
|
const Duration(seconds: 2),
|
|
);
|
|
return false;
|
|
} else {
|
|
this._showActionError(action, fallback: '提交失败');
|
|
return false;
|
|
}
|
|
}
|
|
|
|
void _onSubmitSuccess(int boxNo, int quantity, int? boxItemId) {
|
|
_feedbackService.trigger(FeedbackEvent.submitSuccess);
|
|
|
|
setState(() {
|
|
if (_mode == BoxingMode.singleCode && boxItemId != null) {
|
|
_currentZongpaiBoxes = List.from(_currentZongpaiBoxes)
|
|
..add(
|
|
CurrentZongpaiBoxData(
|
|
boxItemId: boxItemId,
|
|
boxNo: boxNo,
|
|
quantity: quantity,
|
|
),
|
|
);
|
|
}
|
|
this._addExistingBoxItem(boxNo, quantity, boxItemId);
|
|
_maxBoxNo = _maxBoxNo > boxNo ? _maxBoxNo : boxNo;
|
|
});
|
|
|
|
switch (_mode) {
|
|
case BoxingMode.singleCode:
|
|
final remaining = _remainingQuantity;
|
|
if (remaining <= 0) {
|
|
this._showStatusOverride(
|
|
'装箱成功',
|
|
StatusDotColor.green,
|
|
const Duration(milliseconds: 1500),
|
|
);
|
|
} else {
|
|
setState(() {
|
|
_phase = BoxingPhase.scanned;
|
|
_boxNoController.text = (_maxBoxNo + 1).toString();
|
|
_quantityController.text = remaining.toString();
|
|
_quantityController.selection = TextSelection(
|
|
baseOffset: 0,
|
|
extentOffset: _quantityController.text.length,
|
|
);
|
|
_isDuplicateBoxNo = false;
|
|
});
|
|
_focusQuantityInput();
|
|
this._showStatusOverride(
|
|
'请继续完成剩余数量装箱',
|
|
StatusDotColor.green,
|
|
const Duration(milliseconds: 1500),
|
|
);
|
|
}
|
|
|
|
case BoxingMode.multiCode:
|
|
_lastScannedPaichanNo = _paichanNo;
|
|
setState(() {
|
|
if (boxItemId != null) {
|
|
_manyToOnePackedItems.add(
|
|
ManyToOnePackedItem(
|
|
boxItemId: boxItemId,
|
|
zongpaiNo: _zongpaiNo!,
|
|
paichanNo: _paichanNo,
|
|
workOrderNo: _workOrderNo,
|
|
boxNo: boxNo,
|
|
quantity: quantity,
|
|
totalQuantity: _erpQuantity,
|
|
),
|
|
);
|
|
}
|
|
_phase = BoxingPhase.waiting;
|
|
_zongpaiNo = null;
|
|
_editingPackedItemId = null;
|
|
_editingPackedQuantity = '';
|
|
_deletingPackedItemId = null;
|
|
});
|
|
this._showStatusOverride(
|
|
'装箱成功,请继续扫码',
|
|
StatusDotColor.green,
|
|
const Duration(milliseconds: 1500),
|
|
);
|
|
}
|
|
}
|
|
|
|
void _onUpdateSuccess(
|
|
CurrentZongpaiBoxData editing,
|
|
int boxNo,
|
|
int quantity,
|
|
) {
|
|
_feedbackService.trigger(FeedbackEvent.submitSuccess);
|
|
|
|
setState(() {
|
|
_currentZongpaiBoxes = _currentZongpaiBoxes.map((item) {
|
|
if (item.boxItemId != editing.boxItemId) return item;
|
|
return CurrentZongpaiBoxData(
|
|
boxItemId: item.boxItemId,
|
|
boxNo: boxNo,
|
|
quantity: quantity,
|
|
);
|
|
}).toList();
|
|
this._replaceExistingBoxItem(editing, boxNo, quantity);
|
|
_editingBox = null;
|
|
_boxNoController.text = (_maxBoxNo + 1).toString();
|
|
final remaining = _remainingQuantity;
|
|
if (remaining > 0) {
|
|
_quantityController.text = remaining.toString();
|
|
} else {
|
|
_quantityController.clear();
|
|
}
|
|
_isDuplicateBoxNo = false;
|
|
});
|
|
this._showStatusOverride(
|
|
'修改成功',
|
|
StatusDotColor.green,
|
|
const Duration(milliseconds: 1500),
|
|
);
|
|
}
|
|
}
|