Skip to content

Commit

Permalink
fix no login usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Chuiantw1212 committed May 13, 2024
1 parent 10938bd commit df685e8
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 57 deletions.
95 changes: 42 additions & 53 deletions components/calculator/career/labor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<el-col :span="12">
<el-form-item :label="`- 勞保自付額`">
<el-text>{{ Number(career.insurance?.expense).toLocaleString() }} (負擔率{{
laborInsurace.premiumRate[career.insuredUnit] }}%)</el-text>
laborInsurace.premiumRate[career.insuredUnit] }}%)</el-text>
</el-form-item>
</el-col>
</el-row>
Expand Down Expand Up @@ -125,7 +125,7 @@
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label="月支出" required>
<el-form-item label="月支出">
<el-input-number v-model="career.monthlyExpense" :min="0" :step="1000"
@change="calculateCareer($event)" />
</el-form-item>
Expand Down Expand Up @@ -249,9 +249,7 @@ function calculateCareer(options: any = { propagate: true }) {
calculatePensionSalary()
calculateCareerPensionContribution()
calculateHealthPremium()
debounce(() => {
drawChartAndCalculateIncome(propagate)
})(propagate)
drawChartAndCalculateIncome(propagate)
if (propagate) {
emits('update:modelValue', career.value)
}
Expand Down Expand Up @@ -421,6 +419,7 @@ function calculateMonthlySaving() {
}
// 畫圖
let incomeChartInstance = ref<Chart>()
const debounceId = ref()
function drawChartAndCalculateIncome(propagate = false) {
const { monthlyBasicSalary, insuredUnit, employeeWelfareFund, insurance, pension } = career.value
if (isUnableToDraw.value) {
Expand Down Expand Up @@ -516,16 +515,12 @@ function drawChartAndCalculateIncome(propagate = false) {
})
}

if (0 <= fv) {
if (0 < fv) {
dataAndDataIndex.push({
label: '定期定額',
data: [0, fv],
datasetIndex: 0,
})
} else {
if (!errorMssage.pending()) {
errorMssage()
}
}

const labels = dataAndDataIndex.map(item => item.label)
Expand Down Expand Up @@ -558,34 +553,44 @@ function drawChartAndCalculateIncome(propagate = false) {
]
}

if (incomeChartInstance.value) {
incomeChartInstance.value.data = data
incomeChartInstance.value.update()
return
}
const ctx: any = document.getElementById('incomeChart')
const chartInstance = new Chart(ctx, {
type: 'bar',
data: data,
options: {
plugins: {
tooltip: {
callbacks: {
label: tooltipFormat,
clearTimeout(debounceId.value)
debounceId.value = setTimeout(() => {
// 錯誤訊息
if (fv <= 0) {
if (!errorMssage.pending()) {
errorMssage()
}
}
// 繪圖
if (incomeChartInstance.value) {
incomeChartInstance.value.data = data
incomeChartInstance.value.update()
} else {
const ctx: any = document.getElementById('incomeChart')
const chartInstance = new Chart(ctx, {
type: 'bar',
data: data,
options: {
plugins: {
tooltip: {
callbacks: {
label: tooltipFormat,
}
}
},
scales: {
x: {
stacked: true,
},
y: {
stacked: true
}
}
}
},
scales: {
x: {
stacked: true,
},
y: {
stacked: true
}
}
})
incomeChartInstance = shallowRef(chartInstance)
}
})
incomeChartInstance = shallowRef(chartInstance)
}, 250)
}
function tooltipFormat(tooltipItems) {
const { raw } = tooltipItems
Expand All @@ -594,27 +599,11 @@ function tooltipFormat(tooltipItems) {
}

import { ElMessage, } from 'element-plus'
import { throttle, debounce } from '../lodash.js'
import { throttle, } from '../lodash.js'
const errorMssage = throttle(() => {
// ElMessage.error('收入:兩袖清風!')
ElMessage.error('收入:兩袖清風!')
}, 4000)


const debounceId = ref()
function debounce(func, delay = 250) {
return (immediate) => {
clearTimeout(debounceId.value)
if (immediate) {
func()
} else {
debounceId.value = setTimeout(() => {
debounceId.value = undefined
func()
}, delay)
}
}
}

defineExpose({
calculateCareer,
})
Expand Down
3 changes: 3 additions & 0 deletions components/calculator/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ const userForm = reactive({
monthlyContribution: 0,
weddingExpense: 0,
yearOfBirth: '',
monthlyNetPay: 0,
monthlyExpense: 0,
},
parenting: {
childAnnualExpense: 212767,
Expand All @@ -366,6 +368,7 @@ const userForm = reactive({
downpayGoal: 0,
monthlyRepay: 0,
downpayYear: 0,
downpayTotalPrice: 0,
},
estatePrice: {
county: '',
Expand Down
8 changes: 5 additions & 3 deletions components/calculator/retirement.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
</el-col>
<el-col :span="12">
<el-form-item label="退休後餘命">
<el-text>{{ retirement.lifeExpectancy }} 年</el-text>
<el-text>{{ retirement.lifeExpectancy }} 年
({{ Math.ceil(retirement.yearOfRetire + retirement.lifeExpectancy) }})</el-text>
</el-form-item>
</el-col>
</el-row> -->
Expand Down Expand Up @@ -285,8 +286,9 @@ const retirement = computed(() => {
return props.modelValue
})
const isFormDisabled = computed(() => {
const { monthlyBasicSalary } = props.career
return !monthlyBasicSalary
const { monthlyBasicSalary, } = props.career
const { careerInsuranceType } = props.profile
return !monthlyBasicSalary || !careerInsuranceType
})
const unableToDraw = computed(() => {
const { monthlyBasicSalary } = props.career
Expand Down
6 changes: 5 additions & 1 deletion components/calculator/spouse.vue
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ function calculatecSpouse(options: any = { propagate: true }) {
}
function calculateMonthlyContribution() {
const { monthlyNetPay, monthlyExpense } = spouse.value
spouse.value.monthlyContribution = monthlyNetPay - monthlyExpense
if (monthlyNetPay) {
spouse.value.monthlyContribution = monthlyNetPay - monthlyExpense
} else {
spouse.value.monthlyContribution = 0
}
}
function calculateYearOfMarriage() {
const { yearOfMarriage } = spouse.value
Expand Down

0 comments on commit df685e8

Please sign in to comment.