feat(mobile-app): 引荐列表支持展开/收拢功能
- 初始只显示前10条引荐记录 - 超过10人时显示"..."按钮可点击展开全部 - 展开后显示"收起"按钮可点击收拢 - 加载更多时显示loading指示器 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
4ee355a7cd
commit
8eb5b410cc
|
|
@ -66,6 +66,9 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
|
|||
|
||||
// 直推数据(从 referral-service 获取)
|
||||
List<Map<String, dynamic>> _referrals = [];
|
||||
int _totalReferralCount = 0; // 直推总人数
|
||||
bool _isReferralListExpanded = false; // 引荐列表是否展开
|
||||
bool _isLoadingMoreReferrals = false; // 是否正在加载更多引荐
|
||||
|
||||
// 团队树根节点(缓存以保持展开状态)
|
||||
TeamTreeNode? _teamTreeRootNode;
|
||||
|
|
@ -401,6 +404,8 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
|
|||
'personal': r.personalPlantingCount, // 个人认种量
|
||||
'team': r.teamPlantingCount, // 团队认种量
|
||||
}).toList();
|
||||
_totalReferralCount = directReferrals.total; // 保存总数
|
||||
_isReferralListExpanded = false; // 重置展开状态
|
||||
});
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
|
|
@ -422,6 +427,46 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
|
|||
}
|
||||
}
|
||||
|
||||
/// 展开引荐列表(加载全部数据)
|
||||
Future<void> _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) => <String, dynamic>{
|
||||
'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<void> _loadAuthorizationData({bool isRefresh = false}) async {
|
||||
|
|
@ -3349,6 +3394,11 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
|
|||
|
||||
/// 构建引荐列表
|
||||
Widget _buildReferralList() {
|
||||
// 决定显示多少条
|
||||
final displayList = _isReferralListExpanded
|
||||
? _referrals
|
||||
: _referrals.take(10).toList();
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
|
|
@ -3366,7 +3416,7 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
|
|||
),
|
||||
),
|
||||
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<ProfilePage> {
|
|||
),
|
||||
),
|
||||
)),
|
||||
// 展开/收拢按钮
|
||||
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),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue