Enhance price set import functionality with preview options and update handling. Added new endpoints for previewing product library pulls and Excel imports, along with support for update-only imports. Updated internationalization messages for import success and error scenarios.
This commit is contained in:
@@ -18,8 +18,11 @@
|
||||
:psv-id="form.version.psvId"
|
||||
@update:psv-id="onPsvIdUpdate"
|
||||
:set-type="form.basic.setType"
|
||||
:price-build-mode="form.version.priceBuildMode"
|
||||
@update:price-build-mode="onPriceBuildModeUpdate"
|
||||
:version-no="form.version.versionNo"
|
||||
:ref-data="refData"
|
||||
:live-persist="livePersist"
|
||||
/>
|
||||
|
||||
<div class="wizard-actions">
|
||||
@@ -27,7 +30,7 @@
|
||||
<el-button v-if="active > 0 && !directStep2" @click="active--">上一步</el-button>
|
||||
<el-button v-if="active === 0" type="primary" :loading="creating" @click="goStep2">创建套餐价格</el-button>
|
||||
<el-button v-if="active === 0" type="info" :loading="saving" @click="saveDraft">保存</el-button>
|
||||
<el-button v-if="active === 1" type="primary" @click="finishEdit">完成</el-button>
|
||||
<el-button v-if="active === 1" type="primary" :loading="creating" @click="finishEdit">完成</el-button>
|
||||
</div>
|
||||
|
||||
<el-dialog
|
||||
@@ -77,6 +80,8 @@ const detailsRef = ref()
|
||||
const copyMode = computed(() => String(route.query.copyVersion || '') === '1')
|
||||
/** Entered from detail: continue-config / copy-version jump to step2 — hide 上一步 */
|
||||
const directStep2 = computed(() => copyMode.value || String(route.query.step || '') === '2')
|
||||
/** Edit existing version: live PUT/pull/import. New create / copy-version: defer until finish. */
|
||||
const livePersist = computed(() => !!form.priceSetId && !copyMode.value)
|
||||
|
||||
const step1Title = '基本信息'
|
||||
const step2Title = '编辑产品价格'
|
||||
@@ -84,7 +89,7 @@ const step2Title = '编辑产品价格'
|
||||
const form = reactive({
|
||||
priceSetId: undefined,
|
||||
basic: createEmptyBasicInfo(),
|
||||
version: { psvId: undefined, versionNo: 'V1', effectiveTime: undefined, expireTime: undefined },
|
||||
version: { psvId: undefined, versionNo: 'V1', effectiveTime: undefined, expireTime: undefined, priceBuildMode: undefined },
|
||||
details: [],
|
||||
products: [],
|
||||
customers: []
|
||||
@@ -142,45 +147,65 @@ async function runSaveWithProgress(payload) {
|
||||
}
|
||||
}
|
||||
|
||||
/** Step1 -> Step2: create empty draft version only; products/details persist on pull or Excel import */
|
||||
/** Step1 -> Step2: validate only; no DB write on create (defer until finish). */
|
||||
async function goStep2() {
|
||||
const validBasic = await basicRef.value.validate()
|
||||
if (!validBasic) return
|
||||
|
||||
if (form.priceSetId && form.version.psvId) {
|
||||
active.value = 1
|
||||
return
|
||||
}
|
||||
|
||||
creating.value = true
|
||||
try {
|
||||
// Never auto-pull product library on enter Step2 (even if old clients sent the flag).
|
||||
const payload = buildPayload()
|
||||
delete payload.pullFromLibrary
|
||||
delete payload.forcePullLibrary
|
||||
delete payload.details
|
||||
const priceSetId = await runSaveWithProgress(payload)
|
||||
form.priceSetId = priceSetId
|
||||
const fresh = await getPriceSet(priceSetId)
|
||||
applySetData(fresh.data || {}, false)
|
||||
if (!(form.products || []).some(p => p && p.productCode) && !form.version.priceBuildMode) {
|
||||
form.details = []
|
||||
form.products = []
|
||||
if (!form.version.psvId) {
|
||||
const versions = (fresh.data && fresh.data.versions) || []
|
||||
const v = (fresh.data && fresh.data.version && fresh.data.version.psvId)
|
||||
? fresh.data.version
|
||||
: versions[0]
|
||||
if (v && v.psvId) {
|
||||
form.version.psvId = v.psvId
|
||||
form.version.versionNo = v.versionNo || form.version.versionNo
|
||||
}
|
||||
}
|
||||
if (!form.version.psvId) {
|
||||
proxy.$modal.msgError('套餐版本创建失败,请重试')
|
||||
}
|
||||
active.value = 1
|
||||
}
|
||||
|
||||
/** Step2 finish: create/copy async save all; edit already live-saved. */
|
||||
async function finishEdit() {
|
||||
if (livePersist.value) {
|
||||
if (!form.priceSetId) {
|
||||
goBack()
|
||||
return
|
||||
}
|
||||
active.value = 1
|
||||
proxy.$modal.msgSuccess('已创建空套餐版本,请在第 2 步拉取或导入价格')
|
||||
proxy.$modal.msgSuccess('修改已实时落库')
|
||||
const obj = {
|
||||
path: '/customer/setDetail',
|
||||
query: { priceSetId: form.priceSetId }
|
||||
}
|
||||
if (proxy.$tab) {
|
||||
proxy.$tab.closeOpenPage(obj)
|
||||
} else {
|
||||
proxy.$router.push(obj)
|
||||
}
|
||||
return
|
||||
}
|
||||
const validBasic = await basicRef.value.validate()
|
||||
if (!validBasic) {
|
||||
active.value = 0
|
||||
return
|
||||
}
|
||||
if (!form.version.priceBuildMode) {
|
||||
proxy.$modal.msgWarning('请先选择创建价格方式')
|
||||
return
|
||||
}
|
||||
const detailRows = (form.details || []).filter(d => d && d.productCode)
|
||||
if (!detailRows.length) {
|
||||
proxy.$modal.msgWarning('请先拉取产品或导入 Excel 建价')
|
||||
return
|
||||
}
|
||||
creating.value = true
|
||||
try {
|
||||
const payload = buildPayload({ forceDetails: true })
|
||||
const priceSetId = await runSaveWithProgress(payload)
|
||||
form.priceSetId = priceSetId
|
||||
proxy.$modal.msgSuccess('套餐已保存')
|
||||
const obj = {
|
||||
path: '/customer/setDetail',
|
||||
query: { priceSetId }
|
||||
}
|
||||
if (proxy.$tab) {
|
||||
proxy.$tab.closeOpenPage(obj)
|
||||
} else {
|
||||
proxy.$router.push(obj)
|
||||
}
|
||||
} catch (e) {
|
||||
// surfaced
|
||||
} finally {
|
||||
@@ -188,24 +213,6 @@ async function goStep2() {
|
||||
}
|
||||
}
|
||||
|
||||
/** Step2: prices already live-saved via PUT /detail; go to detail page. */
|
||||
function finishEdit() {
|
||||
if (!form.priceSetId) {
|
||||
goBack()
|
||||
return
|
||||
}
|
||||
proxy.$modal.msgSuccess('修改已实时落库')
|
||||
const obj = {
|
||||
path: '/customer/setDetail',
|
||||
query: { priceSetId: form.priceSetId }
|
||||
}
|
||||
if (proxy.$tab) {
|
||||
proxy.$tab.closeOpenPage(obj)
|
||||
} else {
|
||||
proxy.$router.push(obj)
|
||||
}
|
||||
}
|
||||
|
||||
/** Step0 only: persist basic draft (no detail wipe). */
|
||||
async function saveDraft() {
|
||||
const validBasic = await basicRef.value.validate()
|
||||
@@ -226,27 +233,36 @@ async function saveDraft() {
|
||||
}
|
||||
}
|
||||
|
||||
function buildPayload() {
|
||||
function buildPayload(opts = {}) {
|
||||
const { basic, version } = form
|
||||
const detailRows = form.details.filter(d => d && d.productCode)
|
||||
// Price edits already persist via PUT /detail; product remove uses DELETE.
|
||||
// Omit details when all rows already have psdId so save only updates header/version.
|
||||
// Edit live-save: omit details when all rows already have psdId.
|
||||
// Create finish: forceDetails sends all rows (psdId cleared) for insert.
|
||||
const hasUnsavedDetail = detailRows.some(d => d.psdId == null)
|
||||
const payload = {
|
||||
priceSetId: form.priceSetId,
|
||||
priceSetName: basic.priceSetName,
|
||||
setType: basic.setType,
|
||||
defaultDiscount: basic.setType === 'DISCOUNT' ? basic.defaultDiscount : undefined,
|
||||
setType: 'FIXED',
|
||||
defaultDiscount: undefined,
|
||||
priceSetNote: basic.priceSetNote,
|
||||
version: {
|
||||
psvId: copyMode.value ? undefined : version.psvId,
|
||||
versionNo: version.versionNo
|
||||
versionNo: version.versionNo,
|
||||
priceBuildMode: version.priceBuildMode || undefined
|
||||
}
|
||||
}
|
||||
if (hasUnsavedDetail) {
|
||||
payload.details = detailRows.map(toDetailPayload)
|
||||
if (opts.forceDetails || hasUnsavedDetail) {
|
||||
payload.details = detailRows.map(d => {
|
||||
const p = toDetailPayload(d)
|
||||
if (opts.forceDetails) {
|
||||
delete p.psdId
|
||||
delete p.pspId
|
||||
delete p.priceSetId
|
||||
delete p.psvId
|
||||
}
|
||||
return p
|
||||
})
|
||||
}
|
||||
// Customer bind is managed on detail page APIs; only send when present to avoid wipe.
|
||||
const customers = form.customers.filter(c => c && c.customerCode).map(toCustomerPayload)
|
||||
if (customers.length) {
|
||||
payload.customers = customers
|
||||
@@ -267,11 +283,50 @@ function onPsvIdUpdate(psvId) {
|
||||
if (psvId != null && psvId !== '') form.version.psvId = psvId
|
||||
}
|
||||
|
||||
/** Step2 chose PULL / IMPORT: edit live-saves mode; create only local + optional preview pull. */
|
||||
async function onPriceBuildModeUpdate(mode) {
|
||||
if (!mode) return
|
||||
const prev = form.version.priceBuildMode
|
||||
if (prev === mode) return
|
||||
form.version.priceBuildMode = mode
|
||||
try {
|
||||
// Create/copy: switching build mode clears the product table before reload/import.
|
||||
if (!livePersist.value && prev) {
|
||||
form.details.splice(0, form.details.length)
|
||||
form.products.splice(0, form.products.length)
|
||||
if (detailsRef.value && detailsRef.value.clearLocalDraft) {
|
||||
detailsRef.value.clearLocalDraft()
|
||||
}
|
||||
}
|
||||
if (livePersist.value) {
|
||||
const payload = buildPayload()
|
||||
delete payload.pullFromLibrary
|
||||
delete payload.forcePullLibrary
|
||||
delete payload.details
|
||||
await runSaveWithProgress(payload)
|
||||
}
|
||||
await nextTick()
|
||||
if (mode === 'PULL' && detailsRef.value && detailsRef.value.pullAllFromLibrary) {
|
||||
const hasProducts = (form.products || []).some(p => p && p.productCode)
|
||||
if (!hasProducts) {
|
||||
await detailsRef.value.pullAllFromLibrary({ silent: true })
|
||||
proxy.$modal.msgSuccess('已拉取产品列表,可继续编辑价格')
|
||||
} else if (prev !== mode) {
|
||||
proxy.$modal.msgSuccess('已切换为按产品价建价,可导入 Excel 修改价格')
|
||||
}
|
||||
} else if (mode === 'IMPORT' && prev !== mode) {
|
||||
proxy.$modal.msgSuccess('请导入 Excel 建价')
|
||||
}
|
||||
} catch (e) {
|
||||
form.version.priceBuildMode = prev
|
||||
}
|
||||
}
|
||||
|
||||
function applySetData(data, asCopy) {
|
||||
form.priceSetId = data.priceSetId
|
||||
Object.assign(form.basic, {
|
||||
priceSetName: data.priceSetName,
|
||||
setType: data.setType || 'FIXED',
|
||||
setType: 'FIXED',
|
||||
defaultDiscount: data.defaultDiscount != null ? Number(data.defaultDiscount) : 88,
|
||||
priceSetNote: data.priceSetNote
|
||||
})
|
||||
@@ -285,11 +340,13 @@ function applySetData(data, asCopy) {
|
||||
form.version.versionNo = nextVersionNo(versions)
|
||||
form.version.effectiveTime = undefined
|
||||
form.version.expireTime = undefined
|
||||
form.version.priceBuildMode = undefined
|
||||
} else {
|
||||
form.version.psvId = current.psvId
|
||||
form.version.versionNo = current.versionNo || nextVersionNo(versions)
|
||||
form.version.effectiveTime = current.effectiveTime
|
||||
form.version.expireTime = current.expireTime
|
||||
form.version.priceBuildMode = current.priceBuildMode || undefined
|
||||
}
|
||||
form.details = []
|
||||
form.products = asCopy ? [] : ((current.products || []).map(p => ({ ...p })))
|
||||
|
||||
Reference in New Issue
Block a user