307 lines
11 KiB
Vue
307 lines
11 KiB
Vue
<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 label="计费条件" width="110">
|
|
<template #default="{ row }">
|
|
<el-select v-model="row.calcRule" clearable size="small" placeholder="不限">
|
|
<el-option label="邮编" value="POSTCODE" />
|
|
<el-option label="尺寸" value="SIZE" />
|
|
<el-option label="重量" value="WEIGHT" />
|
|
</el-select>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column label="条件参数" min-width="160">
|
|
<template #default="{ row }"><el-input v-model="row.calcParam" size="small" placeholder="07 / side:80 / 30" /></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: '', calcRule: '', calcParam: '', 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,
|
|
calcRule: row.calcRule,
|
|
calcParam: row.calcParam,
|
|
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,
|
|
calcRule: row.calcRule,
|
|
calcParam: row.calcParam,
|
|
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>
|