|
@@ -495,65 +495,49 @@
|
|
|
*/
|
|
*/
|
|
|
allocateInvoiceAmount(data) {
|
|
allocateInvoiceAmount(data) {
|
|
|
if (Array.isArray(data)) {
|
|
if (Array.isArray(data)) {
|
|
|
- // 处理数组
|
|
|
|
|
data.forEach(item => {
|
|
data.forEach(item => {
|
|
|
if (item && typeof item === 'object') {
|
|
if (item && typeof item === 'object') {
|
|
|
- let remainingTotal = Number(item.amountTotalPrice) || 0;
|
|
|
|
|
- const details = item.details || [];
|
|
|
|
|
-
|
|
|
|
|
- // 按顺序分配金额
|
|
|
|
|
- details.forEach((detail) => {
|
|
|
|
|
- if (remainingTotal <= 0) {
|
|
|
|
|
- // 剩余金额为0,分配0
|
|
|
|
|
- detail.invoiceAmount = 0;
|
|
|
|
|
- } else {
|
|
|
|
|
- // 获取当前明细的unInvoiceAmount
|
|
|
|
|
- const unInvoiceAmount = Number(detail.unInvoiceAmount) || 0;
|
|
|
|
|
-
|
|
|
|
|
- if (remainingTotal > unInvoiceAmount) {
|
|
|
|
|
- // 剩余金额大于unInvoiceAmount,分配unInvoiceAmount
|
|
|
|
|
- detail.invoiceAmount = unInvoiceAmount;
|
|
|
|
|
- remainingTotal -= unInvoiceAmount;
|
|
|
|
|
- } else {
|
|
|
|
|
- // 剩余金额小于等于unInvoiceAmount,分配剩余金额
|
|
|
|
|
- detail.invoiceAmount = remainingTotal;
|
|
|
|
|
- remainingTotal = 0;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ this.allocateSingleInvoiceAmount(item);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
return data;
|
|
return data;
|
|
|
} else if (data && typeof data === 'object') {
|
|
} else if (data && typeof data === 'object') {
|
|
|
- // 处理单个对象
|
|
|
|
|
- let remainingTotal = Number(data.amountTotalPrice) || 0;
|
|
|
|
|
- const details = data.details || [];
|
|
|
|
|
-
|
|
|
|
|
- // 按顺序分配金额
|
|
|
|
|
- details.forEach((detail) => {
|
|
|
|
|
- if (remainingTotal <= 0) {
|
|
|
|
|
- // 剩余金额为0,分配0
|
|
|
|
|
- detail.invoiceAmount = 0;
|
|
|
|
|
- } else {
|
|
|
|
|
- // 获取当前明细的unInvoiceAmount
|
|
|
|
|
- const unInvoiceAmount = Number(detail.unInvoiceAmount) || 0;
|
|
|
|
|
-
|
|
|
|
|
- if (remainingTotal > unInvoiceAmount) {
|
|
|
|
|
- // 剩余金额大于unInvoiceAmount,分配unInvoiceAmount
|
|
|
|
|
- detail.invoiceAmount = unInvoiceAmount;
|
|
|
|
|
- remainingTotal -= unInvoiceAmount;
|
|
|
|
|
- } else {
|
|
|
|
|
- // 剩余金额小于等于unInvoiceAmount,分配剩余金额
|
|
|
|
|
- detail.invoiceAmount = remainingTotal;
|
|
|
|
|
- remainingTotal = 0;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
|
|
+ this.allocateSingleInvoiceAmount(data);
|
|
|
return data;
|
|
return data;
|
|
|
}
|
|
}
|
|
|
return data;
|
|
return data;
|
|
|
},
|
|
},
|
|
|
|
|
+ allocateSingleInvoiceAmount(item) {
|
|
|
|
|
+ let remainingTotal = this.toPrecision(item.amountTotalPrice);
|
|
|
|
|
+ const details = item.details || [];
|
|
|
|
|
+
|
|
|
|
|
+ details.forEach((detail) => {
|
|
|
|
|
+ if (remainingTotal <= 0) {
|
|
|
|
|
+ detail.invoiceAmount = 0;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const unInvoiceAmount = this.toPrecision(detail.unInvoiceAmount);
|
|
|
|
|
+
|
|
|
|
|
+ if (remainingTotal > unInvoiceAmount) {
|
|
|
|
|
+ detail.invoiceAmount = this.fromPrecision(unInvoiceAmount);
|
|
|
|
|
+ remainingTotal = this.subPrecision(remainingTotal, unInvoiceAmount);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ detail.invoiceAmount = this.fromPrecision(remainingTotal);
|
|
|
|
|
+ remainingTotal = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+ toPrecision(value) {
|
|
|
|
|
+ const num = parseFloat(value) || 0;
|
|
|
|
|
+ return Math.round(num * 100);
|
|
|
|
|
+ },
|
|
|
|
|
+ fromPrecision(value) {
|
|
|
|
|
+ const num = parseFloat(value) || 0;
|
|
|
|
|
+ return (num / 100).toFixed(2);
|
|
|
|
|
+ },
|
|
|
|
|
+ subPrecision(a, b) {
|
|
|
|
|
+ return a - b;
|
|
|
|
|
+ },
|
|
|
|
|
|
|
|
setSinglePrice(row, data) {
|
|
setSinglePrice(row, data) {
|
|
|
let index = this.tableForm.detailList.findIndex(item => item.key == row.relatedOrderNo);
|
|
let index = this.tableForm.detailList.findIndex(item => item.key == row.relatedOrderNo);
|
|
@@ -644,6 +628,20 @@
|
|
|
// 3. 处理验证结果
|
|
// 3. 处理验证结果
|
|
|
try {
|
|
try {
|
|
|
await Promise.all(validationPromises);
|
|
await Promise.all(validationPromises);
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 校验 amountTotalPrice 和 defaultAmountTotalPrice 是否相等
|
|
|
|
|
+ for (let i = 0; i < this.tableForm.detailList.length; i++) {
|
|
|
|
|
+ const item = this.tableForm.detailList[i];
|
|
|
|
|
+ const amountTotalPrice = parseFloat(item.amountTotalPrice) || 0;
|
|
|
|
|
+ const defaultAmountTotalPrice = parseFloat(item.defaultAmountTotalPrice) || 0;
|
|
|
|
|
+
|
|
|
|
|
+ if (amountTotalPrice !== defaultAmountTotalPrice) {
|
|
|
|
|
+ this.$message.warning(`第${i + 1}条本次开票合计(${amountTotalPrice})必须等于本次开票金额合计(${defaultAmountTotalPrice})`);
|
|
|
|
|
+ reject(false);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
resolve(this.tableForm);
|
|
resolve(this.tableForm);
|
|
|
console.log('this.tableForm~~~',this.tableForm);
|
|
console.log('this.tableForm~~~',this.tableForm);
|
|
|
} catch (error) {
|
|
} catch (error) {
|