From 9e83127113b775c8209b3852e85567117d0ae63f Mon Sep 17 00:00:00 2001 From: hailin Date: Fri, 30 Jan 2026 20:46:50 -0800 Subject: [PATCH] =?UTF-8?q?fix(mining-app):=20C2C"=E6=88=91=E7=9A=84"?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=BE=85=E6=8E=A5=E5=8D=95=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=96=E6=B6=88=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在我的订单卡片上直接显示取消按钮(PENDING状态), 弹出确认对话框后调用 cancelOrder API Co-Authored-By: Claude Opus 4.5 --- .../pages/c2c/c2c_market_page.dart | 67 +++++++++++++++++-- 1 file changed, 63 insertions(+), 4 deletions(-) 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,