重构产品价和红线价功能
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),
|
||||
|
||||
Reference in New Issue
Block a user