调整应付配置和应付列表订单的费用重算

This commit is contained in:
liuminghui
2026-11-17 17:47:01 +08:00
parent 9483bb4899
commit 6b2b205083
45 changed files with 1448 additions and 2131 deletions
@@ -6,7 +6,7 @@
<el-descriptions-item label="价卡归属">{{ pane.item.supplierName || '-' }}</el-descriptions-item>
<el-descriptions-item label="生效日期">{{ pane.item.effectiveDate || '-' }}</el-descriptions-item>
<el-descriptions-item label="国家/口岸">{{ pane.item.countryScope || '-' }}</el-descriptions-item>
<el-descriptions-item label="费用类型">{{ pane.item.chargeType || '-' }}</el-descriptions-item>
<el-descriptions-item label="费用类型">{{ chargeTypeText(pane.item.chargeType) }}</el-descriptions-item>
<el-descriptions-item label="每公斤加价">{{ pane.item.extraPerKg || '-' }}</el-descriptions-item>
<el-descriptions-item label="服务类型">{{ pane.item.serviceType || '-' }}</el-descriptions-item>
<el-descriptions-item label="分类">{{ pane.item.classification || '-' }}</el-descriptions-item>
@@ -269,8 +269,20 @@
import { h, onMounted, watch } from 'vue'
import { ElInput } from 'element-plus'
import { listSurchargeOptions } from '@/api/price/surcharge'
import { useDict } from '@/utils/dict'
import PaySurchargePickerDialog from './PaySurchargePickerDialog.vue'
const { order_charge_type } = useDict('order_charge_type')
function chargeTypeText(value) {
const hit = (order_charge_type.value || []).find(item => item.value === value)
if (hit) return hit.label
if (value === 'PER_KG') return '常规计费'
if (value === 'FLAT') return '一口价'
if (value === 'EXTRA') return '续重价'
return value || '-'
}
const props = defineProps({
product: {
type: Object,
@@ -0,0 +1,290 @@
<template>
<el-dialog v-model="visible" title="新增应付价卡" width="1080px" append-to-body destroy-on-close @closed="reset">
<el-form label-width="88px">
<el-row :gutter="12">
<el-col :span="8">
<el-form-item label="计费模式" required>
<el-select v-model="form.chargeType" style="width: 100%" @change="onMode">
<el-option v-for="item in modes" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="产品名称" required>
<el-input v-model="form.productName" maxlength="80" placeholder="渠道或产品名称" />
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="价卡归属">
<el-input v-model="form.supplierName" maxlength="40" placeholder="供应商" />
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="币种">
<el-select v-model="form.currency" filterable placeholder="请选择币种" style="width: 100%">
<el-option v-for="item in currencyOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
</el-col>
<el-col :span="16">
<el-form-item label="国家/口岸">
<el-select
v-model="scopeCodes"
multiple
filterable
collapse-tags
collapse-tags-tooltip
placeholder="不选则按价格行里的国家汇总"
style="width: 100%"
>
<el-option v-for="item in regions" :key="item.countryCode2" :label="regionLabel(item)" :value="item.countryCode2" />
</el-select>
</el-form-item>
</el-col>
</el-row>
</el-form>
<div class="bar">
<span>{{ hint }}</span>
<el-button type="primary" link @click="addRow">添加一行</el-button>
</div>
<el-table :data="rows" border size="small" max-height="360">
<el-table-column label="国家" min-width="200">
<template #default="{ row }">
<el-select
v-model="row.countryCode"
filterable
clearable
size="small"
placeholder="选择国家"
style="width: 100%"
@change="code => onCountry(row, code)"
>
<el-option v-for="item in regions" :key="item.countryCode2" :label="regionLabel(item)" :value="item.countryCode2" />
</el-select>
</template>
</el-table-column>
<el-table-column label="分区" min-width="120">
<template #default="{ row }"><el-input v-model="row.zoneName" size="small" placeholder="不分区可空" /></template>
</el-table-column>
<el-table-column v-if="form.chargeType !== 'EXTRA'" label="重量下限KG" width="120">
<template #default="{ row }"><el-input v-model="row.weightMin" size="small" /></template>
</el-table-column>
<el-table-column v-if="form.chargeType !== 'EXTRA'" label="重量上限KG" width="120">
<template #default="{ row }"><el-input v-model="row.weightMax" size="small" /></template>
</el-table-column>
<el-table-column v-if="form.chargeType === 'PER_KG'" label="单价" width="110">
<template #default="{ row }"><el-input v-model="row.price" size="small" /></template>
</el-table-column>
<el-table-column v-if="form.chargeType === 'FLAT'" label="价格" width="110">
<template #default="{ row }"><el-input v-model="row.price" size="small" /></template>
</el-table-column>
<el-table-column v-if="form.chargeType === 'EXTRA'" label="首重KG" width="110">
<template #default="{ row }"><el-input v-model="row.weightMax" size="small" /></template>
</el-table-column>
<el-table-column v-if="form.chargeType === 'EXTRA'" label="首重价格" width="110">
<template #default="{ row }"><el-input v-model="row.price" size="small" /></template>
</el-table-column>
<el-table-column v-if="form.chargeType === 'EXTRA'" label="续重单价" width="110">
<template #default="{ row }"><el-input v-model="row.extraPrice" size="small" /></template>
</el-table-column>
<el-table-column label="操作" width="160" align="center">
<template #default="{ $index }">
<el-button v-if="$index > 0" link type="primary" @click="copyPrev($index)">复制上一行</el-button>
<el-button link type="danger" @click="rows.splice($index, 1)">删除</el-button>
</template>
</el-table-column>
</el-table>
<template #footer>
<el-button @click="visible = false">取消</el-button>
<el-button type="primary" :loading="saving" @click="submit">保存</el-button>
</template>
</el-dialog>
</template>
<script setup>
import { savePayManual } from '@/api/price/pay'
import { listRegionOptions } from '@/api/data/region'
import { useDict } from '@/utils/dict'
const emit = defineEmits(['saved'])
const { proxy } = getCurrentInstance()
const { order_charge_type, bms_currency } = useDict('order_charge_type', 'bms_currency')
const fallbackModes = [
{ label: '常规计费', value: 'PER_KG' },
{ label: '一口价', value: 'FLAT' },
{ label: '续重价', value: 'EXTRA' }
]
const visible = ref(false)
const saving = ref(false)
const regions = ref([])
const scopeCodes = ref([])
const form = reactive({ chargeType: 'FLAT', productName: '', supplierName: '', currency: 'EUR' })
const rows = ref([])
const currencyOptions = computed(() => {
const dict = (bms_currency.value || []).map(item => ({
label: item.label || item.value,
value: item.value
}))
return dict.length ? dict : [{ label: 'EUR', value: 'EUR' }]
})
const modes = computed(() => {
const dict = (order_charge_type.value || []).filter(item => ['PER_KG', 'FLAT', 'EXTRA'].includes(item.value))
return dict.length ? dict : fallbackModes
})
const hint = computed(() => {
if (form.chargeType === 'PER_KG') return '常规计费:运费 = 单价 × 计费重(公斤)。重量落在哪一档,就用那一档的单价。'
if (form.chargeType === 'EXTRA') return '续重价:不超过首重收首重价格;超出部分 = 超出公斤 × 续重单价。'
return '一口价:计费重落在重量段内,收这一档的固定金额。'
})
function open() {
reset()
loadRegions()
visible.value = true
}
function loadRegions() {
if (regions.value.length) return
listRegionOptions().then(res => {
regions.value = res.data || []
})
}
function regionLabel(item) {
const name = item.countryNameCn || item.countryNameEn || ''
const code = item.countryCode2 || ''
return name ? `${item.flagEmoji || ''} ${name} (${code})`.trim() : code
}
function regionName(code) {
const hit = regions.value.find(item => item.countryCode2 === code)
return hit ? (hit.countryNameCn || hit.countryNameEn || code) : code
}
function onCountry(row, code) {
row.countryCode = code || ''
row.countryName = code ? regionName(code) : ''
}
function reset() {
form.chargeType = 'FLAT'
form.productName = ''
form.supplierName = ''
form.currency = 'EUR'
scopeCodes.value = []
rows.value = [blankRow()]
saving.value = false
}
function onMode() {
rows.value = [blankRow()]
}
function blankRow() {
return { countryName: '', countryCode: '', zoneName: '', weightMin: '0', weightMax: '', price: '', extraPrice: '' }
}
function addRow() {
rows.value.push(blankRow())
}
function copyPrev(index) {
const prev = rows.value[index - 1]
if (!prev) return
rows.value[index] = { ...prev }
}
function num(value, title) {
const text = String(value ?? '').trim()
if (!text) {
proxy.$modal.msgError('请填写' + title)
return null
}
const parsed = Number(text)
if (Number.isNaN(parsed)) {
proxy.$modal.msgError(title + '必须是数字')
return null
}
return parsed
}
async function submit() {
if (!form.productName.trim()) {
proxy.$modal.msgError('请填写产品名称')
return
}
if (!rows.value.length) {
proxy.$modal.msgError('请至少添加一行价格')
return
}
const bands = []
const surcharges = []
for (const row of rows.value) {
const price = num(row.price, form.chargeType === 'PER_KG' ? '单价' : form.chargeType === 'EXTRA' ? '首重价格' : '价格')
if (price == null) return
if (form.chargeType === 'EXTRA') {
const firstKg = num(row.weightMax, '首重KG')
const extra = num(row.extraPrice, '续重单价')
if (firstKg == null || extra == null) return
bands.push({
countryName: row.countryName,
countryCode: row.countryCode,
zoneName: row.zoneName,
weightMin: 0,
weightMax: firstKg,
price
})
surcharges.push({
zoneName: row.zoneName,
amount: extra,
calcParam: String(firstKg)
})
continue
}
const min = num(row.weightMin, '重量下限')
const max = num(row.weightMax, '重量上限')
if (min == null || max == null) return
bands.push({
countryName: row.countryName,
countryCode: row.countryCode,
zoneName: row.zoneName,
weightMin: min,
weightMax: max,
price
})
}
saving.value = true
try {
const countryScope = scopeCodes.value.map(regionName).filter(Boolean).join('、')
await savePayManual({
...form,
productName: form.productName.trim(),
countryScope,
weightBands: bands,
surcharges
})
proxy.$modal.msgSuccess('价卡已保存')
visible.value = false
emit('saved')
} finally {
saving.value = false
}
}
defineExpose({ open })
</script>
<style scoped>
.bar {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
color: var(--el-text-color-secondary);
}
</style>
@@ -1,7 +1,19 @@
<template>
<el-dialog v-model="visible" title="导入应付价卡" width="1080px" append-to-body destroy-on-close @closed="reset">
<el-form label-width="88px" class="import-form">
<el-form-item label="产品">
<el-form-item label="导入方式">
<el-radio-group v-model="importMode">
<el-radio value="template">标准模板</el-radio>
<el-radio value="source">承运商原表</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item v-if="importMode === 'template'" label="计费模式">
<el-select v-model="chargeType" placeholder="选择后下载对应模板" style="width: 280px">
<el-option v-for="item in modes" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
<el-button link type="primary" :disabled="!chargeType" @click="downloadTemplate">下载模板</el-button>
</el-form-item>
<el-form-item v-else label="产品">
<el-select v-model="dictValue" clearable filterable placeholder="不选则按工作表名称匹配全部字典产品" style="width: 420px">
<el-option v-for="item in payment_product_type" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
@@ -19,7 +31,7 @@
<el-icon class="upload-icon"><UploadFilled /></el-icon>
<div class="el-upload__text">将 xlsx 价卡拖到此处,或<em>点击选择</em></div>
<template #tip>
<div class="upload-tip">选一个产品就只读对应工作表。不选时,一个文件里有多张表,只读取名称能对上字典的工作表。</div>
<div class="upload-tip">{{ importMode === 'template' ? '请先选择计费模式并下载模板,按模板填写后再上传。示例行不会导入。' : '选一个产品就只读对应工作表。不选时,一个文件里有多张表,只读取名称能对上字典的工作表。' }}</div>
</template>
</el-upload>
@@ -104,18 +116,29 @@
<script setup>
import { ElMessageBox } from 'element-plus'
import { UploadFilled } from '@element-plus/icons-vue'
import { previewPay, payParseProgress, savePay } from '@/api/price/pay'
import { previewPay, previewPayTemplate, payParseProgress, savePay } from '@/api/price/pay'
import { useDict } from '@/utils/dict'
import PayConfigDetail from './PayConfigDetail.vue'
const emit = defineEmits(['saved'])
const { proxy } = getCurrentInstance()
const { payment_product_type } = useDict('payment_product_type')
const { payment_product_type, order_charge_type } = useDict('payment_product_type', 'order_charge_type')
const fallbackModes = [
{ label: '常规计费', value: 'PER_KG' },
{ label: '一口价', value: 'FLAT' },
{ label: '续重价', value: 'EXTRA' }
]
const modes = computed(() => {
const dict = (order_charge_type.value || []).filter(item => ['PER_KG', 'FLAT', 'EXTRA'].includes(item.value))
return dict.length ? dict : fallbackModes
})
const visible = ref(false)
const recognizing = ref(false)
const saving = ref(false)
const overwrite = ref(false)
const importMode = ref('template')
const chargeType = ref('FLAT')
const dictValue = ref('')
const preview = ref(null)
const selected = ref([])
@@ -133,6 +156,11 @@ const skippedText = computed(() => (preview.value?.skippedSheets || []).filter(B
let parseSeq = 0
let progressTimer = null
function downloadTemplate() {
const hit = modes.value.find(item => item.value === chargeType.value)
proxy.download('/price/pay/template', { chargeType: chargeType.value }, `${hit?.label || '价卡'}模板.xlsx`)
}
function open() {
reset()
visible.value = true
@@ -143,6 +171,8 @@ function reset() {
preview.value = null
selected.value = []
overwrite.value = false
importMode.value = 'template'
chargeType.value = 'FLAT'
dictValue.value = ''
activeKey.value = ''
recognizing.value = false
@@ -161,6 +191,10 @@ async function onFile(uploadFile) {
proxy.$modal.msgError('请上传xlsx价卡')
return
}
if (importMode.value === 'template' && !chargeType.value) {
proxy.$modal.msgError('请先选择计费模式')
return
}
const seq = ++parseSeq
const progressId = createProgressId()
recognizing.value = true
@@ -169,7 +203,9 @@ async function onFile(uploadFile) {
parseStatus.value = undefined
startProgress(seq, progressId)
try {
const res = await previewPay(raw, dictValue.value, progressId, event => {
const requestPreview = importMode.value === 'template'
? previewPayTemplate(raw, chargeType.value)
: previewPay(raw, dictValue.value, progressId, event => {
if (seq !== parseSeq || !event?.total) return
const uploaded = Math.min(8, Math.round(event.loaded * 8 / event.total))
if (uploaded > parsePercent.value) {
@@ -177,6 +213,7 @@ async function onFile(uploadFile) {
parseMessage.value = '正在上传价卡…'
}
})
const res = await requestPreview
if (seq !== parseSeq) return
parsePercent.value = 100
parseMessage.value = '解析完成'
@@ -1,741 +0,0 @@
<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 }}
</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>
</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>
<div class="control">
<el-select v-model="row.matchMode" size="small">
<el-option label="任一命中" value="ANY" />
<el-option label="全部命中" value="ALL" />
</el-select>
</div>
</div>
<div class="field">
<span class="label">重量前提 kg</span>
<div class="control">
<el-input v-model="row.weightMin" size="small" placeholder="下限" />
<span class="sep">至</span>
<el-input v-model="row.weightMax" size="small" placeholder="上限" />
</div>
</div>
<div class="field">
<span class="label">最长边 cm</span>
<div class="control">
<el-input v-model="row.longestMin" size="small" placeholder="下限" />
<span class="sep">至</span>
<el-input v-model="row.longestMax" size="small" placeholder="上限" />
</div>
</div>
<div class="field">
<span class="label">次长边 cm</span>
<div class="control">
<el-input v-model="row.secondMin" size="small" placeholder="下限" />
<span class="sep">至</span>
<el-input v-model="row.secondMax" size="small" placeholder="上限" />
</div>
</div>
<div class="field">
<span class="label">三边之和 cm</span>
<div class="control">
<el-input v-model="row.sumMin" size="small" placeholder="下限" />
<span class="sep">至</span>
<el-input v-model="row.sumMax" size="small" placeholder="上限" />
</div>
</div>
<div class="field">
<span class="label">围长 cm</span>
<div class="control">
<el-input v-model="row.girthMin" size="small" placeholder="下限" />
<span class="sep">至</span>
<el-input v-model="row.girthMax" size="small" placeholder="上限" />
</div>
</div>
<div class="field">
<span class="label">箱规 cm</span>
<div class="control">
<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" class="num" size="small" placeholder="长" />
<el-input v-model="row.boxWidth" class="num" size="small" placeholder="宽" />
<el-input v-model="row.boxHeight" class="num" size="small" placeholder="高" />
</div>
</div>
<div class="field">
<span class="label">体积 m³</span>
<div class="control">
<el-input v-model="row.volumeMin" size="small" placeholder="下限" />
<span class="sep">至</span>
<el-input v-model="row.volumeMax" size="small" placeholder="上限" />
</div>
</div>
<div class="field">
<span class="label">长×宽×高上限 cm³</span>
<div class="control">
<el-input v-model="row.cubicMax" size="small" placeholder="例如 432000" />
</div>
</div>
<div class="field">
<span class="label">每超出 cm</span>
<div class="control">
<el-input v-model="row.exceedStepCm" size="small" placeholder="例如 10" />
</div>
</div>
<div class="field">
<span class="label">运费加收比例 %</span>
<div class="control">
<el-input v-model="row.exceedRatio" size="small" placeholder="例如 35" />
</div>
</div>
<div class="field">
<span class="label">说明</span>
<div class="control">
<el-input v-model="row.remark" size="small" placeholder="这一档的补充说明" />
</div>
</div>
</div>
<div v-else-if="rule.value === 'WEIGHT'" class="rule-grid">
<div class="field">
<span class="label">重量 kg</span>
<div class="control">
<el-input v-model="row.weightMin" size="small" placeholder="下限" />
<span class="sep">至</span>
<el-input v-model="row.weightMax" size="small" placeholder="上限" />
</div>
</div>
<div class="field">
<span class="label">重量口径</span>
<div class="control">
<el-select v-model="row.weightBasis" size="small">
<el-option label="实重" value="ACTUAL" />
<el-option label="计费重" value="CHARGE" />
</el-select>
</div>
</div>
<div class="field">
<span class="label">每超出 kg</span>
<div class="control">
<el-input v-model="row.stepKg" size="small" placeholder="超过上限后按每公斤" />
</div>
</div>
<div class="field">
<span class="label">最低消费</span>
<div class="control">
<el-input v-model="row.minCharge" size="small" placeholder="没有就空着" />
</div>
</div>
<div class="field">
<span class="label">运费加收比例 %</span>
<div class="control">
<el-input v-model="row.exceedRatio" size="small" placeholder="按运费比例加收时填写" />
</div>
</div>
<div class="field">
<span class="label">说明</span>
<div class="control">
<el-input v-model="row.remark" size="small" />
</div>
</div>
</div>
<div v-else-if="rule.value === 'EXTRA_KG'" class="rule-grid">
<div class="field">
<span class="label">超过 kg</span>
<div class="control">
<el-input v-model="row.thresholdKg" size="small" placeholder="超过这个重量后开始续收" />
</div>
</div>
<div class="field">
<span class="label">每超出 kg</span>
<div class="control">
<el-input v-model="row.stepKg" size="small" placeholder="例如 1" />
</div>
</div>
<div class="field">
<span class="label">重量口径</span>
<div class="control">
<el-select v-model="row.weightBasis" size="small">
<el-option label="实重" value="ACTUAL" />
<el-option label="计费重" value="CHARGE" />
</el-select>
</div>
</div>
<div class="field">
<span class="label">最低消费</span>
<div class="control">
<el-input v-model="row.minCharge" size="small" placeholder="例如 17.5" />
</div>
</div>
<div class="field">
<span class="label">邮编</span>
<div class="control">
<el-input v-model="row.postcodes" size="small" type="textarea" :rows="2" placeholder="续收还要限定邮编时填写,支持 KA27-28 这种区间" />
</div>
</div>
</div>
<div v-else-if="rule.value === 'POSTCODE' || rule.value === 'ZONE'" class="rule-grid">
<div class="field">
<span class="label">分区</span>
<div class="control">
<el-select v-model="row.zoneName" filterable size="small" placeholder="选择附加费里的高、中、低区">
<el-option v-for="zone in zoneOptions" :key="zone" :label="zone" :value="zone" />
</el-select>
</div>
</div>
<div class="field">
<span class="label">邮编前缀</span>
<div class="control">
<el-input v-model="row.postcodes" size="small" type="textarea" :rows="2" placeholder="多个用逗号或换行。前缀、完整邮编、1000-1099、KA27-28 都可以" />
</div>
</div>
<div class="field">
<span class="label">国家</span>
<div class="control">
<el-input v-model="row.country" size="small" placeholder="不填则不限,例如 DE 或 德国" />
</div>
</div>
</div>
<div v-else-if="rule.value === 'ALWAYS'" class="rule-grid">
<div class="field">
<span class="label">费用项</span>
<div class="control">
<el-select v-model="row.feeName" filterable size="small" placeholder="选择这一条要每票收取的费用" @change="(name) => pickFee(row, name)">
<el-option v-for="item in feeOptions" :key="item.feeName" :label="item.feeName" :value="item.feeName" />
</el-select>
</div>
</div>
<div class="field">
<span class="label">计费方式</span>
<div class="control">
<el-select v-model="row.rateMode" size="small">
<el-option label="固定金额" value="FIXED" />
<el-option label="按比例" value="RATIO" />
</el-select>
</div>
</div>
<div class="field">
<span class="label">比例 %</span>
<div class="control">
<el-input v-model="row.ratio" size="small" placeholder="燃油、战争附加费这类" />
</div>
</div>
<div class="field">
<span class="label">计费基数</span>
<div class="control">
<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>
<div class="field">
<span class="label">生效日期</span>
<div class="control">
<el-date-picker v-model="row.periodStart" type="date" value-format="YYYY-MM-DD" placeholder="开始日期" size="small" clearable />
<span class="sep">至</span>
<el-date-picker v-model="row.periodEnd" type="date" value-format="YYYY-MM-DD" placeholder="结束日期" size="small" clearable />
</div>
</div>
<div class="field">
<span class="label">说明</span>
<div class="control">
<el-input v-model="row.remark" size="small" placeholder="例如每年 11、12 月固定收取" />
</div>
</div>
</div>
<div v-else class="rule-grid">
<div class="field">
<span class="label">退回方式</span>
<div class="control">
<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>
<div class="field">
<span class="label">重量 kg</span>
<div class="control">
<el-input v-model="row.weightMin" size="small" placeholder="下限" />
<span class="sep">至</span>
<el-input v-model="row.weightMax" size="small" placeholder="上限" />
</div>
</div>
<div class="field">
<span class="label">尺寸命中</span>
<div class="control">
<el-select v-model="row.matchMode" size="small" clearable placeholder="退件还看尺寸时选择">
<el-option label="任一命中" value="ANY" />
<el-option label="全部命中" value="ALL" />
</el-select>
</div>
</div>
<div class="field">
<span class="label">最长边 cm</span>
<div class="control">
<el-input v-model="row.longestMin" size="small" placeholder="下限" />
<span class="sep">至</span>
<el-input v-model="row.longestMax" size="small" placeholder="上限" />
</div>
</div>
<div class="field">
<span class="label">围长 cm</span>
<div class="control">
<el-input v-model="row.girthMin" size="small" placeholder="下限" />
<span class="sep">至</span>
<el-input v-model="row.girthMax" size="small" placeholder="上限" />
</div>
</div>
<div class="field">
<span class="label">三边之和 cm</span>
<div class="control">
<el-input v-model="row.sumMin" size="small" placeholder="下限" />
<span class="sep">至</span>
<el-input v-model="row.sumMax" size="small" placeholder="上限" />
</div>
</div>
<div class="field">
<span class="label">说明</span>
<div class="control">
<el-input v-model="row.remark" size="small" placeholder="例如拒收、地址错误退回" />
</div>
</div>
</div>
</div>
</div>
</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 { getPay, listPay, listPaySurchargeRule, 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: '命中邮编',
hint: '按附加费里的高、中、低区填写邮编前缀。订单邮编命中这一区,才加这一区的附加费。前缀、完整邮编和区间都认。国家不填则不限目的国。'
},
{
value: 'ZONE',
label: '命中分区',
hint: '写法和命中邮编一样,表示这些邮编属于哪个地区。命中后按该地区的附加费收取。运费用的地区仍按应付邮编配置。'
},
{
value: 'ALWAYS',
label: '每票都收',
hint: '每一条都要选费用项,没被选中的费用不会按每票收取。燃油、去碳按比例填写比例和基数,旺季再填生效日期。'
},
{
value: 'RETURN',
label: '退件',
hint: '同正向运费、空运或陆运分开配。超尺寸或超重才退件的,把重量和最长边、围长写在同一条。'
}
]
const visible = ref(false)
const saving = ref(false)
const searching = ref(false)
const keyword = ref('')
const found = ref([])
const products = ref([])
const feeOptions = ref([])
const feeCounts = ref({})
const zoneOptions = 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 === 'POSTCODE' || rule === 'ZONE') {
return { zoneName: '', postcodes: '', country: '' }
}
if (rule === 'ALWAYS') {
return { feeName: '', scId: '', 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 = []
feeOptions.value = []
feeCounts.value = {}
zoneOptions.value = []
blankGroups()
saving.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)
}
function versionOf(row) {
return {
key: String(row.productId),
productId: row.productId,
feeProductId: row.versionProductId || row.productId,
productName: row.productName || '未命名产品'
}
}
function addProduct(row, skipped) {
const item = versionOf(row)
if (!item.productId) {
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)
loadFees()
}
function removeProduct(item) {
products.value = products.value.filter(product => product.key !== item.key)
loadFees()
}
let feeToken = 0
function loadFees() {
const token = ++feeToken
const bound = products.value.slice()
if (!bound.length) {
feeOptions.value = []
feeCounts.value = {}
zoneOptions.value = keepZones([])
return Promise.resolve()
}
return Promise.all(bound.map(item => getPay(item.feeProductId || item.productId).catch(() => null))).then(results => {
if (token !== feeToken) return
const map = new Map()
const counts = {}
const zones = new Set()
results.forEach(res => {
const local = {}
const rows = res?.data?.surcharges || []
rows.forEach(fee => {
const name = String(fee.feeName || '').trim()
const zone = String(fee.zoneName || '').trim()
if (zone) zones.add(zone)
if (!name) return
local[name] = (local[name] || 0) + 1
if (!map.has(name)) map.set(name, { feeName: name, scId: fee.scId || '' })
})
Object.keys(local).forEach(name => {
counts[name] = Math.max(counts[name] || 0, local[name])
})
})
zoneOptions.value = keepZones([...zones])
feeCounts.value = counts
for (const row of groups.ALWAYS || []) {
const name = String(row.feeName || '').trim()
if (name && !map.has(name)) map.set(name, { feeName: name, scId: row.scId || '' })
}
feeOptions.value = [...map.values()]
})
}
function keepZones(zones) {
const set = new Set(zones)
for (const rule of ['POSTCODE', 'ZONE']) {
for (const row of groups[rule] || []) {
const zone = String(row.zoneName || '').trim()
if (zone) set.add(zone)
}
}
return [...set]
}
function pickFee(row, name) {
const found = feeOptions.value.find(item => item.feeName === name)
row.scId = found?.scId || ''
}
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) return
row[key] = key === 'periodStart' || key === 'periodEnd' ? asDate(detail[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))
}
const map = new Map(feeOptions.value.map(item => [item.feeName, item]))
for (const row of groups.ALWAYS || []) {
const name = String(row.feeName || '').trim()
if (name && !map.has(name)) map.set(name, { feeName: name, scId: row.scId || '' })
}
feeOptions.value = [...map.values()]
zoneOptions.value = keepZones(zoneOptions.value)
}
function asDate(value) {
const text = String(value).trim()
if (/^\d{4}-\d{2}-\d{2}/.test(text)) return text.slice(0, 10)
const monthDay = text.match(/^(\d{1,2})-(\d{1,2})$/)
if (!monthDay) return ''
const year = new Date().getFullYear()
return `${year}-${monthDay[1].padStart(2, '0')}-${monthDay[2].padStart(2, '0')}`
}
function loadRules(productId) {
listPaySurchargeRule(productId).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 save() {
if (!products.value.length) {
proxy.$modal.msgError('请选择要绑定的产品')
return
}
for (const rule of ['POSTCODE', 'ZONE']) {
if (!enabled[rule]) continue
const label = rule === 'POSTCODE' ? '命中邮编' : '命中分区'
for (const row of groups[rule]) {
if (!String(row.zoneName || '').trim() || !String(row.postcodes || '').trim()) {
proxy.$modal.msgError(label + '要选择分区,并填写邮编前缀')
return
}
}
}
if (enabled.ALWAYS) {
for (const row of groups.ALWAYS) {
if (!String(row.feeName || '').trim()) {
proxy.$modal.msgError('每票都收要选择费用项')
return
}
}
}
saving.value = true
loadFees().then(() => {
const duplicated = sameTypeFees()
if (duplicated.length) {
proxy.$modal.alert('存在两笔同类型的附加费:' + duplicated.join('、'))
return
}
return savePaySurchargeRule({
products: products.value.map(item => ({
productId: item.productId,
productName: item.productName
})),
rules: payloadRules()
}).then(() => {
proxy.$modal.msgSuccess('已保存,计算时按当前生效版本上的附加费执行')
visible.value = false
})
}).finally(() => {
saving.value = false
})
}
function sameTypeFees() {
if (!enabled.ALWAYS) return []
const seen = new Set()
const duplicated = []
for (const row of groups.ALWAYS) {
const name = String(row.feeName || '').trim()
if (!name) continue
if (seen.has(name) || Number(feeCounts.value[name] || 0) >= 2) duplicated.push(name)
seen.add(name)
}
return [...new Set(duplicated)]
}
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: 12px 20px 12px 28px; margin-bottom: 10px; overflow: visible; }
.rule-grid { display: grid; grid-template-columns: 1fr 1fr; column-gap: 48px; row-gap: 12px; align-items: center; }
.field { display: grid; grid-template-columns: 104px minmax(0, 1fr); column-gap: 8px; align-items: center; min-width: 0; }
.field .label { width: 104px; min-width: 0; justify-self: end; text-align: right; white-space: nowrap; overflow: visible; font-size: 13px; line-height: 24px; color: var(--el-text-color-regular); }
.control { display: flex; align-items: center; gap: 6px; min-width: 0; }
.control :deep(.el-input),
.control :deep(.el-select),
.control :deep(.el-textarea),
.control :deep(.el-date-editor) { flex: 1 1 0; width: 0 !important; min-width: 0; max-width: none; }
.control :deep(.mode) { flex: 1.7 1 0; }
.control :deep(.num) { flex: 0.75 1 0; }
.field .sep { flex: none; color: var(--el-text-color-secondary); line-height: 24px; }
</style>