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>
113 lines
3.2 KiB
Dart
113 lines
3.2 KiB
Dart
// ignore_for_file: invalid_use_of_protected_member, unnecessary_this
|
|
|
|
part of '../../boxing_page.dart';
|
|
|
|
extension _BoxingMultiOpsPart on _BoxingPageState {
|
|
void _finishManyToOneBox() {
|
|
setState(() {
|
|
_manyToOnePackedItems.clear();
|
|
_editingPackedItemId = null;
|
|
_editingPackedQuantity = '';
|
|
_deletingPackedItemId = null;
|
|
_zongpaiNo = null;
|
|
_phase = BoxingPhase.waiting;
|
|
_quantityController.clear();
|
|
_boxNoController.text = (_maxBoxNo + 1).toString();
|
|
_statusOverrideText = null;
|
|
_statusOverrideDot = null;
|
|
});
|
|
}
|
|
|
|
void _startEditPackedItem(ManyToOnePackedItem item) {
|
|
setState(() {
|
|
_editingPackedItemId = item.boxItemId;
|
|
_editingPackedQuantity = item.quantity.toString();
|
|
_deletingPackedItemId = null;
|
|
});
|
|
}
|
|
|
|
void _cancelEditPackedItem() {
|
|
setState(() {
|
|
_editingPackedItemId = null;
|
|
_editingPackedQuantity = '';
|
|
});
|
|
}
|
|
|
|
Future<void> _savePackedItem(ManyToOnePackedItem item) async {
|
|
final quantity = int.tryParse(_editingPackedQuantity);
|
|
final boxNo = int.tryParse(_boxNoController.text.trim());
|
|
if (quantity == null || quantity <= 0 || boxNo == null || boxNo <= 0) {
|
|
this._showStatusOverride(
|
|
'请输入有效箱号和数量',
|
|
StatusDotColor.red,
|
|
const Duration(seconds: 2),
|
|
);
|
|
return;
|
|
}
|
|
|
|
setState(() => _isSubmitting = true);
|
|
final action = await _apiActions.updateBoxRecord(
|
|
boxItemId: item.boxItemId,
|
|
boxNo: boxNo,
|
|
quantity: quantity,
|
|
);
|
|
if (!mounted) return;
|
|
|
|
setState(() => _isSubmitting = false);
|
|
if (action.success) {
|
|
setState(() {
|
|
final index = _manyToOnePackedItems.indexWhere(
|
|
(packed) => packed.boxItemId == item.boxItemId,
|
|
);
|
|
if (index >= 0) {
|
|
_manyToOnePackedItems[index] = _manyToOnePackedItems[index].copyWith(
|
|
boxNo: boxNo,
|
|
quantity: quantity,
|
|
);
|
|
}
|
|
this._replaceExistingPackedItem(item, boxNo, quantity);
|
|
_editingPackedItemId = null;
|
|
_editingPackedQuantity = '';
|
|
});
|
|
this._showStatusOverride(
|
|
'修改成功',
|
|
StatusDotColor.green,
|
|
const Duration(milliseconds: 1500),
|
|
);
|
|
} else {
|
|
this._showActionError(action, fallback: '修改失败');
|
|
}
|
|
}
|
|
|
|
Future<void> _deletePackedItem(ManyToOnePackedItem item) async {
|
|
setState(() => _isSubmitting = true);
|
|
final action = await _apiActions.deleteBoxRecord(boxItemId: item.boxItemId);
|
|
if (!mounted) return;
|
|
|
|
setState(() {
|
|
_isSubmitting = false;
|
|
if (action.success) {
|
|
_manyToOnePackedItems.removeWhere(
|
|
(packed) => packed.boxItemId == item.boxItemId,
|
|
);
|
|
this._removeExistingBoxItem(item.boxItemId);
|
|
if (_editingPackedItemId == item.boxItemId) {
|
|
_editingPackedItemId = null;
|
|
_editingPackedQuantity = '';
|
|
}
|
|
_deletingPackedItemId = null;
|
|
}
|
|
});
|
|
|
|
if (action.success) {
|
|
this._showStatusOverride(
|
|
'删除成功',
|
|
StatusDotColor.green,
|
|
const Duration(milliseconds: 1500),
|
|
);
|
|
} else {
|
|
this._showActionError(action, fallback: '删除失败');
|
|
}
|
|
}
|
|
}
|