重构产品价和红线价功能
This commit is contained in:
@@ -143,6 +143,7 @@
|
||||
width="560px"
|
||||
:show-update-support="false"
|
||||
:import-desc="importDesc"
|
||||
:file-limit="5"
|
||||
:submit-handler="runImportAsync"
|
||||
@success="onImportSuccess"
|
||||
/>
|
||||
@@ -153,6 +154,7 @@
|
||||
width="560px"
|
||||
:show-update-support="false"
|
||||
:import-desc="countryImportDesc"
|
||||
:file-limit="5"
|
||||
:before-submit="validateCountryImport"
|
||||
:submit-handler="runCountryImportAsync"
|
||||
@success="onImportSuccess"
|
||||
@@ -482,7 +484,6 @@ function mergeLocalProducts(existing, incoming) {
|
||||
const key = String(p.productCode).toUpperCase()
|
||||
const prev = map.get(key) || {}
|
||||
const next = { ...prev, ...p }
|
||||
if (p.pefId == null && prev.pefId != null) next.pefId = prev.pefId
|
||||
map.set(key, next)
|
||||
}
|
||||
return Array.from(map.values())
|
||||
@@ -573,26 +574,32 @@ function validateCountryImport() {
|
||||
return ''
|
||||
}
|
||||
|
||||
function unwrapUploadFiles(uploadFile) {
|
||||
const list = Array.isArray(uploadFile) ? uploadFile : [uploadFile]
|
||||
const out = []
|
||||
for (const item of list) {
|
||||
const raw = item && (item.raw || item)
|
||||
if (raw) out.push(raw)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
async function runImportAsync(uploadFile, countryCode) {
|
||||
const raw = uploadFile && (uploadFile.raw || uploadFile)
|
||||
if (!raw) {
|
||||
const files = unwrapUploadFiles(uploadFile)
|
||||
if (!files.length) {
|
||||
throw new Error('请先选择文件')
|
||||
}
|
||||
// Do not open a second el-dialog over ExcelImportDialog: closing the overlay
|
||||
// click-throughs into el-upload and EP crashes (inputRef.value.value = '').
|
||||
// Excel build-price (IMPORT mode): merge by product+country. Modify-price / other modes unchanged.
|
||||
const replaceByProductCountry = !isModifyImport.value || !!countryCode
|
||||
if (!props.livePersist) {
|
||||
const res = await previewImportDetailPrices(raw, {
|
||||
const res = await previewImportDetailPrices(files, {
|
||||
updateOnly: isModifyImport.value && !countryCode,
|
||||
replaceByProductCountry,
|
||||
countryCode: countryCode || undefined,
|
||||
details: props.details || []
|
||||
})
|
||||
const data = res.data || {}
|
||||
if (data.pefId != null) {
|
||||
emit('update:pefId', data.pefId)
|
||||
}
|
||||
const ids = Array.isArray(data.pefIds) ? data.pefIds : (data.pefId != null ? [data.pefId] : [])
|
||||
ids.forEach(id => emit('update:pefId', id))
|
||||
const products = replaceByProductCountry
|
||||
? mergeLocalProducts(props.products, data.products || [])
|
||||
: (isModifyImport.value ? (props.products || []) : (data.products || []))
|
||||
@@ -600,7 +607,7 @@ async function runImportAsync(uploadFile, countryCode) {
|
||||
return data.message || '导入完成'
|
||||
}
|
||||
const { task } = await importSetDetailPricesAsync(
|
||||
raw,
|
||||
files,
|
||||
{
|
||||
priceSetId: props.priceSetId,
|
||||
psvId: await resolvePsvId(false),
|
||||
|
||||
@@ -113,6 +113,7 @@ const form = reactive({
|
||||
})
|
||||
/** Draft IMPORT Excel attachment id; stamped onto prc_price_set_product on finish */
|
||||
const draftPefId = ref(undefined)
|
||||
const draftPefIds = ref([])
|
||||
const savedPriceBuildMode = ref(undefined)
|
||||
const savedProductsSnapshot = ref([])
|
||||
const buildModeDirty = computed(() =>
|
||||
@@ -314,7 +315,9 @@ function buildPayload(opts = {}) {
|
||||
priceBuildMode: version.priceBuildMode || undefined
|
||||
}
|
||||
}
|
||||
if (draftPefId.value != null) {
|
||||
if (draftPefIds.value.length) {
|
||||
payload.pefIds = draftPefIds.value.slice()
|
||||
} else if (draftPefId.value != null) {
|
||||
payload.pefId = draftPefId.value
|
||||
}
|
||||
if (opts.forceDetails || hasUnsavedDetail) {
|
||||
@@ -376,6 +379,11 @@ function onPsvIdUpdate(psvId) {
|
||||
|
||||
function onPefIdUpdate(pefId) {
|
||||
draftPefId.value = pefId
|
||||
if (pefId == null || pefId === '') return
|
||||
const id = String(pefId)
|
||||
if (!draftPefIds.value.some(x => String(x) === id)) {
|
||||
draftPefIds.value.push(pefId)
|
||||
}
|
||||
}
|
||||
|
||||
/** Step2 chose PULL / IMPORT: edit live-saves mode; create only local + optional preview pull. */
|
||||
@@ -391,6 +399,7 @@ function onPriceBuildModeUpdate(mode) {
|
||||
form.version.priceBuildMode = mode
|
||||
if (mode !== 'IMPORT') {
|
||||
draftPefId.value = undefined
|
||||
draftPefIds.value = []
|
||||
}
|
||||
form.details.splice(0, form.details.length)
|
||||
if (detailsRef.value && detailsRef.value.clearLocalDraft) {
|
||||
@@ -485,6 +494,7 @@ function applySetData(data, asCopy, asNewVersion) {
|
||||
form.version.status = undefined
|
||||
form.version.priceBuildMode = undefined
|
||||
draftPefId.value = undefined
|
||||
draftPefIds.value = []
|
||||
savedPriceBuildMode.value = undefined
|
||||
form.details = []
|
||||
form.products = []
|
||||
@@ -498,6 +508,7 @@ function applySetData(data, asCopy, asNewVersion) {
|
||||
form.version.status = (resume && resume.status) || '0'
|
||||
form.version.priceBuildMode = undefined
|
||||
draftPefId.value = undefined
|
||||
draftPefIds.value = []
|
||||
savedPriceBuildMode.value = undefined
|
||||
form.details = []
|
||||
form.products = []
|
||||
@@ -509,6 +520,7 @@ function applySetData(data, asCopy, asNewVersion) {
|
||||
form.version.status = current.status
|
||||
form.version.priceBuildMode = current.priceBuildMode || undefined
|
||||
draftPefId.value = undefined
|
||||
draftPefIds.value = []
|
||||
savedPriceBuildMode.value = current.priceBuildMode || undefined
|
||||
form.details = []
|
||||
form.products = (current.products || []).map(p => ({ ...p }))
|
||||
|
||||
@@ -421,7 +421,6 @@ export function toDetailPayload(d) {
|
||||
return {
|
||||
psdId: d.psdId || undefined,
|
||||
psvId: d.psvId || undefined,
|
||||
priceSetId: d.priceSetId || undefined,
|
||||
productCode: d.productCode,
|
||||
productName: d.productName,
|
||||
countryCode: d.countryCode || undefined,
|
||||
|
||||
Reference in New Issue
Block a user