修改套餐价格

This commit is contained in:
wuweihua
2026-10-16 10:43:45 +08:00
parent 622d2a4c40
commit 2689138b6a
9 changed files with 572 additions and 277 deletions
+74 -10
View File
@@ -72,7 +72,7 @@ import {
toCustomerPayload,
toDetailPayload
} from './utils/priceSet'
import { getPriceSet, savePriceSetAsync } from '@/api/price/set'
import { getPriceSet, savePriceSetAsync, createPriceSetVersion, deletePriceSetVersion } from '@/api/price/set'
const { proxy } = getCurrentInstance()
const route = useRoute()
@@ -202,12 +202,19 @@ async function finishEdit() {
delete payload.details
await runSaveWithProgress(payload)
savedPriceBuildMode.value = form.version.priceBuildMode
savedProductsSnapshot.value = (form.products || []).map(p => ({ ...p }))
await nextTick()
if (form.version.priceBuildMode === 'PULL' && detailsRef.value && detailsRef.value.pullAllFromLibrary) {
await detailsRef.value.pullAllFromLibrary({ silent: true })
savedProductsSnapshot.value = (form.products || []).map(p => ({ ...p }))
proxy.$modal.msgSuccess("建价方式已保存")
} else if (form.version.priceBuildMode === 'IMPORT') {
// Backend copied prior version into this draft; refresh product list from current psv
await refreshProductsFromCurrentVersion()
proxy.$modal.msgSuccess("建价方式已保存,已带出上一版产品")
} else {
savedProductsSnapshot.value = (form.products || []).map(p => ({ ...p }))
proxy.$modal.msgSuccess("建价方式已保存")
}
proxy.$modal.msgSuccess("建价方式已保存")
} catch (e) {
return
} finally {
@@ -243,6 +250,12 @@ async function finishEdit() {
}
creating.value = true
try {
if (newVersionMode.value && form.version.psvId == null && form.priceSetId) {
const verRes = await createPriceSetVersion(form.priceSetId)
if (verRes.data != null) {
form.version.psvId = verRes.data
}
}
const payload = buildPayload({ forceDetails: true })
const priceSetId = await runSaveWithProgress(payload)
form.priceSetId = priceSetId
@@ -296,7 +309,7 @@ function buildPayload(opts = {}) {
defaultDiscount: undefined,
priceSetNote: basic.priceSetNote,
version: {
psvId: copyMode.value ? undefined : version.psvId,
psvId: (copyMode.value || (newVersionMode.value && version.psvId == null)) ? undefined : version.psvId,
versionNo: version.versionNo,
priceBuildMode: version.priceBuildMode || undefined
}
@@ -323,7 +336,30 @@ function buildPayload(opts = {}) {
return payload
}
function goBack() {
/**
* New-version flow creates an empty draft as soon as user clicks "新建价格版本".
* If user cancels without finishing (no build mode / no details on server), remove that orphan draft.
*/
async function tryDeleteEmptyNewVersionDraft() {
if (!newVersionMode.value || !form.priceSetId || form.version.psvId == null) return
const psvId = form.version.psvId
try {
const res = await getPriceSet(form.priceSetId)
const versions = (res.data || {}).versions || []
const v = versions.find(x => x && String(x.psvId) === String(psvId))
if (!v || String(v.status) !== '0') return
const noMode = !v.priceBuildMode
const noDetails = !(Number(v.detailCount) > 0) && !(v.details || []).length
if (noMode && noDetails) {
await deletePriceSetVersion(psvId)
}
} catch (e) {
// ignore cleanup errors; still navigate back
}
}
async function goBack() {
await tryDeleteEmptyNewVersionDraft()
const obj = (newVersionMode.value || copyMode.value) && form.priceSetId
? { path: '/customer/setDetail', query: { priceSetId: form.priceSetId } }
: { path: '/customer/set' }
@@ -383,7 +419,20 @@ function onPriceBuildModeUpdate(mode) {
}).catch(() => {})
})
} else if (mode === 'IMPORT') {
proxy.$modal.msgSuccess("请导入 Excel 建价")
nextTick(() => {
const loader = detailsRef.value && detailsRef.value.loadLatestPriorVersionDraft
if (!loader) {
proxy.$modal.msgSuccess("请导入 Excel 建价")
return
}
loader().then(ok => {
proxy.$modal.msgSuccess(ok
? "已带出上一版全部产品,导入 Excel 按产品+国家覆盖或新增"
: "暂无上一版产品,请导入 Excel 建价")
}).catch(() => {
proxy.$modal.msgSuccess("请导入 Excel 建价")
})
})
}
}
@@ -401,6 +450,20 @@ function reloadSavedProductsForCreate() {
})
}
async function refreshProductsFromCurrentVersion() {
if (!form.priceSetId) return
const res = await getPriceSet(form.priceSetId)
const data = res.data || {}
const versions = data.versions || []
const qPsv = form.version.psvId
const byQuery = qPsv != null ? versions.find(v => String(v.psvId) === String(qPsv)) : null
const current = byQuery || data.version || versions[0] || {}
const list = (current.products || []).map(p => ({ ...p }))
form.products.splice(0, form.products.length, ...list)
form.details.splice(0, form.details.length)
savedProductsSnapshot.value = list.map(p => ({ ...p }))
}
function applySetData(data, asCopy, asNewVersion) {
form.priceSetId = data.priceSetId
Object.assign(form.basic, {
@@ -426,12 +489,13 @@ function applySetData(data, asCopy, asNewVersion) {
form.details = []
form.products = []
} else if (asNewVersion) {
// Pre-created empty draft from detail page; same step2 UX as create package
form.version.psvId = current.psvId
form.version.versionNo = current.versionNo || nextVersionNo(versions)
// Draft is created on finish only. Resume only when query has psvId (legacy empty draft).
const resume = qPsv != null ? byQuery : null
form.version.psvId = resume ? resume.psvId : undefined
form.version.versionNo = (resume && resume.versionNo) || nextVersionNo(versions)
form.version.effectiveTime = undefined
form.version.expireTime = undefined
form.version.status = current.status || '0'
form.version.status = (resume && resume.status) || '0'
form.version.priceBuildMode = undefined
draftPefId.value = undefined
savedPriceBuildMode.value = undefined