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 a11f6f8 commit 79f5e0f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
6 changes: 4 additions & 2 deletions src/webview/setAmount.ts
Expand Up @@ -14,7 +14,7 @@ import ReusedWebviewPanel from './ReusedWebviewPanel';
const cloneDeep = require('lodash.clonedeep');

async function setAmount(fundService: FundService) {
const list = fundDataHandler(fundService);
// const list = fundDataHandler(fundService);
const panel = ReusedWebviewPanel.create(
'setFundAmountWebview',
`基金持仓金额设置`,
Expand Down Expand Up @@ -76,9 +76,11 @@ function fundDataHandler(fundService: FundService) {
amount: amountObj[item.info?.code]?.amount || 0,
earningPercent: item.info?.earningPercent,
unitPrice: item.info?.unitPrice,
priceDate: formatDate(item.info?.time),
// priceDate: formatDate(item.info?.time),
earnings: item.info?.earnings || 0,
yestEarnings: amountObj[item.info.code]?.earnings || 0,
price: item.info?.yestclose,
priceDate: item.info?.yestPriceDate,
};
});

Expand Down
28 changes: 19 additions & 9 deletions template/fund-amount.html
Expand Up @@ -461,21 +461,31 @@ <h2 style="text-align: center; color: #409eff">
}
});
$('#save').click(() => {
const ammountObj = {};
// const ammountObj = {};
let totalMoney = 0;
fundList.forEach((item) => {
let amount = $('#' + item.code).val();
let unitPrice = $('#' + item.code + '_unit').val();
amount = isNaN(Number(amount)) ? 0 : Number(amount);
unitPrice = isNaN(Number(unitPrice)) ? 0 : Number(unitPrice);

if (typeof ammountObj[item.code] !== 'object') {
ammountObj[item.code] = {};
}
ammountObj[item.code].amount = amount;
ammountObj[item.code].unitPrice = unitPrice;
const earnings = item.earnings || 0;
ammountObj[item.code].earnings = earnings;
item.amount = amount; // 持仓金额
item.unitPrice = unitPrice; // 成本价
totalMoney += amount; // 持仓金额

// if (typeof ammountObj[item.code] !== 'object') {
// ammountObj[item.code] = {};
// }
// ammountObj[item.code].amount = amount;
// ammountObj[item.code].unitPrice = unitPrice;
// const earnings = item.earnings || 0;
// ammountObj[item.code].earnings = earnings;
});
$('#totalMoney').html(totalMoney.toFixed(2));
vscode.postMessage({
command: 'success',
text: JSON.stringify(fundList),
});
return

fetchInfo(fundList, ({ Expansion = {}, Datas = [] }) => {
const dates = [
Expand Down

0 comments on commit 79f5e0f

Please sign in to comment.