新增按国家去重区块标题接口,优化计费列表请求方式

This commit is contained in:
wuweihua
2026-11-12 13:45:09 +08:00
parent d2c75e0c51
commit cf336f7a67
22 changed files with 436 additions and 99 deletions
@@ -1,5 +1,5 @@
<template>
<el-dialog :title="title" v-model="visible" width="640px" append-to-body>
<el-dialog :title="title" v-model="visible" width="720px" append-to-body>
<basic-form ref="formRef" v-model="form" :schemas="schemas" label-width="100px" />
<template #footer>
<el-button type="primary" @click="submitForm">确 定</el-button>
@@ -10,101 +10,148 @@
<script setup>
import BasicForm from '@/components/BasicForm'
import { getSurcharge, addSurcharge, updateSurcharge } from '@/api/price/surcharge'
import { getSurcharge, addSurcharge, updateSurcharge, listSurchargeBlockOptions } from '@/api/price/surcharge'
import { listRegionOptions } from '@/api/data/region'
const emit = defineEmits(['success'])
const { proxy } = getCurrentInstance()
const { payment_product_type } = useDict('payment_product_type')
const formRef = ref()
const visible = ref(false)
const title = ref('')
const form = ref(emptyForm())
const regionOptions = ref([])
const blockOptions = ref([])
const loadingBlocks = ref(false)
const suppressCountryWatch = ref(false)
const calcModeOptions = [
{ value: 'MANUAL', label: '暂不计费' },
{ value: 'ALWAYS', label: '每票都收' },
{ value: 'POSTCODE', label: '命中邮编' },
{ value: 'ZONE', label: '命中分区' },
{ value: 'EXTRA_KG', label: '超重续收' },
{ value: 'WEIGHT', label: '超重' },
{ value: 'SIZE', label: '超尺寸' },
{ value: 'RETURN', label: '退件' }
]
const countrySelectOptions = computed(() => {
const all = [{ label: "全部国家", value: '' }]
const all = [{ label: '全部国家', value: '' }]
return all.concat((regionOptions.value || []).map(r => ({
label: regionLabel(r),
value: r.countryCode2
})))
})
const channelProductOptions = computed(() =>
(payment_product_type.value || []).map(item => ({
label: item.label,
value: item.value
}))
)
const blockSelectOptions = computed(() =>
(blockOptions.value || []).map(title => ({ label: title, value: title }))
)
const schemas = computed(() => [
{
label: "附加费名称",
label: '附加费名称',
prop: 'scName',
component: 'input',
placeholder: "如 燃油附加费",
placeholder: '如 燃油附加费',
span: 12,
width: '100%',
props: { maxlength: 100 },
rules: [{ required: true, message: "附加费名称不能为空", trigger: 'blur' }]
rules: [{ required: true, message: '附加费名称不能为空', trigger: 'blur' }]
},
{
label: "费用类型",
label: '费用类型',
prop: 'feeType',
component: 'select',
placeholder: "请选择",
placeholder: '请选择',
dict: 'bms_fee_type',
span: 12,
width: '100%',
disabled: true,
rules: [{ required: true, message: "请选择费用类型", trigger: 'change' }]
rules: [{ required: true, message: '请选择费用类型', trigger: 'change' }]
},
{
label: "计费方式",
label: '计费方式',
prop: 'chargeType',
component: 'select',
placeholder: "请选择",
dict: 'bms_charge_type',
placeholder: '请选择',
options: calcModeOptions,
span: 12,
width: '100%',
rules: [{ required: true, message: "请选择计费方式", trigger: 'change' }]
rules: [{ required: true, message: '请选择计费方式', trigger: 'change' }]
},
{
label: "计费数值",
label: '渠道产品',
prop: 'dictValue',
component: 'select',
placeholder: '请选择渠道产品',
options: channelProductOptions.value,
span: 12,
width: '100%',
props: { filterable: true, clearable: true }
},
{
label: '计费数值',
prop: 'chargeValue',
component: 'inputNumber',
span: 12,
width: '100%',
props: { min: 0, precision: 6, step: 1, controlsPosition: 'right' },
rules: [{ required: true, message: "计费数值不能为空", trigger: 'blur' }]
rules: [{ required: true, message: '计费数值不能为空', trigger: 'blur' }]
},
{
label: "币种",
label: '币种',
prop: 'currency',
component: 'select',
placeholder: "请选择",
placeholder: '请选择',
dict: 'bms_currency',
span: 12,
width: '100%'
},
{
label: "取值方式",
label: '取值方式',
prop: 'roundMode',
component: 'select',
placeholder: "请选择",
placeholder: '请选择',
dict: 'bms_round_mode',
span: 12,
width: '100%',
rules: [{ required: true, message: "请选择取值方式", trigger: 'change' }]
rules: [{ required: true, message: '请选择取值方式', trigger: 'change' }]
},
{
label: "适用国家",
label: '适用国家',
prop: 'countryCode',
component: 'select',
placeholder: "全部国家",
placeholder: '全部国家',
options: countrySelectOptions.value,
span: 12,
width: '100%',
props: { filterable: true, clearable: true }
},
{
label: "备注",
label: '分区',
prop: 'blockTitle',
component: 'select',
placeholder: form.value.countryCode ? (loadingBlocks.value ? '加载中...' : '请选择分区/区块') : '请先选择国家',
options: blockSelectOptions.value,
span: 12,
width: '100%',
disabled: !form.value.countryCode || loadingBlocks.value,
props: { filterable: true, clearable: true }
},
{
label: '备注',
prop: 'scNote',
component: 'textarea',
placeholder: "请输入备注",
placeholder: '请输入备注',
span: 24,
width: '100%',
props: { rows: 2, maxlength: 500 }
@@ -116,11 +163,13 @@ function emptyForm() {
scId: undefined,
scName: undefined,
feeType: 'SURCHARGE',
chargeType: 'FIXED',
dictValue: undefined,
chargeType: 'MANUAL',
chargeValue: 0,
currency: 'CNY',
roundMode: 'HALF_UP',
countryCode: undefined,
blockTitle: undefined,
scNote: undefined
}
}
@@ -137,25 +186,64 @@ function ensureRegions() {
})
}
function resolveCountryName(code) {
if (!code) return ''
const region = (regionOptions.value || []).find(item => item.countryCode2 === code)
return region?.countryNameCn || region?.countryNameEn || ''
}
function loadBlockOptions(code, keepCurrent) {
if (!code) {
blockOptions.value = []
if (!keepCurrent) form.value.blockTitle = undefined
return Promise.resolve()
}
loadingBlocks.value = true
const countryName = resolveCountryName(code)
return listSurchargeBlockOptions({ countryCode: code, countryName: countryName || undefined })
.then(res => {
const list = (res.data || []).filter(Boolean)
blockOptions.value = list
if (!keepCurrent) {
form.value.blockTitle = undefined
} else if (form.value.blockTitle && !list.includes(form.value.blockTitle)) {
// keep current title even if not in options (legacy)
blockOptions.value = [form.value.blockTitle].concat(list)
}
})
.catch(() => {
blockOptions.value = []
})
.finally(() => {
loadingBlocks.value = false
})
}
function reset() {
form.value = emptyForm()
blockOptions.value = []
nextTick(() => formRef.value?.clearValidate())
}
function open(row) {
reset()
ensureRegions()
if (!row) {
title.value = "新建附加费"
visible.value = true
return
}
getSurcharge(row.scId).then(res => {
const data = res.data || {}
form.value = { ...emptyForm(), ...data }
title.value = "修改附加费"
visible.value = true
nextTick(() => formRef.value?.clearValidate())
ensureRegions().then(() => {
if (!row) {
title.value = '新建附加费'
visible.value = true
return
}
getSurcharge(row.scId).then(res => {
const data = res.data || {}
suppressCountryWatch.value = true
form.value = { ...emptyForm(), ...data }
title.value = '修改附加费'
visible.value = true
loadBlockOptions(form.value.countryCode, true).finally(() => {
suppressCountryWatch.value = false
nextTick(() => formRef.value?.clearValidate())
})
})
})
}
@@ -164,17 +252,26 @@ function submitForm() {
if (!valid) return
const payload = { ...form.value }
if (!payload.countryCode) payload.countryCode = undefined
if (!payload.dictValue) payload.dictValue = undefined
if (!payload.blockTitle) payload.blockTitle = undefined
if (!payload.chargeType) payload.chargeType = 'MANUAL'
if (payload.chargeValue != null) payload.chargeValue = Number(payload.chargeValue)
const req = payload.scId != null ? updateSurcharge(payload) : addSurcharge(payload)
req.then(() => {
proxy.$modal.msgSuccess(payload.scId != null ? "修改成功" : "新增成功")
proxy.$modal.msgSuccess(payload.scId != null ? '修改成功' : '新增成功')
visible.value = false
emit('success')
}).catch(() => {
// 后端返回 warn(601「未做任何修改」) 时由全局拦截器弹提示,此处吞掉 reject
// backend warn(601) handled globally
})
})
}
watch(() => form.value.countryCode, (code, prev) => {
if (suppressCountryWatch.value) return
if (code === prev) return
loadBlockOptions(code, false)
})
defineExpose({ open })
</script>