|
@@ -486,6 +486,32 @@
|
|
|
// 立即更新价格,无需设置isLoadingFromApi为true
|
|
// 立即更新价格,无需设置isLoadingFromApi为true
|
|
|
this.refreshprice();
|
|
this.refreshprice();
|
|
|
},
|
|
},
|
|
|
|
|
+ // 获取比例换算金额的基准(优惠后总金额)
|
|
|
|
|
+ // 取值顺序:
|
|
|
|
|
+ // 1. 父组件通过 setDiscountAmount() 传入的 discountAmount(由合同/订单的
|
|
|
|
|
+ // 「优惠后总金额」驱动,是首选来源);
|
|
|
|
|
+ // 2. info.payAmount(销售订单/采购订单用这个字段);
|
|
|
|
|
+ // 3. info.discountTotalPrice(合同用这个字段);
|
|
|
|
|
+ // 4. info.totalAmount / info.totalPrice(只剩总金额时的最后兜底)。
|
|
|
|
|
+ // 逐级回退是为了防住两类坏情况:
|
|
|
|
|
+ // a) 来源单据不含 payAmount 时 Number(undefined)=NaN,会把计划金额写成 "NaN";
|
|
|
|
|
+ // b) 父组件在物品清单异步回显期间广播了 0,把基准清零,比例算出来的金额变成 0。
|
|
|
|
|
+ getBaseAmount() {
|
|
|
|
|
+ const candidates = [
|
|
|
|
|
+ this.discountAmount,
|
|
|
|
|
+ this.info && this.info.payAmount,
|
|
|
|
|
+ this.info && this.info.discountTotalPrice,
|
|
|
|
|
+ this.info && this.info.totalAmount,
|
|
|
|
|
+ this.info && this.info.totalPrice
|
|
|
|
|
+ ];
|
|
|
|
|
+ for (const value of candidates) {
|
|
|
|
|
+ const amount = Number(value);
|
|
|
|
|
+ if (!Number.isNaN(amount) && amount > 0) {
|
|
|
|
|
+ return amount;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ },
|
|
|
typeChange(val, index = null) {
|
|
typeChange(val, index = null) {
|
|
|
// console.log(val, index, '55555');
|
|
// console.log(val, index, '55555');
|
|
|
if (val) {
|
|
if (val) {
|
|
@@ -514,7 +540,10 @@
|
|
|
async ratioInput(val, index = null) {
|
|
async ratioInput(val, index = null) {
|
|
|
val = Number(val);
|
|
val = Number(val);
|
|
|
if (isNaN(val)) val = 0;
|
|
if (isNaN(val)) val = 0;
|
|
|
- this.discountAmount = Number(this.info.payAmount);
|
|
|
|
|
|
|
+ // 换算基准为优惠后总金额,不能直接取 info.payAmount:
|
|
|
|
|
+ // 报价单/核价单/商机等来源的表单不带该字段,Number(undefined) 为 NaN
|
|
|
|
|
+ const discountAmount = this.getBaseAmount();
|
|
|
|
|
+ this.discountAmount = discountAmount;
|
|
|
try {
|
|
try {
|
|
|
if (index != null) {
|
|
if (index != null) {
|
|
|
// 计算含本次新输入值的累计比例
|
|
// 计算含本次新输入值的累计比例
|
|
@@ -534,7 +563,7 @@
|
|
|
|
|
|
|
|
// 计算当前行计划金额
|
|
// 计算当前行计划金额
|
|
|
let newval = (val / 100).toFixed(2);
|
|
let newval = (val / 100).toFixed(2);
|
|
|
- let price = formatPrice(this.discountAmount * newval);
|
|
|
|
|
|
|
+ let price = formatPrice(discountAmount * newval);
|
|
|
this.$set(this.form.datasource[index], 'price', price);
|
|
this.$set(this.form.datasource[index], 'price', price);
|
|
|
|
|
|
|
|
// 计算累计金额(含当前行),单位换算为元(避免浮点精度问题)
|
|
// 计算累计金额(含当前行),单位换算为元(避免浮点精度问题)
|
|
@@ -547,7 +576,7 @@
|
|
|
) / 100;
|
|
) / 100;
|
|
|
|
|
|
|
|
// 多期时累计金额不能超过 discountAmount,使用 0.01 容差避免精度问题
|
|
// 多期时累计金额不能超过 discountAmount,使用 0.01 容差避免精度问题
|
|
|
- const discountAmt = Number(this.discountAmount);
|
|
|
|
|
|
|
+ const discountAmt = discountAmount;
|
|
|
if (totalAmount - discountAmt > 0.01) {
|
|
if (totalAmount - discountAmt > 0.01) {
|
|
|
this.$message.error('总金额不能超过优惠后总金额');
|
|
this.$message.error('总金额不能超过优惠后总金额');
|
|
|
this.$set(this.form.datasource[index], 'ratio', null);
|
|
this.$set(this.form.datasource[index], 'ratio', null);
|
|
@@ -562,7 +591,7 @@
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
let newval = (val / 100).toFixed(2);
|
|
let newval = (val / 100).toFixed(2);
|
|
|
- let price = formatPrice(this.discountAmount * newval);
|
|
|
|
|
|
|
+ let price = formatPrice(discountAmount * newval);
|
|
|
return price;
|
|
return price;
|
|
|
}
|
|
}
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
@@ -742,7 +771,7 @@
|
|
|
item.typeName = '交货款';
|
|
item.typeName = '交货款';
|
|
|
item.ratio = 100;
|
|
item.ratio = 100;
|
|
|
// 比例 100% 时金额等于优惠后总金额;同步算出避免切回"是"时 price 留空
|
|
// 比例 100% 时金额等于优惠后总金额;同步算出避免切回"是"时 price 留空
|
|
|
- this.discountAmount = Number(this.info.payAmount);
|
|
|
|
|
|
|
+ this.discountAmount = this.getBaseAmount();
|
|
|
item.price = formatPrice(this.discountAmount);
|
|
item.price = formatPrice(this.discountAmount);
|
|
|
item.key = i + 1;
|
|
item.key = i + 1;
|
|
|
item.issueNumber = i + 1;
|
|
item.issueNumber = i + 1;
|