diff --git a/frontend/mobile-app/lib/features/profile/presentation/pages/profile_page.dart b/frontend/mobile-app/lib/features/profile/presentation/pages/profile_page.dart index 3cac0248..86ef7292 100644 --- a/frontend/mobile-app/lib/features/profile/presentation/pages/profile_page.dart +++ b/frontend/mobile-app/lib/features/profile/presentation/pages/profile_page.dart @@ -66,6 +66,9 @@ class _ProfilePageState extends ConsumerState { // 直推数据(从 referral-service 获取) List> _referrals = []; + int _totalReferralCount = 0; // 直推总人数 + bool _isReferralListExpanded = false; // 引荐列表是否展开 + bool _isLoadingMoreReferrals = false; // 是否正在加载更多引荐 // 团队树根节点(缓存以保持展开状态) TeamTreeNode? _teamTreeRootNode; @@ -401,6 +404,8 @@ class _ProfilePageState extends ConsumerState { 'personal': r.personalPlantingCount, // 个人认种量 'team': r.teamPlantingCount, // 团队认种量 }).toList(); + _totalReferralCount = directReferrals.total; // 保存总数 + _isReferralListExpanded = false; // 重置展开状态 }); } } catch (e, stackTrace) { @@ -422,6 +427,46 @@ class _ProfilePageState extends ConsumerState { } } + /// 展开引荐列表(加载全部数据) + Future _expandReferralList() async { + if (_isLoadingMoreReferrals) return; + + setState(() { + _isLoadingMoreReferrals = true; + }); + + try { + final referralService = ref.read(referralServiceProvider); + final response = await referralService.getDirectReferrals(limit: 200); + + if (mounted) { + setState(() { + _referrals = response.referrals.map((r) => { + 'serial': r.accountSequence, + 'personal': r.personalPlantingCount, + 'team': r.teamPlantingCount, + }).toList(); + _isReferralListExpanded = true; + _isLoadingMoreReferrals = false; + }); + } + } catch (e) { + debugPrint('[ProfilePage] 加载更多引荐失败: $e'); + if (mounted) { + setState(() { + _isLoadingMoreReferrals = false; + }); + } + } + } + + /// 收拢引荐列表(只显示前10条) + void _collapseReferralList() { + setState(() { + _isReferralListExpanded = false; + }); + } + /// 加载授权数据 (from authorization-service) /// [isRefresh] 是否为刷新操作(刷新时不显示加载状态) Future _loadAuthorizationData({bool isRefresh = false}) async { @@ -3349,6 +3394,11 @@ class _ProfilePageState extends ConsumerState { /// 构建引荐列表 Widget _buildReferralList() { + // 决定显示多少条 + final displayList = _isReferralListExpanded + ? _referrals + : _referrals.take(10).toList(); + return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -3366,7 +3416,7 @@ class _ProfilePageState extends ConsumerState { ), ), const SizedBox(height: 8), - ..._referrals.map((referral) => Padding( + ...displayList.map((referral) => Padding( padding: const EdgeInsets.only(bottom: 4), child: Container( padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8), @@ -3399,6 +3449,46 @@ class _ProfilePageState extends ConsumerState { ), ), )), + // 展开/收拢按钮 + if (_totalReferralCount > 10) + Padding( + padding: const EdgeInsets.only(top: 4), + child: GestureDetector( + onTap: _isLoadingMoreReferrals + ? null + : (_isReferralListExpanded + ? _collapseReferralList + : _expandReferralList), + child: Container( + width: double.infinity, + padding: const EdgeInsets.symmetric(vertical: 8), + decoration: BoxDecoration( + color: const Color(0xCCFFF5E6), + borderRadius: BorderRadius.circular(8), + ), + child: Center( + child: _isLoadingMoreReferrals + ? const SizedBox( + width: 16, + height: 16, + child: CircularProgressIndicator( + strokeWidth: 2, + color: Color(0xFF5D4037), + ), + ) + : Text( + _isReferralListExpanded ? '收起' : '...', + style: const TextStyle( + fontSize: 14, + fontFamily: 'Inter', + fontWeight: FontWeight.w500, + color: Color(0xFF5D4037), + ), + ), + ), + ), + ), + ), ], ); }