提单费用调整

This commit is contained in:
liuminghui
2026-11-10 15:21:03 +08:00
parent e6a9fcf0a2
commit da9efc422e
16 changed files with 911 additions and 170 deletions
@@ -1,24 +1,57 @@
<template>
<el-dialog v-model="visible" :title="title" width="980px" append-to-body destroy-on-close @closed="reset">
<el-dialog v-model="visible" :title="title" width="1360px" append-to-body destroy-on-close @closed="reset">
<div v-loading="loading">
<div class="fee-toolbar">
<el-button type="primary" plain icon="Plus" @click="addRow">新增</el-button>
<span class="fee-hint">只保存本次新增、修改和删除的费用,未改动的行不会重写。</span>
</div>
<el-table :data="rows" border size="small" max-height="320" row-key="rowKey" empty-text="暂无费用,点击新增">
<el-table-column label="费用项" min-width="160">
<el-table-column min-width="180">
<template #header><span class="col-label"><i v-if="allocRequired" class="req-star">*</i>费用阶段</span></template>
<template #default="{ row }">
<el-select v-model="row.feeType" filterable clearable placeholder="请选择" style="width: 100%">
<el-option v-for="item in bms_fee_type" :key="item.value" :label="item.label" :value="item.value" />
<el-select v-model="row.feeLevel" filterable clearable placeholder="请选择" style="width: 100%">
<el-option v-for="item in bms_fee_level" :key="item.value" :label="item.label" :value="String(item.value)" />
</el-select>
</template>
</el-table-column>
<el-table-column label="价格" width="150">
<el-table-column width="120">
<template #header><span class="col-label"><i class="req-star">*</i>是否分摊</span></template>
<template #default="{ row }">
<el-select v-model="row.allocFlag" placeholder="请选择" style="width: 100%" @change="changeAlloc(row)">
<el-option v-for="item in bill_fee_alloc" :key="item.value" :label="item.label" :value="String(item.value)" />
</el-select>
</template>
</el-table-column>
<el-table-column v-if="allocRequired" min-width="150">
<template #header><span class="col-label"><i class="req-star">*</i>分摊维度(票)</span></template>
<template #default="{ row }">
<el-select v-if="String(row.allocFlag) === '1'" v-model="row.allocDim" placeholder="请选择" style="width: 100%">
<el-option v-for="item in bill_fee_alloc_dim" :key="item.value" :label="item.label" :value="String(item.value)" />
</el-select>
</template>
</el-table-column>
<el-table-column label="费用状态" width="100" align="center">
<template #default="{ row }">
<dict-tag :options="bill_fee_status" :value="row.billFeeStatus || '0'" />
</template>
</el-table-column>
<el-table-column min-width="160">
<template #header><span class="col-label"><i class="req-star">*</i>费用项</span></template>
<template #default="{ row }">
<el-select v-model="row.feeType" filterable remote clearable reserve-keyword placeholder="输入费用名称"
:remote-method="searchSurcharge" :loading="surchargeLoading" style="width: 100%" @change="name => onFeeChange(row, name)">
<el-option v-for="item in surchargeOptions" :key="item.scId" :label="item.scName" :value="item.scId" />
</el-select>
</template>
</el-table-column>
<el-table-column width="150">
<template #header><span class="col-label"><i class="req-star">*</i>价格</span></template>
<template #default="{ row }">
<el-input-number v-model="row.price" :min="0" :precision="4" :controls="false" :value-on-clear="null" placeholder="价格" style="width: 100%" />
</template>
</el-table-column>
<el-table-column label="收费币种" width="140">
<el-table-column width="140">
<template #header><span class="col-label"><i class="req-star">*</i>收费币种</span></template>
<template #default="{ row }">
<el-select v-model="row.currency" filterable clearable placeholder="请选择" style="width: 100%">
<el-option v-for="item in bms_currency" :key="item.value" :label="item.label" :value="item.value" />
@@ -91,10 +124,11 @@
<script setup>
import { listAirBillFee, listAirBillFeeLog, saveAirBillFee } from '@/api/price/airBill'
import { listSurchargeOptions } from '@/api/price/surcharge'
import { parseTime } from '@/utils/bms'
const { proxy } = getCurrentInstance()
const { bms_fee_type, bms_currency } = useDict('bms_fee_type', 'bms_currency')
const { bms_fee_level, bms_currency, bill_fee_status, bill_fee_alloc, bill_fee_alloc_dim } = useDict('bms_fee_level', 'bms_currency', 'bill_fee_status', 'bill_fee_alloc', 'bill_fee_alloc_dim')
const visible = ref(false)
const loading = ref(false)
@@ -107,10 +141,14 @@ const logs = ref([])
const logPageNum = ref(1)
const logPageSize = ref(10)
const logTotal = ref(0)
const surchargeOptions = ref([])
const surchargeLoading = ref(false)
let rowSeed = 0
let logSeq = 0
let surchargeSeq = 0
const title = computed(() => billCode.value ? `提单费用 - ${billCode.value}` : '提单费用')
const allocRequired = computed(() => rows.value.some(row => String(row.allocFlag) === '1'))
const dirty = computed(() => deletedIds.value.length > 0 || rows.value.some(row => rowChanged(row)))
function open(row) {
@@ -130,6 +168,9 @@ function reset() {
logPageSize.value = 10
logTotal.value = 0
logSeq += 1
surchargeSeq += 1
surchargeOptions.value = []
surchargeLoading.value = false
saving.value = false
loading.value = false
logLoading.value = false
@@ -139,6 +180,7 @@ function load() {
logPageNum.value = 1
loadFees()
loadLogs()
searchSurcharge('')
}
function loadFees() {
@@ -151,16 +193,58 @@ function loadFees() {
rowKey: `fee-${item.id}`,
id: item.id,
feeType: item.feeType == null ? '' : String(item.feeType),
feeName: item.feeName || '',
feeLevel: item.feeLevel == null ? '' : String(item.feeLevel),
allocFlag: item.allocFlag == null || item.allocFlag === '' ? '0' : String(item.allocFlag),
allocDim: item.allocDim == null ? '' : String(item.allocDim),
billFeeStatus: item.billFeeStatus == null || item.billFeeStatus === '' ? '0' : String(item.billFeeStatus),
price: item.price === null || item.price === undefined ? null : Number(item.price),
currency: item.currency || '',
remark: item.remark || '',
origin: snapshot(item)
}))
pinSelectedFees()
}).finally(() => {
if (code === billCode.value) loading.value = false
})
}
function pinSelectedFees() {
const known = new Map(surchargeOptions.value.map(item => [String(item.scId), item]))
for (const row of rows.value) {
if (!row.feeType) continue
if (!known.has(String(row.feeType))) {
known.set(String(row.feeType), { scId: String(row.feeType), scName: row.feeName || String(row.feeType) })
}
}
surchargeOptions.value = [...known.values()]
}
function searchSurcharge(keyword) {
const seq = ++surchargeSeq
surchargeLoading.value = true
const params = { ssCode: 'on' }
const name = String(keyword || '').trim()
if (name) params.scName = name
listSurchargeOptions(params).then(res => {
if (seq !== surchargeSeq) return
surchargeOptions.value = (res.data || []).map(item => ({
scId: item.scId == null ? '' : String(item.scId),
scName: item.scName || ''
})).filter(item => item.scId)
pinSelectedFees()
}).catch(() => {
if (seq === surchargeSeq) pinSelectedFees()
}).finally(() => {
if (seq === surchargeSeq) surchargeLoading.value = false
})
}
function onFeeChange(row, id) {
const found = surchargeOptions.value.find(item => String(item.scId) === String(id || ''))
row.feeName = found ? found.scName : ''
}
function unwrapLogs(res) {
const rows = res?.rows
if (Array.isArray(rows)) {
@@ -207,6 +291,11 @@ function addRow() {
rowKey: `new-${rowSeed}`,
id: null,
feeType: '',
feeName: '',
feeLevel: '',
allocFlag: '0',
allocDim: '',
billFeeStatus: '0',
price: null,
currency: '',
remark: '',
@@ -214,6 +303,10 @@ function addRow() {
})
}
function changeAlloc(row) {
if (String(row.allocFlag) !== '1') row.allocDim = ''
}
function removeRow(row) {
if (row.id != null && !deletedIds.value.some(id => String(id) === String(row.id))) {
deletedIds.value.push(row.id)
@@ -224,6 +317,9 @@ function removeRow(row) {
function snapshot(item) {
return {
feeType: item.feeType || '',
feeLevel: item.feeLevel || '',
allocFlag: item.allocFlag == null || item.allocFlag === '' ? '0' : String(item.allocFlag),
allocDim: item.allocDim || '',
price: normPrice(item.price),
currency: item.currency || '',
remark: (item.remark || '').trim()
@@ -233,6 +329,9 @@ function snapshot(item) {
function currentOf(row) {
return {
feeType: row.feeType || '',
feeLevel: row.feeLevel || '',
allocFlag: row.allocFlag || '',
allocDim: String(row.allocFlag) === '1' ? (row.allocDim || '') : '',
price: normPrice(row.price),
currency: row.currency || '',
remark: (row.remark || '').trim()
@@ -248,20 +347,40 @@ function normPrice(value) {
function rowChanged(row) {
if (!row.origin) {
const now = currentOf(row)
return !!(now.feeType || now.price || now.currency || now.remark)
return !!(now.feeType || now.feeLevel || now.allocFlag === '1' || now.allocDim || now.price || now.currency || now.remark)
}
const now = currentOf(row)
return now.feeType !== row.origin.feeType || now.price !== row.origin.price
return now.feeType !== row.origin.feeType || now.feeLevel !== row.origin.feeLevel || now.allocFlag !== row.origin.allocFlag
|| now.allocDim !== row.origin.allocDim || now.price !== row.origin.price
|| now.currency !== row.origin.currency || now.remark !== row.origin.remark
}
function rowError(row) {
if (String(row.allocFlag) !== '0' && String(row.allocFlag) !== '1') return '请选择是否分摊'
if (String(row.allocFlag) === '1' && !row.feeLevel) return '如需分摊费用至订单,请选择费用所属阶段'
if (String(row.allocFlag) === '1' && !row.allocDim) return '如需分摊费用至订单,请选择分摊维度'
if (!row.feeType) return '请选择费用项'
if (row.price === null || row.price === undefined || row.price === '') return '请填写价格'
if (Number(row.price) < 0) return '价格不能小于0'
if (!row.currency) return '请选择收费币种'
return ''
}
function save() {
const invalid = rows.value.find(row => rowChanged(row) && rowError(row))
if (invalid) {
proxy.$modal.msgError(rowError(invalid))
return
}
const inserts = []
const updates = []
rows.value.forEach(row => {
if (!rowChanged(row)) return
const payload = {
feeType: row.feeType || '',
feeLevel: row.feeLevel || '',
allocFlag: row.allocFlag || '',
allocDim: String(row.allocFlag) === '1' ? (row.allocDim || '') : '',
price: row.price,
currency: row.currency || '',
remark: (row.remark || '').trim()
@@ -323,6 +442,18 @@ defineExpose({ open })
color: var(--el-text-color-secondary);
font-size: 12px;
}
.col-label {
display: inline-flex;
align-items: flex-start;
line-height: 1.2;
}
.req-star {
color: var(--el-color-danger);
font-style: normal;
font-weight: 700;
margin-right: 2px;
line-height: 1;
}
.log-title {
margin: 16px 0 8px;
font-weight: 600;