🐛 结算导入去掉模板结算金额依赖并取消编辑回算
导入后按运输费与费用项自动合计结算金额,编辑费用项时不再覆盖结算金额。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -604,6 +604,38 @@ const dedupeColumns = columns => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const settlementAmountColumn = {
|
||||||
|
prop: 'settlementAmount',
|
||||||
|
label: '结算金额',
|
||||||
|
editor: 'number',
|
||||||
|
minWidth: 120,
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 模板已去掉结算金额;明细仍展示,并插在费用项之后、日期列之前 */
|
||||||
|
const ensureSettlementAmountColumn = columns => {
|
||||||
|
if (columns.some(column => column.prop === 'settlementAmount')) {
|
||||||
|
return columns;
|
||||||
|
}
|
||||||
|
const result = [...columns];
|
||||||
|
let insertAt = result.findIndex(column =>
|
||||||
|
['actualStartDate', 'actualEndDate', 'planStartDate', 'planEndDate', 'remark', 'waybillIdentifier'].includes(
|
||||||
|
column.prop
|
||||||
|
)
|
||||||
|
);
|
||||||
|
if (insertAt < 0) {
|
||||||
|
const lastFeeIndex = [...result].map((column, index) => (column.isFeeItem ? index : -1)).filter(index => index >= 0).pop();
|
||||||
|
const transportFeeIndex = result.findIndex(column => column.prop === 'transportFee');
|
||||||
|
insertAt =
|
||||||
|
lastFeeIndex !== undefined
|
||||||
|
? lastFeeIndex + 1
|
||||||
|
: transportFeeIndex >= 0
|
||||||
|
? transportFeeIndex + 1
|
||||||
|
: result.length;
|
||||||
|
}
|
||||||
|
result.splice(insertAt, 0, { ...settlementAmountColumn });
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
const detailColumns = computed(() => {
|
const detailColumns = computed(() => {
|
||||||
const historyColumns =
|
const historyColumns =
|
||||||
form.waybillMode === 'history'
|
form.waybillMode === 'history'
|
||||||
@@ -619,16 +651,13 @@ const detailColumns = computed(() => {
|
|||||||
const fallback = [
|
const fallback = [
|
||||||
...columnsBeforeFee,
|
...columnsBeforeFee,
|
||||||
...feeItemNames.value.map(name => feeColumn(name)),
|
...feeItemNames.value.map(name => feeColumn(name)),
|
||||||
{
|
{ ...settlementAmountColumn },
|
||||||
prop: 'settlementAmount',
|
|
||||||
label: '结算金额',
|
|
||||||
editor: 'number',
|
|
||||||
minWidth: 120,
|
|
||||||
},
|
|
||||||
...columnsAfterFee,
|
...columnsAfterFee,
|
||||||
];
|
];
|
||||||
const uploaded = parsedHeaders.value.map(columnFromHeader).filter(Boolean);
|
const uploaded = parsedHeaders.value.map(columnFromHeader).filter(Boolean);
|
||||||
const columns = dedupeColumns(uploaded.length ? uploaded : fallback);
|
const columns = ensureSettlementAmountColumn(
|
||||||
|
dedupeColumns(uploaded.length ? uploaded : fallback)
|
||||||
|
);
|
||||||
return [...historyColumns, ...columns];
|
return [...historyColumns, ...columns];
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -717,6 +746,7 @@ const formatCell = (row, column) => {
|
|||||||
return value ?? '';
|
return value ?? '';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** 导入解析后自动合计结算金额;编辑运输费/费用项时不再回算 */
|
||||||
const recalcSettlementAmount = row => {
|
const recalcSettlementAmount = row => {
|
||||||
const transportFee = toNumber(row.transportFee ?? row.freight);
|
const transportFee = toNumber(row.transportFee ?? row.freight);
|
||||||
row.transportFee = transportFee;
|
row.transportFee = transportFee;
|
||||||
@@ -735,6 +765,18 @@ const recalcSettlementAmount = row => {
|
|||||||
row.settlementAmount = settlementAmount;
|
row.settlementAmount = settlementAmount;
|
||||||
row.otherFeeTotal = Number(feeSum.toFixed(2));
|
row.otherFeeTotal = Number(feeSum.toFixed(2));
|
||||||
row.freightTotal = settlementAmount;
|
row.freightTotal = settlementAmount;
|
||||||
|
row['运费合计'] = settlementAmount;
|
||||||
|
};
|
||||||
|
|
||||||
|
const syncOtherFeeTotal = row => {
|
||||||
|
if (!row.feeItems || typeof row.feeItems !== 'object') {
|
||||||
|
row.feeItems = {};
|
||||||
|
}
|
||||||
|
let feeSum = 0;
|
||||||
|
feeItemNames.value.forEach(name => {
|
||||||
|
feeSum += toNumber(row.feeItems[name] ?? row[name]);
|
||||||
|
});
|
||||||
|
row.otherFeeTotal = Number(feeSum.toFixed(2));
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateNumberCell = (row, column, value) => {
|
const updateNumberCell = (row, column, value) => {
|
||||||
@@ -744,17 +786,16 @@ const updateNumberCell = (row, column, value) => {
|
|||||||
if (!row.feeItems) row.feeItems = {};
|
if (!row.feeItems) row.feeItems = {};
|
||||||
row.feeItems[column.prop] = '';
|
row.feeItems[column.prop] = '';
|
||||||
row[column.prop] = '';
|
row[column.prop] = '';
|
||||||
} else {
|
syncOtherFeeTotal(row);
|
||||||
row[column.prop] = column.editor === 'optionalNumber' ? '' : '';
|
|
||||||
if (column.prop === 'transportFee') row.freight = '';
|
|
||||||
if (column.prop === 'unitPrice') row.transportUnitPrice = '';
|
|
||||||
}
|
|
||||||
if (column.prop === 'settlementAmount') {
|
|
||||||
row.settlementAmount = '';
|
|
||||||
row.freightTotal = '';
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
recalcSettlementAmount(row);
|
row[column.prop] = '';
|
||||||
|
if (column.prop === 'transportFee') row.freight = '';
|
||||||
|
if (column.prop === 'unitPrice') row.transportUnitPrice = '';
|
||||||
|
if (column.prop === 'settlementAmount') {
|
||||||
|
row.freightTotal = '';
|
||||||
|
row['运费合计'] = '';
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const [integer = '', decimal = ''] = raw.replace(/[^\d.]/g, '').split('.');
|
const [integer = '', decimal = ''] = raw.replace(/[^\d.]/g, '').split('.');
|
||||||
@@ -764,21 +805,20 @@ const updateNumberCell = (row, column, value) => {
|
|||||||
if (!row.feeItems) row.feeItems = {};
|
if (!row.feeItems) row.feeItems = {};
|
||||||
row.feeItems[column.prop] = normalized;
|
row.feeItems[column.prop] = normalized;
|
||||||
row[column.prop] = normalized;
|
row[column.prop] = normalized;
|
||||||
} else {
|
syncOtherFeeTotal(row);
|
||||||
row[column.prop] = normalized;
|
return;
|
||||||
if (column.prop === 'transportFee') {
|
}
|
||||||
row.freight = normalized;
|
row[column.prop] = normalized;
|
||||||
}
|
if (column.prop === 'transportFee') {
|
||||||
if (column.prop === 'unitPrice') {
|
row.freight = normalized;
|
||||||
row.transportUnitPrice = normalized;
|
}
|
||||||
}
|
if (column.prop === 'unitPrice') {
|
||||||
if (column.prop === 'settlementAmount') {
|
row.transportUnitPrice = normalized;
|
||||||
row.freightTotal = normalized;
|
}
|
||||||
row['运费合计'] = normalized;
|
if (column.prop === 'settlementAmount') {
|
||||||
return;
|
row.freightTotal = normalized;
|
||||||
}
|
row['运费合计'] = normalized;
|
||||||
}
|
}
|
||||||
recalcSettlementAmount(row);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const importFieldText = value => String(value ?? '').trim();
|
const importFieldText = value => String(value ?? '').trim();
|
||||||
@@ -854,11 +894,8 @@ const normalizeParsedRow = (item, index) => {
|
|||||||
applyVehicleNo(row, vehicleNo);
|
applyVehicleNo(row, vehicleNo);
|
||||||
row.transportUnitPrice = row.unitPrice;
|
row.transportUnitPrice = row.unitPrice;
|
||||||
row.freight = row.transportFee;
|
row.freight = row.transportFee;
|
||||||
if (row.settlementAmount === '' || row.settlementAmount === null || row.settlementAmount === undefined) {
|
// 模板无结算金额列:导入后按运输费+费用项自动合计
|
||||||
recalcSettlementAmount(row);
|
recalcSettlementAmount(row);
|
||||||
} else {
|
|
||||||
row.freightTotal = row.settlementAmount;
|
|
||||||
}
|
|
||||||
return row;
|
return row;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user