// ignore_for_file: invalid_use_of_protected_member, unnecessary_this part of '../../boxing_page.dart'; extension _BoxingSingleOpsPart on _BoxingPageState { void _startEditAssigned(CurrentZongpaiBoxData item) { setState(() { _editingAssignedItemId = item.boxItemId; _editingAssignedQuantity = item.quantity.toString(); _deletingAssignedItemId = null; _statusOverrideText = null; _statusOverrideDot = null; }); } void _cancelEditAssigned() { setState(() { _editingAssignedItemId = null; _editingAssignedQuantity = ''; }); } int _maxAssignedQuantity(CurrentZongpaiBoxData item) { return boxing_calculations.maxAssignedQuantity( totalQuantity: _erpQuantity, packedQuantity: _packedQuantity, itemQuantity: item.quantity, ); } void _refreshSingleCodeNewInput({bool focusQuantity = true}) { _boxNoController.text = (_maxBoxNo + 1).toString(); final remaining = _remainingQuantity; if (remaining > 0) { _quantityController.text = remaining.toString(); _quantityController.selection = TextSelection( baseOffset: 0, extentOffset: _quantityController.text.length, ); if (focusQuantity) { _focusQuantityInput(); } } else { _quantityController.clear(); } _isDuplicateBoxNo = false; } Future _saveAssignedItem(CurrentZongpaiBoxData item) async { final quantity = int.tryParse(_editingAssignedQuantity); if (quantity == null || quantity <= 0) { this._showStatusOverride( '请输入有效数量', StatusDotColor.red, const Duration(seconds: 2), ); return; } if (quantity > this._maxAssignedQuantity(item)) { this._showStatusOverride( '超出可装数量上限', StatusDotColor.red, const Duration(seconds: 2), ); return; } setState(() => _isSubmitting = true); final action = await _apiActions.updateBoxRecord( boxItemId: item.boxItemId, boxNo: item.boxNo, quantity: quantity, ); if (!mounted) return; setState(() => _isSubmitting = false); if (action.success) { setState(() { _currentZongpaiBoxes = _currentZongpaiBoxes.map((box) { if (box.boxItemId != item.boxItemId) return box; return CurrentZongpaiBoxData( boxItemId: box.boxItemId, boxNo: box.boxNo, quantity: quantity, ); }).toList(); this._replaceExistingBoxItem(item, item.boxNo, quantity); _editingAssignedItemId = null; _editingAssignedQuantity = ''; this._refreshSingleCodeNewInput(); }); this._showStatusOverride( '修改成功', StatusDotColor.green, const Duration(milliseconds: 1500), ); } else { this._showActionError(action, fallback: '修改失败'); } } Future _deleteAssignedItem(CurrentZongpaiBoxData item) async { setState(() => _isSubmitting = true); final action = await _apiActions.deleteBoxRecord(boxItemId: item.boxItemId); if (!mounted) return; setState(() { _isSubmitting = false; if (action.success) { _currentZongpaiBoxes = _currentZongpaiBoxes .where((box) => box.boxItemId != item.boxItemId) .toList(); this._removeExistingBoxItem(item.boxItemId); if (_editingAssignedItemId == item.boxItemId) { _editingAssignedItemId = null; _editingAssignedQuantity = ''; } _deletingAssignedItemId = null; this._refreshSingleCodeNewInput(); } }); if (action.success) { this._showStatusOverride( '删除成功', StatusDotColor.green, const Duration(milliseconds: 1500), ); } else { this._showActionError(action, fallback: '删除失败'); } } }