Skip to content

Commit

Permalink
fix retirement
Browse files Browse the repository at this point in the history
  • Loading branch information
Chuiantw1212 committed May 13, 2024
1 parent 02be6d6 commit ff76138
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 60 deletions.
2 changes: 1 addition & 1 deletion components/calculator/parenting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ function showChildExpense(tooltipItems) {
}
const debounceId = ref()
function debounce(func, delay = 100) {
function debounce(func, delay = 150) {
return (immediate) => {
clearTimeout(debounceId.value)
if (immediate) {
Expand Down
19 changes: 1 addition & 18 deletions components/calculator/profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,7 @@ function openSignInDialog() {
async function calculateProfile(options: any = { propagate: true }) {
const { propagate = true } = options
customDebounce(() => {
drawProfileChart(propagate)
})(propagate)
drawProfileChart(propagate)
}
async function drawProfileChart(propagate = false) {
Expand Down Expand Up @@ -276,21 +274,6 @@ async function drawProfileChart(propagate = false) {
}
}
const debounceId = ref()
function customDebounce(func, delay = 100) {
return (immediate) => {
clearTimeout(debounceId.value)
if (immediate) {
func()
} else {
debounceId.value = setTimeout(() => {
debounceId.value = undefined
func()
}, delay)
}
}
}
defineExpose({
calculateProfile,
toggleSignInDialog
Expand Down
43 changes: 12 additions & 31 deletions components/calculator/retirement.vue
Original file line number Diff line number Diff line change
Expand Up @@ -334,17 +334,11 @@ async function calculateRetirement(options: any = { propagate: true }) {
}
calculateRetirementExpense()
const { propagate = true } = options
const pensionLumpSumDataPromise = new Promise((resolve) => {
customDebounce(async () => {
const pensionLumpSumData = await drawRetirementAssetChart(propagate)
resolve(pensionLumpSumData)
})(false)
// 儲存參數
if (propagate) {
emits('update:modelValue', retirement.value)
}
})
return pensionLumpSumDataPromise
const pensionLumpSumData = await drawRetirementAssetChart()
if (propagate) {
emits('update:modelValue', retirement.value)
}
return pensionLumpSumData
}
function resetData() {
retirement.value.insurance.annuity = 0
Expand Down Expand Up @@ -549,6 +543,8 @@ function calculateRetirementExpense() {
const selectedItem: IOptionItem = props.config.retirementQuartile[qualityLevel - 1]
retirement.value.annualExpense = Number(selectedItem.value)
}
const debounceId = ref()
async function drawRetirementAssetChart() {
if (unableToDraw.value) {
return
Expand Down Expand Up @@ -590,8 +586,6 @@ async function drawRetirementAssetChart() {
const retirementAnnualExpenseData: number[] = []
const estateData: number[] = []
const { careerInsuranceType } = props.profile
// if (['employee', 'entrepreneur'].includes(careerInsuranceType)) {
pv = employerContribution + employeeContrubution + employerContributionIncome + employeeContrubutionIncome
// 退休前資產累積
for (let i = 1; i <= n; i++) {
Expand All @@ -611,7 +605,6 @@ async function drawRetirementAssetChart() {
}
calculatePensionLumpsumTax(fv)
pv += insurance.lumpsum
// 退休後退休支出
let insuranceAnnuityInflationModifier = 1
Expand Down Expand Up @@ -690,8 +683,11 @@ async function drawRetirementAssetChart() {
}
// 繪圖
if (pensionChartInstance.value) {
pensionChartInstance.value.data = chartData
pensionChartInstance.value.update()
clearTimeout(debounceId.value)
debounceId.value = setTimeout(() => {
pensionChartInstance.value.data = chartData
pensionChartInstance.value.update()
}, 150)
} else {
const ctx: any = document.getElementById('pensionChart')
const chartInstance = new Chart(ctx, {
Expand Down Expand Up @@ -734,21 +730,6 @@ const errorMssage = throttle(() => {
// ElMessage.error('退休:晚節不保!')
}, 4000)
const debounceId = ref()
function customDebounce(func, delay = 100) {
return (immediate) => {
clearTimeout(debounceId.value)
if (immediate) {
func()
} else {
debounceId.value = setTimeout(() => {
debounceId.value = undefined
func()
}, delay)
}
}
}
defineExpose({
calculateRetirement,
});
Expand Down
15 changes: 6 additions & 9 deletions components/calculator/security.vue
Original file line number Diff line number Diff line change
Expand Up @@ -374,15 +374,12 @@ function drawLifeAssetChart() {
labels: labels.slice(0, yearsToRetirement)
}
if (securityChartInstance.value) {
const promise = new Promise(async (resolve) => {
clearTimeout(debounceId.value)
debounceId.value = setTimeout(async () => {
debounceId.value = undefined
securityChartInstance.value.data = chartData
// resolve(principleData)
securityChartInstance.value.update()
}, 150)
})
clearTimeout(debounceId.value)
debounceId.value = setTimeout(async () => {
debounceId.value = undefined
securityChartInstance.value.data = chartData
securityChartInstance.value.update()
}, 150)
} else {
const ctx: any = document.getElementById('securityChart')
const chartInstance = new Chart(ctx, {
Expand Down
2 changes: 1 addition & 1 deletion components/calculator/spouse.vue
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ function drawMarriageChart(propagate = true) {
}
const debounceId = ref()
function debounce(func, delay = 100) {
function debounce(func, delay = 150) {
return (immediate) => {
clearTimeout(debounceId.value)
if (immediate) {
Expand Down

0 comments on commit ff76138

Please sign in to comment.