套餐加分区功能
This commit is contained in:
@@ -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