个人所得税计算
写成一个方法calcMoney
data(){
return{
index:-1, // 个人所得税所属的纳税阶段,
incomeData:[{incomeTax: "0.5",money: 30000}, {incomeTax: "0.8",money: 66000}, {incomeTax: "1",money: 100000}], //个人所得税计算区间,是活的,后台返回的
formData:{
demandBudget:0, // 预算金额,不是固定的,是活的,输入预算金额计算个人所得税,
income:0,// 个人所得税金额
}
}
}
// 个人所得税计算
calcMoney() {
for(let i=0;i<this.incomeData.length;i++){
if(this.formData.demandBudget<=this.incomeData[i].money){
this.index = i;
break;
}else{
this.index = -1;
}
}
if(this.index === 0){
// 还未到纳税标准
this.formData.income = 0
}
else if(this.index>0){
// 在纳税区间内,未超过最高纳税标准
let money1 = 0;
let money2 = 0;
money1 = (this.formData.demandBudget - this.incomeData[this.index-1].money)*this.incomeData[this.index-1].incomeTax*0.01;
for(let i =0;i<=this.index;i++){
if(i-2>=0){
money2 = money2+((this.incomeData[i-1].money-this.incomeData[i-2].money)*this.incomeData[i-2].incomeTax*0.01);
}
}
this.formData.income = money1 + money2;
}
else{
// 已超过最高纳税金额
if(this.formData.demandBudget>0){
let money1 = 0;
let money2 = 0;
let leng = this.incomeData.length; // 个人所得税纳税标准条数
money1 = (this.formData.demandBudget - this.incomeData[leng-1].money)*this.incomeData[leng-1].incomeTax*0.01;
for(let i =0;i<=leng;i++){
if(i-2>=0){
money2 = money2+((this.incomeData[i-1].money-this.incomeData[i-2].money)*this.incomeData[i-2].incomeTax*0.01)
}
}
this.formData.income = money1 + money2;
}
}
}