🐛 结算导入去掉模板结算金额依赖并取消编辑回算
导入后按运输费与费用项自动合计结算金额,编辑费用项时不再覆盖结算金额。 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 historyColumns =
|
||||
form.waybillMode === 'history'
|
||||
@@ -619,16 +651,13 @@ const detailColumns = computed(() => {
|
||||
const fallback = [
|
||||
...columnsBeforeFee,
|
||||
...feeItemNames.value.map(name => feeColumn(name)),
|
||||
{
|
||||
prop: 'settlementAmount',
|
||||
label: '结算金额',
|
||||
editor: 'number',
|
||||
minWidth: 120,
|
||||
},
|
||||
{ ...settlementAmountColumn },
|
||||
...columnsAfterFee,
|
||||
];
|
||||
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];
|
||||
});
|
||||
|
||||
@@ -717,6 +746,7 @@ const formatCell = (row, column) => {
|
||||
return value ?? '';
|
||||
};
|
||||
|
||||
/** 导入解析后自动合计结算金额;编辑运输费/费用项时不再回算 */
|
||||
const recalcSettlementAmount = row => {
|
||||
const transportFee = toNumber(row.transportFee ?? row.freight);
|
||||
row.transportFee = transportFee;
|
||||
@@ -735,6 +765,18 @@ const recalcSettlementAmount = row => {
|
||||
row.settlementAmount = settlementAmount;
|
||||
row.otherFeeTotal = Number(feeSum.toFixed(2));
|
||||
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) => {
|
||||
@@ -744,17 +786,16 @@ const updateNumberCell = (row, column, value) => {
|
||||
if (!row.feeItems) row.feeItems = {};
|
||||
row.feeItems[column.prop] = '';
|
||||
row[column.prop] = '';
|
||||
} else {
|
||||
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 = '';
|
||||
syncOtherFeeTotal(row);
|
||||
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;
|
||||
}
|
||||
const [integer = '', decimal = ''] = raw.replace(/[^\d.]/g, '').split('.');
|
||||
@@ -764,21 +805,20 @@ const updateNumberCell = (row, column, value) => {
|
||||
if (!row.feeItems) row.feeItems = {};
|
||||
row.feeItems[column.prop] = normalized;
|
||||
row[column.prop] = normalized;
|
||||
} else {
|
||||
row[column.prop] = normalized;
|
||||
if (column.prop === 'transportFee') {
|
||||
row.freight = normalized;
|
||||
}
|
||||
if (column.prop === 'unitPrice') {
|
||||
row.transportUnitPrice = normalized;
|
||||
}
|
||||
if (column.prop === 'settlementAmount') {
|
||||
row.freightTotal = normalized;
|
||||
row['运费合计'] = normalized;
|
||||
return;
|
||||
}
|
||||
syncOtherFeeTotal(row);
|
||||
return;
|
||||
}
|
||||
row[column.prop] = normalized;
|
||||
if (column.prop === 'transportFee') {
|
||||
row.freight = normalized;
|
||||
}
|
||||
if (column.prop === 'unitPrice') {
|
||||
row.transportUnitPrice = normalized;
|
||||
}
|
||||
if (column.prop === 'settlementAmount') {
|
||||
row.freightTotal = normalized;
|
||||
row['运费合计'] = normalized;
|
||||
}
|
||||
recalcSettlementAmount(row);
|
||||
};
|
||||
|
||||
const importFieldText = value => String(value ?? '').trim();
|
||||
@@ -854,11 +894,8 @@ const normalizeParsedRow = (item, index) => {
|
||||
applyVehicleNo(row, vehicleNo);
|
||||
row.transportUnitPrice = row.unitPrice;
|
||||
row.freight = row.transportFee;
|
||||
if (row.settlementAmount === '' || row.settlementAmount === null || row.settlementAmount === undefined) {
|
||||
recalcSettlementAmount(row);
|
||||
} else {
|
||||
row.freightTotal = row.settlementAmount;
|
||||
}
|
||||
// 模板无结算金额列:导入后按运输费+费用项自动合计
|
||||
recalcSettlementAmount(row);
|
||||
return row;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user