新增提单管理和提单计费页面

This commit is contained in:
liuminghui
2026-11-11 16:36:17 +08:00
parent 7869205afc
commit efd92b5663
47 changed files with 1712 additions and 369 deletions
@@ -0,0 +1,429 @@
<template>
<div class="app-container air-role-fee">
<div class="page-head">
<span class="page-title">{{ title }}</span>
</div>
<div class="bill-bar">
<el-input
v-model="billCodeText"
type="textarea"
:rows="2"
resize="none"
placeholder="提单号,多个用逗号或换行分隔,可多选"
/>
<el-button type="primary" :loading="billLoading" @click="searchBills">查询提单</el-button>
</div>
<el-table
ref="billTableRef"
:data="bills"
border
size="small"
max-height="220"
row-key="billCode"
empty-text="请输入提单号后查询"
@selection-change="onBillSelect"
>
<el-table-column type="selection" width="48" />
<el-table-column
v-for="col in billColumns"
:key="col.prop"
:prop="col.prop"
:label="col.label"
:width="col.width"
:min-width="col.minWidth"
:align="col.align"
show-overflow-tooltip
>
<template #default="{ row }">{{ showCell(row, col) }}</template>
</el-table-column>
</el-table>
<div class="fee-toolbar">
<el-button type="primary" plain icon="Plus" v-hasPermi="[perm]" @click="addRows">新增</el-button>
<el-button type="primary" plain icon="Upload" v-hasPermi="[perm]" @click="openImport">导入</el-button>
<el-button v-hasPermi="[perm]" :loading="feeLoading" @click="loadFees">查询已有费用</el-button>
<span class="page-hint">已选 {{ selected.length }} 个提单。导入和新增都会写到每一个已选提单。</span>
</div>
<el-table :data="rows" border size="small" max-height="420" row-key="rowKey" empty-text="暂无费用">
<el-table-column prop="billCode" label="提单号" min-width="150" show-overflow-tooltip />
<el-table-column min-width="180">
<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" :disabled="locked(row)" style="width: 100%"
@change="id => onFeeChange(row, id)">
<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" :disabled="locked(row)" style="width: 100%" />
</template>
</el-table-column>
<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="请选择" :disabled="locked(row)" style="width: 100%">
<el-option v-for="item in bms_currency" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</template>
</el-table-column>
<el-table-column label="备注" min-width="180">
<template #default="{ row }">
<el-input v-model="row.remark" maxlength="500" clearable :disabled="locked(row)" />
</template>
</el-table-column>
<el-table-column label="操作" width="90" align="center">
<template #default="{ row }">
<span v-if="locked(row)" class="locked-text">{{ row.billFeeStatus === '3' ? '已确定' : '已分摊' }}</span>
<el-button v-else link type="danger" v-hasPermi="[perm]" @click="removeRow(row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<div class="fee-footer">
<el-button type="primary" v-hasPermi="[perm]" :disabled="!dirty" :loading="saving" @click="save">保存</el-button>
</div>
<excel-import-dialog
ref="importRef"
:title="`${title}导入`"
width="640px"
:show-update-support="false"
:import-desc="importDesc"
:template-download-handler="downloadTemplate"
:submit-handler="submitImport"
/>
</div>
</template>
<script setup>
import { listAirRoleBills, listAirRoleFees, saveAirRoleFees, importAirRoleFee } from '@/api/price/airFee'
import { listSurchargeOptions } from '@/api/price/surcharge'
import { download } from '@/utils/request'
import { parseTime } from '@/utils/bms'
import ExcelImportDialog from '@/components/ExcelImportDialog'
const props = defineProps({
scene: { type: String, required: true }
})
const { proxy } = getCurrentInstance()
const { bms_currency } = useDict('bms_currency')
const titles = { air: '空运费用', declare: '报关费用', clear: '清关费用' }
const perms = { air: 'price:airFee:air', declare: 'price:airFee:declare', clear: 'price:airFee:clear' }
const title = computed(() => titles[props.scene] || '提单费用')
const perm = computed(() => perms[props.scene] || '')
const billColumnMap = {
air: [
{ prop: 'billCode', label: '提单号', minWidth: 160 },
{ prop: 'airNo', label: '航班号', minWidth: 120 },
{ prop: 'actualAirNo', label: '实际航班号', minWidth: 120 },
{ prop: 'airCompany', label: '航空公司', minWidth: 120 },
{ prop: 'airCompanyAgent', label: '航空公司代理', minWidth: 150 },
{ prop: 'startAirport', label: '始发机场', width: 100 },
{ prop: 'endAirport', label: '目的机场', width: 100 },
{ prop: 'desPort', label: '目的港', width: 100 },
{ prop: 'routeName', label: '航线名称', minWidth: 120 },
{ prop: 'boardNo', label: '板号', width: 110 },
{ prop: 'pieceNumber', label: '总件数', width: 90, align: 'right' },
{ prop: 'actualWeight', label: '实际重量', width: 110, align: 'right' },
{ prop: 'volumeWeight', label: '体积重', width: 100, align: 'right' },
{ prop: 'bandBoxWeight', label: '打板重量', width: 110, align: 'right' },
{ prop: 'firstLandingTime', label: '首程落地时间', width: 170, time: true },
{ prop: 'startTime', label: '起飞时间', width: 170, time: true },
{ prop: 'arriveTime', label: '到达时间', width: 170, time: true },
{ prop: 'airOtherFee', label: '空运其他费用', width: 120, align: 'right' }
],
declare: [
{ prop: 'billCode', label: '提单号', minWidth: 160 },
{ prop: 'declareCode', label: '报关公司编码', minWidth: 140 },
{ prop: 'baoguanFee', label: '报关费', width: 120, align: 'right' },
{ prop: 'baoguanOtherFee', label: '报关其他费用', width: 130, align: 'right' }
],
clear: [
{ prop: 'billCode', label: '提单号', minWidth: 160 },
{ prop: 'clearanceCode', label: '清关编码', minWidth: 120 },
{ prop: 'qingguanAgent', label: '清关代理', minWidth: 140 },
{ prop: 'clearanceOpCode', label: '清关操作人', minWidth: 120 },
{ prop: 'desPort', label: '目的港', width: 100 },
{ prop: 'desPortAgentCode', label: '目的港代理编码', minWidth: 140 },
{ prop: 'desPortAgentFee', label: '目的港代理费', width: 130, align: 'right' },
{ prop: 'clearanceTime', label: '清关时间', width: 170, time: true },
{ prop: 'arriveStockTime', label: '到仓时间', width: 170, time: true },
{ prop: 'stockAddr', label: '出仓仓库地址', minWidth: 160 }
]
}
const billColumns = computed(() => billColumnMap[props.scene] || billColumnMap.air)
function showCell(row, col) {
const value = row?.[col.prop]
if (value === null || value === undefined || value === '') return '-'
if (col.time) return parseTime(value) || '-'
return value
}
const importDesc = [
'模板字段:费用名称、价格、币种、备注。',
'示例数据:燃油附加费、1000、EUR、导入时需清空这行示例数据。',
'导入前请删除示例行,否则这一行不会写入。',
'导入结果会添加到当前勾选的每一个提单,确认后点保存。'
]
const billCodeText = ref('')
const bills = ref([])
const selected = ref([])
const rows = ref([])
const deleted = ref([])
const billLoading = ref(false)
const feeLoading = ref(false)
const saving = ref(false)
const surchargeOptions = ref([])
const surchargeLoading = ref(false)
const importRef = ref()
let rowSeed = 0
let surchargeSeq = 0
const dirty = computed(() => deleted.value.length > 0 || rows.value.some(row => rowChanged(row)))
function parseCodes(raw) {
return [...new Set(String(raw || '').split(/[\s,,;;]+/).map(item => item.trim()).filter(Boolean))]
}
function searchBills() {
const codes = parseCodes(billCodeText.value)
if (!codes.length) {
proxy.$modal.msgWarning('请输入提单号')
return
}
billLoading.value = true
listAirRoleBills(codes.join(',')).then(res => {
const list = res.data || []
bills.value = list
selected.value = []
const found = new Set(list.map(item => item.billCode))
const missing = codes.filter(code => !found.has(code))
if (missing.length) proxy.$modal.msgWarning('未找到提单:' + missing.join('、'))
}).finally(() => {
billLoading.value = false
})
}
function onBillSelect(list) {
selected.value = list || []
}
async function loadFees(force = false) {
if (!selected.value.length) {
proxy.$modal.msgWarning('请先勾选提单')
return
}
if (force !== true && dirty.value) {
try {
await proxy.$modal.confirm('查询会覆盖当前未保存的费用,是否继续?')
} catch {
return
}
}
feeLoading.value = true
const codes = selected.value.map(item => item.billCode).join(',')
listAirRoleFees(props.scene, codes).then(res => {
deleted.value = []
rows.value = (res.data || []).map(item => toRow(item, true))
pinSelectedFees()
}).finally(() => {
feeLoading.value = false
})
searchSurcharge('')
}
function toRow(item, saved) {
const row = {
rowKey: saved ? `fee-${item.id}` : `new-${++rowSeed}`,
id: saved ? item.id : null,
billCode: item.billCode || '',
feeType: item.feeType == null ? '' : String(item.feeType),
feeName: item.feeName || '',
price: item.price === null || item.price === undefined ? null : Number(item.price),
currency: item.currency || '',
remark: item.remark || '',
billFeeStatus: item.billFeeStatus == null || item.billFeeStatus === '' ? '0' : String(item.billFeeStatus)
}
row.origin = saved ? snapshot(row) : null
return row
}
function snapshot(row) {
return {
feeType: row.feeType || '',
price: row.price === null || row.price === undefined || row.price === '' ? '' : String(Number(row.price)),
currency: row.currency || '',
remark: (row.remark || '').trim()
}
}
function currentOf(row) {
return {
feeType: row.feeType || '',
price: row.price === null || row.price === undefined || row.price === '' ? '' : String(Number(row.price)),
currency: row.currency || '',
remark: (row.remark || '').trim()
}
}
function rowChanged(row) {
if (!row.origin) return !!(row.feeType || row.price || row.currency || row.remark)
const now = currentOf(row)
return now.feeType !== row.origin.feeType || now.price !== row.origin.price
|| now.currency !== row.origin.currency || now.remark !== row.origin.remark
}
function locked(row) {
return row?.billFeeStatus === '1' || row?.billFeeStatus === '3'
}
function addRows() {
if (!selected.value.length) {
proxy.$modal.msgWarning('请先勾选提单')
return
}
selected.value.forEach(bill => rows.value.push(toRow({ billCode: bill.billCode }, false)))
}
function removeRow(row) {
if (row.id != null && !deleted.value.some(item => String(item.id) === String(row.id))) {
deleted.value.push({ id: row.id, billCode: row.billCode })
}
rows.value = rows.value.filter(item => item.rowKey !== row.rowKey)
}
function rowError(row) {
if (!row.billCode) 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 bills = new Map()
function bucket(code) {
if (!bills.has(code)) bills.set(code, { billCode: code, inserts: [], updates: [], deletes: [] })
return bills.get(code)
}
rows.value.forEach(row => {
if (!rowChanged(row)) return
const payload = {
feeType: row.feeType || '',
price: row.price,
currency: row.currency || '',
remark: (row.remark || '').trim()
}
const bag = bucket(row.billCode)
if (row.id) bag.updates.push({ id: row.id, ...payload })
else bag.inserts.push(payload)
})
deleted.value.forEach(item => bucket(item.billCode).deletes.push(item.id))
const list = [...bills.values()].filter(item => item.inserts.length || item.updates.length || item.deletes.length)
if (!list.length) {
proxy.$modal.msgError('没有需要保存的变更')
return
}
saving.value = true
saveAirRoleFees({ scene: props.scene, bills: list }).then(res => {
proxy.$modal.msgSuccess(res.msg || '保存成功')
deleted.value = []
loadFees(true)
}).finally(() => {
saving.value = false
})
}
function openImport() {
if (!selected.value.length) {
proxy.$modal.msgWarning('请先勾选提单')
return
}
importRef.value?.open?.()
}
function downloadTemplate() {
return download('/price/airFee/importTemplate', {}, '提单费用导入模板.xlsx')
}
async function submitImport(file) {
const raw = file?.raw || file
const form = new FormData()
form.append('file', raw)
form.append('scene', props.scene)
const res = await importAirRoleFee(form)
const imported = res.data || []
if (!imported.length) throw new Error('没有可导入的费用')
selected.value.forEach(bill => {
imported.forEach(item => rows.value.push(toRow({ ...item, billCode: bill.billCode }, false)))
})
pinSelectedFees()
return res.msg || `已读入 ${imported.length} 条费用,请确认后保存`
}
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()
}).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 pinSelectedFees() {
const known = new Map(surchargeOptions.value.map(item => [String(item.scId), item]))
rows.value.forEach(row => {
if (row.feeType && !known.has(String(row.feeType))) {
known.set(String(row.feeType), { scId: String(row.feeType), scName: row.feeName || String(row.feeType) })
}
})
surchargeOptions.value = [...known.values()]
}
searchSurcharge('')
</script>
<style scoped>
.page-head, .bill-bar, .fee-toolbar, .fee-footer {
display: flex;
align-items: center;
gap: 12px;
}
.page-head { margin-bottom: 12px; }
.page-title { font-size: 16px; font-weight: 600; }
.page-hint { color: var(--el-text-color-secondary); font-size: 12px; }
.bill-bar { margin-bottom: 10px; align-items: flex-start; }
.bill-bar .el-textarea { max-width: 520px; }
.fee-toolbar { margin: 16px 0 10px; }
.fee-footer { margin-top: 12px; justify-content: flex-end; }
.col-label { display: inline-flex; align-items: flex-start; }
.req-star { color: var(--el-color-danger); font-style: normal; font-weight: 700; margin-right: 2px; }
.locked-text { color: var(--el-text-color-secondary); font-size: 12px; }
</style>