导入新产品,20.套餐编辑的时候,不能低于基准价,低于就提示不能保存
This commit is contained in:
@@ -99,6 +99,8 @@ const props = defineProps({
|
||||
})
|
||||
const emit = defineEmits(['update:modelValue', 'pick-surcharge', 'row-change'])
|
||||
|
||||
const { proxy } = getCurrentInstance()
|
||||
|
||||
const keyword = ref('')
|
||||
const editingKey = ref('')
|
||||
const committing = ref(false)
|
||||
@@ -109,7 +111,7 @@ const title = computed(() => {
|
||||
const name = props.productName || ''
|
||||
return code + ' · ' + name + ' · 国家服务价格'
|
||||
})
|
||||
const hint = '黄色行=已改价;点编辑图标后修改,失焦即刻写入数据库。单位:运费 RMB/KG,挂号费 RMB/票。'
|
||||
const hint = '黄色行=已改价;点编辑图标后修改,失焦即刻写入数据库。单位:运费 RMB/KG,挂号费 RMB/票。不能低于导入基准价。'
|
||||
const phSearch = '搜索国家/分区'
|
||||
const colCountry = '国家'
|
||||
const colZone = '分区'
|
||||
@@ -136,6 +138,8 @@ function setEditRef(el, row, field) {
|
||||
|
||||
function startEdit(row, field) {
|
||||
if (!row) return
|
||||
row._editPrevFv = row.fvValue
|
||||
row._editPrevReg = row.fvRegistrationFee
|
||||
editingKey.value = cellKey(row, field)
|
||||
nextTick(() => {
|
||||
const el = editInputRefs[editingKey.value]
|
||||
@@ -143,13 +147,36 @@ function startEdit(row, field) {
|
||||
})
|
||||
}
|
||||
|
||||
function isBelowFloor(value, floor) {
|
||||
if (value == null || value === '' || floor == null || floor === '') return false
|
||||
const n = Number(value)
|
||||
const f = Number(floor)
|
||||
if (Number.isNaN(n) || Number.isNaN(f)) return false
|
||||
return n + 1e-8 < f
|
||||
}
|
||||
|
||||
function belowFloorMessage(field, floor) {
|
||||
const name = field === 'fv' ? '\u5957\u9910\u8fd0\u8d39' : '\u5957\u9910\u6302\u53f7\u8d39'
|
||||
const prec = field === 'fv' ? 4 : 2
|
||||
return name + '\u4e0d\u80fd\u4f4e\u4e8e\u5bfc\u5165\u57fa\u51c6\u4ef7 ' + formatNum(floor, prec)
|
||||
}
|
||||
|
||||
async function commitEdit(row, field) {
|
||||
if (committing.value) return
|
||||
if (editingKey.value !== cellKey(row, field)) return
|
||||
editingKey.value = ''
|
||||
if (!row || !row.psdId) return
|
||||
committing.value = true
|
||||
editingKey.value = ''
|
||||
try {
|
||||
if (!row) return
|
||||
const floor = field === 'fv' ? row._floorFreight : row._floorReg
|
||||
const value = field === 'fv' ? row.fvValue : row.fvRegistrationFee
|
||||
if (isBelowFloor(value, floor)) {
|
||||
if (field === 'fv') row.fvValue = row._editPrevFv
|
||||
else row.fvRegistrationFee = row._editPrevReg
|
||||
proxy.$modal.msgError(belowFloorMessage(field, floor))
|
||||
return
|
||||
}
|
||||
if (!row.psdId) return
|
||||
emit('row-change', row)
|
||||
} finally {
|
||||
committing.value = false
|
||||
|
||||
@@ -268,6 +268,8 @@ function countryToDetail(item, productCode, productName) {
|
||||
const baseReg = item.registrationFee != null ? Number(item.registrationFee) : undefined
|
||||
row._baseFreight = baseFv
|
||||
row._baseReg = baseReg
|
||||
row._floorFreight = baseFv
|
||||
row._floorReg = baseReg
|
||||
row.fvValue = baseFv
|
||||
row.fvRegistrationFee = baseReg
|
||||
row.effectiveDate = item.effectiveDate
|
||||
@@ -293,7 +295,9 @@ function openPrice(row) {
|
||||
return r
|
||||
})
|
||||
editGroup.value = row
|
||||
priceVisible.value = true
|
||||
Promise.resolve(stampPriceFloors(editRows.value, row.productCode)).finally(() => {
|
||||
priceVisible.value = true
|
||||
})
|
||||
}
|
||||
|
||||
/** 抽屉里点附加费:带行 = 行级(只改该行,国家+重量段),不带 = 产品级(覆盖全部明细行) */
|
||||
@@ -319,10 +323,45 @@ async function persistDetail(row, withSurcharge) {
|
||||
/** drawer field change -> immediate DB update */
|
||||
async function onRowPriceChange(row) {
|
||||
if (!row || !row.psdId) return
|
||||
const prevFv = row._editPrevFv
|
||||
const prevReg = row._editPrevReg
|
||||
try {
|
||||
await persistDetail(row, false)
|
||||
proxy.$modal.msgSuccess('价格已更新')
|
||||
} catch (e) {}
|
||||
} catch (e) {
|
||||
if (prevFv !== undefined) row.fvValue = prevFv
|
||||
if (prevReg !== undefined) row.fvRegistrationFee = prevReg
|
||||
}
|
||||
}
|
||||
|
||||
function applyImportedFloor(row, hit) {
|
||||
if (!row || !hit) return
|
||||
if (hit.freightPrice != null) row._floorFreight = Number(hit.freightPrice)
|
||||
if (hit.registrationFee != null) row._floorReg = Number(hit.registrationFee)
|
||||
}
|
||||
|
||||
function findImportedCountry(rows, row) {
|
||||
if (!rows || !rows.length || !row) return null
|
||||
if (row.productCountryId != null) {
|
||||
const byId = rows.find(item => Number(item.detailId) === Number(row.productCountryId))
|
||||
if (byId) return byId
|
||||
}
|
||||
return rows.find(item => {
|
||||
const sameCountry = (row.countryCode && item.countryCode
|
||||
&& String(row.countryCode).toUpperCase() === String(item.countryCode).toUpperCase())
|
||||
|| (!row.countryCode && row.countryName && item.countryName && row.countryName === item.countryName)
|
||||
if (!sameCountry) return false
|
||||
if (row.weightMin != null && item.weightMin != null && Number(row.weightMin) !== Number(item.weightMin)) return false
|
||||
if (row.weightMax != null && item.weightMax != null && Number(row.weightMax) !== Number(item.weightMax)) return false
|
||||
return row.weightMin != null || row.weightMax != null
|
||||
}) || null
|
||||
}
|
||||
|
||||
function stampPriceFloors(rows, productCode) {
|
||||
if (!props.refData || !productCode || !rows || !rows.length) return Promise.resolve()
|
||||
return props.refData.ensureCountries(productCode, props.effectiveTime).then(list => {
|
||||
rows.forEach(row => applyImportedFloor(row, findImportedCountry(list, row)))
|
||||
})
|
||||
}
|
||||
|
||||
async function saveDiscount() {
|
||||
|
||||
Reference in New Issue
Block a user