|
|
@@ -366,14 +366,14 @@
|
|
|
info: {
|
|
|
handler(newval) {
|
|
|
if (newval && newval.receiptPaymentList) {
|
|
|
- this.isLoadingFromApi = true;
|
|
|
- this.form.datasource = newval.receiptPaymentList;
|
|
|
- if (newval.payAmount) {
|
|
|
- this.discountAmount = newval.payAmount;
|
|
|
- }
|
|
|
- setTimeout(() => {
|
|
|
- this.isLoadingFromApi = false;
|
|
|
- }, 100);
|
|
|
+ // this.isLoadingFromApi = true;
|
|
|
+ // this.form.datasource = newval.receiptPaymentList;
|
|
|
+ // if (newval.payAmount) {
|
|
|
+ // this.discountAmount = newval.payAmount;
|
|
|
+ // }
|
|
|
+ // setTimeout(() => {
|
|
|
+ // this.isLoadingFromApi = false;
|
|
|
+ // }, 100);
|
|
|
}
|
|
|
},
|
|
|
deep: true
|
|
|
@@ -382,11 +382,11 @@
|
|
|
methods: {
|
|
|
setDiscountAmount(val) {
|
|
|
console.log(val, '000000');
|
|
|
- this.isLoadingFromApi = true;
|
|
|
+ // this.isLoadingFromApi = true;
|
|
|
this.discountAmount = val;
|
|
|
- setTimeout(() => {
|
|
|
- this.isLoadingFromApi = false;
|
|
|
- }, 100);
|
|
|
+ // setTimeout(() => {
|
|
|
+ // this.isLoadingFromApi = false;
|
|
|
+ // }, 100);
|
|
|
},
|
|
|
typeChange(val, index = null) {
|
|
|
// console.log(val, index, '55555');
|
|
|
@@ -451,12 +451,40 @@
|
|
|
refreshprice() {
|
|
|
// console.log(this.form, '666666');
|
|
|
let newData = this.form.datasource;
|
|
|
+
|
|
|
+ // 先根据比例计算所有价格
|
|
|
newData.forEach(async (r, index) => {
|
|
|
if (r.ratio) {
|
|
|
console.log(this.ratioInput(Number(r.ratio)), '9999888888');
|
|
|
r.price = await this.ratioInput(Number(r.ratio));
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ // 验证并调整最后一行价格,确保总和等于优惠后的总金额
|
|
|
+ setTimeout(() => {
|
|
|
+ const allPriceSum = newData.reduce((acc, cur) => acc + Number(cur.price || 0), 0);
|
|
|
+ const discountAmount = Number(this.discountAmount);
|
|
|
+ // 直接计算比例总和,避免字符串转换问题
|
|
|
+ const allRatio = newData.reduce((acc, cur) => acc + Number(cur.ratio || 0), 0);
|
|
|
+
|
|
|
+ // 检查是否所有数据都有price且比例合计为100%
|
|
|
+ const allHavePrice = newData.every(item => item.price != null && item.price !== '');
|
|
|
+
|
|
|
+ if (allHavePrice && Math.abs(allRatio - 100) < 0.01 && Math.abs(allPriceSum - discountAmount) > 0.01) {
|
|
|
+ // 调整最后一行的价格
|
|
|
+ if (newData.length > 0) {
|
|
|
+ const lastIndex = newData.length - 1;
|
|
|
+ // 计算其他行的价格总和
|
|
|
+ const otherPriceSum = newData.slice(0, lastIndex).reduce((acc, cur) => acc + Number(cur.price || 0), 0);
|
|
|
+ // 计算最后一行应该有的价格
|
|
|
+ const lastPrice = discountAmount - otherPriceSum;
|
|
|
+ this.$set(newData, lastIndex, {
|
|
|
+ ...newData[lastIndex],
|
|
|
+ price: lastPrice.toFixed(2)
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, 0);
|
|
|
},
|
|
|
// 返回列表数据
|
|
|
getTableValue() {
|
|
|
@@ -608,12 +636,23 @@
|
|
|
const basicRatio = 100 / tempPeriod;
|
|
|
let totalRatio = 0;
|
|
|
|
|
|
+ // 保存原有数据
|
|
|
+ const existingData = [...this.form.datasource];
|
|
|
+
|
|
|
// 生成付款计划列表项
|
|
|
const tempList = [];
|
|
|
|
|
|
// 根据传入的period参数生成付款计划
|
|
|
for (let i = 0; i < tempPeriod; i++) {
|
|
|
let item = JSON.parse(JSON.stringify(this.defaultForm));
|
|
|
+ // let item;
|
|
|
+ // // 如果原有数据中有对应项,则保留原有数据
|
|
|
+ // if (i < existingData.length) {
|
|
|
+ // item = JSON.parse(JSON.stringify(existingData[i]));
|
|
|
+ // } else {
|
|
|
+ // item = JSON.parse(JSON.stringify(this.defaultForm));
|
|
|
+ // }
|
|
|
+
|
|
|
// 获取日期:如果i小于日期数组长度则使用对应日期,否则设为空
|
|
|
const deadLine = i < dateRange.length ? dateRange[i] : '';
|
|
|
const ratio = parseFloat(basicRatio.toFixed(2));
|
|
|
@@ -638,6 +677,7 @@
|
|
|
this.form.datasource = tempList;
|
|
|
// this.$set(this.form, 'datasource', tempList);
|
|
|
console.log('付款计划列表:', this.form.datasource);
|
|
|
+ this.$forceUpdate();
|
|
|
},
|
|
|
// 添加
|
|
|
handlAdd() {
|