Skip to content

Commit

Permalink
fix: 更新持仓金额和成本价后,更新基金收益率
Browse files Browse the repository at this point in the history
  • Loading branch information
gittig11 committed Mar 5, 2022
1 parent 79f5e0f commit a43edde
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions template/fund-amount.html
Expand Up @@ -199,7 +199,6 @@ <h2 style="text-align: center; color: #409eff">
Math.random().toString(32).substr(2);

let sortType = 'default';
let totalEarnings = 0;
const list = $('.list');
let fundList = [];
let priceDate = new Date().toDateString();
Expand All @@ -221,10 +220,6 @@ <h2 style="text-align: center; color: #409eff">

function init(data) {
// const fundList = ${JSON.stringify(list)};
let listStr = '';
totalEarnings = 0;
let totalMoney = 0;

if (sortType !== 'default') {
fundList = data.sort((a, b) => {
const ae = a.earningPercent || 0;
Expand All @@ -234,9 +229,15 @@ <h2 style="text-align: center; color: #409eff">
} else {
fundList = data;
}

// console.log(fundList);

init2()
}

function init2() {
let listStr = '';
let totalMoney = 0;
let totalEarnings = 0;
fundList.forEach((item, index) => {
const amount = item.amount || 0;
const unitPrice = item.unitPrice || 0;
Expand Down Expand Up @@ -471,6 +472,13 @@ <h2 style="text-align: center; color: #409eff">
item.amount = amount; // 持仓金额
item.unitPrice = unitPrice; // 成本价
totalMoney += amount; // 持仓金额
// 收益率
if (unitPrice !== 0) {
profitPercent = (item.price - unitPrice) / unitPrice * 100;
item.earningPercent = profitPercent.toFixed(2);
} else {
item.earningPercent = 0;
}

// if (typeof ammountObj[item.code] !== 'object') {
// ammountObj[item.code] = {};
Expand All @@ -481,6 +489,7 @@ <h2 style="text-align: center; color: #409eff">
// ammountObj[item.code].earnings = earnings;
});
$('#totalMoney').html(totalMoney.toFixed(2));
init2()
vscode.postMessage({
command: 'success',
text: JSON.stringify(fundList),
Expand Down

0 comments on commit a43edde

Please sign in to comment.