This commit is contained in:
2026-08-25 22:35:50 +08:00
parent cb98355715
commit 3da2d428f3
11 changed files with 883 additions and 130 deletions
@@ -190,8 +190,16 @@
<div
class="settlement-detail-page__detail-panel-body settlement-detail-page__adjust-panel-body"
>
<div v-if="isReceivable" class="settlement-detail-page__adjust-toolbar">
<el-button type="primary" :disabled="adjustDialog.loading" @click="addAdjustFee">
新增费用
</el-button>
</div>
<el-table v-loading="adjustDialog.loading" :data="adjustRows" border>
<el-table-column type="index" label="序号" width="64" align="center" />
<el-table-column label="来源" width="110" align="center">
<template #default="{ row }">{{ feeSourceLabel(row.dataSource) }}</template>
</el-table-column>
<el-table-column
v-for="column in adjustFeeColumns"
:key="column.prop || column.feeItemName"
@@ -201,29 +209,92 @@
show-overflow-tooltip
>
<template #default="{ row }">
<span
v-if="row.manualFee && ['billingFactor', 'billingType'].includes(column.prop)"
>
-
</span>
<el-input
v-if="column.prop === 'transportQuantityText' && !row.manualFee"
v-else-if="column.prop === 'cargoName' && row.manualFee"
v-model="row.cargoName"
clearable
maxlength="100"
placeholder="请输入"
/>
<span v-else-if="column.prop === 'cargoName'">
{{ formatDetailCell(row, column.prop) }}
</span>
<el-cascader
v-else-if="column.prop === 'cargoType' && row.manualFee"
v-model="row.cargoTypePath"
class="settlement-detail-page__adjust-control"
:options="transportCargoTypeOptions"
:props="cargoTypeCascaderProps"
:loading="cargoTypeLoading"
clearable
filterable
:filter-method="filterCargoType"
placeholder="请选择到二级"
@visible-change="visible => visible && loadCargoTypeOptions()"
@change="value => handleAdjustCargoTypeChange(row, value)"
/>
<span v-else-if="column.prop === 'cargoType'">
{{ formatDetailCell(row, column.prop) }}
</span>
<el-select
v-else-if="column.prop === 'priceUnit'"
v-model="row.priceUnit"
class="settlement-detail-page__adjust-control"
:loading="priceUnitLoading"
clearable
filterable
placeholder="请选择"
@visible-change="visible => visible && loadPriceUnitOptions()"
>
<el-option
v-for="item in priceUnitOptions"
:key="item.id || item.dictKey || item.dictValue"
:label="item.dictValue"
:value="item.dictValue"
/>
</el-select>
<el-input
v-else-if="adjustTextProps.includes(column.prop)"
v-model="row[column.prop]"
clearable
:maxlength="adjustTextMaxlength(column.prop)"
placeholder="请输入"
/>
<el-input
v-else-if="column.prop === 'transportQuantityText'"
class="settlement-detail-page__adjust-input"
:model-value="row.transportQuantity"
inputmode="decimal"
@input="value => handleAdjustDecimalInput(row, 'transportQuantity', value)"
/>
<el-input
v-else-if="column.prop === 'mileage' && !row.manualFee"
v-else-if="column.prop === 'unitPrice'"
class="settlement-detail-page__adjust-input"
:model-value="row.unitPrice"
inputmode="decimal"
@input="value => handleAdjustDecimalInput(row, 'unitPrice', value)"
/>
<el-input
v-else-if="column.prop === 'mileage'"
class="settlement-detail-page__adjust-input"
:model-value="row.mileage"
inputmode="decimal"
@input="value => handleAdjustDecimalInput(row, 'mileage', value)"
/>
<el-input
v-else-if="column.prop === 'freightAmount' && !row.manualFee"
v-else-if="column.prop === 'freightAmount'"
class="settlement-detail-page__adjust-input"
:model-value="row.freightAmount"
inputmode="decimal"
@input="value => handleAdjustDecimalInput(row, 'freightAmount', value, 'freight')"
/>
<el-input
v-else-if="column.dynamic && !row.manualFee"
v-else-if="column.dynamic"
class="settlement-detail-page__adjust-input"
:model-value="row.feeItems[column.feeItemName]"
inputmode="decimal"
@@ -551,6 +622,7 @@ import {
import * as api from '@/api/settlement/receivable-payable-detail';
import { getList as getContractList } from '@/api/business/contract-manage';
import { getContractOptions as getSettlementContractOptions } from '@/api/settlement/preSettlement';
import { getList as getCargoTypeList } from '@/api/base/cargo-type';
import { exportBlob } from '@/api/common';
import { getDictionary } from '@/api/system/dictbiz';
import { downloadXls } from '@/utils/util';
@@ -594,7 +666,20 @@ export default {
adjustDialog: { visible: false, loading: false, submitting: false, row: null },
adjustRows: [],
adjustDynamicFeeColumns: [],
adjustCalculateTimers: {},
adjustTextProps: ['specification', 'model', 'billingFactor', 'billingType'],
cargoTypeOptions: [],
cargoTypeFlatOptions: [],
cargoTypeLoading: false,
cargoTypeRequest: null,
cargoTypeCascaderProps: {
label: 'cargoName',
value: 'id',
children: 'children',
emitPath: true,
},
priceUnitOptions: [],
priceUnitLoading: false,
priceUnitRequest: null,
changeRows: [],
changePage: { current: 1, size: 10, total: 0 },
changeDialog: { loading: false },
@@ -630,6 +715,9 @@ export default {
if (this.settlementType === 'payable') return '应付';
return '应收应付';
},
isReceivable() {
return this.settlementType === 'receivable';
},
visibleSearchFields() {
return this.searchExpanded ? this.searchFields : this.searchFields.slice(0, 4);
},
@@ -662,9 +750,14 @@ export default {
{ label: '变更原因', prop: 'changeReason', minWidth: 220 },
];
},
transportCargoTypeOptions() {
return this.cargoTypeOptions.filter(item => item.children?.length);
},
},
mounted() {
this.loadTransportTypeOptions();
this.loadCargoTypeOptions();
this.loadPriceUnitOptions();
this.loadTable();
},
methods: {
@@ -682,6 +775,152 @@ export default {
this.transportTypeOptions.find(item => String(item.value) === String(value))?.label || value
);
},
loadCargoTypeOptions() {
if (this.cargoTypeOptions.length) return Promise.resolve(this.cargoTypeOptions);
if (this.cargoTypeRequest) return this.cargoTypeRequest;
this.cargoTypeLoading = true;
this.cargoTypeRequest = getCargoTypeList(1, 9999)
.then(res => {
this.cargoTypeOptions = this.buildCargoTypeTree(this.extractRecords(res));
this.cargoTypeFlatOptions = this.flattenCargoTypeOptions(this.cargoTypeOptions);
return this.cargoTypeOptions;
})
.finally(() => {
this.cargoTypeLoading = false;
this.cargoTypeRequest = null;
});
return this.cargoTypeRequest;
},
loadPriceUnitOptions() {
if (this.priceUnitOptions.length) return Promise.resolve(this.priceUnitOptions);
if (this.priceUnitRequest) return this.priceUnitRequest;
this.priceUnitLoading = true;
this.priceUnitRequest = getDictionary({ code: 'unit_fee' })
.then(res => {
this.priceUnitOptions = this.extractRecords(res);
return this.priceUnitOptions;
})
.finally(() => {
this.priceUnitLoading = false;
this.priceUnitRequest = null;
});
return this.priceUnitRequest;
},
buildCargoTypeTree(cargoTypes = []) {
const flatCargoTypes = [];
const collectCargoTypes = list => {
(list || []).forEach(item => {
flatCargoTypes.push({ ...item, children: undefined });
if (item.children?.length) collectCargoTypes(item.children);
});
};
collectCargoTypes(cargoTypes);
const nodeMap = new Map();
const codeMap = new Map();
flatCargoTypes.forEach(item => {
const id = item.id ?? item.cargoCode ?? item.code;
if (id === undefined || id === null) return;
const node = {
...item,
id: String(id),
cargoName: this.formatCargoTypeLabel(item),
cargoCode: item.cargoCode || item.code || '',
parentId:
item.parentId === undefined || item.parentId === null ? '' : String(item.parentId),
parentCargoCode: item.parentCargoCode || item.parentCode || '',
children: [],
};
nodeMap.set(node.id, node);
if (node.cargoCode) codeMap.set(String(node.cargoCode), node);
});
const rootNodes = [];
nodeMap.forEach(node => {
const parent =
nodeMap.get(node.parentId) ||
codeMap.get(String(node.parentCargoCode || '')) ||
codeMap.get(String(node.parentId || ''));
if (parent && parent !== node && Number(node.typeLevel) !== 1) {
parent.children.push(node);
} else {
rootNodes.push(node);
}
});
return rootNodes.map(item => this.normalizeCargoTypeNode(item, 1)).filter(Boolean);
},
normalizeCargoTypeNode(cargoType, level = 1, parentPath = []) {
if (level > 2) return null;
const id = String(cargoType.id);
const path = [...parentPath, id];
const children =
level === 1
? (cargoType.children || [])
.map(item => this.normalizeCargoTypeNode(item, level + 1, path))
.filter(Boolean)
: [];
return {
...cargoType,
id,
cargoName: this.formatCargoTypeLabel(cargoType),
path,
leaf: level === 2,
children: children.length ? children : undefined,
};
},
flattenCargoTypeOptions(options = []) {
const result = [];
const collectOptions = list => {
(list || []).forEach(item => {
result.push(item);
if (item.children?.length) collectOptions(item.children);
});
};
collectOptions(options);
return result;
},
formatCargoTypeLabel(item = {}) {
return item.cargoName || item.name || item.typeName || item.label || '';
},
filterCargoType(node, keyword) {
const text = String(keyword || '').trim();
if (!text) return true;
const labels = node.pathLabels?.length ? node.pathLabels : [node.label];
return (
labels.some(label => String(label || '').includes(text)) ||
String(node.text || '').includes(text)
);
},
getCargoTypePathLabels(path = []) {
let options = this.cargoTypeOptions;
const labels = [];
(path || []).forEach(value => {
const option = (options || []).find(item => String(item.id) === String(value));
if (!option) return;
labels.push(option.cargoName || '');
options = option.children || [];
});
return labels.filter(Boolean);
},
resolveCargoTypePath(cargoTypeName) {
const name = String(cargoTypeName || '').trim();
if (!name) return [];
const cargoType = this.cargoTypeFlatOptions.find(item => {
const label = this.formatCargoTypeLabel(item);
return item.path?.length >= 2 && (label === name || name.endsWith(label));
});
return cargoType?.path || [];
},
handleAdjustCargoTypeChange(row, value) {
const path =
Array.isArray(value) && value.length >= 2
? value.slice(0, 2).map(item => String(item))
: [];
const labels = this.getCargoTypePathLabels(path);
row.cargoTypePath = path;
row.cargoType = labels.length ? labels[labels.length - 1] : '';
row.cargoName = '';
},
formatColumnValue(row, column) {
if (column.prop === 'transportType') return this.transportTypeLabel(row[column.prop]);
if (column.prop === 'transportQuantity') return this.fixedTwoDecimals(row[column.prop]);
@@ -750,8 +989,6 @@ export default {
this.detailDialog.row = null;
},
closeAdjustPanel() {
Object.values(this.adjustCalculateTimers).forEach(timer => clearTimeout(timer));
this.adjustCalculateTimers = {};
this.adjustDialog.visible = false;
this.adjustDialog.row = null;
},
@@ -760,8 +997,23 @@ export default {
this.openWaybillDetail(row);
return;
}
if (this.settlementType === 'payable' && column.prop === 'preSettlementNo') {
this.openSettlementDetail('/settlement/pre-settlement', row.preSettlementNo);
return;
}
if (this.settlementType === 'payable' && column.prop === 'formalSettlementNo') {
this.openSettlementDetail('/settlement/formal-settlement', row.formalSettlementNo);
return;
}
this.openDetailDialog(row);
},
openSettlementDetail(path, detailNo) {
if (!detailNo) {
this.$message.info('当前记录未关联结算单详情');
return;
}
this.$router.push({ path, query: { detailNo } });
},
openWaybillDetail(row) {
if (!row.waybillId) {
this.$message.info('当前记录未关联运单详情');
@@ -787,7 +1039,11 @@ export default {
this.closeDetailPanel();
this.adjustDialog = { ...this.adjustDialog, visible: true, row, loading: true };
try {
const res = await api.getFeeDetail(row.id);
const [res] = await Promise.all([
api.getFeeDetail(row.id),
this.loadCargoTypeOptions(),
this.loadPriceUnitOptions(),
]);
const data = res.data?.data || res.data || res || {};
this.adjustDynamicFeeColumns = (data.feeItemNames || []).map(name => ({
label: name,
@@ -811,23 +1067,53 @@ export default {
freightAmount: Number(item.freightAmount || 0),
originalAmount: Number(item.originalAmount || 0),
feeItems,
manualFee: item.billingFactor === '手工调整',
feeItemName: item.billingFactor === '手工调整' ? Object.keys(feeItems)[0] || '' : '',
feeType: item.billingType === '手工扣费' ? 'deduct' : 'charge',
amount: item.billingFactor === '手工调整' ? Math.abs(Number(item.afterAmount || 0)) : 0,
dataSource:
item.dataSource || (item.billingFactor === '手工调整' ? '手工录入' : '自动生成'),
manualFee: item.dataSource === '手工录入' || item.billingFactor === '手工调整',
cargoTypePath: this.resolveCargoTypePath(item.cargoType),
};
if (adjusted.manualFee) this.recalculateManualAdjustRow(adjusted);
else this.recalculateAdjustRow(adjusted);
this.recalculateAdjustRow(adjusted);
return adjusted;
});
} finally {
this.adjustDialog.loading = false;
}
},
recalculateManualAdjustRow(row) {
const amount = Number(row.amount || 0);
row.afterAmount = Number((row.feeType === 'deduct' ? -amount : amount).toFixed(2));
row.adjustAmount = Number((row.afterAmount - Number(row.originalAmount || 0)).toFixed(2));
addAdjustFee() {
if (!this.isReceivable) return;
const feeItems = this.adjustDynamicFeeColumns.reduce((items, column) => {
items[column.feeItemName] = 0;
return items;
}, {});
this.adjustRows.push({
dataSource: '手工录入',
cargoName: '',
cargoType: '',
cargoTypePath: [],
specification: '',
model: '',
billingFactor: '-',
billingType: '-',
transportQuantity: '',
priceUnit: '',
unitPrice: '',
mileage: null,
freightAmount: '',
originalAmount: 0,
originalAmountText: '-',
adjustAmount: 0,
afterAmount: 0,
feeItems,
manualFee: true,
remark: '',
changeReason: '',
});
},
feeSourceLabel(value) {
return value === '手工录入' ? '手工录入' : '自动生成';
},
adjustTextMaxlength(prop) {
return ['billingFactor', 'billingType'].includes(prop) ? 100 : 255;
},
fixedTwoDecimals(value) {
return Number(value || 0).toFixed(2);
@@ -845,48 +1131,12 @@ export default {
},
handleAdjustDecimalInput(row, prop, value, changedField) {
row[prop] = this.normalizeAdjustDecimal(value);
if (['transportQuantity', 'mileage'].includes(prop)) {
this.scheduleAdjustedFeeCalculation(row);
return;
}
this.recalculateAdjustRow(row, changedField);
},
handleAdjustFeeItemInput(row, feeItemName, value) {
row.feeItems[feeItemName] = this.normalizeAdjustDecimal(value);
this.recalculateAdjustRow(row, feeItemName);
},
scheduleAdjustedFeeCalculation(row) {
const key = String(row.id);
clearTimeout(this.adjustCalculateTimers[key]);
row.calculateSequence = Number(row.calculateSequence || 0) + 1;
const sequence = row.calculateSequence;
this.adjustCalculateTimers[key] = setTimeout(
() => this.calculateAdjustedFee(row, sequence),
350
);
},
async calculateAdjustedFee(row, sequence) {
if (!this.adjustDialog.row || !row.id) return;
row.calculating = true;
try {
const res = await api.calculateAdjustedFee({
detailId: this.adjustDialog.row.id,
feeId: row.id,
transportQuantity: row.transportQuantity,
mileage: row.mileage,
freightAmount: row.freightAmount,
feeItems: row.feeItems,
});
if (sequence !== row.calculateSequence || !this.adjustDialog.visible) return;
const data = res.data?.data || res.data || res || {};
row.freightAmount = Number(data.freightAmount || 0);
row.feeItems = { ...row.feeItems, ...(data.feeItems || {}) };
row.adjustAmount = Number(data.adjustAmount || 0);
row.afterAmount = Number(data.afterAmount || 0);
} finally {
if (sequence === row.calculateSequence) row.calculating = false;
}
},
recalculateAdjustRow(row, changedField) {
if (changedField && changedField !== 'freight' && this.isFreightFeeItem(changedField)) {
row.freightAmount = Number(row.feeItems[changedField] || 0);
@@ -913,28 +1163,25 @@ export default {
this.$message.warning('没有可调整的费用明细');
return;
}
const invalidManualRow = this.adjustRows.find(
row =>
row.manualFee && (!String(row.feeItemName || '').trim() || Number(row.amount || 0) <= 0)
);
if (invalidManualRow) {
this.$message.warning('请完整填写手工费用项目和金额');
return;
}
this.adjustDialog.submitting = true;
try {
await api.adjustFee({
detailId: this.adjustDialog.row.id,
rows: this.adjustRows.map(row => ({
id: row.id,
cargoName: row.cargoName,
cargoType: row.cargoType,
specification: row.specification,
model: row.model,
billingFactor: row.billingFactor,
billingType: row.billingType,
transportQuantity: row.transportQuantity,
priceUnit: row.priceUnit,
unitPrice: row.unitPrice,
mileage: row.mileage,
freightAmount: row.freightAmount,
feeItems: row.feeItems,
manualFee: row.manualFee === true,
feeItemName: row.feeItemName,
feeType: row.feeType,
amount: row.amount,
remark: row.remark,
changeReason: row.changeReason,
})),
@@ -1392,16 +1639,15 @@ export default {
}
},
handleExport() {
const params = this.buildRequestParams(
this.normalizeQuery(this.query, 'generateDateRange', 'generateStartDate', 'generateEndDate')
);
if (this.selection.length) {
params.ids = this.selection.map(item => item.id).join(',');
}
exportBlob(
'/blade-transport/receivable-payable-detail/export-receivable-payable-detail',
this.buildRequestParams(
this.normalizeQuery(
this.query,
'generateDateRange',
'generateStartDate',
'generateEndDate'
)
),
params,
{ feedback: true }
).then(res => {
downloadXls(
@@ -1508,6 +1754,14 @@ export default {
const data = res.data?.data || res.data || res || {};
return data.records ? data : { records: data.records || [], total: data.total || 0 };
},
extractRecords(res) {
const data = res?.data?.data || res?.data || res;
if (Array.isArray(data)) return data;
if (Array.isArray(data?.records)) return data.records;
if (Array.isArray(data?.data)) return data.data;
if (Array.isArray(data?.data?.records)) return data.data.records;
return [];
},
noop() {},
},
};
@@ -1625,6 +1879,18 @@ export default {
}
}
.settlement-detail-page__adjust-toolbar {
display: flex;
align-items: center;
justify-content: flex-end;
margin-bottom: 12px;
background: transparent;
}
.settlement-detail-page__adjust-control {
width: 100%;
}
.settlement-detail-page__generate-search {
margin-bottom: 16px;
padding: 12px 12px 4px;