新增产品和附加费删除标记,优化版本编辑逻辑
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<div v-if="panes.length" class="label-detail">
|
||||
<section v-for="pane in panes" :key="pane.key" class="label-product">
|
||||
<el-tabs v-model="pane.tab">
|
||||
<el-tab-pane :label="`重量段(${(pane.item.weightBands || []).length})`" name="band">
|
||||
<el-tab-pane :label="bandTabLabel(pane)" name="band">
|
||||
<el-input v-model="pane.bandKeyword" clearable placeholder="筛选国家、分区、重量段、计费条件、邮编、费用项" class="label-filter" />
|
||||
<el-table
|
||||
:data="displayBands(pane)"
|
||||
@@ -503,8 +503,16 @@ watch(source, (list) => {
|
||||
}))
|
||||
}, { immediate: true })
|
||||
|
||||
function aliveRows(list) {
|
||||
return (list || []).filter(row => row && row.deleted !== true)
|
||||
}
|
||||
|
||||
function bandTabLabel(pane) {
|
||||
return '重量段(' + aliveRows(pane?.item?.weightBands).length + ')'
|
||||
}
|
||||
|
||||
function filteredBands(pane) {
|
||||
return filterRows(pane.item.weightBands || [], pane.bandKeyword, ['countryName', 'countryCode', 'zoneCode', 'zoneName', 'postcodeParam', 'weightLabel', 'feeType', 'chargeMode', 'chargeName', 'calcParam', 'priceUnit', 'extraPriceUnit'])
|
||||
return filterRows(aliveRows(pane.item.weightBands), pane.bandKeyword, ['countryName', 'countryCode', 'zoneCode', 'zoneName', 'postcodeParam', 'weightLabel', 'feeType', 'chargeMode', 'chargeName', 'calcParam', 'priceUnit', 'extraPriceUnit'])
|
||||
}
|
||||
|
||||
const FEE_TYPE_ORDER = { FREIGHT: 1, REGISTRATION: 2, REMOTE: 3 }
|
||||
@@ -527,7 +535,7 @@ function feeTypeOrder(row) {
|
||||
}
|
||||
|
||||
function bandViewSignature(pane) {
|
||||
const bands = pane?.item?.weightBands || []
|
||||
const bands = aliveRows(pane?.item?.weightBands)
|
||||
const keyword = pane?.bandKeyword || ''
|
||||
let hash = bands.length + ':' + keyword
|
||||
for (let i = 0; i < bands.length; i++) {
|
||||
@@ -611,16 +619,15 @@ function invalidateBandView(pane) {
|
||||
}
|
||||
|
||||
function filteredFees(pane) {
|
||||
return filterRows(pane.item.surcharges || [], pane.feeKeyword, ['feeName', 'amount', 'currency', 'priceUnit', 'feeDesc', 'calcRule', 'calcParam'])
|
||||
return filterRows(aliveRows(pane.item.surcharges), pane.feeKeyword, ['feeName', 'amount', 'currency', 'priceUnit', 'feeDesc', 'calcRule', 'calcParam'])
|
||||
}
|
||||
|
||||
function feeTabLabel(pane) {
|
||||
const fees = pane.item.surcharges || []
|
||||
return '附加费(' + fees.length + ')'
|
||||
return '附加费(' + aliveRows(pane?.item?.surcharges).length + ')'
|
||||
}
|
||||
|
||||
function feeCheckedCount(pane) {
|
||||
return (pane?.item?.surcharges || []).filter(fee => fee && fee._checked === true).length
|
||||
return aliveRows(pane?.item?.surcharges).filter(fee => fee && fee._checked === true).length
|
||||
}
|
||||
|
||||
function isAllFilteredFeesChecked(pane) {
|
||||
@@ -644,7 +651,7 @@ function setFilteredFeesChecked(pane, value) {
|
||||
async function removeCheckedFees(pane) {
|
||||
const list = pane?.item?.surcharges
|
||||
if (!list?.length) return
|
||||
const checked = list.filter(fee => fee && fee._checked === true)
|
||||
const checked = aliveRows(list).filter(fee => fee && fee._checked === true)
|
||||
if (!checked.length) {
|
||||
proxy.$modal.msgWarning('请先勾选要删除的附加费')
|
||||
return
|
||||
@@ -654,10 +661,18 @@ async function removeCheckedFees(pane) {
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
const remain = list.filter(fee => !(fee && fee._checked === true))
|
||||
pane.item.surcharges = remain
|
||||
const maxPage = Math.max(1, Math.ceil(remain.length / pageSize) || 1)
|
||||
for (const fee of checked) {
|
||||
if (fee.surchargeId != null) {
|
||||
fee.deleted = true
|
||||
fee._checked = false
|
||||
} else {
|
||||
const index = list.indexOf(fee)
|
||||
if (index >= 0) list.splice(index, 1)
|
||||
}
|
||||
}
|
||||
const maxPage = Math.max(1, Math.ceil(aliveRows(list).length / pageSize) || 1)
|
||||
if (pane.feePageNo > maxPage) pane.feePageNo = maxPage
|
||||
invalidateBandView(pane)
|
||||
proxy.$modal.msgSuccess(`已删除 ${checked.length} 项`)
|
||||
}
|
||||
|
||||
@@ -666,7 +681,7 @@ const feePickerVisible = ref(false)
|
||||
const feePickerPane = ref(null)
|
||||
|
||||
const feePickerExcludeIds = computed(() => {
|
||||
const fees = feePickerPane.value?.item?.surcharges || []
|
||||
const fees = aliveRows(feePickerPane.value?.item?.surcharges)
|
||||
return fees.map(fee => fee?.scId).filter(id => id != null)
|
||||
})
|
||||
|
||||
@@ -736,8 +751,13 @@ function onFeePickerConfirm(list) {
|
||||
}
|
||||
|
||||
function removeRow(list, row) {
|
||||
const index = list.indexOf(row)
|
||||
if (index >= 0) list.splice(index, 1)
|
||||
if (!list || !row) return
|
||||
if (row.bandId != null || row.surchargeId != null) {
|
||||
row.deleted = true
|
||||
} else {
|
||||
const index = list.indexOf(row)
|
||||
if (index >= 0) list.splice(index, 1)
|
||||
}
|
||||
for (const pane of panes.value) {
|
||||
if (pane?.item?.weightBands === list || pane?.item?.surcharges === list) invalidateBandView(pane)
|
||||
}
|
||||
|
||||
@@ -33,23 +33,13 @@
|
||||
<el-table-column :label="colBoundChannels" min-width="180" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ boundChannelText(row) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="colAction" width="160" align="center" fixed="right">
|
||||
<el-table-column :label="colAction" width="90" align="center" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" @click="openProduct(row)" v-hasPermi="['price:label:query', 'price:label:edit']">编辑</el-button>
|
||||
<el-button link type="primary" @click="openBindList(row)" v-hasPermi="['price:label:edit']">绑定</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<el-drawer v-model="detailVisible" :title="detailTitle" size="78%" destroy-on-close append-to-body>
|
||||
<label-config-detail
|
||||
v-loading="detailLoading"
|
||||
:product="detail"
|
||||
:editable="canEditDetail"
|
||||
:saving-row-key="savingRowKey"
|
||||
@save-row="saveDetailRow"
|
||||
/>
|
||||
</el-drawer>
|
||||
|
||||
<el-drawer
|
||||
v-model="bindListVisible"
|
||||
@@ -128,16 +118,10 @@
|
||||
<script setup>
|
||||
import {
|
||||
listLabelProducts,
|
||||
getLabelProduct,
|
||||
updateLabelProduct,
|
||||
updateLabelWeightBand,
|
||||
updateLabelSurcharge,
|
||||
listLabelProductChannels,
|
||||
replaceLabelProductChannels
|
||||
} from '@/api/price/label'
|
||||
import { checkPermi } from '@/utils/permission'
|
||||
import { listChannelOptions } from '@/api/masterdata/serviceChannel'
|
||||
import LabelConfigDetail from './LabelConfigDetail.vue'
|
||||
|
||||
const props = defineProps({
|
||||
visible: { type: Boolean, default: false },
|
||||
@@ -150,13 +134,6 @@ const { proxy } = getCurrentInstance()
|
||||
const loading = ref(false)
|
||||
const rows = ref([])
|
||||
const keyword = ref('')
|
||||
const detailVisible = ref(false)
|
||||
const detailLoading = ref(false)
|
||||
const detailSaving = ref(false)
|
||||
const savingRowKey = ref('')
|
||||
const detail = ref(null)
|
||||
const canEditDetail = computed(() => checkPermi(['price:label:edit']))
|
||||
|
||||
const bindListVisible = ref(false)
|
||||
const bindListLoading = ref(false)
|
||||
const bindProductId = ref(null)
|
||||
@@ -194,12 +171,6 @@ const title = computed(() => {
|
||||
return label ? `版本明细 · ${label}` : '版本明细'
|
||||
})
|
||||
|
||||
const detailTitle = computed(() => {
|
||||
if (!detail.value) return '产品明细'
|
||||
const no = detail.value.versionNo ? `第 ${detail.value.versionNo} 版` : ''
|
||||
return `${detail.value.productName || '产品'} ${no}`.trim()
|
||||
})
|
||||
|
||||
const bindListTitle = computed(() => {
|
||||
return bindProductName.value ? `绑定渠道 · ${bindProductName.value}` : '绑定渠道'
|
||||
})
|
||||
@@ -270,86 +241,6 @@ async function load() {
|
||||
}
|
||||
}
|
||||
|
||||
function cleanMoney(product) {
|
||||
if (!product) return
|
||||
;(product.weightBands || []).forEach(row => {
|
||||
if (!row) return
|
||||
if (row.price === '') row.price = null
|
||||
if (row.extraPrice === '') row.extraPrice = null
|
||||
if (row.weightMin === '') row.weightMin = null
|
||||
if (row.weightMax === '') row.weightMax = null
|
||||
})
|
||||
;(product.surcharges || []).forEach(row => {
|
||||
if (row && row.amount === '') row.amount = null
|
||||
})
|
||||
}
|
||||
|
||||
async function persistDetail() {
|
||||
if (!detail.value?.productId) {
|
||||
throw new Error('NO_PRODUCT')
|
||||
}
|
||||
cleanMoney(detail.value)
|
||||
await updateLabelProduct(detail.value)
|
||||
const versionId = detail.value.versionId || detail.value.termId
|
||||
const res = await getLabelProduct(detail.value.productId, versionId)
|
||||
detail.value = res.data || detail.value
|
||||
await load()
|
||||
emit('changed')
|
||||
}
|
||||
|
||||
async function saveDetailRow(payload) {
|
||||
if (!detail.value || savingRowKey.value || detailSaving.value) {
|
||||
payload?.done?.(false)
|
||||
return
|
||||
}
|
||||
savingRowKey.value = payload?.rowKey || 'row'
|
||||
let ok = false
|
||||
try {
|
||||
const row = payload?.row
|
||||
if (payload?.kind === 'band') {
|
||||
if (!row?.bandId) throw new Error('NO_BAND')
|
||||
if (row.price === '') row.price = null
|
||||
if (row.extraPrice === '') row.extraPrice = null
|
||||
await updateLabelWeightBand({
|
||||
bandId: row.bandId,
|
||||
feeType: row.feeType,
|
||||
chargeMode: row.chargeMode,
|
||||
calcParam: row.calcParam,
|
||||
postcodeParam: row.postcodeParam,
|
||||
price: row.price,
|
||||
extraPrice: row.extraPrice
|
||||
})
|
||||
} else if (payload?.kind === 'fee') {
|
||||
if (!row?.surchargeId) throw new Error('NO_FEE')
|
||||
if (row.amount === '') row.amount = null
|
||||
await updateLabelSurcharge(row)
|
||||
} else {
|
||||
await persistDetail()
|
||||
}
|
||||
ok = true
|
||||
proxy.$modal.msgSuccess('该行已保存')
|
||||
} catch (e) {
|
||||
ok = false
|
||||
} finally {
|
||||
savingRowKey.value = ''
|
||||
payload?.done?.(ok)
|
||||
}
|
||||
}
|
||||
|
||||
async function openProduct(row) {
|
||||
detailVisible.value = true
|
||||
detailLoading.value = true
|
||||
detailSaving.value = false
|
||||
savingRowKey.value = ''
|
||||
detail.value = null
|
||||
try {
|
||||
const res = await getLabelProduct(row.productId, row.versionId || row.termId)
|
||||
detail.value = res.data || null
|
||||
} finally {
|
||||
detailLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function ensureChannelOptions() {
|
||||
if (channelOptions.value.length) return
|
||||
const res = await listChannelOptions({ blOpen: '1' })
|
||||
|
||||
@@ -128,6 +128,7 @@ const form = reactive({
|
||||
basic: createEmptyBasicInfo()
|
||||
})
|
||||
const productRows = ref([])
|
||||
const removedProducts = ref([])
|
||||
const productTableRef = ref()
|
||||
const selectedProducts = ref([])
|
||||
const importMeta = reactive({
|
||||
@@ -165,7 +166,7 @@ const pageBanner = computed(() => {
|
||||
return `新建版本:${name}(${code})`
|
||||
})
|
||||
const headerTip = computed(() => {
|
||||
if (editVersionMode.value) return '可重新导入或修改明细;完成后覆盖本版本,不新增版本号'
|
||||
if (editVersionMode.value) return '可重新导入或修改明细;完成后按ID更新/新增/删除,不新增版本号'
|
||||
if (newVersionMode.value) return '导入后生成待生效新版本;生效时间请回详情页设置'
|
||||
return '打单价卡与应付独立;解析后回填到此表,可删除不需要的产品,编辑明细后点完成保存'
|
||||
})
|
||||
@@ -190,6 +191,7 @@ async function loadPackageHeader() {
|
||||
async function loadEditProducts() {
|
||||
if (!editVersionMode.value || !priceSetId.value || !versionNo.value) return
|
||||
loadingProducts.value = true
|
||||
removedProducts.value = []
|
||||
try {
|
||||
const res = await listLabelProducts(priceSetId.value, versionNo.value)
|
||||
const list = res.data || []
|
||||
@@ -244,6 +246,34 @@ function productKey(row) {
|
||||
return row?.rowKey || `${row?.sheetName || ''}-${row?.productName || ''}`
|
||||
}
|
||||
|
||||
function aliveDetailRows(list) {
|
||||
return (list || []).filter(row => row && row.deleted !== true)
|
||||
}
|
||||
|
||||
function markProductRemoved(row) {
|
||||
if (!row) return
|
||||
const vid = row.versionId || row.termId
|
||||
const pid = row.productId
|
||||
const dup = (removedProducts.value || []).some(item => {
|
||||
if (vid != null && (item.versionId || item.termId) != null) {
|
||||
return String(item.versionId || item.termId) === String(vid)
|
||||
}
|
||||
return pid != null && item.productId != null && String(item.productId) === String(pid)
|
||||
})
|
||||
if (dup) return
|
||||
removedProducts.value.push({
|
||||
...row,
|
||||
deleted: true,
|
||||
weightBands: aliveDetailRows(row.weightBands).filter(b => b.bandId != null).map(b => ({ ...b, deleted: true })),
|
||||
surcharges: aliveDetailRows(row.surcharges).filter(s => s.surchargeId != null).map(s => ({ ...s, deleted: true }))
|
||||
})
|
||||
}
|
||||
|
||||
function buildSaveProducts() {
|
||||
const active = (productRows.value || []).filter(row => row && row.deleted !== true)
|
||||
return [...(removedProducts.value || []), ...active]
|
||||
}
|
||||
|
||||
async function removeProduct(row) {
|
||||
if (!row) return
|
||||
try {
|
||||
@@ -252,6 +282,9 @@ async function removeProduct(row) {
|
||||
return
|
||||
}
|
||||
const key = productKey(row)
|
||||
if (editVersionMode.value && (row.versionId || row.productId)) {
|
||||
markProductRemoved(row)
|
||||
}
|
||||
productRows.value = productRows.value.filter(item => productKey(item) !== key)
|
||||
selectedProducts.value = selectedProducts.value.filter(item => productKey(item) !== key)
|
||||
if (detailRowKey.value === key) {
|
||||
@@ -272,6 +305,11 @@ async function removeSelectedProducts() {
|
||||
return
|
||||
}
|
||||
const keys = new Set(rows.map(productKey))
|
||||
if (editVersionMode.value) {
|
||||
for (const row of rows) {
|
||||
if (row.versionId || row.productId) markProductRemoved(row)
|
||||
}
|
||||
}
|
||||
productRows.value = productRows.value.filter(item => !keys.has(productKey(item)))
|
||||
selectedProducts.value = []
|
||||
if (keys.has(detailRowKey.value)) {
|
||||
@@ -281,6 +319,13 @@ async function removeSelectedProducts() {
|
||||
}
|
||||
|
||||
function onImportConfirm(payload) {
|
||||
if (editVersionMode.value) {
|
||||
for (const row of productRows.value || []) {
|
||||
if (row?.versionId || row?.productId) markProductRemoved(row)
|
||||
}
|
||||
} else {
|
||||
removedProducts.value = []
|
||||
}
|
||||
productRows.value = payload?.products || []
|
||||
selectedProducts.value = []
|
||||
importMeta.sourceFile = payload?.sourceFile || ''
|
||||
@@ -319,8 +364,8 @@ function applyEditedProduct() {
|
||||
proxy.$modal.msgError('未找到对应产品行')
|
||||
return false
|
||||
}
|
||||
const bands = edited.weightBands || []
|
||||
const fees = edited.surcharges || []
|
||||
const bands = aliveDetailRows(edited.weightBands)
|
||||
const fees = aliveDetailRows(edited.surcharges)
|
||||
const extras = edited.extraLines || []
|
||||
productRows.value.splice(idx, 1, {
|
||||
...edited,
|
||||
@@ -375,19 +420,22 @@ async function finish() {
|
||||
proxy.$modal.msgWarning(editVersionMode.value ? '缺少套餐编号,无法编辑版本' : '缺少套餐编号,无法新建版本')
|
||||
return
|
||||
}
|
||||
if (!productRows.value.length) {
|
||||
proxy.$modal.msgWarning('请先导入并确认价卡产品')
|
||||
return
|
||||
}
|
||||
// 抽屉未关闭时先回写勾选,避免丢失
|
||||
if (detailVisible.value && detailProduct.value && detailRowKey.value) {
|
||||
applyEditedProduct()
|
||||
}
|
||||
const saveProducts = buildSaveProducts()
|
||||
if (!saveProducts.length) {
|
||||
proxy.$modal.msgWarning('请先导入并确认价卡产品')
|
||||
return
|
||||
}
|
||||
const activeCount = saveProducts.filter(p => !p.deleted).length
|
||||
const removedCount = saveProducts.filter(p => p.deleted).length
|
||||
const tip = editVersionMode.value
|
||||
? `将覆盖版本 V${versionNo.value} 的 ${productRows.value.length} 个产品,确认继续?`
|
||||
? `将按ID更新版本 V${versionNo.value}(保留 ${activeCount} 个产品,删除 ${removedCount} 个),确认继续?`
|
||||
: newVersionMode.value
|
||||
? `将为套餐「${form.basic.priceSetName || ''}」新建待生效版本并保存 ${productRows.value.length} 个产品,确认继续?`
|
||||
: `将创建打单套餐并保存 ${productRows.value.length} 个产品,确认继续?`
|
||||
? `将为套餐「${form.basic.priceSetName || ''}」新建待生效版本并保存 ${activeCount} 个产品,确认继续?`
|
||||
: `将创建打单套餐并保存 ${activeCount} 个产品,确认继续?`
|
||||
try {
|
||||
await proxy.$modal.confirm(tip)
|
||||
} catch {
|
||||
@@ -400,7 +448,7 @@ async function finish() {
|
||||
try {
|
||||
const payload = {
|
||||
overwrite: editVersionMode.value ? true : importMeta.overwrite,
|
||||
products: productRows.value
|
||||
products: saveProducts
|
||||
}
|
||||
if (editVersionMode.value) {
|
||||
payload.priceSetId = priceSetId.value
|
||||
|
||||
Reference in New Issue
Block a user