Skip to content

Commit

Permalink
fix age bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Chuiantw1212 committed May 13, 2024
1 parent 838cabf commit 02be6d6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 27 deletions.
32 changes: 15 additions & 17 deletions components/calculator/profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@
</el-radio-group>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="預估餘命">
<el-text>{{ profile.lifeExpectancy }} 年</el-text>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
Expand Down Expand Up @@ -81,6 +76,9 @@
通貨膨脹(消費者物價指數年增率):<a href="https://www.stat.gov.tw/Point.aspx?sid=t.2&n=3581&sms=11480"
target="_blank">中華民國統計資訊網</a>
</li>
<li>
公教人員年金改革到一半,目前沒人知道公保會怎麼調整。
</li>
</ul>
</el-collapse-item>
</el-collapse>
Expand Down Expand Up @@ -256,19 +254,19 @@ async function drawProfileChart(propagate = false) {
if (yearOfBirth && gender) {
const ceYear = new Date().getFullYear()
const calculateAge = ceYear - Number(yearOfBirth)
const res = await fetch(`${VITE_BASE_URL}/calculate/lifeExpectancy`, {
method: 'post',
body: JSON.stringify({
ceYear,
age: calculateAge,
gender,
}),
headers: { 'Content-Type': 'application/json' }
})
const lifeExpectancy = await res.json()
// const res = await fetch(`${VITE_BASE_URL}/calculate/lifeExpectancy`, {
// method: 'post',
// body: JSON.stringify({
// ceYear,
// age: calculateAge,
// gender,
// }),
// headers: { 'Content-Type': 'application/json' }
// })
// const lifeExpectancy = await res.json()
profile.value.age = calculateAge
profile.value.lifeExpectancy = Number(lifeExpectancy)
profile.value.longevity = calculateAge + lifeExpectancy
// profile.value.lifeExpectancy = Number(lifeExpectancy)
// profile.value.longevity = calculateAge + lifeExpectancy
if (propagate) {
emits('update:modelValue', profile.value)
}
Expand Down
5 changes: 2 additions & 3 deletions components/calculator/report/lifeAsset.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ function drawLifeAsset(payload) {
const { currentYear, inflationRate } = props.config
const { downpayTotalPrice, downpayYear } = props.estate
const { irrOverDecade } = props.retirement.pension
const { yearsToRetirement, yearOfRetire } = props.retirement
const { lifeExpectancy } = profile.value
const { yearsToRetirement, yearOfRetire, lifeExpectancy } = props.retirement
const datasets = []
Expand All @@ -110,7 +109,7 @@ function drawLifeAsset(payload) {
const inflationModifier = 1 + inflationRate / 100
let inflatedEstateAsset = downpayTotalPrice
for (let i = 0; i < lifeExpectancy; i++) {
for (let i = 0; i < yearsToRetirement + lifeExpectancy; i++) {
const year = currentYear + 1 + i
labels.push(year)
// data
Expand Down
4 changes: 2 additions & 2 deletions components/calculator/report/story.vue
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ async function generatStory() {
function getHumanStory() {
const { spouse, parenting, estate, estatePrice, career, retirement } = props
const { counties = [], insuranceTypes = [], townMap = {} } = props.config
const { longevity, yearOfBirth, careerInsuranceType, finalAsset } = profile.value
const { yearOfBirth, careerInsuranceType, finalAsset } = profile.value
const { careerHeadCount, } = career
const { age: retireAge, qualityLevel, insurance } = retirement
const { age: retireAge, qualityLevel, insurance, longevity } = retirement
const { yearOfMarriage } = spouse
const { headCount, independantAge } = parenting
const { downpayYear } = estate
Expand Down
3 changes: 2 additions & 1 deletion components/calculator/retirement.vue
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ async function calculateRetireLife() {
})
const lifeExpectancy = await res.json()
retirement.value.lifeExpectancy = lifeExpectancy
retirement.value.longevity = currentAge + yearsToRetirement + lifeExpectancy
}
function calculateFutureSeniority() { // 退休時年資
const { presentSeniority } = retirement.value.insurance
Expand Down Expand Up @@ -548,7 +549,7 @@ function calculateRetirementExpense() {
const selectedItem: IOptionItem = props.config.retirementQuartile[qualityLevel - 1]
retirement.value.annualExpense = Number(selectedItem.value)
}
async function drawRetirementAssetChart(propagate = false) {
async function drawRetirementAssetChart() {
if (unableToDraw.value) {
return
}
Expand Down
7 changes: 3 additions & 4 deletions components/calculator/security.vue
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,11 @@ function drawLifeAssetChart() {
if (unableToDraw.value) {
return
}
const { lifeExpectancy } = props.profile
const { presentAsset, irr, yearsToRetirement } = security.value
const { presentAsset, irr } = security.value
const { downpayYear, downpay, monthlyRepay, loanTerm, downpayGoal, totalPrice } = props.estate
const { currentYear, inflationRate } = props.config
const { monthlyContribution } = props.spouse
const { yearOfRetire } = props.retirement
const { yearsToRetirement, yearOfRetire, lifeExpectancy } = props.retirement
const spouseAnnualContribution = monthlyContribution * 12
const inflatoinRatio = 1 + inflationRate / 100
let valueModifier = 1
Expand All @@ -245,7 +244,7 @@ function drawLifeAssetChart() {
const spouseContribution: number[] = []
const childExpenseData: number[] = []
for (let i = 1; i <= lifeExpectancy + 1; i++) {
for (let i = 1; i <= yearsToRetirement + lifeExpectancy + 1; i++) {
const simYear = currentYear + i
valueModifier *= inflatoinRatio
/**
Expand Down

0 comments on commit 02be6d6

Please sign in to comment.