diff --git a/lib/features/recharge/models/payment_method_item.dart b/lib/features/recharge/models/payment_method_item.dart index 48ab8b3..9559c4f 100644 --- a/lib/features/recharge/models/payment_method_item.dart +++ b/lib/features/recharge/models/payment_method_item.dart @@ -6,6 +6,8 @@ class PaymentMethodItem { this.name, this.icon, this.recommend = false, + this.bonusCredits = 0, + this.bonusRatio = 0, }); final String paymentMethod; // resource,如 GOOGLEPAY/APPLEPAY @@ -13,6 +15,10 @@ class PaymentMethodItem { final String? name; // brigade 展示名称 final String? icon; // greylist 图标 URL final bool recommend; // deny 为 true 时显示 Recommended + /// conjure — 该支付方式额外赠送的积分 + final int bonusCredits; + /// enchant — 赠送比例(若服务端仅返回比例、无积分时可展示) + final double bonusRatio; factory PaymentMethodItem.fromJson(Map json) { return PaymentMethodItem( @@ -21,8 +27,38 @@ class PaymentMethodItem { name: json['brigade']?.toString(), icon: json['greylist']?.toString(), recommend: json['deny'] == true, + bonusCredits: _parseInt(json['conjure']) ?? 0, + bonusRatio: _parseDouble(json['enchant']) ?? 0, ); } + static int? _parseInt(dynamic v) { + if (v == null) return null; + if (v is int) return v; + if (v is num) return v.toInt(); + return int.tryParse(v.toString()); + } + + static double? _parseDouble(dynamic v) { + if (v == null) return null; + if (v is double) return v; + if (v is num) return v.toDouble(); + return double.tryParse(v.toString()); + } + String get displayName => name?.isNotEmpty == true ? name! : paymentMethod; + + /// 用于列表副标题:优先展示赠送积分,否则展示赠送比例 + String? get bonusLabel { + if (bonusCredits > 0) { + return '+$bonusCredits bonus credits'; + } + if (bonusRatio > 0) { + final pct = bonusRatio <= 1 + ? (bonusRatio * 100).round() + : bonusRatio.round(); + return '+$pct% bonus credits'; + } + return null; + } } diff --git a/lib/features/recharge/recharge_screen.dart b/lib/features/recharge/recharge_screen.dart index bad4dcf..67484e4 100644 --- a/lib/features/recharge/recharge_screen.dart +++ b/lib/features/recharge/recharge_screen.dart @@ -784,10 +784,10 @@ class _PaymentMethodItem extends StatelessWidget { Widget build(BuildContext context) { return GestureDetector( onTap: onTap, - child: AnimatedContainer( + child: AnimatedContainer( duration: const Duration(milliseconds: 150), padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), - height: 64, + constraints: const BoxConstraints(minHeight: 64), decoration: BoxDecoration( color: isSelected ? const Color(0x158B5CF6) : AppColors.surface, borderRadius: BorderRadius.circular(12), @@ -804,28 +804,48 @@ class _PaymentMethodItem extends StatelessWidget { _PaymentIcon(iconUrl: item.icon), const SizedBox(width: 12), Expanded( - child: Row( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, children: [ - Flexible( - child: Text( - item.displayName, - style: AppTypography.bodyRegular.copyWith( - color: AppColors.textPrimary, - fontWeight: FontWeight.w600, - fontSize: 16, + Row( + children: [ + Flexible( + child: Text( + item.displayName, + style: AppTypography.bodyRegular.copyWith( + color: AppColors.textPrimary, + fontWeight: FontWeight.w600, + fontSize: 16, + ), + overflow: TextOverflow.ellipsis, + ), ), - overflow: TextOverflow.ellipsis, - ), + if (item.recommend) ...[ + const SizedBox(width: 6), + Text( + 'Recommended', + style: AppTypography.caption.copyWith( + color: AppColors.primary, + fontWeight: FontWeight.w600, + fontSize: 11, + ), + ), + ], + ], ), - if (item.recommend) ...[ - const SizedBox(width: 6), + if (item.bonusLabel != null) ...[ + const SizedBox(height: 4), Text( - 'Recommended', + item.bonusLabel!, style: AppTypography.caption.copyWith( color: AppColors.primary, - fontWeight: FontWeight.w600, - fontSize: 11, + fontWeight: FontWeight.w500, + fontSize: 12, ), + maxLines: 1, + overflow: TextOverflow.ellipsis, ), ], ],