套餐加分区功能
This commit is contained in:
@@ -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 }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user