111
This commit is contained in:
@@ -78,16 +78,30 @@ class AccountTrade {
|
||||
});
|
||||
|
||||
factory AccountTrade.fromJson(Map<String, dynamic> json) {
|
||||
// 后端返回 value(当前价值),前端用 currentValue
|
||||
final quantityNum =
|
||||
double.tryParse(json['quantity']?.toString() ?? '0') ?? 0;
|
||||
final avgPriceNum =
|
||||
double.tryParse(json['avgPrice']?.toString() ?? '0') ?? 0;
|
||||
final currentValueNum =
|
||||
double.tryParse(json['value']?.toString() ?? '0') ??
|
||||
double.tryParse(json['currentValue']?.toString() ?? '0') ??
|
||||
0;
|
||||
final totalCostNum = quantityNum * avgPriceNum;
|
||||
final profitNum = currentValueNum - totalCostNum;
|
||||
final double profitRateNum =
|
||||
totalCostNum > 0 ? (profitNum / totalCostNum) * 100.0 : 0.0;
|
||||
|
||||
return AccountTrade(
|
||||
id: json['id'] as int? ?? 0,
|
||||
userId: json['userId'] as int? ?? 0,
|
||||
coinCode: json['coinCode'] as String? ?? '',
|
||||
quantity: json['quantity']?.toString() ?? '0',
|
||||
avgPrice: json['avgPrice']?.toString() ?? '0.00',
|
||||
totalCost: json['totalCost']?.toString() ?? '0.00',
|
||||
currentValue: json['currentValue']?.toString() ?? '0.00',
|
||||
profit: json['profit']?.toString() ?? '0.00',
|
||||
profitRate: (json['profitRate'] as num?)?.toDouble() ?? 0,
|
||||
totalCost: totalCostNum.toStringAsFixed(2),
|
||||
currentValue: currentValueNum.toStringAsFixed(2),
|
||||
profit: profitNum.toStringAsFixed(2),
|
||||
profitRate: profitRateNum,
|
||||
updateTime: json['updateTime'] != null
|
||||
? DateTime.tryParse(json['updateTime'])
|
||||
: null,
|
||||
|
||||
Reference in New Issue
Block a user