应付配置增加附加费配置,应付账单新增核销、对账、凭证、审核功能

This commit is contained in:
liuminghui
2026-11-12 18:20:32 +08:00
parent 1ba431540d
commit 6675808dfc
55 changed files with 5898 additions and 185 deletions
@@ -191,23 +191,11 @@
</el-table-column>
<el-table-column prop="calcRule" label="计费条件" width="140">
<template #default="{ row }">
<el-select v-if="isRowEditing(row)" v-model="row.calcRule" size="small" placeholder="暂不计费">
<el-option v-for="item in calcRules" :key="item.value" :label="item.label" :value="item.value" />
<el-select v-if="isRowEditing(row)" :model-value="feeBillFlag(row)" size="small" @change="value => setFeeBill(row, value)">
<el-option label="需要计费" value="BILL" />
<el-option label="暂不计费" value="MANUAL" />
</el-select>
<span v-else>{{ calcRuleLabel(row.calcRule) }}</span>
</template>
</el-table-column>
<el-table-column prop="calcParam" label="条件参数" min-width="220" show-overflow-tooltip>
<template #default="{ row }">
<span v-if="!isRowEditing(row)">{{ feeCondition(row) }}</span>
<template v-else>
<div v-if="conditionHint(row)" class="pay-cond-hint">{{ conditionHint(row) }}</div>
<cell-text
v-if="showCalcParamEditor(row)"
v-model="row.calcParam"
:edit="true"
/>
</template>
<span v-else>{{ feeBillFlag(row) === 'BILL' ? '需要计费' : '暂不计费' }}</span>
</template>
</el-table-column>
<el-table-column v-if="editable" label="操作" width="120" align="center" fixed="right">
@@ -471,50 +459,16 @@ const CellText = {
}
}
const calcRules = [
{ value: 'ALWAYS', label: '每票都收' },
{ value: 'POSTCODE', label: '命中邮编' },
{ value: 'ZONE', label: '命中分区' },
{ value: 'EXTRA_KG', label: '超重续收' },
{ value: 'WEIGHT', label: '超重' },
{ value: 'SIZE', label: '超尺寸' },
{ value: 'RETURN', label: '退件' },
{ value: 'MANUAL', label: '暂不计费' }
]
function calcRuleLabel(value) {
return calcRules.find(item => item.value === value)?.label || '暂不计费'
function feeBillFlag(row) {
return row?.calcRule && row.calcRule !== 'MANUAL' ? 'BILL' : 'MANUAL'
}
function conditionHint(row) {
const parts = []
const hasMin = row.weightMin != null && row.weightMin !== ''
const hasMax = row.weightMax != null && row.weightMax !== ''
if (hasMin || hasMax) {
parts.push(`${hasMin ? row.weightMin : ''}-${hasMax ? row.weightMax : ''}kg`)
function setFeeBill(row, value) {
if (value === 'MANUAL') {
row.calcRule = 'MANUAL'
return
}
if (row.postcodeParam) {
parts.push(`邮编 ${row.postcodeParam}`)
}
return parts.join(';')
}
function hasCalcParam(row) {
const text = String(row?.calcParam ?? '').trim()
if (!text) return false
return text !== String(row?.postcodeParam ?? '').trim()
}
function showCalcParamEditor(row) {
return hasCalcParam(row) || !conditionHint(row)
}
function feeCondition(row) {
const parts = []
const hint = conditionHint(row)
if (hint) parts.push(hint)
if (hasCalcParam(row)) parts.push(String(row.calcParam).trim())
return parts.join(';') || '-'
if (!row.calcRule || row.calcRule === 'MANUAL') row.calcRule = 'ALWAYS'
}
const pageSize = 20
@@ -0,0 +1,530 @@
<template>
<el-dialog v-model="visible" title="附加费配置" width="1080px" append-to-body destroy-on-close @closed="reset">
<div class="rule-body">
<div class="rule-block">
<div class="rule-title">绑定产品</div>
<div class="rule-products">
<el-tag v-for="item in products" :key="item.key" closable class="rule-tag" @close="removeProduct(item)">
{{ item.productName }} · 第 {{ item.versionNo || 1 }} 版
</el-tag>
<span v-if="!products.length" class="rule-empty">还没有产品。勾选列表后打开,或在下面查询后加入。</span>
</div>
<div class="rule-search">
<el-input v-model="keyword" clearable placeholder="按产品名称查询" @keyup.enter="searchProducts" />
<el-button type="primary" plain :loading="searching" @click="searchProducts">查询</el-button>
</div>
<el-table v-if="found.length" :data="found" border size="small" max-height="180" empty-text="没有产品">
<el-table-column prop="productName" label="产品名称" min-width="180" show-overflow-tooltip />
<el-table-column prop="versionNo" label="版本" width="70" align="center" />
<el-table-column label="有效期" min-width="180" show-overflow-tooltip>
<template #default="{ row }">{{ termText(row) }}</template>
</el-table-column>
<el-table-column label="操作" width="80" align="center">
<template #default="{ row }">
<el-button link type="primary" @click="addProduct(row)">加入</el-button>
</template>
</el-table-column>
</el-table>
<p class="rule-hint">配置写到每个产品当前生效的版本。同一版本再次保存会覆盖原来的一份。</p>
</div>
<div class="rule-block">
<div class="rule-title">计费条件</div>
<div class="rule-switches">
<div v-for="rule in ruleDefs" :key="rule.value" class="rule-switch">
<span>{{ rule.label }}</span>
<el-switch v-model="enabled[rule.value]" @change="value => toggleRule(rule.value, value)" />
</div>
</div>
<p v-if="enabled.POSTCODE" class="rule-hint">打开后,用订单目的国去应付邮编配置里对国家和邮编。邮编前缀和完整邮编都会判断,命中偏远或岛屿才加这笔附加费。</p>
<p v-if="enabled.ZONE" class="rule-hint">打开后,用订单目的国和邮编去应付邮编配置里对上分区,再加这一档附加费。</p>
</div>
<div v-for="rule in openedRules" :key="rule.value" class="rule-block">
<div class="rule-bar">
<span class="rule-title">{{ rule.label }}</span>
<el-button type="primary" link @click="addRow(rule.value)">新增一条</el-button>
</div>
<p class="rule-hint">{{ rule.hint }}</p>
<div v-for="(row, index) in groups[rule.value]" :key="index" class="rule-card">
<div class="rule-card-bar">
<span>第 {{ index + 1 }} 条</span>
<el-button link type="danger" @click="groups[rule.value].splice(index, 1)">删除</el-button>
</div>
<div v-if="rule.value === 'SIZE'" class="rule-grid">
<div class="field">
<span class="label">命中方式</span>
<el-select v-model="row.matchMode" size="small">
<el-option label="任一命中" value="ANY" />
<el-option label="全部命中" value="ALL" />
</el-select>
</div>
<div class="field">
<span class="label">重量前提 kg</span>
<el-input v-model="row.weightMin" size="small" placeholder="下限" />
<span class="sep">至</span>
<el-input v-model="row.weightMax" size="small" placeholder="上限" />
</div>
<div class="field">
<span class="label">最长边 cm</span>
<el-input v-model="row.longestMin" size="small" placeholder="下限" />
<span class="sep">至</span>
<el-input v-model="row.longestMax" size="small" placeholder="上限" />
</div>
<div class="field">
<span class="label">次长边 cm</span>
<el-input v-model="row.secondMin" size="small" placeholder="下限" />
<span class="sep">至</span>
<el-input v-model="row.secondMax" size="small" placeholder="上限" />
</div>
<div class="field">
<span class="label">三边之和 cm</span>
<el-input v-model="row.sumMin" size="small" placeholder="下限" />
<span class="sep">至</span>
<el-input v-model="row.sumMax" size="small" placeholder="上限" />
</div>
<div class="field">
<span class="label">围长 cm</span>
<el-input v-model="row.girthMin" size="small" placeholder="下限" />
<span class="sep">至</span>
<el-input v-model="row.girthMax" size="small" placeholder="上限" />
</div>
<div class="field">
<span class="label">箱规 cm</span>
<el-select v-model="row.boxMode" size="small" class="mode">
<el-option label="任一边超过" value="OVER" />
<el-option label="小于最小尺寸" value="UNDER" />
</el-select>
<el-input v-model="row.boxLength" size="small" placeholder="长" />
<el-input v-model="row.boxWidth" size="small" placeholder="宽" />
<el-input v-model="row.boxHeight" size="small" placeholder="高" />
</div>
<div class="field">
<span class="label">体积 m³</span>
<el-input v-model="row.volumeMin" size="small" placeholder="下限" />
<span class="sep">至</span>
<el-input v-model="row.volumeMax" size="small" placeholder="上限" />
</div>
<div class="field">
<span class="label">长×宽×高上限 cm³</span>
<el-input v-model="row.cubicMax" size="small" placeholder="例如 432000" />
</div>
<div class="field">
<span class="label">每超出 cm</span>
<el-input v-model="row.exceedStepCm" size="small" placeholder="例如 10" />
</div>
<div class="field">
<span class="label">运费加收比例 %</span>
<el-input v-model="row.exceedRatio" size="small" placeholder="例如 35" />
</div>
<div class="field span-2">
<span class="label">说明</span>
<el-input v-model="row.remark" size="small" placeholder="这一档的补充说明" />
</div>
</div>
<div v-else-if="rule.value === 'WEIGHT'" class="rule-grid">
<div class="field">
<span class="label">重量 kg</span>
<el-input v-model="row.weightMin" size="small" placeholder="下限" />
<span class="sep">至</span>
<el-input v-model="row.weightMax" size="small" placeholder="上限" />
</div>
<div class="field">
<span class="label">重量口径</span>
<el-select v-model="row.weightBasis" size="small">
<el-option label="实重" value="ACTUAL" />
<el-option label="计费重" value="CHARGE" />
</el-select>
</div>
<div class="field">
<span class="label">每超出 kg</span>
<el-input v-model="row.stepKg" size="small" placeholder="超过上限后按每公斤" />
</div>
<div class="field">
<span class="label">最低消费</span>
<el-input v-model="row.minCharge" size="small" placeholder="没有就空着" />
</div>
<div class="field">
<span class="label">运费加收比例 %</span>
<el-input v-model="row.exceedRatio" size="small" placeholder="按运费比例加收时填写" />
</div>
<div class="field">
<span class="label">说明</span>
<el-input v-model="row.remark" size="small" />
</div>
</div>
<div v-else-if="rule.value === 'EXTRA_KG'" class="rule-grid">
<div class="field">
<span class="label">超过 kg</span>
<el-input v-model="row.thresholdKg" size="small" placeholder="超过这个重量后开始续收" />
</div>
<div class="field">
<span class="label">每超出 kg</span>
<el-input v-model="row.stepKg" size="small" placeholder="例如 1" />
</div>
<div class="field">
<span class="label">重量口径</span>
<el-select v-model="row.weightBasis" size="small">
<el-option label="实重" value="ACTUAL" />
<el-option label="计费重" value="CHARGE" />
</el-select>
</div>
<div class="field">
<span class="label">最低消费</span>
<el-input v-model="row.minCharge" size="small" placeholder="例如 17.5" />
</div>
<div class="field span-2">
<span class="label">邮编</span>
<el-input v-model="row.postcodes" size="small" type="textarea" :rows="2" placeholder="续收还要限定邮编时填写,支持 KA27-28 这种区间" />
</div>
</div>
<div v-else-if="rule.value === 'ALWAYS'" class="rule-grid">
<div class="field">
<span class="label">计费方式</span>
<el-select v-model="row.rateMode" size="small">
<el-option label="固定金额" value="FIXED" />
<el-option label="按比例" value="RATIO" />
</el-select>
</div>
<div class="field">
<span class="label">比例 %</span>
<el-input v-model="row.ratio" size="small" placeholder="燃油、战争附加费这类" />
</div>
<div class="field">
<span class="label">计费基数</span>
<el-select v-model="row.chargeBase" size="small" clearable placeholder="按比例时选择">
<el-option label="处理费" value="HANDLE" />
<el-option label="派送费" value="DELIVERY" />
<el-option label="运费加附加费" value="FREIGHT_FEE" />
</el-select>
</div>
<div class="field">
<span class="label">生效日期</span>
<el-input v-model="row.periodStart" size="small" placeholder="开始,如 11-01" />
<span class="sep">至</span>
<el-input v-model="row.periodEnd" size="small" placeholder="结束,如 12-23" />
</div>
<div class="field span-2">
<span class="label">说明</span>
<el-input v-model="row.remark" size="small" placeholder="例如每年 11、12 月固定收取" />
</div>
</div>
<div v-else class="rule-grid">
<div class="field">
<span class="label">退回方式</span>
<el-select v-model="row.chargeMode" size="small">
<el-option label="同正向运费" value="SAME" />
<el-option label="空运退回" value="AIR" />
<el-option label="陆运退回" value="ROAD" />
<el-option label="固定金额" value="FIXED" />
</el-select>
</div>
<div class="field">
<span class="label">重量 kg</span>
<el-input v-model="row.weightMin" size="small" placeholder="下限" />
<span class="sep">至</span>
<el-input v-model="row.weightMax" size="small" placeholder="上限" />
</div>
<div class="field">
<span class="label">尺寸命中</span>
<el-select v-model="row.matchMode" size="small" clearable placeholder="退件还看尺寸时选择">
<el-option label="任一命中" value="ANY" />
<el-option label="全部命中" value="ALL" />
</el-select>
</div>
<div class="field">
<span class="label">最长边 cm</span>
<el-input v-model="row.longestMin" size="small" placeholder="下限" />
<span class="sep">至</span>
<el-input v-model="row.longestMax" size="small" placeholder="上限" />
</div>
<div class="field">
<span class="label">围长 cm</span>
<el-input v-model="row.girthMin" size="small" placeholder="下限" />
<span class="sep">至</span>
<el-input v-model="row.girthMax" size="small" placeholder="上限" />
</div>
<div class="field">
<span class="label">三边之和 cm</span>
<el-input v-model="row.sumMin" size="small" placeholder="下限" />
<span class="sep">至</span>
<el-input v-model="row.sumMax" size="small" placeholder="上限" />
</div>
<div class="field span-2">
<span class="label">说明</span>
<el-input v-model="row.remark" size="small" placeholder="例如拒收、地址错误退回" />
</div>
</div>
</div>
</div>
</div>
<template #footer>
<el-button :disabled="!products.length" :loading="copying" @click="copyPrevious">复制上一版本</el-button>
<el-button @click="visible = false">取消</el-button>
<el-button type="primary" :loading="saving" @click="save">保存</el-button>
</template>
</el-dialog>
</template>
<script setup>
import { listPay, listPaySurchargeRule, previousPaySurchargeRule, savePaySurchargeRule } from '@/api/price/pay'
const { proxy } = getCurrentInstance()
const ruleDefs = [
{
value: 'SIZE',
label: '超尺寸',
hint: '按报价里的每一档填写。只写最长边>120 就只填下限;100<最长边≤200 则下限、上限都填。围长是长+2×(宽+高)。任一命中对应「或 / 任一边超过」,全部命中对应「且 / 同时满足」。运费另加 35%、70% 填加收比例,每超出 10cm 填超出步长。'
},
{
value: 'WEIGHT',
label: '超重',
hint: '30<W≤70 填下限 30、上限 70;只写超过 30KG 就只填下限。超过 300kg 后每公斤续收的,填每超出。报价写明按实际重量、不按体积重时,口径选实重。'
},
{
value: 'EXTRA_KG',
label: '超重续收',
hint: '超过某个重量后只收超出部分。偏远按公斤且有最低消费的,把邮编和最低消费写在这一条。'
},
{ value: 'POSTCODE', label: '命中邮编', switchOnly: true },
{ value: 'ZONE', label: '命中分区', switchOnly: true },
{
value: 'ALWAYS',
label: '每票都收',
hint: '燃油、去碳、道路通行、旺季这类。按比例的填写比例和基数,旺季填写生效日期。'
},
{
value: 'RETURN',
label: '退件',
hint: '同正向运费、空运或陆运分开配。超尺寸或超重才退件的,把重量和最长边、围长写在同一条。'
}
]
const visible = ref(false)
const saving = ref(false)
const copying = ref(false)
const searching = ref(false)
const keyword = ref('')
const found = ref([])
const products = ref([])
const enabled = reactive({})
const groups = reactive({})
function blank(rule) {
if (rule === 'SIZE') {
return { matchMode: 'ANY', boxMode: 'OVER', weightMin: '', weightMax: '', longestMin: '', longestMax: '', secondMin: '', secondMax: '', sumMin: '', sumMax: '', girthMin: '', girthMax: '', boxLength: '', boxWidth: '', boxHeight: '', volumeMin: '', volumeMax: '', cubicMax: '', exceedStepCm: '', exceedRatio: '', remark: '' }
}
if (rule === 'WEIGHT') {
return { weightMin: '', weightMax: '', weightBasis: 'ACTUAL', stepKg: '', minCharge: '', exceedRatio: '', remark: '' }
}
if (rule === 'EXTRA_KG') {
return { thresholdKg: '', stepKg: '1', weightBasis: 'ACTUAL', minCharge: '', postcodes: '' }
}
if (rule === 'ALWAYS') {
return { rateMode: 'FIXED', ratio: '', chargeBase: '', periodStart: '', periodEnd: '', remark: '' }
}
return { chargeMode: 'SAME', weightMin: '', weightMax: '', matchMode: '', longestMin: '', longestMax: '', girthMin: '', girthMax: '', sumMin: '', sumMax: '', remark: '' }
}
function blankGroups() {
for (const rule of ruleDefs) {
enabled[rule.value] = false
groups[rule.value] = []
}
}
function reset() {
keyword.value = ''
found.value = []
products.value = []
blankGroups()
saving.value = false
copying.value = false
searching.value = false
}
function open(rows) {
reset()
visible.value = true
const skipped = []
for (const row of rows || []) addProduct(row, skipped)
if (skipped.length) proxy.$modal.msgWarning('有产品还没有生效版本,未带入:' + skipped.join('、'))
const first = products.value[0]
if (first) loadRules(first.productId, first.termId)
}
function versionOf(row) {
return {
key: String(row.versionProductId || row.productId) + ':' + String(row.termId || ''),
productId: row.versionProductId || row.productId,
termId: row.termId,
versionNo: row.versionNo,
productName: row.productName || '未命名产品'
}
}
function addProduct(row, skipped) {
const item = versionOf(row)
if (!item.productId || !item.termId) {
if (skipped) skipped.push(item.productName)
else proxy.$modal.msgWarning(item.productName + '还没有生效版本,不能绑定')
return
}
if (products.value.some(product => product.key === item.key)) return
products.value.push(item)
}
function removeProduct(item) {
products.value = products.value.filter(product => product.key !== item.key)
}
function termText(row) {
const start = row.termStart || row.effectiveStart || ''
const end = row.termEnd || row.effectiveEnd || ''
if (!start && !end) return '-'
return (String(start).slice(0, 10) || '不限') + ' 至 ' + (String(end).slice(0, 10) || '不限')
}
function searchProducts() {
searching.value = true
listPay({ productName: keyword.value.trim(), templateOnly: true, currentOnly: true, pageNum: 1, pageSize: 20 }).then(res => {
found.value = res.rows || []
}).finally(() => {
searching.value = false
})
}
function toggleRule(rule, value) {
const def = ruleDefs.find(item => item.value === rule)
if (def?.switchOnly) return
if (value && !groups[rule].length) groups[rule].push(blank(rule))
}
function addRow(rule) {
groups[rule].push(blank(rule))
}
function applyRules(list) {
blankGroups()
for (const item of list || []) {
const rule = item.calcRule
if (!groups[rule]) continue
enabled[rule] = item.enabled !== '0'
if (ruleDefs.find(def => def.value === rule)?.switchOnly) continue
if (item.enabled === '0') continue
const row = blank(rule)
const detail = item.detail || {}
Object.keys(row).forEach(key => {
if (detail[key] !== undefined && detail[key] !== null) row[key] = String(detail[key])
})
groups[rule].push(row)
}
for (const rule of ruleDefs) {
if (rule.switchOnly) continue
if (enabled[rule.value] && !groups[rule.value].length) groups[rule.value].push(blank(rule.value))
}
}
function loadRules(productId, termId) {
listPaySurchargeRule(productId, termId).then(res => applyRules(res.data || []))
}
const openedRules = computed(() => ruleDefs.filter(rule => enabled[rule.value] && !rule.switchOnly))
function detailOf(rule, row) {
const detail = {}
const template = blank(rule)
Object.keys(template).forEach(key => {
const value = row[key]
if (value === '' || value === null || value === undefined) return
detail[key] = value
})
return detail
}
function payloadRules() {
const rules = []
for (const rule of ruleDefs) {
if (!enabled[rule.value]) continue
if (rule.switchOnly) {
rules.push({ calcRule: rule.value, enabled: '1', detail: {} })
continue
}
const rows = groups[rule.value].length ? groups[rule.value] : [blank(rule.value)]
rows.forEach(row => {
rules.push({ calcRule: rule.value, enabled: '1', detail: detailOf(rule.value, row) })
})
}
return rules
}
function copyPrevious() {
const first = products.value[0]
if (!first) return
copying.value = true
previousPaySurchargeRule(first.productId).then(res => {
const list = res.data || []
if (!list.length) {
proxy.$modal.msgWarning('上一版本没有计费条件')
return
}
applyRules(list)
proxy.$modal.msgSuccess('已带入上一版本,保存后写到当前版本')
}).finally(() => {
copying.value = false
})
}
function save() {
if (!products.value.length) {
proxy.$modal.msgError('请选择要绑定的产品')
return
}
saving.value = true
savePaySurchargeRule({
products: products.value.map(item => ({
productId: item.productId,
termId: item.termId,
versionNo: item.versionNo,
productName: item.productName
})),
rules: payloadRules()
}).then(() => {
proxy.$modal.msgSuccess('已保存到当前版本')
visible.value = false
}).finally(() => {
saving.value = false
})
}
defineExpose({ open })
</script>
<style scoped>
.rule-body { max-height: 68vh; overflow: auto; padding-right: 4px; }
.rule-block { margin-bottom: 16px; }
.rule-title { font-weight: 600; }
.rule-products { display: flex; flex-wrap: wrap; gap: 8px; min-height: 32px; margin: 8px 0; }
.rule-tag { margin: 0; }
.rule-empty { color: var(--el-text-color-secondary); font-size: 13px; }
.rule-search { display: flex; gap: 8px; margin-bottom: 8px; }
.rule-hint { margin: 6px 0 8px; color: var(--el-text-color-secondary); font-size: 12px; line-height: 1.5; }
.rule-switches { display: flex; flex-wrap: wrap; gap: 12px 20px; margin-top: 8px; }
.rule-switch { display: flex; align-items: center; gap: 8px; }
.rule-bar, .rule-card-bar { display: flex; align-items: center; justify-content: space-between; }
.rule-card { border: 1px solid var(--el-border-color); border-radius: 6px; padding: 8px 12px 12px; margin-bottom: 10px; }
.rule-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; }
.field { display: flex; align-items: center; gap: 6px; min-width: 0; }
.field .label { width: 118px; flex: none; font-size: 13px; color: var(--el-text-color-regular); }
.field .el-input, .field .el-select { flex: 1; min-width: 0; }
.field .sep { flex: none; color: var(--el-text-color-secondary); }
.field .mode { flex: 0 0 118px; }
.span-2 { grid-column: 1 / -1; }
</style>