diff --git a/frontend/mining-app/lib/presentation/pages/c2c/c2c_market_page.dart b/frontend/mining-app/lib/presentation/pages/c2c/c2c_market_page.dart index 7992d729..f4a2cd66 100644 --- a/frontend/mining-app/lib/presentation/pages/c2c/c2c_market_page.dart +++ b/frontend/mining-app/lib/presentation/pages/c2c/c2c_market_page.dart @@ -509,10 +509,30 @@ class _C2cMarketPageState extends ConsumerState ], ), const SizedBox(height: 8), - // 时间 - Text( - '创建于 ${_formatDateTime(order.createdAt)}', - style: TextStyle(fontSize: 12, color: AppColors.textSecondaryOf(context)), + // 时间 + 操作按钮 + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + '创建于 ${_formatDateTime(order.createdAt)}', + style: TextStyle(fontSize: 12, color: AppColors.textSecondaryOf(context)), + ), + if (order.status == C2cOrderStatus.pending) + GestureDetector( + onTap: () => _handleCancelOrder(order), + child: Container( + padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4), + decoration: BoxDecoration( + border: Border.all(color: _red.withOpacity(0.5)), + borderRadius: BorderRadius.circular(4), + ), + child: Text( + '取消', + style: TextStyle(fontSize: 12, color: _red), + ), + ), + ), + ], ), ], ), @@ -962,6 +982,45 @@ class _C2cMarketPageState extends ConsumerState ); } + Future _handleCancelOrder(C2cOrderModel order) async { + final confirmed = await showDialog( + context: context, + builder: (ctx) => AlertDialog( + title: const Text('确认取消'), + content: const Text('确定要取消此订单吗?'), + actions: [ + TextButton( + onPressed: () => Navigator.pop(ctx, false), + child: const Text('暂不'), + ), + TextButton( + onPressed: () => Navigator.pop(ctx, true), + child: Text('确认取消', style: TextStyle(color: _red)), + ), + ], + ), + ); + if (confirmed != true) return; + + final notifier = ref.read(c2cTradingNotifierProvider.notifier); + final success = await notifier.cancelOrder(order.orderNo); + + if (success && mounted) { + ref.invalidate(myC2cOrdersProvider); + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar(content: Text('订单已取消'), backgroundColor: _green), + ); + } else if (mounted) { + final error = ref.read(c2cTradingNotifierProvider).error; + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text('取消失败: ${error ?? '未知错误'}'), + backgroundColor: _red, + ), + ); + } + } + Future _takeOrder( C2cOrderModel order, { String? quantity,