Browse Source

价格导入

master
常熟吴彦祖 7 days ago
parent
commit
fc95f26818
  1. 10
      config/index.js
  2. 32
      src/api/initialImport.js
  3. 111
      src/views/modules/sys/initialImport.vue

10
config/index.js

@ -12,6 +12,16 @@ module.exports = {
assetsPublicPath: '/', assetsPublicPath: '/',
// 代理列表, 是否开启代理通过[./dev.env.js]配置 // 代理列表, 是否开启代理通过[./dev.env.js]配置
proxyTable: devEnv.OPEN_PROXY === false ? {} : { proxyTable: devEnv.OPEN_PROXY === false ? {} : {
// V2 价格导入代理先匹配,入站及后端等待均允许 30 分钟。- rqrq
'/proxyApi/**/initialImport/supplierPrice/v2/**': {
target: 'http://127.0.0.1:7002',
changeOrigin: true,
timeout: 30 * 60 * 1000,
proxyTimeout: 30 * 60 * 1000,
pathRewrite: {
'^/proxyApi': '/'
}
},
'/proxyApi': { '/proxyApi': {
target: 'http://127.0.0.1:7002', target: 'http://127.0.0.1:7002',
changeOrigin: true, changeOrigin: true,

32
src/api/initialImport.js

@ -29,6 +29,38 @@ export const saveSupplierPrice = data => http({
timeout: 30 * 60 * 1000 timeout: 30 * 60 * 1000
}) })
// 新版价格期初导入:旧版三个调用保留,页面改用下面的 V2 接口。- rqrq
const SUPPLIER_PRICE_IMPORT_TIMEOUT = 30 * 60 * 1000
export const downloadSupplierPriceTemplateV2 = () => http({
url: http.adornUrl('/sys/initialImport/supplierPrice/v2/template'),
method: 'get',
responseType: 'blob',
timeout: SUPPLIER_PRICE_IMPORT_TIMEOUT
})
export const previewSupplierPriceV2 = (file, site) => {
const formData = new FormData()
formData.append('file', file)
formData.append('site', site)
return http({
url: http.adornUrl('/sys/initialImport/supplierPrice/v2/preview'),
method: 'post',
data: formData,
headers: {
'Content-Type': 'multipart/form-data'
},
timeout: SUPPLIER_PRICE_IMPORT_TIMEOUT
})
}
export const saveSupplierPriceV2 = data => http({
url: http.adornUrl('/sys/initialImport/supplierPrice/v2/save'),
method: 'post',
data: http.adornData(data),
timeout: SUPPLIER_PRICE_IMPORT_TIMEOUT
})
export const downloadPartSkuTemplate = () => http({ export const downloadPartSkuTemplate = () => http({
url: http.adornUrl('/sys/initialImport/partSku/template'), url: http.adornUrl('/sys/initialImport/partSku/template'),
method: 'get', method: 'get',

111
src/views/modules/sys/initialImport.vue

@ -15,6 +15,7 @@
<el-button <el-button
type="primary" type="primary"
icon="el-icon-upload2" icon="el-icon-upload2"
:disabled="importBusy || dialogVisible"
@click="openImportDialog(scope.row.type)"> @click="openImportDialog(scope.row.type)">
{{ scope.row.name }} {{ scope.row.name }}
</el-button> </el-button>
@ -28,9 +29,9 @@
:visible.sync="dialogVisible" :visible.sync="dialogVisible"
:width="dialogWidth" :width="dialogWidth"
top="5vh" top="5vh"
:show-close="!saving"
:show-close="!importBusy"
:close-on-click-modal="false" :close-on-click-modal="false"
:close-on-press-escape="!saving"
:close-on-press-escape="!importBusy"
:before-close="handleDialogClose" :before-close="handleDialogClose"
@closed="handleDialogClosed"> @closed="handleDialogClosed">
<div class="dialog-toolbar"> <div class="dialog-toolbar">
@ -38,14 +39,14 @@
v-if="isPoOrderImport" v-if="isPoOrderImport"
v-model="poCustomer" v-model="poCustomer"
:site="currentSite" :site="currentSite"
:disabled="previewLoading || saving"
:disabled="importBusy"
@input="handlePoCustomerChange" @input="handlePoCustomerChange"
class="po-import-customer-picker" /> class="po-import-customer-picker" />
<el-button <el-button
type="primary" type="primary"
icon="el-icon-download" icon="el-icon-download"
:loading="templateDownloading" :loading="templateDownloading"
:disabled="previewLoading || saving"
:disabled="importBusy"
@click="handleDownloadTemplate"> @click="handleDownloadTemplate">
下载导入模板 下载导入模板
</el-button> </el-button>
@ -56,20 +57,20 @@
:auto-upload="false" :auto-upload="false"
:show-file-list="false" :show-file-list="false"
:limit="1" :limit="1"
:disabled="previewLoading || saving"
:disabled="importBusy"
:on-change="handleFileChange" :on-change="handleFileChange"
:on-exceed="handleFileExceed"> :on-exceed="handleFileExceed">
<el-button <el-button
icon="el-icon-upload2" icon="el-icon-upload2"
:loading="previewLoading" :loading="previewLoading"
:disabled="previewLoading || saving">
:disabled="importBusy">
选择导入文件 选择导入文件
</el-button> </el-button>
</el-upload> </el-upload>
<el-button <el-button
icon="el-icon-download" icon="el-icon-download"
:loading="exporting" :loading="exporting"
:disabled="previewLoading || saving || exporting || !previewRows.length"
:disabled="importBusy || !previewRows.length"
@click="handleExportPreview"> @click="handleExportPreview">
导出校验结果 导出校验结果
</el-button> </el-button>
@ -98,7 +99,7 @@
align="left" align="left"
show-overflow-tooltip /> show-overflow-tooltip />
<el-table-column <el-table-column
v-if="isPoOrderImport"
v-if="isPoOrderImport || activeImportType === 'supplierPrice'"
prop="excelRowNo" prop="excelRowNo"
label="Excel行号" label="Excel行号"
width="90" width="90"
@ -124,7 +125,7 @@
@click="handleSave"> @click="handleSave">
{{ saveButtonText }} {{ saveButtonText }}
</el-button> </el-button>
<el-button :disabled="previewLoading || saving" @click="dialogVisible = false">关闭</el-button>
<el-button :disabled="importBusy" @click="dialogVisible = false">关闭</el-button>
</div> </div>
</el-dialog> </el-dialog>
</div> </div>
@ -134,13 +135,13 @@
import { import {
downloadPoOrderTemplate, downloadPoOrderTemplate,
downloadPartSkuTemplate, downloadPartSkuTemplate,
downloadSupplierPriceTemplate,
downloadSupplierPriceTemplateV2,
previewPartSku, previewPartSku,
previewPoOrder, previewPoOrder,
previewSupplierPrice,
previewSupplierPriceV2,
savePartSku, savePartSku,
savePoOrderBatch, savePoOrderBatch,
saveSupplierPrice
saveSupplierPriceV2
} from '@/api/initialImport' } from '@/api/initialImport'
import ComPoOrderCustomerPicker from '@/views/modules/order/com_poOrder_CustomerPicker.vue' import ComPoOrderCustomerPicker from '@/views/modules/order/com_poOrder_CustomerPicker.vue'
@ -161,7 +162,7 @@ export default {
{ {
type: 'supplierPrice', type: 'supplierPrice',
name: '供应商价格期初导入', name: '供应商价格期初导入',
description: '导入供应商物料的QTY/PO、MOQ/COLOR、QTY/CARTON、阶梯数量和阶梯价格。'
description: '单次最多2000行,超过请分批导入。按表头导入供应商物料数量、阶梯价、备注、供应商简称和物料属性,SKU仅展示;价格明细相同不生成镜像。'
}, },
// { // {
// type: 'partSku', // type: 'partSku',
@ -193,7 +194,9 @@ export default {
missingSuppliers: [], missingSuppliers: [],
supplierPriceColumns: [ supplierPriceColumns: [
{ prop: 'rawCode', label: 'RAW CODE', width: 120, align: 'center' }, { prop: 'rawCode', label: 'RAW CODE', width: 120, align: 'center' },
{ prop: 'supplier', label: '供应商名称', width: 180, align: 'center' },
{ prop: 'sku', label: 'SKU', width: 120, align: 'center' },
{ prop: 'supplier', label: 'SUPPLIER', width: 140, align: 'left' },
{ prop: 'fullName', label: 'full name', width: 220, align: 'left' },
{ prop: 'moqColor', label: 'MOQ/COLOR', width: 80, align: 'center' }, { prop: 'moqColor', label: 'MOQ/COLOR', width: 80, align: 'center' },
{ prop: 'qtyPo', label: 'QTY/PO', width: 80, align: 'center' }, { prop: 'qtyPo', label: 'QTY/PO', width: 80, align: 'center' },
{ prop: 'qtyCarton', label: 'QTY/CARTON', width: 90, align: 'center' }, { prop: 'qtyCarton', label: 'QTY/CARTON', width: 90, align: 'center' },
@ -214,6 +217,12 @@ export default {
{ prop: 'priceTier6', label: 'Price_Tier_6', width: 90, align: 'center' }, { prop: 'priceTier6', label: 'Price_Tier_6', width: 90, align: 'center' },
{ prop: 'priceTier7', label: 'Price_Tier_7', width: 90, align: 'center' }, { prop: 'priceTier7', label: 'Price_Tier_7', width: 90, align: 'center' },
{ prop: 'priceTier8', label: 'Price_Tier_8', width: 90, align: 'center' }, { prop: 'priceTier8', label: 'Price_Tier_8', width: 90, align: 'center' },
{ prop: 'fsc', label: 'fsc', width: 100, align: 'left' },
{ prop: 'fscClaim', label: 'FSC claim', width: 140, align: 'left' },
{ prop: 'leadFreePellet', label: 'Lead free Pellet', width: 140, align: 'left' },
{ prop: 'awareDpp', label: 'AWARE DPP', width: 140, align: 'left' },
{ prop: 'coo', label: 'COO', width: 100, align: 'left' },
{ prop: 'refill', label: 'refill', width: 100, align: 'left' },
{ prop: 'remark', label: 'Remark', width: 160, align: 'left' }, { prop: 'remark', label: 'Remark', width: 160, align: 'left' },
{ prop: 'latestChanges', label: 'latest changes', width: 160, align: 'left' } { prop: 'latestChanges', label: 'latest changes', width: 160, align: 'left' }
], ],
@ -224,6 +233,10 @@ export default {
} }
}, },
computed: { computed: {
// 所有导入操作共用忙碌状态,处理期间禁止重复提交、切换文件或关闭弹框。- rqrq
importBusy () {
return this.previewLoading || this.saving || this.templateDownloading || this.exporting
},
currentSite () { currentSite () {
return this.$store.state.user.site || '' return this.$store.state.user.site || ''
}, },
@ -268,7 +281,7 @@ export default {
}, },
saveDisabled () { saveDisabled () {
// 任意导入类型只要存在黄标行,就不允许继续保存。 // 任意导入类型只要存在黄标行,就不允许继续保存。
if (this.previewLoading || this.saving || !this.previewRows.length || this.hasInvalidPreviewRows) {
if (this.importBusy || !this.previewRows.length || this.hasInvalidPreviewRows) {
return true return true
} }
if (this.isPoOrderImport) { if (this.isPoOrderImport) {
@ -300,6 +313,9 @@ export default {
return true return true
}, },
openImportDialog (type) { openImportDialog (type) {
if (this.importBusy || this.dialogVisible) {
return
}
if (!this.ensureInitialImportAvailable()) { if (!this.ensureInitialImportAvailable()) {
return return
} }
@ -311,6 +327,9 @@ export default {
this.dialogVisible = true this.dialogVisible = true
}, },
handleFileChange (file) { handleFileChange (file) {
if (this.importBusy) {
return
}
if (!this.ensureInitialImportAvailable()) { if (!this.ensureInitialImportAvailable()) {
this.clearSelectedFile() this.clearSelectedFile()
return return
@ -350,14 +369,14 @@ export default {
this.$message.success(`Excel读取成功,共${this.previewRows.length}行`) this.$message.success(`Excel读取成功,共${this.previewRows.length}行`)
this.showMissingDataAlert() this.showMissingDataAlert()
} else { } else {
this.$message.error((data && data.msg) || 'Excel读取失败')
this.showImportPreviewError((data && data.msg) || 'Excel读取失败')
this.clearSelectedFile() this.clearSelectedFile()
} }
}).catch(error => { }).catch(error => {
const message = error && error.response && error.response.data && error.response.data.msg const message = error && error.response && error.response.data && error.response.data.msg
? error.response.data.msg ? error.response.data.msg
: 'Excel读取失败,请检查文件格式' : 'Excel读取失败,请检查文件格式'
this.$message.error(message)
this.showImportPreviewError(message)
this.clearSelectedFile() this.clearSelectedFile()
}).finally(() => { }).finally(() => {
this.previewLoading = false this.previewLoading = false
@ -369,7 +388,19 @@ export default {
} }
return this.activeImportType === 'partSku' return this.activeImportType === 'partSku'
? previewPartSku(rawFile, site) ? previewPartSku(rawFile, site)
: previewSupplierPrice(rawFile, site)
: previewSupplierPriceV2(rawFile, site)
},
// 新版价格读取失败需保留提示,方便用户看清公式来源和单元格位置;其他导入沿用原提示。- rqrq
showImportPreviewError (message) {
if (this.activeImportType !== 'supplierPrice') {
this.$message.error(message)
return
}
this.$alert(message, '导入文件读取失败', {
confirmButtonText: '确定',
type: 'error',
customClass: 'initial-import-error-alert'
}).catch(() => {})
}, },
buildPoOrderColumns (columnMapping) { buildPoOrderColumns (columnMapping) {
// 预览表按模板字段展示;物料编码等于 Item,供应商编码仍由 Vendor Name 解析。 // 预览表按模板字段展示;物料编码等于 Item,供应商编码仍由 Vendor Name 解析。
@ -386,6 +417,9 @@ export default {
return columns return columns
}, },
handlePoCustomerChange () { handlePoCustomerChange () {
if (this.importBusy) {
return
}
if (!this.importFile && !this.previewRows.length) { if (!this.importFile && !this.previewRows.length) {
return return
} }
@ -397,13 +431,16 @@ export default {
this.clearSelectedFile() this.clearSelectedFile()
}, },
handleFileExceed (files) { handleFileExceed (files) {
if (this.previewLoading || !files || !files.length) {
if (this.importBusy || !files || !files.length) {
return return
} }
this.clearSelectedFile() this.clearSelectedFile()
this.handleFileChange({ raw: files[0], name: files[0].name }) this.handleFileChange({ raw: files[0], name: files[0].name })
}, },
handleDownloadTemplate () { handleDownloadTemplate () {
if (this.importBusy) {
return
}
if (!this.ensureInitialImportAvailable()) { if (!this.ensureInitialImportAvailable()) {
return return
} }
@ -443,7 +480,7 @@ export default {
} }
return this.activeImportType === 'partSku' return this.activeImportType === 'partSku'
? downloadPartSkuTemplate ? downloadPartSkuTemplate
: downloadSupplierPriceTemplate
: downloadSupplierPriceTemplateV2
}, },
resolveDownloadTemplateFileName () { resolveDownloadTemplateFileName () {
if (this.isPoOrderImport) { if (this.isPoOrderImport) {
@ -454,6 +491,9 @@ export default {
: '供应商价格期初导入模板.xlsx' : '供应商价格期初导入模板.xlsx'
}, },
handleSave () { handleSave () {
if (this.importBusy) {
return
}
if (!this.ensureInitialImportAvailable()) { if (!this.ensureInitialImportAvailable()) {
return return
} }
@ -479,7 +519,7 @@ export default {
}, },
performSave (site) { performSave (site) {
this.saving = true this.saving = true
const saveRequest = this.activeImportType === 'partSku' ? savePartSku : saveSupplierPrice
const saveRequest = this.activeImportType === 'partSku' ? savePartSku : saveSupplierPriceV2
saveRequest({ saveRequest({
site, site,
rows: this.previewRows rows: this.previewRows
@ -540,7 +580,8 @@ export default {
}, },
/** /**
* 从保存接口失败结果中取出用户可读错误。 * 从保存接口失败结果中取出用户可读错误。
* HTTP 200 + code=500 时错误在 data.msg;网络/超时时走 axios error。
* HTTP 200 + code=500 时错误在 data.msg;区分网络中断、请求超时和代理错误。- rqrq
* 请求断开无法判定后端事务结果,提示先确认结果,避免重复导入。
*/ */
resolveImportSaveErrorMessage (error, fallback) { resolveImportSaveErrorMessage (error, fallback) {
if (!error) { if (!error) {
@ -550,10 +591,21 @@ export default {
if (responseData && responseData.msg) { if (responseData && responseData.msg) {
return responseData.msg return responseData.msg
} }
if (error.message && /timeout/i.test(error.message)) {
return '保存超时,请缩小导入行数后重试'
const message = error.message || ''
const timeout = Number(error.config && error.config.timeout)
const timeoutText = timeout > 0 ? `(本次请求等待上限为${Math.ceil(timeout / 60000)}分钟)` : ''
if (error.code === 'ERR_NETWORK' || /network error/i.test(message)) {
return `网络连接已中断,浏览器未收到服务器的最终响应${timeoutText}。后端可能仍在处理,请先确认导入结果,避免重复提交。`
}
if (error.code === 'ECONNABORTED' || error.code === 'ETIMEDOUT' || /timeout/i.test(message)) {
return `等待服务器响应超时${timeoutText},浏览器未收到最终结果。请先确认后端处理结果,避免重复提交。`
}
const status = error.response && error.response.status
if (status === 502 || status === 503 || status === 504) {
const reason = status === 504 ? '代理或网关等待后端响应超时' : '代理或网关暂时无法正常连接后端'
return `${reason}(HTTP ${status})。请先确认后端处理结果,避免重复提交。`
} }
return error.message || fallback
return message || fallback
}, },
/** /**
* 导入保存失败必须弹确认框,点确定后才关闭,避免 $message 几秒后消失看不清。 * 导入保存失败必须弹确认框,点确定后才关闭,避免 $message 几秒后消失看不清。
@ -615,6 +667,9 @@ export default {
* 结果:下载 Excel,失败行整行标黄,最后一列为错误信息。 * 结果:下载 Excel,失败行整行标黄,最后一列为错误信息。
*/ */
handleExportPreview () { handleExportPreview () {
if (this.importBusy) {
return
}
if (!this.previewRows.length) { if (!this.previewRows.length) {
this.$message.warning('请先选择导入文件并完成预览') this.$message.warning('请先选择导入文件并完成预览')
return return
@ -640,7 +695,7 @@ export default {
} }
}, },
/** /**
* 导出列与弹框预览一致:错误信息放在最左侧,PO 额外带 Excel 行号。
* 导出列与弹框预览一致:错误信息放在最左侧,PO、价格导入额外带真实 Excel 行号。- rqrq
*/ */
buildPreviewExportColumns () { buildPreviewExportColumns () {
const columns = [{ const columns = [{
@ -649,7 +704,7 @@ export default {
width: 280, width: 280,
align: 'left' align: 'left'
}] }]
if (this.isPoOrderImport) {
if (this.isPoOrderImport || this.activeImportType === 'supplierPrice') {
columns.push({ prop: 'excelRowNo', label: 'Excel行号' }) columns.push({ prop: 'excelRowNo', label: 'Excel行号' })
} }
return columns.concat(this.activeColumns || []) return columns.concat(this.activeColumns || [])
@ -750,7 +805,7 @@ export default {
} }
}, },
handleDialogClose (done) { handleDialogClose (done) {
if (!this.saving) {
if (!this.importBusy) {
done() done()
} }
}, },

Loading…
Cancel
Save