Am在这种情况下,我必须逆转计算标准以使其清楚:
这是上述步骤的演示代码:
let subtotal_with_ewa = Number((this.subtotal_price / 100) * this.unit.reservation.prices.ewa_parentage) + Number(this.subtotal_price);
this.total_ewa = parseFloat((this.subtotal_price / 100) * this.unit.reservation.prices.ewa_parentage).toFixed(2)
this.total_vat = parseFloat((subtotal_with_ewa / 100 ) * this.unit.reservation.prices.vat_parentage).toFixed(2);
this.total_ttx = parseFloat((this.subtotal_price / 100) * this.unit.reservation.prices.tourism_percentage).toFixed(2);
this.total_price = parseFloat(subtotal_with_ewa + Number(this.total_vat) + Number(this.total_tourism)).toFixed(2);
this.unit.reservation.prices.total_price_raw = parseFloat(subtotal_with_ewa + Number(this.total_vat) + Number(this.total_ttx) ).toFixed(2);
this.unit.reservation.prices.total_price = this.unit.reservation.prices.total_price_raw ;
this.total_price = this.unit.reservation.prices.total_price ;
this.unit.reservation.prices.price = this.subtotal_price
现在的问题是:要使整个操作相反,我该怎么做,我的意思是,如果我改变了总计值,我需要做些什么,我需要重新计算这些值,直到再次获得小计...。有什么想法吗?
答案 0 :(得分:0)
您需要使计算出的属性能够在依赖关系更改时重新计算,例如:
subtotal_with_ewa(){
return Number((this.subtotal_price / 100) *
this.unit.reservation.prices.ewa_parentage) + Number(this.subtotal_price);
}
您可以使用具有计算属性的getter和setter或将它们与字段上的绑定v模型分开。
答案 1 :(得分:0)
以下功能可以解决问题。
该函数接受每个税额的百分比作为参数,并返回一个将所有值都包含的json。
function fromSubTotal(subTotal, pre, vato, tx) {
const preAmount = subTotal * pre / 100
const vatoAmount = (subTotal + pre) * vato / 100
const txAmount = subTotal * tx / 100
const total = subTotal + preAmount + vatoAmount + txAmount
return {subTotal, preAmount, vatoAmount, txAmount, total}
}
function fromTotal(total, pre, vato, tx) {
const subTotal = (total * 100) / (100 + pre + tx + (1.01 * pre * vato))
return fromSubTotal(subTotal, pre, vato, tx)
}
// eg.
console.log(fromSubTotal(100,1,1,1))
console.log(fromTotal(103.01,1,1,1))