调整结算

This commit is contained in:
2026-09-05 00:04:46 +08:00
parent 96f2fa0eb5
commit 3bac9b6472
11 changed files with 688 additions and 352 deletions
@@ -254,11 +254,11 @@
{{ missingAttachmentTypeText }}
</span>
</template>
<div class="formal-editor__attachment-actions">
<template #extra>
<el-button type="primary" :disabled="!attachments.length" @click="downloadAttachments">
批量下载
</el-button>
</div>
</template>
<el-table :data="attachments" border @selection-change="handleAttachmentSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column type="index" label="序号" width="64" align="center" />
@@ -677,98 +677,157 @@
</el-dialog>
<el-dialog
v-model="detailAmountAdjust.visible"
v-model="adjust.visible"
title="结算明细调整"
width="520px"
width="96%"
append-to-body
destroy-on-close
>
<el-form
:model="detailAmountAdjust"
label-position="right"
label-width="auto"
class="formal-editor__amount-adjust"
>
<el-form-item label="原金额">
<span>{{ formatMoney(detailAmountAdjust.originalAmount) }}</span>
</el-form-item>
<el-form-item label="调整金额" required>
<el-input-number
v-model="detailAmountAdjust.adjustAmount"
:precision="2"
:step="0.01"
:controls="false"
/>
</el-form-item>
<el-form-item label="结算金额">
<span>{{ formatMoney(detailAmountAdjustSettlementAmount) }}</span>
</el-form-item>
</el-form>
<template #footer>
<el-button @click="detailAmountAdjust.visible = false">取消</el-button>
<el-button type="primary" @click="confirmDetailAmountAdjustment">提交</el-button>
</template>
</el-dialog>
<el-dialog v-model="adjust.visible" title="结算明细调整" width="92%" append-to-body>
<el-table v-loading="adjust.loading" :data="adjust.rows" border>
<el-table-column type="index" label="序号" width="64" align="center" />
<el-table-column prop="cargoName" label="货物名称" min-width="130" align="center" />
<el-table-column type="index" label="序号" width="64" fixed="left" align="center" />
<el-table-column prop="cargoName" label="货物名称" min-width="140" align="center" />
<el-table-column prop="cargoType" label="货物类型" min-width="130" align="center" />
<el-table-column label="运输总量" min-width="130" align="center"
><template #default="{ row }"
><el-input-number
<el-table-column label="计费规则" min-width="190" align="center">
<template #default="{ row }">
<div class="formal-editor__billing-rule-cell">
<span>{{ displayValue(billingRuleName(row)) }}</span>
<el-icon
class="formal-editor__billing-rule-icon"
title="查看计费规则详情"
@click="openBillingRuleInfo(row)"
>
<InfoFilled />
</el-icon>
</div>
</template>
</el-table-column>
<el-table-column label="运输总量" min-width="150" align="center">
<template #default="{ row }">
<el-input-number
v-model="row.transportQuantity"
:min="0"
:precision="2"
:controls="false" /></template
></el-table-column>
<el-table-column label="里程(KM" min-width="130" align="center"
><template #default="{ row }"
><el-input-number
v-model="row.mileage"
:controls="false"
/>
</template>
</el-table-column>
<el-table-column label="里程(KM" min-width="140" align="center">
<template #default="{ row }">
<el-input-number v-model="row.mileage" :min="0" :precision="2" :controls="false" />
</template>
</el-table-column>
<el-table-column label="运输单价" min-width="140" align="center">
<template #default="{ row }">
<el-input-number v-model="row.unitPrice" :min="0" :precision="2" :controls="false" />
</template>
</el-table-column>
<el-table-column
v-for="feeItem in adjustFeeItemNames"
:key="feeItem"
:label="feeItem"
min-width="140"
align="center"
>
<template #default="{ row }">
<el-input-number
v-model="row.feeItems[feeItem]"
:min="0"
:precision="2"
:controls="false" /></template
></el-table-column>
<el-table-column label="运输单价" min-width="130" align="center"
><template #default="{ row }"
><el-input-number
v-model="row.unitPrice"
:min="0"
:precision="2"
:controls="false" /></template
></el-table-column>
<el-table-column label="运费" min-width="130" align="center"
><template #default="{ row }"
><el-input-number
v-model="row.freightAmount"
:min="0"
:precision="2"
:controls="false" /></template
></el-table-column>
<el-table-column label="结算金额(含税)" min-width="165" align="center"
><template #default="{ row }"
><el-input-number
v-model="row.settlementAmountTax"
:min="0"
:precision="2"
:controls="false" /></template
></el-table-column>
<el-table-column label="备注" min-width="180" align="center"
><template #default="{ row }"><el-input v-model="row.remark" maxlength="200" /></template
></el-table-column>
:controls="false"
@change="recalculateAdjustRow(row, feeItem)"
/>
</template>
</el-table-column>
<el-table-column label="结算金额(含税)" min-width="170" align="center">
<template #default="{ row }">
<el-input-number v-model="row.settlementAmountTax" :precision="2" :controls="false" />
</template>
</el-table-column>
<el-table-column label="备注" min-width="200" align="center">
<template #default="{ row }">
<el-input v-model="row.remark" maxlength="200" />
</template>
</el-table-column>
</el-table>
<el-form label-position="right" label-width="auto" class="formal-editor__adjust-reason">
<el-form-item label="调整原因" required
><el-input v-model="adjust.reason" type="textarea" maxlength="200" show-word-limit
/></el-form-item>
</el-form>
<template #footer
><el-button @click="adjust.visible = false">取消</el-button
><el-button type="primary" :loading="adjust.saving" @click="saveAdjustment"
>保存</el-button
></template
<el-form
:model="adjust"
label-position="right"
label-width="auto"
class="formal-editor__adjust-reason"
>
<el-form-item label="调整原因" required>
<el-input v-model="adjust.reason" maxlength="200" show-word-limit />
</el-form-item>
</el-form>
<template #footer>
<el-button @click="adjust.visible = false">取消</el-button>
<el-button type="primary" :loading="adjust.saving" @click="saveAdjustment">
保存
</el-button>
</template>
</el-dialog>
<el-dialog
v-model="billingRuleDialog.visible"
title="计费规则详情"
width="720px"
append-to-body
destroy-on-close
>
<template v-if="billingRuleDialog.rule">
<div class="dialog-section-title">计费规则</div>
<el-descriptions :column="2" border class="formal-editor__billing-rule-detail">
<el-descriptions-item label="规则名称">{{
displayValue(billingRuleDialog.rule.name)
}}</el-descriptions-item>
<el-descriptions-item label="费用类型">{{
displayValue(billingRuleDialog.rule.feeType)
}}</el-descriptions-item>
<el-descriptions-item label="费用项">{{
displayValue(billingRuleDialog.rule.feeItem)
}}</el-descriptions-item>
<el-descriptions-item label="计费要素">{{
displayValue(billingRuleDialog.rule.billingElement)
}}</el-descriptions-item>
<el-descriptions-item label="计费类型">{{
displayValue(billingRuleDialog.rule.billingType)
}}</el-descriptions-item>
<el-descriptions-item label="计费单位">{{
displayValue(billingRuleDialog.rule.billingUnit)
}}</el-descriptions-item>
<el-descriptions-item label="单价">{{
displayValue(billingRuleDialog.rule.unitPrice)
}}</el-descriptions-item>
<el-descriptions-item label="最低计费量">{{
displayValue(billingRuleDialog.rule.minimumBillingWeight)
}}</el-descriptions-item>
<el-descriptions-item label="计费区间">{{
billingRuleRanges(billingRuleDialog.rule)
}}</el-descriptions-item>
<el-descriptions-item label="备注" :span="2">{{
displayValue(billingRuleDialog.rule.remark)
}}</el-descriptions-item>
</el-descriptions>
<div class="dialog-section-title formal-editor__billing-rule-match-title">匹配条件</div>
<el-descriptions :column="2" border class="formal-editor__billing-rule-detail">
<el-descriptions-item label="起运地">{{
displayValue(billingRuleDialog.rule.matchCondition.origin)
}}</el-descriptions-item>
<el-descriptions-item label="目的地">{{
displayValue(billingRuleDialog.rule.matchCondition.destination)
}}</el-descriptions-item>
<el-descriptions-item label="运输方式">{{
displayValue(billingRuleDialog.rule.matchCondition.transportMode)
}}</el-descriptions-item>
<el-descriptions-item label="货物类型">{{
displayValue(billingRuleDialog.rule.matchCondition.cargoType)
}}</el-descriptions-item>
</el-descriptions>
</template>
<el-empty v-else description="暂无计费规则详情" />
<template #footer>
<el-button type="primary" @click="billingRuleDialog.visible = false">关闭</el-button>
</template>
</el-dialog>
</component>
</template>
@@ -786,7 +845,10 @@ import {
getReceiptClaims,
save,
} from '@/api/settlement/formalSettlement';
import { getDetail as getPreSettlementDetail } from '@/api/settlement/preSettlement';
import {
getDetail as getPreSettlementDetail,
getDetailFees as getPreSettlementDetailFees,
} from '@/api/settlement/preSettlement';
import {
createFormalSettlementForm,
formalSettlementFormFields,
@@ -800,12 +862,14 @@ import {
} from '@/option/settlement/formalSettlementTable';
import { getDictionary } from '@/api/system/dictbiz';
import { h } from 'vue';
import { InfoFilled } from '@element-plus/icons-vue';
import { mapGetters } from 'vuex';
import { downloadFileByUrl } from '@/utils/util';
import * as XLSX from 'xlsx';
export default {
name: 'FormalSettlementEditor',
components: { InfoFilled },
props: {
modelValue: Boolean,
recordId: [String, Number],
@@ -893,12 +957,11 @@ export default {
detailId: null,
reason: '',
rows: [],
targetRow: null,
},
detailAmountAdjust: {
billingRuleDialog: {
visible: false,
row: null,
originalAmount: 0,
adjustAmount: 0,
rule: null,
},
detailCollapsed: false,
detailQuery: {
@@ -950,14 +1013,6 @@ export default {
summaryTotal() {
return this.summaryFees.reduce((total, row) => total + Number(row.settlementAmount || 0), 0);
},
detailAmountAdjustSettlementAmount() {
return Number(
(
Number(this.detailAmountAdjust.originalAmount || 0) +
Number(this.detailAmountAdjust.adjustAmount || 0)
).toFixed(2)
);
},
filteredDetails() {
return this.details.filter(row =>
Object.entries(this.appliedDetailQuery).every(([field, keyword]) => {
@@ -972,6 +1027,13 @@ export default {
const missing = this.getMissingAttachmentTypes();
return missing.length ? `未上传:${missing.join('、')}` : '';
},
adjustFeeItemNames() {
const names = new Set();
this.adjust.rows.forEach(row => {
Object.keys(row.feeItems || {}).forEach(name => names.add(name));
});
return Array.from(names);
},
},
watch: {
modelValue: {
@@ -993,6 +1055,34 @@ export default {
},
},
methods: {
async loadFormalDetail(id) {
const response = await getDetail(id);
const data = this.unwrapData(response);
this.form = {
...createFormalSettlementForm(),
...data,
sourcePreSettlementIds: (data.sources || []).map(item => item.preSettlementId),
sourceDetailIds: (data.details || [])
.filter(item => !item.sourcePreSettlementId)
.map(item => item.sourceDetailId),
};
this.sources = data.sources || [];
this.details = data.details || [];
this.summaryFees = data.summaryFees || [];
this.paymentApplications = data.paymentApplications || [];
if (this.readonly && this.form.settlementType === 'receivable') {
this.receiptClaims = this.unwrapData(await getReceiptClaims(id)) || [];
}
this.adjustments = data.adjustments || [];
this.changeRecords = data.changeRecords || [];
this.attachments = this.parseAttachments(data.attachmentsJson);
this.selectedAttachmentRows = [];
this.invoices = data.invoices || [];
this.sortAttachments();
this.contracts = this.allContracts.filter(
item => String(item.projectId) === String(this.form.projectId)
);
},
async initialize() {
const newRecordAudit = this.recordId
? null
@@ -1014,11 +1104,9 @@ export default {
this.invoices = [];
this.invoiceClaimNo = '';
this.attachmentUploadFiles = [];
this.detailAmountAdjust = {
this.billingRuleDialog = {
visible: false,
row: null,
originalAmount: 0,
adjustAmount: 0,
rule: null,
};
this.detailCollapsed = false;
this.resetDetailQuery(false);
@@ -1037,32 +1125,7 @@ export default {
}
this.loading = true;
try {
const response = await getDetail(this.recordId);
const data = this.unwrapData(response);
this.form = {
...createFormalSettlementForm(),
...data,
sourcePreSettlementIds: (data.sources || []).map(item => item.preSettlementId),
sourceDetailIds: (data.details || [])
.filter(item => !item.sourcePreSettlementId)
.map(item => item.sourceDetailId),
};
this.sources = data.sources || [];
this.details = data.details || [];
this.summaryFees = data.summaryFees || [];
this.paymentApplications = data.paymentApplications || [];
if (this.readonly && this.form.settlementType === 'receivable') {
this.receiptClaims = this.unwrapData(await getReceiptClaims(this.recordId)) || [];
}
this.adjustments = data.adjustments || [];
this.changeRecords = data.changeRecords || [];
this.attachments = this.parseAttachments(data.attachmentsJson);
this.selectedAttachmentRows = [];
this.invoices = data.invoices || [];
this.sortAttachments();
this.contracts = this.allContracts.filter(
item => String(item.projectId) === String(this.form.projectId)
);
await this.loadFormalDetail(this.recordId);
} finally {
this.loading = false;
}
@@ -1339,7 +1402,6 @@ export default {
const range = this.detailCandidate.query.createTimeRange || [];
const params = {
contractId: this.form.contractId,
settlementType: this.form.settlementType,
batchNo: this.detailCandidate.query.batchNo,
createStartDate: range[0],
createEndDate: range[1],
@@ -1529,66 +1591,228 @@ export default {
)}.xlsx`
);
},
billingRuleName(row) {
return this.normalizeBillingRule(row).name;
},
openBillingRuleInfo(row) {
this.billingRuleDialog.rule = this.normalizeBillingRule(row);
this.billingRuleDialog.visible = true;
},
normalizeBillingRule(row) {
const source = row || {};
const nested = [
source.billingRule,
source.billingRuleInfo,
source.billingRuleJson,
source.billingRulesJson,
source.billingRules,
source.billingPlanRule,
source.feeRule,
source.rule,
].find(value => value !== undefined && value !== null && value !== '');
const parsedNested = this.parseJsonValue(nested);
const matchedRules = Array.isArray(parsedNested)
? parsedNested.filter(item => item && typeof item === 'object')
: [];
const rule = this.parseObject(matchedRules[0] || parsedNested || nested);
const matchCondition = this.parseObject(
source.matchCondition ?? source.billingMatchCondition ?? rule.matchCondition
);
const ruleNames = matchedRules
.map(item => item.ruleName || item.name || item.billingRuleName || item.feeItem)
.filter(Boolean);
return {
...rule,
name:
source.billingRuleName ||
source.feeRuleName ||
source.ruleName ||
source.billingPlanRuleName ||
source.billingPlanName ||
rule.name ||
rule.ruleName ||
rule.billingRuleName ||
rule.planName ||
rule.billingPlanName ||
ruleNames.join('、') ||
rule.feeItem ||
'',
feeType: source.billingFeeType || source.feeType || rule.feeType,
feeItem: source.billingFeeItem || source.feeItem || rule.feeItem,
billingElement:
source.billingElement ||
source.billingFactor ||
rule.billingElement ||
rule.billingFactor,
billingType: source.billingType || rule.billingType,
billingUnit: source.billingUnit || source.priceUnit || rule.billingUnit || rule.priceUnit,
unitPrice: source.billingUnitPrice ?? source.unitPrice ?? rule.unitPrice,
minimumBillingWeight:
source.minimumBillingWeight ?? rule.minimumBillingWeight ?? rule.lowerLimit,
remark: source.billingRuleRemark || source.ruleRemark || rule.remark,
rules: matchedRules,
matchCondition: {
...matchCondition,
origin: matchCondition.origin || matchCondition.originName,
destination: matchCondition.destination || matchCondition.destinationName,
transportMode: matchCondition.transportMode || matchCondition.transportType,
cargoType: matchCondition.cargoType || matchCondition.cargoTypeName,
},
};
},
billingRuleRanges(rule) {
const ranges = Array.isArray(rule?.limitRanges) ? rule.limitRanges : [];
if (ranges.length) {
return ranges
.map(
item => `${item.lowerLimit ?? '-'}~${item.upperLimit ?? '-'}${item.unitPrice ?? '-'}`
)
.join('');
}
if (rule?.lowerLimit !== undefined || rule?.upperLimit !== undefined) {
return `${rule.lowerLimit ?? '-'}~${rule.upperLimit ?? '-'}`;
}
return '-';
},
recalculateAdjustRow(row, changedField) {
if (changedField && this.isFreightFeeItem(changedField)) {
row.freightAmount = Number(row.feeItems[changedField] || 0);
}
const feeItemTotal = Object.values(row.feeItems || {}).reduce(
(total, value) => total + Number(value || 0),
0
);
const hasFreightItem = Object.keys(row.feeItems || {}).some(this.isFreightFeeItem);
row.settlementAmountTax = Number(
(hasFreightItem ? feeItemTotal : Number(row.freightAmount || 0) + feeItemTotal).toFixed(2)
);
},
async openAdjustDialog(row) {
if (!row.formalSettlementId) {
const originalAmount = Number(
row.originalAmount ??
row.totalAmount ??
Number(row.settlementAmountTax || 0) - Number(row.adjustAmount || 0)
);
this.detailAmountAdjust = {
this.adjust = {
visible: true,
row,
originalAmount: Number(originalAmount.toFixed(2)),
adjustAmount: Number(row.adjustAmount || 0),
loading: true,
saving: false,
detailId: null,
reason: '',
rows: [],
targetRow: row,
};
try {
let feeRows = [];
if (row.sourcePreSettlementId && row.id) {
const response = await getPreSettlementDetailFees(row.id);
feeRows = this.unwrapData(response) || [];
}
this.adjust.rows = (feeRows.length ? feeRows : [row]).map(item => ({
...item,
feeItems: this.parseFeeItems(item.feeItemsJson || item.feeItems),
billingRule: this.normalizeBillingRule(item),
settlementAmountTax:
item.settlementAmountTax ??
item.totalAmount ??
item.afterAmount ??
item.settlementAmount ??
0,
}));
} finally {
this.adjust.loading = false;
}
return;
}
const detailRow = row;
this.adjust = {
visible: true,
loading: true,
saving: false,
detailId: row.id,
detailId: detailRow.id,
reason: '',
rows: [],
targetRow: null,
};
try {
const response = await getDetailFees(row.id);
const response = await getDetailFees(detailRow.id);
const data = this.unwrapData(response);
this.adjust.rows = (data || []).map(item => ({
...item,
feeItems: this.parseFeeItems(item.feeItemsJson),
billingRule: this.normalizeBillingRule(item),
}));
} finally {
this.adjust.loading = false;
}
},
confirmDetailAmountAdjustment() {
const settlementAmount = this.detailAmountAdjustSettlementAmount;
if (!Number.isFinite(settlementAmount) || settlementAmount < 0) {
return this.$message.warning('调整后的结算金额不能小于0');
}
const row = this.detailAmountAdjust.row;
if (!row) return;
row.originalAmount = this.detailAmountAdjust.originalAmount;
row.adjustAmount = Number(this.detailAmountAdjust.adjustAmount || 0);
row.settlementAmountTax = settlementAmount;
row.pendingDetailAdjustment = true;
this.buildSummaryFeesFromDetails();
this.detailAmountAdjust.visible = false;
},
async saveAdjustment() {
if (!this.adjust.reason.trim()) return this.$message.warning('请输入调整原因');
if (!this.adjust.detailId) {
const target = this.adjust.targetRow;
const edited = this.adjust.rows[0];
if (!target || !edited) return;
const originalAmount = Number(
target.originalAmount ??
target.totalAmount ??
target.afterAmount ??
target.settlementAmountTax ??
target.settlementAmount ??
0
);
const settlementAmount = Number(
this.adjust.rows
.reduce((total, item) => total + Number(item.settlementAmountTax || 0), 0)
.toFixed(2)
);
const feeItems = this.adjust.rows.reduce((result, item) => {
Object.entries(item.feeItems || {}).forEach(([name, amount]) => {
result[name] = Number((Number(result[name] || 0) + Number(amount || 0)).toFixed(2));
});
return result;
}, {});
if (!Number.isFinite(settlementAmount) || settlementAmount < 0) {
return this.$message.warning('调整后的结算金额不能小于0');
}
Object.assign(target, {
originalAmount,
adjustAmount: Number((settlementAmount - originalAmount).toFixed(2)),
settlementAmountTax: settlementAmount,
feeItemsJson: JSON.stringify(feeItems),
freightAmount: this.adjust.rows.reduce(
(total, item) => total + Number(item.freightAmount || 0),
0
),
transportQuantity: this.adjust.rows.reduce(
(total, item) => total + Number(item.transportQuantity || 0),
0
),
mileage: this.adjust.rows.reduce((total, item) => total + Number(item.mileage || 0), 0),
unitPrice: edited.unitPrice,
remark: edited.remark,
pendingDetailAdjustment: true,
});
this.buildSummaryFeesFromDetails();
this.adjust.visible = false;
this.$message.success('调整已暂存,请保存正式结算单提交');
return;
}
this.adjust.saving = true;
try {
await adjustDetail({
detailId: this.adjust.detailId,
changeReason: this.adjust.reason,
rows: this.adjust.rows,
rows: this.adjust.rows.map(row => ({
id: row.id,
transportQuantity: row.transportQuantity,
mileage: row.mileage,
unitPrice: row.unitPrice,
freightAmount: row.freightAmount,
feeItems: row.feeItems,
settlementAmountTax: row.settlementAmountTax,
settlementAmountNoTax: row.settlementAmountNoTax,
remark: row.remark,
})),
});
this.$message.success('调整保存成功');
this.adjust.visible = false;
await this.initialize();
await this.loadFormalDetail(this.form.id);
} finally {
this.adjust.saving = false;
}
@@ -1715,6 +1939,53 @@ export default {
if (!url) return this.$message.warning('当前Mock发票暂无可下载附件');
downloadFileByUrl(url, this.invoiceAttachmentName(row));
},
buildSavePayload() {
return {
id: this.form.id,
contractId: this.form.contractId,
settlementType: this.form.settlementType,
sourcePreSettlementIds: this.form.sourcePreSettlementIds,
sourceDetailIds: this.form.sourceDetailIds,
detailAdjustments: this.details
.filter(row => row.pendingDetailAdjustment)
.map(row => ({
sourcePreSettlementDetailId:
row.sourcePreSettlementDetailId || (row.sourcePreSettlementId ? row.id : undefined),
sourceDetailId: row.sourcePreSettlementId ? undefined : row.sourceDetailId || row.id,
adjustAmount: Number(row.adjustAmount || 0),
})),
exchangeRateDate: this.form.exchangeRateDate,
exchangeRate: this.form.exchangeRate,
summaryFees: this.summaryFees
.filter(
row =>
row.manualFlag === 1 ||
row.id ||
Number(row.adjustAmount || 0) !== 0 ||
String(row.remark || '').trim()
)
.map(row => ({
id: row.id || undefined,
feeType: row.feeType,
feeItem: row.feeItem,
adjustAmount: Number(row.adjustAmount || 0),
remark: row.remark,
manualFlag: row.manualFlag || 0,
})),
attachmentsJson: this.stringifyAttachments(this.attachments),
invoices: this.invoices.map(row => ({
invoiceNo: String(row.invoiceNo || '').trim(),
invoiceDate: row.invoiceDate || null,
invoiceType: row.invoiceType || '',
taxRate: Number(row.taxRate || 0),
invoiceAmount: Number(row.invoiceAmount || 0),
availableInvoiceAmount: Number(row.availableInvoiceAmount || 0),
matchedAmount: Number(row.matchedAmount || 0),
attachmentJson: row.attachmentJson || '',
})),
remark: this.form.remark,
};
},
async handleSave() {
await this.$refs.formRef.validate();
if (!this.form.sourcePreSettlementIds.length && !this.form.sourceDetailIds.length) {
@@ -1732,51 +2003,7 @@ export default {
if (!this.validateAttachments()) return;
this.saving = true;
try {
await save({
id: this.form.id,
contractId: this.form.contractId,
settlementType: this.form.settlementType,
sourcePreSettlementIds: this.form.sourcePreSettlementIds,
sourceDetailIds: this.form.sourceDetailIds,
detailAdjustments: this.details
.filter(row => row.pendingDetailAdjustment)
.map(row => ({
sourcePreSettlementDetailId:
row.sourcePreSettlementDetailId || (row.sourcePreSettlementId ? row.id : undefined),
sourceDetailId: row.sourcePreSettlementId ? undefined : row.sourceDetailId || row.id,
adjustAmount: Number(row.adjustAmount || 0),
})),
exchangeRateDate: this.form.exchangeRateDate,
exchangeRate: this.form.exchangeRate,
summaryFees: this.summaryFees
.filter(
row =>
row.manualFlag === 1 ||
row.id ||
Number(row.adjustAmount || 0) !== 0 ||
String(row.remark || '').trim()
)
.map(row => ({
id: row.id || undefined,
feeType: row.feeType,
feeItem: row.feeItem,
adjustAmount: Number(row.adjustAmount || 0),
remark: row.remark,
manualFlag: row.manualFlag || 0,
})),
attachmentsJson: this.stringifyAttachments(this.attachments),
invoices: this.invoices.map(row => ({
invoiceNo: String(row.invoiceNo || '').trim(),
invoiceDate: row.invoiceDate || null,
invoiceType: row.invoiceType || '',
taxRate: Number(row.taxRate || 0),
invoiceAmount: Number(row.invoiceAmount || 0),
availableInvoiceAmount: Number(row.availableInvoiceAmount || 0),
matchedAmount: Number(row.matchedAmount || 0),
attachmentJson: row.attachmentJson || '',
})),
remark: this.form.remark,
});
await save(this.buildSavePayload());
this.$message.success('保存成功');
this.visible = false;
this.$emit('success');
@@ -1994,6 +2221,19 @@ export default {
return {};
}
},
parseJsonValue(value) {
if (value === undefined || value === null || value === '') return null;
if (typeof value === 'object') return value;
try {
return JSON.parse(value);
} catch {
return value;
}
},
parseObject(value) {
const parsed = this.parseJsonValue(value);
return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : {};
},
parseAttachments(value) {
if (!value) return [];
let attachments = value;
@@ -2102,8 +2342,37 @@ export default {
.formal-editor__adjust-reason {
margin-top: 16px;
}
.formal-editor__amount-adjust :deep(.el-input-number) {
width: 100%;
.formal-editor__billing-rule-cell {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 6px;
max-width: 100%;
}
.formal-editor__billing-rule-icon {
flex: 0 0 auto;
color: var(--el-color-primary);
cursor: pointer;
}
.formal-editor__billing-rule-detail {
margin-top: 12px;
}
.formal-editor__billing-rule-match-title {
margin-top: 20px;
}
.dialog-section-title {
display: flex;
align-items: center;
min-height: 22px;
font-size: 16px;
font-weight: 600;
}
.dialog-section-title::before {
width: 4px;
height: 18px;
margin-right: 8px;
background: #409eff;
content: '';
}
.formal-editor__attachment-missing {
margin-left: 12px;
@@ -2111,11 +2380,6 @@ export default {
font-size: 13px;
font-weight: 400;
}
.formal-editor__attachment-actions {
display: flex;
justify-content: flex-end;
margin-bottom: 12px;
}
.formal-editor__attachment-upload {
margin-top: 12px;
}
@@ -82,7 +82,12 @@
添加费用
</el-button>
</template>
<el-table :data="summaryFees" border>
<el-table
:data="summaryFees"
border
show-summary
:summary-method="getSummarySums"
>
<el-table-column type="index" label="序号" width="64" align="center" />
<el-table-column
v-for="column in summaryColumns"
@@ -161,9 +166,6 @@
</template>
</el-table-column>
</el-table>
<div class="pre-settlement-editor__summary-total">
合计:{{ formatMoney(summaryTotal, form.currency) }}
</div>
</section-card>
<section-card title="结算明细">
@@ -298,12 +300,12 @@
</section-card>
<section-card title="附件">
<template #extra>
<el-button type="primary" :disabled="!attachments.length" @click="downloadAttachments">
批量下载
</el-button>
</template>
<div class="pre-settlement-editor__attachment">
<div class="pre-settlement-editor__attachment-actions">
<el-button type="primary" :disabled="!attachments.length" @click="downloadAttachments">
批量下载
</el-button>
</div>
<el-table :data="attachments" border @selection-change="handleAttachmentSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column type="index" label="序号" width="70" align="center" />
@@ -846,6 +848,7 @@
</template>
<script>
import { h } from 'vue';
import { mapGetters } from 'vuex';
import { InfoFilled } from '@element-plus/icons-vue';
import {
@@ -1506,6 +1509,19 @@ export default {
if (Number(row.manualFlag) !== 1) return;
row.settlementAmount = Number(row.originalAmount || 0) + Number(row.adjustAmount || 0);
},
getSummarySums({ columns, data }) {
const sumProps = ['originalAmount', 'adjustAmount', 'settlementAmount'];
return columns.map((column, index) => {
if (index === 0) return '合计';
if (!sumProps.includes(column.property)) return '';
const total = data.reduce((sum, row) => sum + Number(row[column.property] || 0), 0);
const totalText = this.formatMoney(total, this.form.currency);
if (column.property === 'adjustAmount' && total < 0) {
return h('span', { style: { color: 'var(--el-color-danger)' } }, totalText);
}
return totalText;
});
},
buildSummaryFeesFromDetails() {
const summaryMap = new Map();
const defaultFreightItem =
@@ -1630,9 +1646,9 @@ export default {
this.details.push(this.normalizeSourceDetail(row));
}
});
this.buildSummaryFeesFromDetails();
this.candidateDialog.confirming = true;
if (this.deferSave) {
this.buildSummaryFeesFromDetails();
if (this.deferSave || (this.pageMode && !this.form.id)) {
this.candidateDialog.visible = false;
this.candidateDialog.confirming = false;
this.$message.success('结算明细添加成功,请点击保存提交');
@@ -1678,10 +1694,6 @@ export default {
const isPersistedDetail =
row.id && sourceDetailId && String(row.id) !== String(sourceDetailId);
if (isPersistedDetail) return row;
if (this.deferSave) {
this.$message.warning('请先保存预结算单后再调整结算明细');
return null;
}
await this.$refs.formRef?.validate();
this.loading = true;
@@ -2136,14 +2148,6 @@ export default {
}
}
&__attachment-actions {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 8px;
margin-bottom: 12px;
}
&__attachment-upload {
display: flex;
justify-content: flex-start;
@@ -2158,12 +2162,6 @@ export default {
}
}
&__summary-total {
padding: 12px 16px 0;
text-align: right;
font-weight: 600;
}
&__negative-amount {
color: var(--el-color-danger);
}
@@ -228,11 +228,6 @@
<div
class="settlement-detail-page__detail-panel-body settlement-detail-page__adjust-panel-body"
>
<div v-if="isPayable" 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">
@@ -1139,13 +1134,21 @@ export default {
return this.searchExpanded ? this.searchFields : this.searchFields.slice(0, 4);
},
feeDetailColumns() {
return [...feeDetailBaseColumns, ...this.dynamicFeeColumns, ...feeDetailTailColumns];
const baseColumns = feeDetailBaseColumns.filter(column => column.prop !== 'freightAmount');
return [...baseColumns, ...this.dynamicFeeColumns, ...feeDetailTailColumns];
},
displayTableColumns() {
const columns = this.tableColumns.filter(
column => this.settlementType !== 'receivable' || column.prop !== 'preSettlementNo'
);
const totalIndex = columns.findIndex(column => column.prop === 'totalAmountText');
const otherFeeColumn = {
label: '其他费用',
prop: 'tableOtherFeeAmount',
feeSummaryType: 'other',
minWidth: 130,
align: 'right',
};
const dynamicColumns = this.isPayable
? [
{
@@ -1155,22 +1158,19 @@ export default {
minWidth: 130,
align: 'right',
},
{
label: '其他费用',
prop: 'tableOtherFeeAmount',
feeSummaryType: 'other',
otherFeeColumn,
]
: [
...this.tableFeeItemNames.map((name, index) => ({
label: name,
prop: `tableFeeItem${index}`,
feeItemName: name,
dynamic: true,
minWidth: 130,
align: 'right',
},
]
: this.tableFeeItemNames.map((name, index) => ({
label: name,
prop: `tableFeeItem${index}`,
feeItemName: name,
dynamic: true,
minWidth: 130,
align: 'right',
}));
})),
otherFeeColumn,
];
if (totalIndex < 0) return [...columns, ...dynamicColumns];
columns.splice(totalIndex, 0, ...dynamicColumns);
return columns;
@@ -1179,6 +1179,7 @@ export default {
return [...generatePreviewColumns, ...this.dynamicFeeColumns, ...feeDetailTailColumns];
},
adjustFeeColumns() {
const baseColumns = feeDetailBaseColumns.filter(column => column.prop !== 'freightAmount');
const tailColumns = feeDetailTailColumns.filter(column => column.prop !== 'remark');
const afterAmountIndex = tailColumns.findIndex(column => column.prop === 'afterAmountText');
tailColumns.splice(afterAmountIndex + 1, 0, {
@@ -1186,7 +1187,7 @@ export default {
prop: 'changeReason',
minWidth: 220,
});
return [...feeDetailBaseColumns, ...this.adjustDynamicFeeColumns, ...tailColumns];
return [...baseColumns, ...this.adjustDynamicFeeColumns, ...tailColumns];
},
transportCargoTypeOptions() {
return this.cargoTypeOptions.filter(item => item.children?.length);
@@ -1741,6 +1742,7 @@ export default {
freightAmount: Number(item.freightAmount || 0),
originalAmount: Number(item.originalAmount || 0),
feeItems,
changeReason: '',
dataSource:
item.dataSource || (item.billingFactor === '手工调整' ? '手动录入' : '自动生成'),
manualFee:
@@ -1758,39 +1760,6 @@ export default {
this.adjustDialog.loading = false;
}
},
addAdjustFee() {
if (!this.isPayable) 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: '',
calculating: false,
adjustCalculateTimer: null,
adjustCalculateVersion: 0,
});
},
feeSourceLabel(value) {
return ['手动录入', '手动添加', '手工录入'].includes(value) ? '手动录入' : '自动生成';
},
@@ -1908,6 +1877,11 @@ export default {
try {
await api.adjustFee({
detailId: this.adjustDialog.row.id,
adjustReason: [
...new Set(
this.adjustRows.map(row => String(row.changeReason || '').trim()).filter(Boolean)
),
].join(''),
rows: this.adjustRows.map(row => ({
id: row.id,
cargoName: String(row.cargoName || '').trim(),
@@ -2768,14 +2742,6 @@ 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%;
}