From a904c8bd4224a1e80ddede736107434d7cd7ac74 Mon Sep 17 00:00:00 2001 From: hailin Date: Sat, 28 Feb 2026 11:19:27 -0800 Subject: [PATCH] =?UTF-8?q?feat(ledger):=20=E9=A2=84=E7=A7=8D=E4=BB=BD?= =?UTF-8?q?=E9=A2=9D=E5=9C=A8=E6=B5=81=E6=B0=B4=E6=98=8E=E7=BB=86=E4=B8=AD?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=90=88=E5=B9=B6=E5=90=88=E5=90=8C=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除硬编码"预种无合同"逻辑 - PPL 份额点击详情时,查找是否有对应的已签署合并记录 - 有签署合同则显示查看/下载按钮,调用预种合并合同 PDF 接口 - 同时新增 _viewMergeContractPdf / _downloadMergeContractPdf 方法 Co-Authored-By: Claude Sonnet 4.6 --- .../pages/ledger_detail_page.dart | 114 +++++++++++++++++- 1 file changed, 110 insertions(+), 4 deletions(-) diff --git a/frontend/mobile-app/lib/features/trading/presentation/pages/ledger_detail_page.dart b/frontend/mobile-app/lib/features/trading/presentation/pages/ledger_detail_page.dart index d3765863..ecb3439e 100644 --- a/frontend/mobile-app/lib/features/trading/presentation/pages/ledger_detail_page.dart +++ b/frontend/mobile-app/lib/features/trading/presentation/pages/ledger_detail_page.dart @@ -8,6 +8,7 @@ import 'package:flutter_pdfview/flutter_pdfview.dart'; import '../../../../core/di/injection_container.dart'; import '../../../../core/services/wallet_service.dart'; import '../../../../core/services/reward_service.dart'; +import '../../../../core/services/pre_planting_service.dart'; import '../../../../core/utils/date_utils.dart'; /// 账本明细页面 - 显示用户的流水账、统计图表和筛选功能 @@ -1116,18 +1117,40 @@ class _LedgerDetailPageState extends ConsumerState Future _showTransactionDetail(LedgerEntry entry) async { if (entry.refOrderId == null) return; - // 预种订单(PPL 前缀)没有合同,不显示合同按钮 final bool isPrePlanting = entry.refOrderId!.startsWith('PPL'); + // PPL 份额订单:查找是否已有对应的已签署合并合同 + String? signedMergeNo; + if (isPrePlanting) { + try { + final merges = await ref.read(prePlantingServiceProvider).getMyMerges(); + final matched = merges.where( + (m) => m.isSigned && m.sourceOrderNos.contains(entry.refOrderId), + ); + if (matched.isNotEmpty) signedMergeNo = matched.first.mergeNo; + } catch (_) { + // 查不到就不显示合同按钮 + } + } + + if (!mounted) return; showModalBottomSheet( context: context, isScrollControlled: true, backgroundColor: Colors.transparent, builder: (context) => _TransactionDetailSheet( entry: entry, - showContractButtons: !isPrePlanting, - onViewContract: isPrePlanting ? null : () => _viewContractPdf(entry.refOrderId!), - onDownloadContract: isPrePlanting ? null : () => _downloadContractPdf(entry.refOrderId!), + showContractButtons: !isPrePlanting || signedMergeNo != null, + onViewContract: signedMergeNo != null + ? () => _viewMergeContractPdf(signedMergeNo!) + : isPrePlanting + ? null + : () => _viewContractPdf(entry.refOrderId!), + onDownloadContract: signedMergeNo != null + ? () => _downloadMergeContractPdf(signedMergeNo!) + : isPrePlanting + ? null + : () => _downloadContractPdf(entry.refOrderId!), ), ); } @@ -1230,6 +1253,89 @@ class _LedgerDetailPageState extends ConsumerState ); } } + + /// 查看预种合并合同 PDF + Future _viewMergeContractPdf(String mergeNo) async { + showDialog( + context: context, + barrierDismissible: false, + builder: (context) => const Center( + child: CircularProgressIndicator( + valueColor: AlwaysStoppedAnimation(Color(0xFFD4AF37)), + ), + ), + ); + + try { + final prePlantingService = ref.read(prePlantingServiceProvider); + final pdfBytes = await prePlantingService.downloadMergeContractPdf(mergeNo); + + final tempDir = await getTemporaryDirectory(); + final pdfFile = File('${tempDir.path}/merge_contract_$mergeNo.pdf'); + await pdfFile.writeAsBytes(pdfBytes); + + if (!mounted) return; + Navigator.of(context).pop(); + + Navigator.of(context).push( + MaterialPageRoute( + builder: (context) => _ContractPdfViewerPage( + pdfPath: pdfFile.path, + contractNo: mergeNo, + ), + ), + ); + } catch (e) { + if (!mounted) return; + Navigator.of(context).pop(); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text('加载合同失败: $e'), + backgroundColor: Colors.red, + ), + ); + } + } + + /// 下载预种合并合同 PDF + Future _downloadMergeContractPdf(String mergeNo) async { + showDialog( + context: context, + barrierDismissible: false, + builder: (context) => const Center( + child: CircularProgressIndicator( + valueColor: AlwaysStoppedAnimation(Color(0xFFD4AF37)), + ), + ), + ); + + try { + final prePlantingService = ref.read(prePlantingServiceProvider); + final pdfBytes = await prePlantingService.downloadMergeContractPdf(mergeNo); + + final directory = await getApplicationDocumentsDirectory(); + final fileName = 'merge_contract_$mergeNo.pdf'; + final pdfFile = File('${directory.path}/$fileName'); + await pdfFile.writeAsBytes(pdfBytes); + + if (!mounted) return; + Navigator.of(context).pop(); + + await Share.shareXFiles( + [XFile(pdfFile.path)], + subject: '预种合并合同 - $mergeNo', + ); + } catch (e) { + if (!mounted) return; + Navigator.of(context).pop(); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text('下载合同失败: $e'), + backgroundColor: Colors.red, + ), + ); + } + } } /// 交易详情底部弹窗