应付配置的附加费调整

This commit is contained in:
liuminghui
2026-11-18 13:34:00 +08:00
parent ccfb05bf50
commit a72417b2c1
30 changed files with 1338 additions and 107 deletions
@@ -0,0 +1,252 @@
<template>
<el-dialog v-model="visible" :title="title" width="980px" append-to-body destroy-on-close>
<div v-loading="loading" class="board">
<section class="pick">
<div class="pane-title">附加费</div>
<el-select v-model="pickedId" filterable clearable placeholder="选择附加费配置" style="width: 100%">
<el-option v-for="item in available" :key="item.scId" :label="optionLabel(item)" :value="item.scId" />
</el-select>
<el-button type="primary" plain class="add" @click="addPicked">添加</el-button>
<p class="hint">从附加费配置里选择。长宽高、重量和邮编在配置里维护,这里只选用。</p>
</section>
<section class="chosen">
<div class="pane-title">已选附加费</div>
<el-empty v-if="!chosen.length" description="还没有选择附加费" :image-size="64" />
<div v-for="row in chosen" :key="row.scId" class="card">
<div class="card-head">
<strong>{{ row.feeName }}</strong>
<el-tag size="small" effect="plain">{{ chargeLabel(row.calcRule) }}</el-tag>
<span class="meta">{{ valueText(row) }}</span>
<el-button link type="danger" @click="removeRow(row)">移除</el-button>
</div>
<div v-if="row.zoneName" class="scope">分区 {{ row.zoneName }}</div>
<div class="scope">{{ conditionText(row) }}</div>
</div>
</section>
</div>
<template #footer>
<el-button @click="visible = false">取消</el-button>
<el-button type="primary" :loading="saving" @click="save">保存</el-button>
</template>
</el-dialog>
</template>
<script setup>
import { listSurchargeOptions } from '@/api/price/surcharge'
import { listPayConfigSurcharges, savePayConfigSurcharges } from '@/api/price/pay'
const emit = defineEmits(['saved'])
const { proxy } = getCurrentInstance()
const visible = ref(false)
const loading = ref(false)
const saving = ref(false)
const title = ref('附加费')
const termId = ref(null)
const pickedId = ref(null)
const options = ref([])
const chosen = ref([])
const chargeLabelMap = {
MANUAL: '暂不计费',
ALWAYS: '每票都收',
POSTCODE: '命中邮编',
ZONE: '命中分区',
EXTRA_KG: '超重续收',
WEIGHT: '超重',
SIZE: '超尺寸',
RETURN: '退件'
}
const available = computed(() => {
const used = new Set(chosen.value.map(row => String(row.scId)))
return options.value.filter(item => item?.scId != null && !used.has(String(item.scId)))
})
function chargeLabel(rule) {
return chargeLabelMap[rule] || rule || '暂不计费'
}
function toRule(chargeType) {
const code = String(chargeType || '').trim().toUpperCase()
if (code === 'FIXED') return 'ALWAYS'
if (!code || code === 'RATE') return 'MANUAL'
return chargeLabelMap[code] ? code : 'MANUAL'
}
function optionLabel(item) {
const value = item.chargeValue == null ? '' : ` ${item.chargeValue}${item.currency ? ' ' + item.currency : ''}`
return `${item.scName} · ${chargeLabel(toRule(item.chargeType))}${value}`
}
function valueText(row) {
if (row.amount == null || row.amount === '') return ''
return `${row.amount} ${row.currency || ''}`.trim()
}
function rowFromConfig(item) {
return {
scId: item.scId,
feeName: item.scName,
calcRule: toRule(item.chargeType),
amount: item.chargeValue,
currency: item.currency,
zoneName: item.blockTitle || '',
lengthCm: item.lengthCm,
widthCm: item.widthCm,
heightCm: item.heightCm,
overWeightKg: item.overWeightKg,
extraWeightKg: item.extraWeightKg,
postcodeText: item.postcodeText || ''
}
}
function addPicked() {
const item = options.value.find(row => String(row.scId) === String(pickedId.value))
if (!item) {
proxy.$modal.msgWarning('请选择附加费')
return
}
chosen.value.push(rowFromConfig(item))
pickedId.value = null
}
function removeRow(row) {
chosen.value = chosen.value.filter(item => item !== row)
}
function conditionText(row) {
if (row.calcRule === 'SIZE') {
if (Number(row.lengthCm) > 0 && Number(row.widthCm) > 0 && Number(row.heightCm) > 0) {
return `长 ${row.lengthCm} cm,宽 ${row.widthCm} cm,高 ${row.heightCm} cm`
}
return '长宽高还没在附加费配置里填写'
}
if (row.calcRule === 'WEIGHT') {
return row.overWeightKg == null ? '超过重量还没在附加费配置里填写' : `超过 ${row.overWeightKg} kg`
}
if (row.calcRule === 'EXTRA_KG') {
return row.extraWeightKg == null ? '续重起始重量还没在附加费配置里填写' : `超出 ${row.extraWeightKg} kg 后续收`
}
if (row.calcRule === 'POSTCODE') {
return String(row.postcodeText || '').trim() ? `邮编 ${row.postcodeText}` : '邮编还没在附加费配置里填写'
}
return '按附加费配置直接计费'
}
function invalid(row) {
const text = conditionText(row)
return text.includes('还没') ? row.feeName + text : ''
}
async function open(row) {
if (!row?.termId) {
proxy.$modal.msgWarning('请先为这张价卡设置有效期')
return
}
title.value = row.productName || '附加费'
termId.value = row.termId
pickedId.value = null
chosen.value = []
options.value = []
visible.value = true
loading.value = true
try {
const [configs, selected] = await Promise.all([
listSurchargeOptions({ ssCode: 'on' }),
listPayConfigSurcharges(row.termId)
])
options.value = configs.data || []
chosen.value = (selected.data || []).map(item => ({
scId: item.scId,
feeName: item.feeName,
calcRule: item.calcRule,
amount: item.amount,
currency: item.currency,
zoneName: item.zoneName || '',
lengthCm: item.lengthCm,
widthCm: item.widthCm,
heightCm: item.heightCm,
overWeightKg: item.overWeightKg,
extraWeightKg: item.extraWeightKg,
postcodeText: item.postcodeText || ''
}))
} finally {
loading.value = false
}
}
async function save() {
for (const row of chosen.value) {
const message = invalid(row)
if (message) {
proxy.$modal.msgWarning(message)
return
}
}
saving.value = true
try {
await savePayConfigSurcharges(termId.value, chosen.value.map(row => ({ scId: row.scId })))
proxy.$modal.msgSuccess('附加费已保存')
visible.value = false
emit('saved')
} finally {
saving.value = false
}
}
defineExpose({ open })
</script>
<style scoped>
.board {
display: flex;
gap: 16px;
min-height: 420px;
}
.pick {
width: 300px;
flex: none;
}
.chosen {
flex: 1;
min-width: 0;
max-height: 520px;
overflow: auto;
}
.pane-title {
margin-bottom: 10px;
font-weight: 600;
}
.add {
margin-top: 10px;
}
.hint,
.scope {
margin: 10px 0 0;
color: var(--el-text-color-secondary);
font-size: 12px;
line-height: 1.6;
}
.card {
margin-bottom: 10px;
padding: 10px 12px;
border: 1px solid var(--el-border-color);
border-radius: 6px;
}
.card-head {
display: flex;
align-items: center;
gap: 8px;
}
.card-head strong {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.meta {
margin-left: auto;
color: var(--el-text-color-secondary);
}
</style>
@@ -75,7 +75,7 @@
/>
</el-tab-pane>
<el-tab-pane :label="feeTabLabel(pane)" name="fee">
<el-tab-pane v-if="showFees" :label="feeTabLabel(pane)" name="fee">
<div class="pay-edit-bar">
<el-input v-model="pane.feeKeyword" clearable placeholder="筛选附加费用、地区、价格、货币或费用解释" class="pay-filter" @input="pane.feePageNo = 1" />
<el-select v-model="pane.feeBill" clearable placeholder="计费条件" class="pay-bill-filter" @change="pane.feePageNo = 1">
@@ -274,6 +274,8 @@ import PaySurchargePickerDialog from './PaySurchargePickerDialog.vue'
const { order_charge_type } = useDict('order_charge_type')
const showFees = false
function chargeTypeText(value) {
const hit = (order_charge_type.value || []).find(item => item.value === value)
if (hit) return hit.label
@@ -76,7 +76,6 @@
<template #default="{ row }">{{ row.effectiveDate || preview.effectiveDate || '-' }}</template>
</el-table-column>
<el-table-column prop="weightCount" label="重量段" width="80" align="right" />
<el-table-column prop="surchargeCount" label="附加费" width="80" align="right" />
<el-table-column label="识别" width="120">
<template #default="{ row }">
<el-tag :type="statusType(row.parseStatus)" size="small">{{ statusText(row.parseStatus) }}</el-tag>
@@ -64,6 +64,7 @@
<template #col-action="{ row }">
<el-button link type="primary" icon="View" @click="openDetail(row)" v-hasPermi="['price:pay:query']">查看</el-button>
<el-button link type="primary" @click="surchargeRef.open(row)" v-hasPermi="['price:pay:surcharge']">附加费</el-button>
<el-button link type="primary" icon="Calendar" @click="openTermDialog(row)" v-hasPermi="['price:pay:edit']">有效期</el-button>
<el-button link type="primary" icon="Clock" @click="openHistory(row)" v-hasPermi="['price:pay:query']">历史</el-button>
<el-button link type="primary" icon="Delete" @click="handleDelete(row.productId)" v-hasPermi="['price:pay:remove']">删除</el-button>
@@ -72,6 +73,7 @@
<pay-import-dialog ref="importRef" @saved="tableRef.refresh()" />
<pay-create-dialog ref="createRef" @saved="tableRef.refresh()" />
<pay-card-surcharge-dialog ref="surchargeRef" @saved="tableRef.refresh()" />
<el-dialog v-model="bindVisible" title="绑定渠道" width="640px" append-to-body @closed="resetBind">
<el-form label-width="70px">
<el-form-item label="产品">
@@ -210,6 +212,7 @@ import { listChannelOptions } from '@/api/masterdata/serviceChannel'
import { useDict } from '@/utils/dict'
import PayImportDialog from './components/PayImportDialog.vue'
import PayCreateDialog from './components/PayCreateDialog.vue'
import PayCardSurchargeDialog from './components/PayCardSurchargeDialog.vue'
import PayConfigDetail from './components/PayConfigDetail.vue'
const { proxy } = getCurrentInstance()
@@ -217,6 +220,7 @@ const { order_charge_type } = useDict('order_charge_type')
const tableRef = ref()
const importRef = ref()
const createRef = ref()
const surchargeRef = ref()
const detailVisible = ref(false)
const detailLoading = ref(false)
const savingRowKey = ref('')
@@ -273,7 +277,7 @@ const columns = [
{ label: '识别结果', prop: 'parseStatus', align: 'center', width: 120 },
{ label: '来源文件', prop: 'sourceFile', align: 'center', minWidth: 180, showOverflowTooltip: true },
{ label: '创建时间', prop: 'createTime', align: 'center', width: 160, parseTime: true },
{ label: '操作', prop: 'action', align: 'center', width: 280, fixed: 'right', showInToolbar: false }
{ label: '操作', prop: 'action', align: 'center', width: 340, fixed: 'right', showInToolbar: false }
]
const searchColumns = [