Compare commits
4 Commits
99ed3bb9ec
...
9dc714dbeb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9dc714dbeb | ||
|
|
1416cff52c | ||
|
|
12cab16888 | ||
|
|
9aa5d86fde |
1157
lib/pages/accessory_page.dart
Normal file
1157
lib/pages/accessory_page.dart
Normal file
File diff suppressed because it is too large
Load Diff
@@ -65,6 +65,8 @@ class BoxingApiActions {
|
|||||||
required String zongpaiNo,
|
required String zongpaiNo,
|
||||||
required int boxNo,
|
required int boxNo,
|
||||||
required int quantity,
|
required int quantity,
|
||||||
|
String itemType = 'product',
|
||||||
|
int? accessoryId,
|
||||||
}) async {
|
}) async {
|
||||||
final baseUrl = await _requireBaseUrl();
|
final baseUrl = await _requireBaseUrl();
|
||||||
if (baseUrl == null) return _missingApiUrl();
|
if (baseUrl == null) return _missingApiUrl();
|
||||||
@@ -74,6 +76,8 @@ class BoxingApiActions {
|
|||||||
zongpaiNo: zongpaiNo,
|
zongpaiNo: zongpaiNo,
|
||||||
boxNo: boxNo,
|
boxNo: boxNo,
|
||||||
quantity: quantity,
|
quantity: quantity,
|
||||||
|
itemType: itemType,
|
||||||
|
accessoryId: accessoryId,
|
||||||
);
|
);
|
||||||
return _saveResult(result, fallbackMessage: '提交失败');
|
return _saveResult(result, fallbackMessage: '提交失败');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ extension _BoxingScanPart on _BoxingPageState {
|
|||||||
_currentZongpaiBoxes = result.currentZongpaiBoxes;
|
_currentZongpaiBoxes = result.currentZongpaiBoxes;
|
||||||
_existingBoxes = result.existingBoxes;
|
_existingBoxes = result.existingBoxes;
|
||||||
_maxBoxNo = result.maxBoxNo;
|
_maxBoxNo = result.maxBoxNo;
|
||||||
|
_pendingAccessories = result.pendingAccessories;
|
||||||
_phase = BoxingPhase.scanned;
|
_phase = BoxingPhase.scanned;
|
||||||
_isDuplicateBoxNo = false;
|
_isDuplicateBoxNo = false;
|
||||||
_editingBox = null;
|
_editingBox = null;
|
||||||
|
|||||||
@@ -158,4 +158,47 @@ extension _BoxingSubmitPart on _BoxingPageState {
|
|||||||
const Duration(milliseconds: 1500),
|
const Duration(milliseconds: 1500),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _submitAccessory(PendingAccessory accessory) async {
|
||||||
|
if (_zongpaiNo == null || _isSubmitting) return;
|
||||||
|
|
||||||
|
final boxNo = int.tryParse(_boxNoController.text);
|
||||||
|
if (boxNo == null || boxNo <= 0) {
|
||||||
|
this._showStatusOverride(
|
||||||
|
'请先输入有效箱号',
|
||||||
|
StatusDotColor.red,
|
||||||
|
const Duration(seconds: 2),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setState(() => _isSubmitting = true);
|
||||||
|
|
||||||
|
final action = await _apiActions.saveBoxRecord(
|
||||||
|
zongpaiNo: _zongpaiNo!,
|
||||||
|
boxNo: boxNo,
|
||||||
|
quantity: accessory.quantity,
|
||||||
|
itemType: 'accessory',
|
||||||
|
accessoryId: accessory.accessoryId,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!mounted) return;
|
||||||
|
|
||||||
|
setState(() => _isSubmitting = false);
|
||||||
|
|
||||||
|
if (action.success) {
|
||||||
|
_feedbackService.trigger(FeedbackEvent.submitSuccess);
|
||||||
|
// Refresh box info to update pending accessories
|
||||||
|
await this._queryBoxInfo(_zongpaiNo!);
|
||||||
|
if (mounted) {
|
||||||
|
this._showStatusOverride(
|
||||||
|
'${accessory.accessoryType} 已加入箱号 $boxNo',
|
||||||
|
StatusDotColor.green,
|
||||||
|
const Duration(milliseconds: 1500),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this._showActionError(action, fallback: '附件装箱失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ class MultiCodeBody extends StatelessWidget {
|
|||||||
final ValueChanged<ManyToOnePackedItem> onStartDeletePackedItem;
|
final ValueChanged<ManyToOnePackedItem> onStartDeletePackedItem;
|
||||||
final ValueChanged<ManyToOnePackedItem> onDeletePackedItem;
|
final ValueChanged<ManyToOnePackedItem> onDeletePackedItem;
|
||||||
final VoidCallback onCancelDeletePackedItem;
|
final VoidCallback onCancelDeletePackedItem;
|
||||||
|
final List<PendingAccessory> pendingAccessories;
|
||||||
|
final ValueChanged<PendingAccessory> onSubmitAccessory;
|
||||||
|
|
||||||
const MultiCodeBody({
|
const MultiCodeBody({
|
||||||
super.key,
|
super.key,
|
||||||
@@ -69,6 +71,8 @@ class MultiCodeBody extends StatelessWidget {
|
|||||||
required this.onStartDeletePackedItem,
|
required this.onStartDeletePackedItem,
|
||||||
required this.onDeletePackedItem,
|
required this.onDeletePackedItem,
|
||||||
required this.onCancelDeletePackedItem,
|
required this.onCancelDeletePackedItem,
|
||||||
|
required this.pendingAccessories,
|
||||||
|
required this.onSubmitAccessory,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -87,7 +91,7 @@ class MultiCodeBody extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
const _MultiListHeader(),
|
const _MultiListHeader(),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: visibleItems.isEmpty
|
child: visibleItems.isEmpty && pendingAccessories.isEmpty
|
||||||
? Center(
|
? Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
'尚未装入任何物料',
|
'尚未装入任何物料',
|
||||||
@@ -99,8 +103,9 @@ class MultiCodeBody extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
: ListView.builder(
|
: ListView.builder(
|
||||||
itemCount: visibleItems.length,
|
itemCount: visibleItems.length + pendingAccessories.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
|
if (index < visibleItems.length) {
|
||||||
final item = visibleItems[index];
|
final item = visibleItems[index];
|
||||||
return MultiPackedRow(
|
return MultiPackedRow(
|
||||||
item: item,
|
item: item,
|
||||||
@@ -108,7 +113,8 @@ class MultiCodeBody extends StatelessWidget {
|
|||||||
deleting: deletingPackedItemId == item.boxItemId,
|
deleting: deletingPackedItemId == item.boxItemId,
|
||||||
isSubmitting: isSubmitting,
|
isSubmitting: isSubmitting,
|
||||||
editingQuantity: editingPackedQuantity,
|
editingQuantity: editingPackedQuantity,
|
||||||
onEditingQuantityChanged: onEditingPackedQuantityChanged,
|
onEditingQuantityChanged:
|
||||||
|
onEditingPackedQuantityChanged,
|
||||||
onSave: () => onSavePackedItem(item),
|
onSave: () => onSavePackedItem(item),
|
||||||
onCancelEdit: onCancelEditPackedItem,
|
onCancelEdit: onCancelEditPackedItem,
|
||||||
onStartEdit: () => onStartEditPackedItem(item),
|
onStartEdit: () => onStartEditPackedItem(item),
|
||||||
@@ -116,6 +122,14 @@ class MultiCodeBody extends StatelessWidget {
|
|||||||
onDelete: () => onDeletePackedItem(item),
|
onDelete: () => onDeletePackedItem(item),
|
||||||
onCancelDelete: onCancelDeletePackedItem,
|
onCancelDelete: onCancelDeletePackedItem,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
final accIndex = index - visibleItems.length;
|
||||||
|
final acc = pendingAccessories[accIndex];
|
||||||
|
return _MultiAccessoryRow(
|
||||||
|
accessory: acc,
|
||||||
|
isSubmitting: isSubmitting,
|
||||||
|
onSubmit: () => onSubmitAccessory(acc),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -604,3 +618,72 @@ class _MultiSubmitRow extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _MultiAccessoryRow extends StatelessWidget {
|
||||||
|
final PendingAccessory accessory;
|
||||||
|
final bool isSubmitting;
|
||||||
|
final VoidCallback onSubmit;
|
||||||
|
|
||||||
|
const _MultiAccessoryRow({
|
||||||
|
required this.accessory,
|
||||||
|
required this.isSubmitting,
|
||||||
|
required this.onSubmit,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Container(
|
||||||
|
height: 40,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.orange.shade50,
|
||||||
|
border: Border(bottom: BorderSide(color: Colors.grey.shade200)),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Icon(Icons.build, size: 14, color: Colors.orange.shade600),
|
||||||
|
const SizedBox(width: 6),
|
||||||
|
Expanded(
|
||||||
|
flex: 40,
|
||||||
|
child: Text(
|
||||||
|
accessory.accessoryType,
|
||||||
|
style: const TextStyle(fontSize: 13, fontWeight: FontWeight.w500),
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
flex: 20,
|
||||||
|
child: Text(
|
||||||
|
'\u00d7${accessory.quantity}',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 13,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: Colors.grey.shade700,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: 28,
|
||||||
|
child: ElevatedButton(
|
||||||
|
onPressed: isSubmitting ? null : onSubmit,
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: isSubmitting
|
||||||
|
? Colors.grey.shade300
|
||||||
|
: Colors.orange.shade600,
|
||||||
|
foregroundColor: Colors.white,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(4),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: const Text(
|
||||||
|
'加入本箱',
|
||||||
|
style: TextStyle(fontSize: 11, fontWeight: FontWeight.w700),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ class SingleCodeBody extends StatelessWidget {
|
|||||||
final ValueChanged<CurrentZongpaiBoxData> onStartDeleteAssigned;
|
final ValueChanged<CurrentZongpaiBoxData> onStartDeleteAssigned;
|
||||||
final ValueChanged<CurrentZongpaiBoxData> onDeleteAssignedItem;
|
final ValueChanged<CurrentZongpaiBoxData> onDeleteAssignedItem;
|
||||||
final VoidCallback onCancelDeleteAssigned;
|
final VoidCallback onCancelDeleteAssigned;
|
||||||
|
final List<PendingAccessory> pendingAccessories;
|
||||||
|
final ValueChanged<PendingAccessory> onSubmitAccessory;
|
||||||
|
|
||||||
const SingleCodeBody({
|
const SingleCodeBody({
|
||||||
super.key,
|
super.key,
|
||||||
@@ -74,6 +76,8 @@ class SingleCodeBody extends StatelessWidget {
|
|||||||
required this.onStartDeleteAssigned,
|
required this.onStartDeleteAssigned,
|
||||||
required this.onDeleteAssignedItem,
|
required this.onDeleteAssignedItem,
|
||||||
required this.onCancelDeleteAssigned,
|
required this.onCancelDeleteAssigned,
|
||||||
|
required this.pendingAccessories,
|
||||||
|
required this.onSubmitAccessory,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -114,6 +118,12 @@ class SingleCodeBody extends StatelessWidget {
|
|||||||
onDeleteAssignedItem: onDeleteAssignedItem,
|
onDeleteAssignedItem: onDeleteAssignedItem,
|
||||||
onCancelDeleteAssigned: onCancelDeleteAssigned,
|
onCancelDeleteAssigned: onCancelDeleteAssigned,
|
||||||
),
|
),
|
||||||
|
if (pendingAccessories.isNotEmpty && !isWaiting)
|
||||||
|
_PendingAccessoriesSection(
|
||||||
|
pendingAccessories: pendingAccessories,
|
||||||
|
isSubmitting: isSubmitting,
|
||||||
|
onSubmitAccessory: onSubmitAccessory,
|
||||||
|
),
|
||||||
_SingleBottomArea(
|
_SingleBottomArea(
|
||||||
disabled: isWaiting || isFinished,
|
disabled: isWaiting || isFinished,
|
||||||
boxNoController: boxNoController,
|
boxNoController: boxNoController,
|
||||||
@@ -239,9 +249,7 @@ class _SingleInfoBar extends StatelessWidget {
|
|||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 22,
|
fontSize: 22,
|
||||||
fontWeight: FontWeight.w700,
|
fontWeight: FontWeight.w700,
|
||||||
color: isWaiting
|
color: isWaiting ? Colors.grey.shade400 : Colors.black87,
|
||||||
? Colors.grey.shade400
|
|
||||||
: Colors.black87,
|
|
||||||
),
|
),
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
@@ -252,9 +260,7 @@ class _SingleInfoBar extends StatelessWidget {
|
|||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
isWaiting
|
isWaiting ? '已有 -- 箱' : '已有 ${existingBoxes.length} 箱',
|
||||||
? '已有 -- 箱'
|
|
||||||
: '已有 ${existingBoxes.length} 箱',
|
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
color: isWaiting
|
color: isWaiting
|
||||||
@@ -263,9 +269,7 @@ class _SingleInfoBar extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
isWaiting
|
isWaiting ? '最大箱号 --' : '最大箱号 $maxBoxNo',
|
||||||
? '最大箱号 --'
|
|
||||||
: '最大箱号 $maxBoxNo',
|
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
color: isWaiting
|
color: isWaiting
|
||||||
@@ -576,3 +580,120 @@ class _SingleBottomArea extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _PendingAccessoriesSection extends StatelessWidget {
|
||||||
|
final List<PendingAccessory> pendingAccessories;
|
||||||
|
final bool isSubmitting;
|
||||||
|
final ValueChanged<PendingAccessory> onSubmitAccessory;
|
||||||
|
|
||||||
|
const _PendingAccessoriesSection({
|
||||||
|
required this.pendingAccessories,
|
||||||
|
required this.isSubmitting,
|
||||||
|
required this.onSubmitAccessory,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
height: 28,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.orange.shade50,
|
||||||
|
border: Border(bottom: BorderSide(color: Colors.orange.shade200)),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Icon(Icons.build, size: 14, color: Colors.orange.shade700),
|
||||||
|
const SizedBox(width: 6),
|
||||||
|
Text(
|
||||||
|
'待装箱附件(${pendingAccessories.length} 项)',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 11,
|
||||||
|
fontWeight: FontWeight.w700,
|
||||||
|
color: Colors.orange.shade800,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
...pendingAccessories.map(
|
||||||
|
(acc) => _AccessoryRow(
|
||||||
|
accessory: acc,
|
||||||
|
isSubmitting: isSubmitting,
|
||||||
|
onSubmit: () => onSubmitAccessory(acc),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _AccessoryRow extends StatelessWidget {
|
||||||
|
final PendingAccessory accessory;
|
||||||
|
final bool isSubmitting;
|
||||||
|
final VoidCallback onSubmit;
|
||||||
|
|
||||||
|
const _AccessoryRow({
|
||||||
|
required this.accessory,
|
||||||
|
required this.isSubmitting,
|
||||||
|
required this.onSubmit,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Container(
|
||||||
|
height: 36,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.orange.shade50,
|
||||||
|
border: Border(bottom: BorderSide(color: Colors.grey.shade200)),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
flex: 40,
|
||||||
|
child: Text(
|
||||||
|
accessory.accessoryType,
|
||||||
|
style: const TextStyle(fontSize: 13, fontWeight: FontWeight.w500),
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
flex: 20,
|
||||||
|
child: Text(
|
||||||
|
'\u00d7${accessory.quantity}',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 13,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: Colors.grey.shade700,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: 28,
|
||||||
|
child: ElevatedButton(
|
||||||
|
onPressed: isSubmitting ? null : onSubmit,
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: isSubmitting
|
||||||
|
? Colors.grey.shade300
|
||||||
|
: Colors.orange.shade600,
|
||||||
|
foregroundColor: Colors.white,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(4),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: const Text(
|
||||||
|
'加入本箱',
|
||||||
|
style: TextStyle(fontSize: 11, fontWeight: FontWeight.w700),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -103,15 +103,40 @@ class BoxingDetailPage extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: box.items.map((item) {
|
children: box.items.map((item) {
|
||||||
return Padding(
|
final isAccessory = item.itemType == 'accessory';
|
||||||
padding: const EdgeInsets.symmetric(vertical: 2),
|
return Container(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
vertical: 4,
|
||||||
|
horizontal: 4,
|
||||||
|
),
|
||||||
|
margin: const EdgeInsets.symmetric(vertical: 1),
|
||||||
|
decoration: isAccessory
|
||||||
|
? BoxDecoration(
|
||||||
|
color: Colors.orange.shade50,
|
||||||
|
borderRadius: BorderRadius.circular(4),
|
||||||
|
)
|
||||||
|
: null,
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
|
if (isAccessory)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(right: 6),
|
||||||
|
child: Icon(
|
||||||
|
Icons.build,
|
||||||
|
size: 14,
|
||||||
|
color: Colors.orange.shade700,
|
||||||
|
),
|
||||||
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
flex: 3,
|
flex: 3,
|
||||||
child: Text(
|
child: Text(
|
||||||
item.zongpaiNo,
|
item.zongpaiNo,
|
||||||
style: const TextStyle(fontSize: 14),
|
style: TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: isAccessory
|
||||||
|
? FontWeight.w600
|
||||||
|
: FontWeight.normal,
|
||||||
|
),
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -107,6 +107,9 @@ class _BoxingPageState extends State<BoxingPage> with WidgetsBindingObserver {
|
|||||||
// 多码凑箱:已完成装箱时可跳转的箱号
|
// 多码凑箱:已完成装箱时可跳转的箱号
|
||||||
int? _completedJumpBoxNo;
|
int? _completedJumpBoxNo;
|
||||||
|
|
||||||
|
// 待装箱附件
|
||||||
|
List<PendingAccessory> _pendingAccessories = [];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@@ -244,6 +247,7 @@ class _BoxingPageState extends State<BoxingPage> with WidgetsBindingObserver {
|
|||||||
_isDuplicateBoxNo = false;
|
_isDuplicateBoxNo = false;
|
||||||
_statusOverrideText = null;
|
_statusOverrideText = null;
|
||||||
_statusOverrideDot = null;
|
_statusOverrideDot = null;
|
||||||
|
_pendingAccessories = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// === 重复箱号检测 ===
|
// === 重复箱号检测 ===
|
||||||
@@ -415,6 +419,9 @@ class _BoxingPageState extends State<BoxingPage> with WidgetsBindingObserver {
|
|||||||
this._deletePackedItem(item),
|
this._deletePackedItem(item),
|
||||||
onCancelDeletePackedItem: () =>
|
onCancelDeletePackedItem: () =>
|
||||||
setState(() => _deletingPackedItemId = null),
|
setState(() => _deletingPackedItemId = null),
|
||||||
|
pendingAccessories: _pendingAccessories,
|
||||||
|
onSubmitAccessory: (accessory) =>
|
||||||
|
this._submitAccessory(accessory),
|
||||||
)
|
)
|
||||||
: SingleCodeBody(
|
: SingleCodeBody(
|
||||||
isWaiting:
|
isWaiting:
|
||||||
@@ -465,6 +472,9 @@ class _BoxingPageState extends State<BoxingPage> with WidgetsBindingObserver {
|
|||||||
this._deleteAssignedItem(item),
|
this._deleteAssignedItem(item),
|
||||||
onCancelDeleteAssigned: () =>
|
onCancelDeleteAssigned: () =>
|
||||||
setState(() => _deletingAssignedItemId = null),
|
setState(() => _deletingAssignedItemId = null),
|
||||||
|
pendingAccessories: _pendingAccessories,
|
||||||
|
onSubmitAccessory: (accessory) =>
|
||||||
|
this._submitAccessory(accessory),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,11 @@ import 'package:pad_scanner/services/app_config_service.dart';
|
|||||||
import 'package:pad_scanner/pages/settings_page.dart';
|
import 'package:pad_scanner/pages/settings_page.dart';
|
||||||
import 'package:pad_scanner/pages/registration_page.dart';
|
import 'package:pad_scanner/pages/registration_page.dart';
|
||||||
import 'package:pad_scanner/pages/boxing_page.dart';
|
import 'package:pad_scanner/pages/boxing_page.dart';
|
||||||
|
import 'package:pad_scanner/pages/accessory_page.dart';
|
||||||
import 'package:pad_scanner/services/api_service.dart';
|
import 'package:pad_scanner/services/api_service.dart';
|
||||||
|
|
||||||
/// Module type enum for each available feature card
|
/// Module type enum for each available feature card
|
||||||
enum ModuleType { registration, boxing, shelfQuery }
|
enum ModuleType { registration, boxing, accessory, shelfQuery }
|
||||||
|
|
||||||
/// Module status for PRD state tracking
|
/// Module status for PRD state tracking
|
||||||
enum ModuleStatus { online, developing, planning }
|
enum ModuleStatus { online, developing, planning }
|
||||||
@@ -64,8 +65,16 @@ class _HomePageState extends State<HomePage> {
|
|||||||
route: '/boxing',
|
route: '/boxing',
|
||||||
),
|
),
|
||||||
FeatureCard(
|
FeatureCard(
|
||||||
type: ModuleType.shelfQuery,
|
type: ModuleType.accessory,
|
||||||
shortcut: '3',
|
shortcut: '3',
|
||||||
|
icon: Icons.build,
|
||||||
|
title: '附件登记',
|
||||||
|
status: ModuleStatus.developing,
|
||||||
|
route: '/accessory',
|
||||||
|
),
|
||||||
|
FeatureCard(
|
||||||
|
type: ModuleType.shelfQuery,
|
||||||
|
shortcut: '4',
|
||||||
icon: Icons.search_outlined,
|
icon: Icons.search_outlined,
|
||||||
title: '货架查询',
|
title: '货架查询',
|
||||||
status: ModuleStatus.planning,
|
status: ModuleStatus.planning,
|
||||||
@@ -101,17 +110,11 @@ class _HomePageState extends State<HomePage> {
|
|||||||
|
|
||||||
FeatureCard? _moduleFromShortcut(KeyEvent event) {
|
FeatureCard? _moduleFromShortcut(KeyEvent event) {
|
||||||
final shortcut = _shortcutNumberFromKeyEvent(event);
|
final shortcut = _shortcutNumberFromKeyEvent(event);
|
||||||
if (shortcut == 1) {
|
if (shortcut == null || shortcut < 1 || shortcut > _modules.length) {
|
||||||
return _modules[0];
|
|
||||||
}
|
|
||||||
if (shortcut == 2) {
|
|
||||||
return _modules[1];
|
|
||||||
}
|
|
||||||
if (shortcut == 3) {
|
|
||||||
return _modules[2];
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
return _modules[shortcut - 1];
|
||||||
|
}
|
||||||
|
|
||||||
int? _shortcutNumberFromKeyEvent(KeyEvent event) {
|
int? _shortcutNumberFromKeyEvent(KeyEvent event) {
|
||||||
final key = event.logicalKey;
|
final key = event.logicalKey;
|
||||||
@@ -130,6 +133,11 @@ class _HomePageState extends State<HomePage> {
|
|||||||
event.character == '3') {
|
event.character == '3') {
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
if (key == LogicalKeyboardKey.digit4 ||
|
||||||
|
key == LogicalKeyboardKey.numpad4 ||
|
||||||
|
event.character == '4') {
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,6 +189,9 @@ class _HomePageState extends State<HomePage> {
|
|||||||
case ModuleType.boxing:
|
case ModuleType.boxing:
|
||||||
targetPage = const BoxingPage();
|
targetPage = const BoxingPage();
|
||||||
break;
|
break;
|
||||||
|
case ModuleType.accessory:
|
||||||
|
targetPage = const AccessoryPage();
|
||||||
|
break;
|
||||||
case ModuleType.shelfQuery:
|
case ModuleType.shelfQuery:
|
||||||
return; // 规划中,不导航
|
return; // 规划中,不导航
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,6 +118,30 @@ class PaichaOverviewResult {
|
|||||||
|
|
||||||
// === 装箱模块数据类 ===
|
// === 装箱模块数据类 ===
|
||||||
|
|
||||||
|
/// 待装箱附件
|
||||||
|
class PendingAccessory {
|
||||||
|
final int accessoryId;
|
||||||
|
final String accessoryType;
|
||||||
|
final int quantity;
|
||||||
|
final String? locationCode;
|
||||||
|
|
||||||
|
PendingAccessory({
|
||||||
|
required this.accessoryId,
|
||||||
|
required this.accessoryType,
|
||||||
|
required this.quantity,
|
||||||
|
this.locationCode,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory PendingAccessory.fromJson(Map<String, dynamic> json) {
|
||||||
|
return PendingAccessory(
|
||||||
|
accessoryId: json['accessory_id'] as int,
|
||||||
|
accessoryType: json['accessory_type'] as String,
|
||||||
|
quantity: json['quantity'] as int,
|
||||||
|
locationCode: json['location_code']?.toString(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// 箱号内单个总排号明细
|
/// 箱号内单个总排号明细
|
||||||
class BoxItemData {
|
class BoxItemData {
|
||||||
final int? boxItemId;
|
final int? boxItemId;
|
||||||
@@ -125,6 +149,7 @@ class BoxItemData {
|
|||||||
final String? workOrderNo;
|
final String? workOrderNo;
|
||||||
final int quantity;
|
final int quantity;
|
||||||
final int? totalQuantity;
|
final int? totalQuantity;
|
||||||
|
final String itemType;
|
||||||
|
|
||||||
BoxItemData({
|
BoxItemData({
|
||||||
this.boxItemId,
|
this.boxItemId,
|
||||||
@@ -132,6 +157,7 @@ class BoxItemData {
|
|||||||
this.workOrderNo,
|
this.workOrderNo,
|
||||||
required this.quantity,
|
required this.quantity,
|
||||||
this.totalQuantity,
|
this.totalQuantity,
|
||||||
|
this.itemType = 'product',
|
||||||
});
|
});
|
||||||
|
|
||||||
factory BoxItemData.fromJson(Map<String, dynamic> json) {
|
factory BoxItemData.fromJson(Map<String, dynamic> json) {
|
||||||
@@ -141,6 +167,7 @@ class BoxItemData {
|
|||||||
workOrderNo: json['work_order_no']?.toString(),
|
workOrderNo: json['work_order_no']?.toString(),
|
||||||
quantity: json['quantity'] as int,
|
quantity: json['quantity'] as int,
|
||||||
totalQuantity: json['total_quantity'] as int?,
|
totalQuantity: json['total_quantity'] as int?,
|
||||||
|
itemType: json['item_type'] as String? ?? 'product',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -167,11 +194,13 @@ class CurrentZongpaiBoxData {
|
|||||||
final int boxItemId;
|
final int boxItemId;
|
||||||
final int boxNo;
|
final int boxNo;
|
||||||
final int quantity;
|
final int quantity;
|
||||||
|
final String itemType;
|
||||||
|
|
||||||
CurrentZongpaiBoxData({
|
CurrentZongpaiBoxData({
|
||||||
required this.boxItemId,
|
required this.boxItemId,
|
||||||
required this.boxNo,
|
required this.boxNo,
|
||||||
required this.quantity,
|
required this.quantity,
|
||||||
|
this.itemType = 'product',
|
||||||
});
|
});
|
||||||
|
|
||||||
factory CurrentZongpaiBoxData.fromJson(Map<String, dynamic> json) {
|
factory CurrentZongpaiBoxData.fromJson(Map<String, dynamic> json) {
|
||||||
@@ -179,6 +208,7 @@ class CurrentZongpaiBoxData {
|
|||||||
boxItemId: json['box_item_id'] as int,
|
boxItemId: json['box_item_id'] as int,
|
||||||
boxNo: json['box_no'] as int,
|
boxNo: json['box_no'] as int,
|
||||||
quantity: json['quantity'] as int,
|
quantity: json['quantity'] as int,
|
||||||
|
itemType: json['item_type'] as String? ?? 'product',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -195,6 +225,7 @@ class BoxInfoResult {
|
|||||||
final List<BoxDetailData> existingBoxes;
|
final List<BoxDetailData> existingBoxes;
|
||||||
final int maxBoxNo;
|
final int maxBoxNo;
|
||||||
final int suggestedBoxNo;
|
final int suggestedBoxNo;
|
||||||
|
final List<PendingAccessory> pendingAccessories;
|
||||||
|
|
||||||
BoxInfoResult({
|
BoxInfoResult({
|
||||||
required this.success,
|
required this.success,
|
||||||
@@ -207,6 +238,7 @@ class BoxInfoResult {
|
|||||||
this.existingBoxes = const [],
|
this.existingBoxes = const [],
|
||||||
this.maxBoxNo = 0,
|
this.maxBoxNo = 0,
|
||||||
this.suggestedBoxNo = 1,
|
this.suggestedBoxNo = 1,
|
||||||
|
this.pendingAccessories = const [],
|
||||||
});
|
});
|
||||||
|
|
||||||
factory BoxInfoResult.ok(Map<String, dynamic> json) {
|
factory BoxInfoResult.ok(Map<String, dynamic> json) {
|
||||||
@@ -222,6 +254,11 @@ class BoxInfoResult {
|
|||||||
)
|
)
|
||||||
.toList() ??
|
.toList() ??
|
||||||
[];
|
[];
|
||||||
|
final pendingAccessories =
|
||||||
|
(json['pending_accessories'] as List<dynamic>?)
|
||||||
|
?.map((a) => PendingAccessory.fromJson(a as Map<String, dynamic>))
|
||||||
|
.toList() ??
|
||||||
|
[];
|
||||||
return BoxInfoResult(
|
return BoxInfoResult(
|
||||||
success: true,
|
success: true,
|
||||||
zongpaiNo: json['zongpai_no'] as String?,
|
zongpaiNo: json['zongpai_no'] as String?,
|
||||||
@@ -232,6 +269,7 @@ class BoxInfoResult {
|
|||||||
existingBoxes: boxes,
|
existingBoxes: boxes,
|
||||||
maxBoxNo: json['max_box_no'] as int? ?? 0,
|
maxBoxNo: json['max_box_no'] as int? ?? 0,
|
||||||
suggestedBoxNo: json['suggested_box_no'] as int? ?? 1,
|
suggestedBoxNo: json['suggested_box_no'] as int? ?? 1,
|
||||||
|
pendingAccessories: pendingAccessories,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,6 +337,163 @@ class BoxDeleteResult {
|
|||||||
BoxDeleteResult({required this.success, this.errorMessage});
|
BoxDeleteResult({required this.success, this.errorMessage});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// === 附件模块数据类 ===
|
||||||
|
|
||||||
|
/// 工令号分组(工令号 → 总排号列表)
|
||||||
|
class WorkOrderGroup {
|
||||||
|
final String workOrderNo;
|
||||||
|
final List<String> zongpaiNos;
|
||||||
|
WorkOrderGroup({required this.workOrderNo, required this.zongpaiNos});
|
||||||
|
factory WorkOrderGroup.fromJson(Map<String, dynamic> json) => WorkOrderGroup(
|
||||||
|
workOrderNo: json['work_order_no'] as String,
|
||||||
|
zongpaiNos: (json['zongpai_nos'] as List).map((e) => e as String).toList(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 附件类型预设
|
||||||
|
class AccessoryTypeInfo {
|
||||||
|
final int id;
|
||||||
|
final String name;
|
||||||
|
final int sortOrder;
|
||||||
|
AccessoryTypeInfo({
|
||||||
|
required this.id,
|
||||||
|
required this.name,
|
||||||
|
required this.sortOrder,
|
||||||
|
});
|
||||||
|
factory AccessoryTypeInfo.fromJson(Map<String, dynamic> json) =>
|
||||||
|
AccessoryTypeInfo(
|
||||||
|
id: json['id'] as int,
|
||||||
|
name: json['name'] as String,
|
||||||
|
sortOrder: json['sort_order'] as int,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 附件记录
|
||||||
|
class AccessoryRecord {
|
||||||
|
final int id;
|
||||||
|
final String paichanNo;
|
||||||
|
final String zongpaiNo;
|
||||||
|
final String accessoryType;
|
||||||
|
final int quantity;
|
||||||
|
final String? locationCode;
|
||||||
|
final bool isBoxed;
|
||||||
|
final String createdAt;
|
||||||
|
AccessoryRecord({
|
||||||
|
required this.id,
|
||||||
|
required this.paichanNo,
|
||||||
|
required this.zongpaiNo,
|
||||||
|
required this.accessoryType,
|
||||||
|
required this.quantity,
|
||||||
|
this.locationCode,
|
||||||
|
required this.isBoxed,
|
||||||
|
required this.createdAt,
|
||||||
|
});
|
||||||
|
factory AccessoryRecord.fromJson(Map<String, dynamic> json) =>
|
||||||
|
AccessoryRecord(
|
||||||
|
id: json['id'] as int,
|
||||||
|
paichanNo: json['paichan_no'] as String,
|
||||||
|
zongpaiNo: json['zongpai_no'] as String,
|
||||||
|
accessoryType: json['accessory_type'] as String,
|
||||||
|
quantity: json['quantity'] as int,
|
||||||
|
locationCode: json['location_code'] as String?,
|
||||||
|
isBoxed: json['is_boxed'] as bool,
|
||||||
|
createdAt: json['created_at'] as String,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// === 附件模块结果类 ===
|
||||||
|
|
||||||
|
class WorkOrderQueryResult {
|
||||||
|
final bool success;
|
||||||
|
final String? paichanNo;
|
||||||
|
final List<WorkOrderGroup> workOrders;
|
||||||
|
final String? errorMessage;
|
||||||
|
final String? errorCode;
|
||||||
|
WorkOrderQueryResult({
|
||||||
|
required this.success,
|
||||||
|
this.paichanNo,
|
||||||
|
this.workOrders = const [],
|
||||||
|
this.errorMessage,
|
||||||
|
this.errorCode,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
class AccessoryListResult {
|
||||||
|
final bool success;
|
||||||
|
final List<AccessoryRecord> items;
|
||||||
|
final String? errorMessage;
|
||||||
|
final String? errorCode;
|
||||||
|
AccessoryListResult({
|
||||||
|
required this.success,
|
||||||
|
this.items = const [],
|
||||||
|
this.errorMessage,
|
||||||
|
this.errorCode,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
class AccessoryCreateResult {
|
||||||
|
final bool success;
|
||||||
|
final AccessoryRecord? record;
|
||||||
|
final String? errorMessage;
|
||||||
|
final String? errorCode;
|
||||||
|
AccessoryCreateResult({
|
||||||
|
required this.success,
|
||||||
|
this.record,
|
||||||
|
this.errorMessage,
|
||||||
|
this.errorCode,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
class AccessoryUpdateResult {
|
||||||
|
final bool success;
|
||||||
|
final AccessoryRecord? record;
|
||||||
|
final String? errorMessage;
|
||||||
|
final String? errorCode;
|
||||||
|
AccessoryUpdateResult({
|
||||||
|
required this.success,
|
||||||
|
this.record,
|
||||||
|
this.errorMessage,
|
||||||
|
this.errorCode,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
class AccessoryDeleteResult {
|
||||||
|
final bool success;
|
||||||
|
final String? errorMessage;
|
||||||
|
final String? errorCode;
|
||||||
|
AccessoryDeleteResult({
|
||||||
|
required this.success,
|
||||||
|
this.errorMessage,
|
||||||
|
this.errorCode,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
class AccessoryTypeListResult {
|
||||||
|
final bool success;
|
||||||
|
final List<AccessoryTypeInfo> types;
|
||||||
|
final String? errorMessage;
|
||||||
|
final String? errorCode;
|
||||||
|
AccessoryTypeListResult({
|
||||||
|
required this.success,
|
||||||
|
this.types = const [],
|
||||||
|
this.errorMessage,
|
||||||
|
this.errorCode,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
class AccessoryTypeCreateResult {
|
||||||
|
final bool success;
|
||||||
|
final AccessoryTypeInfo? type;
|
||||||
|
final String? errorMessage;
|
||||||
|
final String? errorCode;
|
||||||
|
AccessoryTypeCreateResult({
|
||||||
|
required this.success,
|
||||||
|
this.type,
|
||||||
|
this.errorMessage,
|
||||||
|
this.errorCode,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
class ApiService {
|
class ApiService {
|
||||||
final http.Client _client;
|
final http.Client _client;
|
||||||
final Duration timeout;
|
final Duration timeout;
|
||||||
@@ -423,18 +618,25 @@ class ApiService {
|
|||||||
required String zongpaiNo,
|
required String zongpaiNo,
|
||||||
required int boxNo,
|
required int boxNo,
|
||||||
required int quantity,
|
required int quantity,
|
||||||
|
String itemType = 'product',
|
||||||
|
int? accessoryId,
|
||||||
}) async {
|
}) async {
|
||||||
final uri = Uri.parse('$baseUrl/CargoTrace/box');
|
final uri = Uri.parse('$baseUrl/CargoTrace/box');
|
||||||
try {
|
try {
|
||||||
|
final bodyMap = <String, dynamic>{
|
||||||
|
'zongpai_no': zongpaiNo,
|
||||||
|
'box_no': boxNo,
|
||||||
|
'quantity': quantity,
|
||||||
|
'item_type': itemType,
|
||||||
|
};
|
||||||
|
if (accessoryId != null) {
|
||||||
|
bodyMap['accessory_id'] = accessoryId;
|
||||||
|
}
|
||||||
final response = await _client
|
final response = await _client
|
||||||
.post(
|
.post(
|
||||||
uri,
|
uri,
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
body: jsonEncode({
|
body: jsonEncode(bodyMap),
|
||||||
'zongpai_no': zongpaiNo,
|
|
||||||
'box_no': boxNo,
|
|
||||||
'quantity': quantity,
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
.timeout(timeout);
|
.timeout(timeout);
|
||||||
|
|
||||||
@@ -524,6 +726,403 @@ class ApiService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// === 附件模块 API 方法 ===
|
||||||
|
|
||||||
|
/// 工令号查询 — GET /CargoTrace/accessory/work-orders
|
||||||
|
Future<WorkOrderQueryResult> queryWorkOrders({
|
||||||
|
required String baseUrl,
|
||||||
|
required String paichanNo,
|
||||||
|
}) async {
|
||||||
|
final uri = Uri.parse(
|
||||||
|
'$baseUrl/CargoTrace/accessory/work-orders',
|
||||||
|
).replace(queryParameters: {'paichan_no': paichanNo});
|
||||||
|
try {
|
||||||
|
final response = await _client
|
||||||
|
.get(uri, headers: {'Content-Type': 'application/json'})
|
||||||
|
.timeout(timeout);
|
||||||
|
|
||||||
|
switch (response.statusCode) {
|
||||||
|
case 200:
|
||||||
|
final body = jsonDecode(response.body) as Map<String, dynamic>;
|
||||||
|
final workOrders =
|
||||||
|
(body['work_orders'] as List<dynamic>?)
|
||||||
|
?.map(
|
||||||
|
(w) => WorkOrderGroup.fromJson(w as Map<String, dynamic>),
|
||||||
|
)
|
||||||
|
.toList() ??
|
||||||
|
[];
|
||||||
|
return WorkOrderQueryResult(
|
||||||
|
success: true,
|
||||||
|
paichanNo: body['paichan_no'] as String?,
|
||||||
|
workOrders: workOrders,
|
||||||
|
);
|
||||||
|
case 400:
|
||||||
|
final body = jsonDecode(response.body) as Map<String, dynamic>;
|
||||||
|
return WorkOrderQueryResult(
|
||||||
|
success: false,
|
||||||
|
errorMessage: body['message']?.toString() ?? '请求参数错误',
|
||||||
|
errorCode: body['error_code']?.toString(),
|
||||||
|
);
|
||||||
|
case 404:
|
||||||
|
return WorkOrderQueryResult(
|
||||||
|
success: false,
|
||||||
|
errorMessage: '未找到该排产号对应的工令号信息',
|
||||||
|
errorCode: 'NOT_FOUND',
|
||||||
|
);
|
||||||
|
default:
|
||||||
|
return WorkOrderQueryResult(
|
||||||
|
success: false,
|
||||||
|
errorMessage: '查询失败 (${response.statusCode})',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return WorkOrderQueryResult(success: false, errorMessage: '网络异常,请检查网络连接');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 附件列表查询 — GET /CargoTrace/accessory
|
||||||
|
Future<AccessoryListResult> listAccessories({
|
||||||
|
required String baseUrl,
|
||||||
|
required String paichanNo,
|
||||||
|
}) async {
|
||||||
|
final uri = Uri.parse(
|
||||||
|
'$baseUrl/CargoTrace/accessory',
|
||||||
|
).replace(queryParameters: {'paichan_no': paichanNo});
|
||||||
|
try {
|
||||||
|
final response = await _client
|
||||||
|
.get(uri, headers: {'Content-Type': 'application/json'})
|
||||||
|
.timeout(timeout);
|
||||||
|
|
||||||
|
switch (response.statusCode) {
|
||||||
|
case 200:
|
||||||
|
final body = jsonDecode(response.body) as Map<String, dynamic>;
|
||||||
|
final items =
|
||||||
|
(body['items'] as List<dynamic>?)
|
||||||
|
?.map(
|
||||||
|
(i) => AccessoryRecord.fromJson(i as Map<String, dynamic>),
|
||||||
|
)
|
||||||
|
.toList() ??
|
||||||
|
[];
|
||||||
|
return AccessoryListResult(success: true, items: items);
|
||||||
|
case 400:
|
||||||
|
final body = jsonDecode(response.body) as Map<String, dynamic>;
|
||||||
|
return AccessoryListResult(
|
||||||
|
success: false,
|
||||||
|
errorMessage: body['message']?.toString() ?? '请求参数错误',
|
||||||
|
errorCode: body['error_code']?.toString(),
|
||||||
|
);
|
||||||
|
case 404:
|
||||||
|
return AccessoryListResult(
|
||||||
|
success: false,
|
||||||
|
errorMessage: '未找到该排产号信息',
|
||||||
|
errorCode: 'NOT_FOUND',
|
||||||
|
);
|
||||||
|
default:
|
||||||
|
return AccessoryListResult(
|
||||||
|
success: false,
|
||||||
|
errorMessage: '查询失败 (${response.statusCode})',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return AccessoryListResult(success: false, errorMessage: '网络异常,请检查网络连接');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 附件创建(上架) — POST /CargoTrace/accessory
|
||||||
|
Future<AccessoryCreateResult> createAccessory({
|
||||||
|
required String baseUrl,
|
||||||
|
required String paichanNo,
|
||||||
|
required String zongpaiNo,
|
||||||
|
required String accessoryType,
|
||||||
|
required int quantity,
|
||||||
|
String? locationCode,
|
||||||
|
}) async {
|
||||||
|
final uri = Uri.parse('$baseUrl/CargoTrace/accessory');
|
||||||
|
try {
|
||||||
|
final bodyMap = <String, dynamic>{
|
||||||
|
'paichan_no': paichanNo,
|
||||||
|
'zongpai_no': zongpaiNo,
|
||||||
|
'accessory_type': accessoryType,
|
||||||
|
'quantity': quantity,
|
||||||
|
};
|
||||||
|
if (locationCode != null) {
|
||||||
|
bodyMap['location_code'] = locationCode;
|
||||||
|
}
|
||||||
|
final response = await _client
|
||||||
|
.post(
|
||||||
|
uri,
|
||||||
|
headers: {'Content-Type': 'application/json'},
|
||||||
|
body: jsonEncode(bodyMap),
|
||||||
|
)
|
||||||
|
.timeout(timeout);
|
||||||
|
|
||||||
|
switch (response.statusCode) {
|
||||||
|
case 200:
|
||||||
|
final body = jsonDecode(response.body) as Map<String, dynamic>;
|
||||||
|
return AccessoryCreateResult(
|
||||||
|
success: true,
|
||||||
|
record: AccessoryRecord.fromJson(body),
|
||||||
|
);
|
||||||
|
case 400:
|
||||||
|
final body = jsonDecode(response.body) as Map<String, dynamic>;
|
||||||
|
return AccessoryCreateResult(
|
||||||
|
success: false,
|
||||||
|
errorMessage: body['message']?.toString() ?? '请求参数错误',
|
||||||
|
errorCode: body['error_code']?.toString(),
|
||||||
|
);
|
||||||
|
case 404:
|
||||||
|
return AccessoryCreateResult(
|
||||||
|
success: false,
|
||||||
|
errorMessage: '未找到该排产号对应的工令号信息',
|
||||||
|
errorCode: 'NOT_FOUND',
|
||||||
|
);
|
||||||
|
case 409:
|
||||||
|
final body = jsonDecode(response.body) as Map<String, dynamic>;
|
||||||
|
return AccessoryCreateResult(
|
||||||
|
success: false,
|
||||||
|
errorMessage: body['message']?.toString() ?? '冲突',
|
||||||
|
errorCode: body['error_code']?.toString(),
|
||||||
|
);
|
||||||
|
default:
|
||||||
|
return AccessoryCreateResult(
|
||||||
|
success: false,
|
||||||
|
errorMessage: '创建失败 (${response.statusCode})',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return AccessoryCreateResult(
|
||||||
|
success: false,
|
||||||
|
errorMessage: '网络异常,请检查网络连接',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 附件更新 — PATCH /CargoTrace/accessory/{id}
|
||||||
|
Future<AccessoryUpdateResult> updateAccessory({
|
||||||
|
required String baseUrl,
|
||||||
|
required int id,
|
||||||
|
String? accessoryType,
|
||||||
|
int? quantity,
|
||||||
|
String? locationCode,
|
||||||
|
}) async {
|
||||||
|
final uri = Uri.parse('$baseUrl/CargoTrace/accessory/$id');
|
||||||
|
try {
|
||||||
|
final bodyMap = <String, dynamic>{};
|
||||||
|
if (accessoryType != null) bodyMap['accessory_type'] = accessoryType;
|
||||||
|
if (quantity != null) bodyMap['quantity'] = quantity;
|
||||||
|
if (locationCode != null) bodyMap['location_code'] = locationCode;
|
||||||
|
|
||||||
|
final response = await _client
|
||||||
|
.patch(
|
||||||
|
uri,
|
||||||
|
headers: {'Content-Type': 'application/json'},
|
||||||
|
body: jsonEncode(bodyMap),
|
||||||
|
)
|
||||||
|
.timeout(timeout);
|
||||||
|
|
||||||
|
switch (response.statusCode) {
|
||||||
|
case 200:
|
||||||
|
final body = jsonDecode(response.body) as Map<String, dynamic>;
|
||||||
|
return AccessoryUpdateResult(
|
||||||
|
success: true,
|
||||||
|
record: AccessoryRecord.fromJson(body),
|
||||||
|
);
|
||||||
|
case 400:
|
||||||
|
final body = jsonDecode(response.body) as Map<String, dynamic>;
|
||||||
|
return AccessoryUpdateResult(
|
||||||
|
success: false,
|
||||||
|
errorMessage: body['message']?.toString() ?? '请求参数错误',
|
||||||
|
errorCode: body['error_code']?.toString(),
|
||||||
|
);
|
||||||
|
case 404:
|
||||||
|
return AccessoryUpdateResult(
|
||||||
|
success: false,
|
||||||
|
errorMessage: '指定附件记录不存在',
|
||||||
|
errorCode: 'NOT_FOUND',
|
||||||
|
);
|
||||||
|
default:
|
||||||
|
return AccessoryUpdateResult(
|
||||||
|
success: false,
|
||||||
|
errorMessage: '更新失败 (${response.statusCode})',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return AccessoryUpdateResult(
|
||||||
|
success: false,
|
||||||
|
errorMessage: '网络异常,请检查网络连接',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 附件删除 — DELETE /CargoTrace/accessory/{id}
|
||||||
|
Future<AccessoryDeleteResult> deleteAccessory({
|
||||||
|
required String baseUrl,
|
||||||
|
required int id,
|
||||||
|
}) async {
|
||||||
|
final uri = Uri.parse('$baseUrl/CargoTrace/accessory/$id');
|
||||||
|
try {
|
||||||
|
final response = await _client
|
||||||
|
.delete(uri, headers: {'Content-Type': 'application/json'})
|
||||||
|
.timeout(timeout);
|
||||||
|
|
||||||
|
switch (response.statusCode) {
|
||||||
|
case 200:
|
||||||
|
return AccessoryDeleteResult(success: true);
|
||||||
|
case 404:
|
||||||
|
return AccessoryDeleteResult(
|
||||||
|
success: false,
|
||||||
|
errorMessage: '指定附件记录不存在',
|
||||||
|
errorCode: 'NOT_FOUND',
|
||||||
|
);
|
||||||
|
default:
|
||||||
|
return AccessoryDeleteResult(
|
||||||
|
success: false,
|
||||||
|
errorMessage: '删除失败 (${response.statusCode})',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return AccessoryDeleteResult(
|
||||||
|
success: false,
|
||||||
|
errorMessage: '网络异常,请检查网络连接',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 附件类型列表 — GET /CargoTrace/accessory-type
|
||||||
|
Future<AccessoryTypeListResult> listAccessoryTypes({
|
||||||
|
required String baseUrl,
|
||||||
|
}) async {
|
||||||
|
final uri = Uri.parse('$baseUrl/CargoTrace/accessory-type');
|
||||||
|
try {
|
||||||
|
final response = await _client
|
||||||
|
.get(uri, headers: {'Content-Type': 'application/json'})
|
||||||
|
.timeout(timeout);
|
||||||
|
|
||||||
|
switch (response.statusCode) {
|
||||||
|
case 200:
|
||||||
|
final body = jsonDecode(response.body) as Map<String, dynamic>;
|
||||||
|
final types =
|
||||||
|
(body['types'] as List<dynamic>?)
|
||||||
|
?.map(
|
||||||
|
(t) =>
|
||||||
|
AccessoryTypeInfo.fromJson(t as Map<String, dynamic>),
|
||||||
|
)
|
||||||
|
.toList() ??
|
||||||
|
[];
|
||||||
|
return AccessoryTypeListResult(success: true, types: types);
|
||||||
|
case 400:
|
||||||
|
final body = jsonDecode(response.body) as Map<String, dynamic>;
|
||||||
|
return AccessoryTypeListResult(
|
||||||
|
success: false,
|
||||||
|
errorMessage: body['message']?.toString() ?? '请求参数错误',
|
||||||
|
errorCode: body['error_code']?.toString(),
|
||||||
|
);
|
||||||
|
default:
|
||||||
|
return AccessoryTypeListResult(
|
||||||
|
success: false,
|
||||||
|
errorMessage: '查询失败 (${response.statusCode})',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return AccessoryTypeListResult(
|
||||||
|
success: false,
|
||||||
|
errorMessage: '网络异常,请检查网络连接',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 附件类型创建 — POST /CargoTrace/accessory-type
|
||||||
|
Future<AccessoryTypeCreateResult> createAccessoryType({
|
||||||
|
required String baseUrl,
|
||||||
|
required String name,
|
||||||
|
int sortOrder = 0,
|
||||||
|
}) async {
|
||||||
|
final uri = Uri.parse('$baseUrl/CargoTrace/accessory-type');
|
||||||
|
try {
|
||||||
|
final response = await _client
|
||||||
|
.post(
|
||||||
|
uri,
|
||||||
|
headers: {'Content-Type': 'application/json'},
|
||||||
|
body: jsonEncode({'name': name, 'sort_order': sortOrder}),
|
||||||
|
)
|
||||||
|
.timeout(timeout);
|
||||||
|
|
||||||
|
switch (response.statusCode) {
|
||||||
|
case 200:
|
||||||
|
final body = jsonDecode(response.body) as Map<String, dynamic>;
|
||||||
|
return AccessoryTypeCreateResult(
|
||||||
|
success: true,
|
||||||
|
type: AccessoryTypeInfo.fromJson(body),
|
||||||
|
);
|
||||||
|
case 400:
|
||||||
|
final body = jsonDecode(response.body) as Map<String, dynamic>;
|
||||||
|
return AccessoryTypeCreateResult(
|
||||||
|
success: false,
|
||||||
|
errorMessage: body['message']?.toString() ?? '请求参数错误',
|
||||||
|
errorCode: body['error_code']?.toString(),
|
||||||
|
);
|
||||||
|
case 409:
|
||||||
|
final body = jsonDecode(response.body) as Map<String, dynamic>;
|
||||||
|
return AccessoryTypeCreateResult(
|
||||||
|
success: false,
|
||||||
|
errorMessage: body['message']?.toString() ?? '附件类型已存在',
|
||||||
|
errorCode: body['error_code']?.toString(),
|
||||||
|
);
|
||||||
|
default:
|
||||||
|
return AccessoryTypeCreateResult(
|
||||||
|
success: false,
|
||||||
|
errorMessage: '创建失败 (${response.statusCode})',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return AccessoryTypeCreateResult(
|
||||||
|
success: false,
|
||||||
|
errorMessage: '网络异常,请检查网络连接',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 附件类型删除 — DELETE /CargoTrace/accessory-type/{id}
|
||||||
|
Future<AccessoryDeleteResult> deleteAccessoryType({
|
||||||
|
required String baseUrl,
|
||||||
|
required int id,
|
||||||
|
}) async {
|
||||||
|
final uri = Uri.parse('$baseUrl/CargoTrace/accessory-type/$id');
|
||||||
|
try {
|
||||||
|
final response = await _client
|
||||||
|
.delete(uri, headers: {'Content-Type': 'application/json'})
|
||||||
|
.timeout(timeout);
|
||||||
|
|
||||||
|
switch (response.statusCode) {
|
||||||
|
case 200:
|
||||||
|
return AccessoryDeleteResult(success: true);
|
||||||
|
case 404:
|
||||||
|
return AccessoryDeleteResult(
|
||||||
|
success: false,
|
||||||
|
errorMessage: '指定附件类型不存在',
|
||||||
|
errorCode: 'NOT_FOUND',
|
||||||
|
);
|
||||||
|
case 409:
|
||||||
|
final body = jsonDecode(response.body) as Map<String, dynamic>;
|
||||||
|
return AccessoryDeleteResult(
|
||||||
|
success: false,
|
||||||
|
errorMessage: body['message']?.toString() ?? '该类型下存在附件记录,无法删除',
|
||||||
|
errorCode: body['error_code']?.toString(),
|
||||||
|
);
|
||||||
|
default:
|
||||||
|
return AccessoryDeleteResult(
|
||||||
|
success: false,
|
||||||
|
errorMessage: '删除失败 (${response.statusCode})',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return AccessoryDeleteResult(
|
||||||
|
success: false,
|
||||||
|
errorMessage: '网络异常,请检查网络连接',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Test connectivity by making a HEAD request to the base URL.
|
/// Test connectivity by making a HEAD request to the base URL.
|
||||||
Future<bool> testConnection(String baseUrl) async {
|
Future<bool> testConnection(String baseUrl) async {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user