套餐加分区功能
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
:closable="false"
|
||||
show-icon
|
||||
class="mb12"
|
||||
title="FIXED 模式:可不填明细(计费取 bms_product_country 默认运费/挂号费);有明细时按产品×国家×重量段覆盖固定价。附加费来自产品关联,只读展示。"
|
||||
title="FIXED 模式:可不填明细(计费取 bms_product_country 默认运费/挂号费);有明细时按产品×国家×分区×重量段覆盖固定价。附加费来自产品关联,只读展示。"
|
||||
/>
|
||||
<el-alert
|
||||
v-else
|
||||
@@ -64,6 +64,29 @@
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column v-if="isFixedType(setType)" label="分区" min-width="140">
|
||||
<template #default="{ row }">
|
||||
<el-select
|
||||
v-if="refData.hasZonesOf(row)"
|
||||
v-model="row.zoneCode"
|
||||
filterable
|
||||
clearable
|
||||
placeholder="选择分区"
|
||||
style="width: 100%"
|
||||
:disabled="!row._countryKey"
|
||||
@change="onZoneChange(row)"
|
||||
>
|
||||
<el-option
|
||||
v-for="z in refData.zoneOptionsOf(row)"
|
||||
:key="z.key"
|
||||
:label="z.label"
|
||||
:value="z.zoneCode"
|
||||
/>
|
||||
</el-select>
|
||||
<span v-else class="muted">-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column v-if="isFixedType(setType)" label="重量段" min-width="150">
|
||||
<template #default="{ row }">
|
||||
<el-select
|
||||
@@ -72,7 +95,7 @@
|
||||
clearable
|
||||
placeholder="选择重量段"
|
||||
style="width: 100%"
|
||||
:disabled="!row._countryKey"
|
||||
:disabled="!row._countryKey || (refData.hasZonesOf(row) && !row.zoneCode)"
|
||||
@change="onWeightChange(row)"
|
||||
>
|
||||
<el-option
|
||||
@@ -158,7 +181,7 @@ const { bms_round_mode } = useDict('bms_round_mode')
|
||||
|
||||
/** 参考数据来自父页面,缓存与请求去重全页面共享 */
|
||||
const { productOptions, surchargesOf, countryOptionsOf, weightOptionsOf } = props.refData
|
||||
const { onProductChange, onCountryChange, onWeightChange } = useDetailCascade(props.refData)
|
||||
const { onProductChange, onCountryChange, onZoneChange, onWeightChange } = useDetailCascade(props.refData)
|
||||
|
||||
function addRow() {
|
||||
props.details.push(createEmptyDetailRow())
|
||||
|
||||
@@ -37,6 +37,21 @@
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col v-if="hasZones" :span="12">
|
||||
<el-form-item label="分区" prop="zoneCode">
|
||||
<el-select
|
||||
v-model="form.zoneCode"
|
||||
filterable
|
||||
clearable
|
||||
placeholder="选择分区"
|
||||
style="width: 100%"
|
||||
:disabled="!form._countryKey"
|
||||
@change="onZoneChange(form)"
|
||||
>
|
||||
<el-option v-for="z in zoneOptions" :key="z.key" :label="z.label" :value="z.zoneCode" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="重量段" prop="weightLabel">
|
||||
<el-select
|
||||
@@ -45,7 +60,7 @@
|
||||
clearable
|
||||
placeholder="选择重量段"
|
||||
style="width: 100%"
|
||||
:disabled="!form._countryKey"
|
||||
:disabled="!form._countryKey || (hasZones && !form.zoneCode)"
|
||||
@change="onWeightChange(form)"
|
||||
>
|
||||
<el-option v-for="w in weightOptions" :key="w.value" :label="w.label" :value="w.value" />
|
||||
@@ -173,8 +188,8 @@ const emit = defineEmits(['success'])
|
||||
const { proxy } = getCurrentInstance()
|
||||
const { bms_round_mode } = useDict('bms_round_mode')
|
||||
|
||||
const { productOptions, surchargesOf, countryOptionsOf, weightOptionsOf } = props.refData
|
||||
const { onProductChange, onCountryChange, onWeightChange } = useDetailCascade(props.refData)
|
||||
const { productOptions, surchargesOf, countryOptionsOf, zoneOptionsOf, hasZonesOf, weightOptionsOf } = props.refData
|
||||
const { onProductChange, onCountryChange, onZoneChange, onWeightChange } = useDetailCascade(props.refData)
|
||||
|
||||
const visible = ref(false)
|
||||
const title = ref('')
|
||||
@@ -189,6 +204,8 @@ const rules = {
|
||||
|
||||
const surcharges = computed(() => surchargesOf(form.value))
|
||||
const countryOptions = computed(() => countryOptionsOf(form.value))
|
||||
const zoneOptions = computed(() => zoneOptionsOf(form.value))
|
||||
const hasZones = computed(() => hasZonesOf(form.value))
|
||||
const weightOptions = computed(() => weightOptionsOf(form.value))
|
||||
|
||||
/** 打开弹窗:row 为空表示新增 */
|
||||
|
||||
@@ -30,6 +30,9 @@
|
||||
<el-table-column label="国家" min-width="130">
|
||||
<template #default="{ row }">{{ row.countryName || row.countryCode || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="分区" min-width="120">
|
||||
<template #default="{ row }">{{ row.zoneName || row.zoneCode || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="重量段" prop="weightLabel" min-width="130" />
|
||||
<el-table-column label="运费单价" min-width="130" align="right">
|
||||
<template #default="{ row }">
|
||||
@@ -119,7 +122,7 @@ const details = computed(() => props.set.details || [])
|
||||
const editable = computed(() => isChildEditable(props.set.status))
|
||||
|
||||
const subTitle = computed(() => isFixedType(props.set.setType)
|
||||
? '按 产品 × 国家 × 重量段 覆盖固定价'
|
||||
? '按 产品 × 国家 × 分区 × 重量段 覆盖固定价'
|
||||
: '按产品限定折扣,留空走套餐默认折扣')
|
||||
|
||||
const hint = computed(() => isFixedType(props.set.setType)
|
||||
|
||||
@@ -8,10 +8,12 @@ import { listProduct, listProductCountries } from '@/api/price/product'
|
||||
import { listSurchargeByProduct } from '@/api/price/surcharge'
|
||||
import {
|
||||
buildCountryOptions,
|
||||
buildZoneOptions,
|
||||
buildWeightOptions,
|
||||
countryHasZones,
|
||||
countryKeyOf,
|
||||
formatWeightLabel,
|
||||
matchCountry,
|
||||
matchCountryZone,
|
||||
toEditableDetailRow
|
||||
} from '../utils/priceSet'
|
||||
|
||||
@@ -96,6 +98,14 @@ export function usePriceSetRefData() {
|
||||
return buildCountryOptions(countryCache[row?.productCode] || [])
|
||||
}
|
||||
|
||||
function zoneOptionsOf(row) {
|
||||
return buildZoneOptions(countryCache[row?.productCode] || [], row || {})
|
||||
}
|
||||
|
||||
function hasZonesOf(row) {
|
||||
return countryHasZones(countryCache[row?.productCode] || [], row || {})
|
||||
}
|
||||
|
||||
/** 明细行可选重量段 */
|
||||
function weightOptionsOf(row) {
|
||||
return buildWeightOptions(countryCache[row?.productCode] || [], row || {})
|
||||
@@ -109,12 +119,14 @@ export function usePriceSetRefData() {
|
||||
ensureSurcharges,
|
||||
surchargesOf,
|
||||
countryOptionsOf,
|
||||
zoneOptionsOf,
|
||||
hasZonesOf,
|
||||
weightOptionsOf
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 明细行级联:产品 → 国家 → 重量段,并带出默认运费 / 挂号费
|
||||
* 明细行级联:产品 → 国家 → 分区 → 重量段,并带出默认运费 / 挂号费
|
||||
*
|
||||
* @param {Object} refData usePriceSetRefData() 的返回值(页面内共享同一份)
|
||||
*/
|
||||
@@ -124,6 +136,9 @@ export function useDetailCascade(refData) {
|
||||
row.countryCode = undefined
|
||||
row.countryName = undefined
|
||||
row._countryKey = undefined
|
||||
row.zoneId = undefined
|
||||
row.zoneCode = undefined
|
||||
row.zoneName = undefined
|
||||
row.weightLabel = undefined
|
||||
row.productCountryId = undefined
|
||||
row.fvValue = undefined
|
||||
@@ -144,6 +159,20 @@ export function useDetailCascade(refData) {
|
||||
const opt = refData.countryOptionsOf(row).find(c => c.key === row._countryKey)
|
||||
row.countryCode = opt ? opt.code : undefined
|
||||
row.countryName = opt ? opt.name : undefined
|
||||
row.zoneId = undefined
|
||||
row.zoneCode = undefined
|
||||
row.zoneName = undefined
|
||||
row.weightLabel = undefined
|
||||
row.productCountryId = undefined
|
||||
row.fvValue = undefined
|
||||
row.fvRegistrationFee = undefined
|
||||
}
|
||||
|
||||
function onZoneChange(row) {
|
||||
const opt = refData.zoneOptionsOf(row).find(z => z.key === row.zoneCode)
|
||||
row.zoneId = opt ? opt.zoneId : undefined
|
||||
row.zoneCode = opt ? opt.zoneCode : undefined
|
||||
row.zoneName = opt ? opt.zoneName : undefined
|
||||
row.weightLabel = undefined
|
||||
row.productCountryId = undefined
|
||||
row.fvValue = undefined
|
||||
@@ -158,6 +187,9 @@ export function useDetailCascade(refData) {
|
||||
return
|
||||
}
|
||||
row.productCountryId = opt.detailId
|
||||
if (opt.zoneId != null) row.zoneId = opt.zoneId
|
||||
if (opt.zoneCode) row.zoneCode = opt.zoneCode
|
||||
if (opt.zoneName) row.zoneName = opt.zoneName
|
||||
if (opt.freightPrice != null) row.fvValue = Number(opt.freightPrice)
|
||||
if (opt.registrationFee != null) row.fvRegistrationFee = Number(opt.registrationFee)
|
||||
}
|
||||
@@ -171,7 +203,8 @@ export function useDetailCascade(refData) {
|
||||
refData.ensureCountries(row.productCode).then(rows => {
|
||||
if (!row.weightLabel) return
|
||||
const hit = rows.find(item => {
|
||||
if (!matchCountry(row, item)) return false
|
||||
if (row.productCountryId != null && Number(item.detailId) === Number(row.productCountryId)) return true
|
||||
if (!matchCountryZone(row, item)) return false
|
||||
return formatWeightLabel(item.weightMin, item.weightMax) === row.weightLabel
|
||||
|| (row.weightLabel.includes(String(item.weightMin)) && row.weightLabel.includes(String(item.weightMax)))
|
||||
})
|
||||
@@ -181,9 +214,12 @@ export function useDetailCascade(refData) {
|
||||
row.productCountryId = hit.detailId
|
||||
if (!row.countryCode) row.countryCode = hit.countryCode
|
||||
if (!row.countryName) row.countryName = hit.countryName
|
||||
if (hit.zoneId != null) row.zoneId = hit.zoneId
|
||||
if (hit.zoneCode) row.zoneCode = hit.zoneCode
|
||||
if (hit.zoneName) row.zoneName = hit.zoneName
|
||||
})
|
||||
return row
|
||||
}
|
||||
|
||||
return { resetRow, onProductChange, onCountryChange, onWeightChange, hydrateRow }
|
||||
return { resetRow, onProductChange, onCountryChange, onZoneChange, onWeightChange, hydrateRow }
|
||||
}
|
||||
|
||||
@@ -115,6 +115,22 @@ export function matchCountry(detail, item) {
|
||||
return !!detail.countryName && item.countryName === detail.countryName
|
||||
}
|
||||
|
||||
/** detail row zone vs product-country row */
|
||||
export function matchZone(detail, item) {
|
||||
const detailHas = !!(detail.zoneCode || detail.zoneId)
|
||||
const itemHas = !!(item.zoneCode || item.zoneId)
|
||||
if (!detailHas && !itemHas) return true
|
||||
if (detailHas !== itemHas) return false
|
||||
if (detail.zoneId != null && item.zoneId != null) return Number(detail.zoneId) === Number(item.zoneId)
|
||||
if (detail.zoneCode && item.zoneCode) return String(detail.zoneCode) === String(item.zoneCode)
|
||||
return false
|
||||
}
|
||||
|
||||
/** country + zone match */
|
||||
export function matchCountryZone(detail, item) {
|
||||
return matchCountry(detail, item) && matchZone(detail, item)
|
||||
}
|
||||
|
||||
/**
|
||||
* 国家下拉选项(按产品的国家配置去重)
|
||||
* @param {Array} rows bms_product_country 行
|
||||
@@ -141,9 +157,39 @@ export function buildCountryOptions(rows) {
|
||||
* @param {Object} row 当前明细行(含国家)
|
||||
* @returns {Array<{value, label, detailId, freightPrice, registrationFee}>}
|
||||
*/
|
||||
export function buildWeightOptions(rows, row) {
|
||||
/**
|
||||
* Zone options for selected country (from product-country rows).
|
||||
* @returns {Array<{key, zoneId, zoneCode, zoneName, label}>}
|
||||
*/
|
||||
export function buildZoneOptions(rows, row) {
|
||||
const map = new Map()
|
||||
;(rows || []).filter(item => matchCountry(row, item)).forEach(item => {
|
||||
if (!item.zoneCode && item.zoneId == null) return
|
||||
const key = item.zoneCode || String(item.zoneId)
|
||||
if (map.has(key)) return
|
||||
map.set(key, {
|
||||
key,
|
||||
zoneId: item.zoneId,
|
||||
zoneCode: item.zoneCode || undefined,
|
||||
zoneName: item.zoneName || undefined,
|
||||
label: item.zoneName || item.zoneCode || key
|
||||
})
|
||||
})
|
||||
return [...map.values()]
|
||||
}
|
||||
|
||||
/** Whether selected country has any zone rows */
|
||||
export function countryHasZones(rows, row) {
|
||||
return buildZoneOptions(rows, row).length > 0
|
||||
}
|
||||
|
||||
export function buildWeightOptions(rows, row) {
|
||||
const list = rows || []
|
||||
if (countryHasZones(list, row) && !(row && (row.zoneCode || row.zoneId))) {
|
||||
return []
|
||||
}
|
||||
const map = new Map()
|
||||
list.filter(item => matchCountryZone(row, item)).forEach(item => {
|
||||
if (item.weightMin == null && item.weightMax == null) return
|
||||
const value = formatWeightLabel(item.weightMin, item.weightMax)
|
||||
if (map.has(value)) return
|
||||
@@ -151,6 +197,9 @@ export function buildWeightOptions(rows, row) {
|
||||
value,
|
||||
label: value,
|
||||
detailId: item.detailId,
|
||||
zoneId: item.zoneId,
|
||||
zoneCode: item.zoneCode,
|
||||
zoneName: item.zoneName,
|
||||
freightPrice: item.freightPrice,
|
||||
registrationFee: item.registrationFee
|
||||
})
|
||||
@@ -186,6 +235,9 @@ export function createEmptyDetailRow() {
|
||||
countryCode: undefined,
|
||||
countryName: undefined,
|
||||
_countryKey: undefined,
|
||||
zoneId: undefined,
|
||||
zoneCode: undefined,
|
||||
zoneName: undefined,
|
||||
weightLabel: undefined,
|
||||
productCountryId: undefined,
|
||||
fvValue: undefined,
|
||||
@@ -235,6 +287,9 @@ export function toDetailPayload(d) {
|
||||
productName: d.productName,
|
||||
countryCode: d.countryCode || undefined,
|
||||
countryName: d.countryName || undefined,
|
||||
zoneId: d.zoneId || undefined,
|
||||
zoneCode: d.zoneCode || undefined,
|
||||
zoneName: d.zoneName || undefined,
|
||||
weightLabel: d.weightLabel || undefined,
|
||||
productCountryId: d.productCountryId || undefined,
|
||||
fvValue: d.fvValue,
|
||||
|
||||
Reference in New Issue
Block a user