优化计费逻辑

This commit is contained in:
wuweihua
2026-10-17 01:37:33 +08:00
parent 52f714c760
commit db6f5e882a
29 changed files with 1460 additions and 145 deletions
+63 -39
View File
@@ -5,21 +5,21 @@
:columns="columns"
:search-columns="searchColumns"
:query="queryList"
search-action-align="center"
:search-per-row="4"
row-key="billId"
selection
:page-sizes="[100, 200, 300, 400]"
:page-size="100"
:height="tableHeight"
virtual
>
<template #search-orderNos="{ model }">
<multi-value-input v-model="model.orderNos" placeholder="订单号" width="100%" :search-method="searchOrderNoOptions" />
</template>
<template #search-trackingNos="{ model }">
<multi-value-input v-model="model.trackingNos" placeholder="运单号" width="100%" :search-method="searchTrackingNoOptions" />
</template>
<template #search-transferNos="{ model }">
<multi-value-input v-model="model.transferNos" placeholder="转单号" width="100%" :search-method="searchTransferNoOptions" />
<template #search-orderIdentifiers="{ model }">
<multi-value-input
v-model="model.orderIdentifiers"
placeholder="订单号/运单号/转单号"
width="100%"
:search-method="searchOrderIdentifiers"
/>
</template>
<template #search-customerCodes="{ model }">
<customer-select
@@ -28,8 +28,9 @@
value-key="customerCode"
label-key="customerName"
code-key="customerCode"
placeholder="请输入"
placeholder="客户名称/客户代码/对外代码"
multiple
remote-search
/>
</template>
<template #search-productCodes="{ model }">
@@ -232,19 +233,13 @@ import EditChargeWeightDialog from './components/EditChargeWeightDialog.vue'
import ExcelImportDialog from '@/components/ExcelImportDialog'
import ChargeWeightImportAttachDrawer from './components/ChargeWeightImportAttachDrawer.vue'
// 订单号下拉远程搜索:返回匹配的订单号列表(最多 20 条)
function searchOrderNoOptions(keyword) {
return listOrderNoOptions(keyword).then(res => res.data || [])
}
// 运单号下拉远程搜索
function searchTrackingNoOptions(keyword) {
return listTrackingNoOptions(keyword).then(res => res.data || [])
}
// 转单号下拉远程搜索
function searchTransferNoOptions(keyword) {
return listTransferNoOptions(keyword).then(res => res.data || [])
// 单号下拉:订单号、运单号、转单号合并候选
function searchOrderIdentifiers(keyword) {
return Promise.all([
listOrderNoOptions(keyword).then(res => res.data || []),
listTrackingNoOptions(keyword).then(res => res.data || []),
listTransferNoOptions(keyword).then(res => res.data || [])
]).then(groups => [...new Set(groups.flat().map(v => String(v)))])
}
// 产品下拉选项:复用 ProductSelect 的模块级产品缓存(全应用只拉一次)
@@ -257,6 +252,37 @@ const productOptions = computed(() =>
)
const tableRef = ref()
const tableHeight = ref(480)
let tableResizeObserver = null
function updateTableHeight() {
const tableEl = document.querySelector('.billing-bill > .basic-table .el-table, .billing-bill > .basic-table .basic-table-virtual')
if (!tableEl) return
const top = tableEl.getBoundingClientRect().top
const paginationReserve = 58
const bottomGap = 12
tableHeight.value = Math.max(240, Math.floor(window.innerHeight - top - paginationReserve - bottomGap))
}
onMounted(() => {
nextTick(() => {
updateTableHeight()
const form = document.querySelector('.billing-bill > .basic-table .basic-form')
if (form && typeof ResizeObserver !== 'undefined') {
tableResizeObserver = new ResizeObserver(() => updateTableHeight())
tableResizeObserver.observe(form)
}
})
window.addEventListener('resize', updateTableHeight)
})
onBeforeUnmount(() => {
window.removeEventListener('resize', updateTableHeight)
if (tableResizeObserver) {
tableResizeObserver.disconnect()
tableResizeObserver = null
}
})
const open = ref(false)
const title = ref('计费详情')
const loading = ref(false)
@@ -286,7 +312,7 @@ const recalcDialogOpen = ref(false)
const recalcMode = ref('PRODUCT')
const columns = [
{ label: '订单号', prop: 'orderNo', minWidth: 140, showOverflowTooltip: true },
{ label: '订单号', prop: 'orderNo', width: 160, fixed: 'left', showOverflowTooltip: true },
{ label: '运单号', prop: 'trackingNo', minWidth: 140, showOverflowTooltip: true },
{ label: '转单号', prop: 'transferNo', minWidth: 140, showOverflowTooltip: true },
{ label: '客户', prop: 'customerName', minWidth: 140, showOverflowTooltip: true },
@@ -320,19 +346,16 @@ const refundStatusOptions = [
{ label: '未退费', value: 'NONE' },
{ label: '已退费', value: 'REFUNDED' }
]
/** billing_fail_status: 0 success / 1 product / 2 country / 3 weight */
const billingFailStatusOptions = [
{ label: '\u8ba1\u8d39\u6210\u529f', value: 0 },
{ label: '\u672a\u5339\u914d\u4ea7\u54c1', value: 1 },
{ label: '\u672a\u5339\u914d\u56fd\u5bb6', value: 2 },
{ label: '\u672a\u5339\u914d\u91cd\u91cf\u6bb5', value: 3 }
{ label: '计费成功', value: 0 },
{ label: '未匹配产品', value: 1 },
{ label: '未匹配国家', value: 2 },
{ label: '未匹配重量段', value: 3 },
]
const searchColumns = [
{ label: '订单号', prop: 'orderNos', placeholder: '订单号' },
{ label: '运单号', prop: 'trackingNos', placeholder: '运单号' },
{ label: '转单号', prop: 'transferNos', placeholder: '转单号' },
{ label: '客户', prop: 'customerCodes', placeholder: '客户代码' },
{ label: '单号', prop: 'orderIdentifiers', placeholder: '订单号/运单号/转单号' },
{ label: '客户', prop: 'customerCodes', placeholder: '客户名称/客户代码/对外代码' },
{ label: '产品代码', prop: 'productCodes', placeholder: '产品代码' },
{
label: '额度欠费',
@@ -443,7 +466,8 @@ function onDetailUpdated(data) {
function hasBatchFeeQuery(q) {
const hasArr = (arr) => Array.isArray(arr) && arr.some(v => v != null && String(v).trim() !== '')
return hasArr(q.orderNos)
return hasArr(q.orderIdentifiers)
|| hasArr(q.orderNos)
|| hasArr(q.trackingNos)
|| hasArr(q.transferNos)
|| hasArr(q.customerCodes)
@@ -488,6 +512,7 @@ function buildRecalcPayload() {
orderNos: rest.orderNos || [],
trackingNos: rest.trackingNos || [],
transferNos: rest.transferNos || [],
orderIdentifiers: rest.orderIdentifiers || [],
customerCodes: rest.customerCodes || [],
productCodes: rest.productCodes || [],
creditArrearsStatus: rest.creditArrearsStatus || undefined
@@ -578,6 +603,7 @@ function buildChargeWeightTemplateQuery() {
orderNos: rest.orderNos || [],
trackingNos: rest.trackingNos || [],
transferNos: rest.transferNos || [],
orderIdentifiers: rest.orderIdentifiers || [],
customerCodes: rest.customerCodes || [],
productCodes: rest.productCodes || [],
creditArrearsStatus: rest.creditArrearsStatus || undefined
@@ -691,15 +717,13 @@ function formatWeight(val) {
function billingFailLabel(status) {
const code = status == null ? 0 : Number(status)
if (code === 1) return '未匹配产品'
if (code === 2) return '未匹配国家'
if (code === 3) return '未匹配重量段'
return '计费成功'
const hit = billingFailStatusOptions.find(item => item.value === code)
return hit ? hit.label : '未知失败'
}
function billingFailTagType(status) {
const code = status == null ? 0 : Number(status)
if (code === 1 || code === 2 || code === 3) return 'danger'
if (code > 0) return 'danger'
return 'success'
}
@@ -193,6 +193,8 @@ function fmtList(arr, max = 5) {
function buildQueryTags(q) {
const tags = []
const identifiers = fmtList(q.orderIdentifiers)
if (identifiers) tags.push("单号" + ':' + identifiers)
const order = fmtList(q.orderNos)
if (order) tags.push("订单号" + ':' + order)
const tracking = fmtList(q.trackingNos)
@@ -256,6 +258,7 @@ function buildPayload() {
orderNos: q.orderNos || [],
trackingNos: q.trackingNos || [],
transferNos: q.transferNos || [],
orderIdentifiers: q.orderIdentifiers || [],
customerCodes: q.customerCodes || [],
productCodes: q.productCodes || [],
creditArrearsStatus: q.creditArrearsStatus || undefined,
@@ -96,7 +96,7 @@
<div class="sec-title">费用明细</div>
<el-tabs v-model="feeTab" class="fee-tabs">
<el-tab-pane label="应收" name="income">
<div class="fee-toolbar">
<div v-if="!readonly" class="fee-toolbar">
<el-button type="primary" plain size="small" icon="Plus" v-hasPermi="['price:billing:feeAdd']" @click="openAddFee">增加费用</el-button>
<el-button type="primary" plain size="small" icon="Edit" v-hasPermi="['price:billing:chargeWeightEdit']" :disabled="detail.refundStatus === 'REFUNDED'" @click="openEditCw">修改计费重</el-button>
</div>
@@ -124,7 +124,7 @@
<el-table-column label="说明" min-width="160" show-overflow-tooltip>
<template #default="{ row }">{{ row.remark || '-' }}</template>
</el-table-column>
<el-table-column label="操作" width="120" align="center" fixed="right">
<el-table-column v-if="!readonly" label="操作" width="120" align="center" fixed="right">
<template #default="{ row }">
<template v-if="canEditManualFee(row)">
<el-button link type="primary" v-hasPermi="['price:billing:feeEdit']" @click="openEditFee(row)">编辑</el-button>
@@ -198,7 +198,8 @@ const props = defineProps({
modelValue: { type: Boolean, default: false },
title: { type: String, default: '计费详情' },
loading: { type: Boolean, default: false },
detail: { type: Object, default: null }
detail: { type: Object, default: null },
readonly: { type: Boolean, default: false }
})
const emit = defineEmits(['update:modelValue', 'updated'])
@@ -335,17 +336,41 @@ function formatDateTime(val) {
return d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate()) + ' ' + pad(d.getHours()) + ':' + pad(d.getMinutes()) + ':' + pad(d.getSeconds())
}
const billingFailStatusOptions = [
{ label: '计费成功', value: 0 },
{ label: '未匹配产品', value: 1 },
{ label: '未匹配国家', value: 2 },
{ label: '未匹配重量段', value: 3 },
{ label: '未绑定套餐', value: 4 },
{ label: '无生效套餐版本', value: 5 },
{ label: '已生成应收账单', value: 6 },
{ label: '产品档案缺失', value: 7 },
{ label: '未命中价格', value: 8 },
{ label: '分区无价格', value: 9 },
{ label: '邮编必填', value: 10 },
{ label: '邮编未匹配分区', value: 11 },
{ label: '上游订单不存在', value: 12 },
{ label: '上游订单号为空', value: 13 },
{ label: '上游客户为空', value: 14 },
{ label: '上游产品为空', value: 15 },
{ label: '上游重量无效', value: 16 },
{ label: '计费时间为空', value: 17 },
{ label: '退费订单无法解析', value: 18 },
{ label: '客户代码为空', value: 19 },
{ label: '客户已停用', value: 20 },
{ label: '运费为空', value: 21 },
{ label: '未知失败', value: 22 }
]
function billingFailLabel(status) {
const code = status == null ? 0 : Number(status)
if (code === 1) return '未匹配产品'
if (code === 2) return '未匹配国家'
if (code === 3) return '未匹配重量段'
return '计费成功'
const hit = billingFailStatusOptions.find(item => item.value === code)
return hit ? hit.label : '未知失败'
}
function billingFailTagType(status) {
const code = status == null ? 0 : Number(status)
if (code === 1 || code === 2 || code === 3) return 'danger'
if (code > 0) return 'danger'
return 'success'
}