Skip to content

Commit

Permalink
fix: fix load-caculator
Browse files Browse the repository at this point in the history
fix: fix load-caculator
  • Loading branch information
yinjg1997 authored Oct 25, 2023
2 parents 0e6ca13 + f1d6059 commit d479810
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
2 changes: 1 addition & 1 deletion loan-calculator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"name": "Loan Calculator",
"id": "he3-loan-calculator",
"icon": "block-outlined",
"version": "1.0.6",
"version": "1.0.7",
"description": "Loan Calculator Tool Documentation\n\nThe Loan Calculator tool is a tool used to calculate loan interest rates and repayment plans. Users can input information such as loan principal, the latest benchmark interest rate, LPR markup, loan term, and repayment method. The tool will automatically calculate the monthly repayment amount, total interest, and total repayment amount, and generate a repayment plan table. Users can also export the repayment plan table as a CSV file.\n\nUse cases:\n\n1. Loan calculation: When applying for a loan, users can use the Loan Calculator tool to calculate the monthly repayment amount, total interest, and total repayment amount, in order to better understand the loan cost and repayment plan.\n\n2. Loan comparison: Users can use the Loan Calculator tool to compare the repayment plans and costs of different loan schemes, in order to choose the optimal loan scheme.\n\n3. Loan management: Users can use the Loan Calculator tool to track loan repayment plans and repayment status, in order to better manage their loans.\n\nInstructions:\n\n1. Open the Loan Calculator tool page.\n\n2. Input information such as loan principal, the latest benchmark interest rate, LPR markup, loan term, and repayment method.\n\n3. Click the \"Calculate\" button, and the tool will automatically calculate the monthly repayment amount, total interest, and total repayment amount, and generate a repayment plan table.\n\n4. Users can view the repayment plan table and export it as a CSV file.\n\nNotes:\n\n1. The input information such as loan principal, the latest benchmark interest rate, LPR markup, loan term, and repayment method must be legal and valid.\n\n2. The monthly repayment amount, total interest, and total repayment amount calculated by the tool are for reference only, and the actual situation may be different.\n\n3. The repayment plan table exported by the user is for reference only, and the actual situation may be different.\n\n4. Users should properly keep the repayment plan table and exported CSV file generated by the Loan Calculator tool to avoid leaking personal information.\n\n5. Users should comply with relevant laws, regulations, and policies when using the Loan Calculator tool, and should not use it for illegal purposes.",
"relatedToolId": [],
"isPublic": true,
Expand Down
37 changes: 16 additions & 21 deletions loan-calculator/src/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,56 +136,57 @@ const he3 = window.$he3;
const loanAmount = ref<number>(1000000);
const latestLPR = ref<number>(4.3);
const LPRPlusValue = ref<number>(0);
// 年利率
const interestRate = ref<number>(0);
// 贷款期限
const loanTerm = ref<number>(360);
const repaymentType = ref<number>(0);
var monthlyPaymentDetail = ref<number[][]>([])
var totalPayNum = ref<number>(0);
var totalInterestNum = ref<number>(0);
const changeMonth = function(e){
// console.log(e);
// debugger;
loanTerm.value = e;
}
}
function calculateInterestRate() {
interestRate.value = Number(latestLPR.value) + 0.01*Number(LPRPlusValue.value);
}
function monthlyInterestRate() {
// 计算月利率
if (interestRate.value === 0) return 0
return interestRate.value / 12 / 100;
}
function monthlyPayment() {
let res: number[][] = []
// 计算每月还款额
if (repaymentType.value==0) {
if (loanAmount.value === 0 || interestRate.value === 0 || loanTerm.value === 0) {
console.log('Returning 0')
// res.push(ref<number>(0).value);
if (loanAmount.value === 0 || loanTerm.value === 0) {
return res;
}
console.log('Not returning 0')
const n = loanTerm.value; // 总期数
const mir = monthlyInterestRate(); // 月利率
const pow = Math.pow(1 + mir, n); // (1+i)^n
const monthlyPaymentAmount = (loanAmount.value * mir * pow) / (pow - 1)
let monthlyPaymentAmount: number
if (mir === 0) {
monthlyPaymentAmount = loanAmount.value / n
} else {
monthlyPaymentAmount = (loanAmount.value * mir * pow) / (pow - 1)
}
var leftLoanAmount = Number(loanAmount.value);
for (let i=0;i<n;i++){
leftLoanAmount -= monthlyPaymentAmount - leftLoanAmount*mir;
if (leftLoanAmount<0) leftLoanAmount = 0;
var temp = [monthlyPaymentAmount, leftLoanAmount*mir, monthlyPaymentAmount-leftLoanAmount*mir, leftLoanAmount]
res.push(temp);
}
} else if (repaymentType.value==1) {
if (loanAmount.value === 0 || interestRate.value === 0 || loanTerm.value === 0) {
console.log('Returning 0')
// res.push(ref<number>(0).value);
}
else if (repaymentType.value==1) {
if (loanAmount.value === 0 || loanTerm.value === 0) {
return res;
}
console.log('Not returning 0')
const n = loanTerm.value; // 总期数
const mir = monthlyInterestRate(); // 月利率
var leftLoanAmount = Number(loanAmount.value);
Expand All @@ -207,7 +208,6 @@ function totalPay() {
for (let i=0;i<monthlyPaymentList.length;i++){
sum+=monthlyPaymentList[i][0];
}
console.log(sum)
return sum;
}
Expand Down Expand Up @@ -240,15 +240,12 @@ function downloadCSV(csv, filename) {
document.body.appendChild(downloadLink);
downloadLink.click();
console.log(csv);
}
//user-defined function to export the data to CSV file format
function exportTableToCSV(filename) {
//declare a JavaScript variable of array type
// console.log(filename);
var csv = [];
var csv = [];
var rows = document.querySelectorAll("table tr");
//merge the whole data in tabular form
Expand All @@ -258,8 +255,6 @@ function exportTableToCSV(filename) {
row.push(cols[j].innerText);
csv.push(row.join(","));
}
console.log(csv);
//call the function to download the CSV file
downloadCSV(csv.join("\n"), filename);
}
Expand All @@ -270,7 +265,7 @@ function exportTableToCSV(filename) {
table-layout: fixed;
width: 100%;
border-collapse: separate;
border: 2px solid var(--primary-color);
border: 2px solid var(--divider-color);
border-spacing: 0;
border-radius: 10px;
}
Expand Down

0 comments on commit d479810

Please sign in to comment.