2 changed files with 606 additions and 0 deletions
@ -0,0 +1,48 @@ |
|||
import http from '@/utils/httpRequest' |
|||
import { createAPI } from '@/utils/httpRequest.js' |
|||
|
|||
/** |
|||
* 国外 Savings 统计报表导入接口。 |
|||
* 预览 120s、保存 300s,与期初导入的超时口径保持一致的独立配置。 |
|||
*/ |
|||
|
|||
// 主页面分页查询
|
|||
export const searchSavingsReportPage = data => createAPI('/srm/srmSavingsReport/page', 'POST', data) |
|||
|
|||
// 下载 Savings 导入模板(固定 11 列表头,与 CNREPORT.xlsx 一致)
|
|||
export const downloadSavingsTemplate = () => http({ |
|||
url: http.adornUrl('/srm/srmSavingsReport/template'), |
|||
method: 'get', |
|||
responseType: 'blob' |
|||
}) |
|||
|
|||
export const previewSavingsReport = (file, site) => { |
|||
const formData = new FormData() |
|||
formData.append('file', file) |
|||
formData.append('site', site) |
|||
return http({ |
|||
url: http.adornUrl('/srm/srmSavingsReport/preview'), |
|||
method: 'post', |
|||
data: formData, |
|||
headers: { |
|||
'Content-Type': 'multipart/form-data' |
|||
}, |
|||
timeout: 120000 |
|||
}) |
|||
} |
|||
|
|||
export const countSavingsReport = (year, month) => http({ |
|||
url: http.adornUrl('/srm/srmSavingsReport/count'), |
|||
method: 'get', |
|||
params: { |
|||
year, |
|||
month |
|||
} |
|||
}) |
|||
|
|||
export const saveSavingsReport = data => http({ |
|||
url: http.adornUrl('/srm/srmSavingsReport/save'), |
|||
method: 'post', |
|||
data: http.adornData(data), |
|||
timeout: 300000 |
|||
}) |
|||
@ -0,0 +1,558 @@ |
|||
<template> |
|||
<div class="mod-srm-savings-report"> |
|||
<el-form :inline="true" label-position="top" :model="searchData"> |
|||
<el-form-item label="年份"> |
|||
<el-select v-model="searchData.year" clearable placeholder="请选择年份" style="width: 120px"> |
|||
<el-option v-for="year in yearOptions" :key="year" :label="year" :value="year" /> |
|||
</el-select> |
|||
</el-form-item> |
|||
<el-form-item label="月份"> |
|||
<el-select v-model="searchData.month" clearable placeholder="请选择月份" style="width: 120px"> |
|||
<el-option v-for="month in monthOptions" :key="month" :label="month + ' 月'" :value="month" /> |
|||
</el-select> |
|||
</el-form-item> |
|||
<el-form-item label="PO单号"> |
|||
<el-input v-model="searchData.poNumber" clearable style="width: 160px" placeholder="请输入PO单号" @keyup.enter.native="searchList" /> |
|||
</el-form-item> |
|||
<el-form-item label="供应商名称"> |
|||
<el-input v-model="searchData.vendorName" clearable style="width: 220px" placeholder="请输入供应商名称" @keyup.enter.native="searchList" /> |
|||
</el-form-item> |
|||
<el-form-item label=" "> |
|||
<el-button type="primary" size="medium" @click="searchList">查询</el-button> |
|||
<el-button type="primary" size="medium" icon="el-icon-upload2" @click="openImportDialog">导入</el-button> |
|||
</el-form-item> |
|||
</el-form> |
|||
|
|||
<el-table |
|||
:height="height" |
|||
:data="dataList" |
|||
border |
|||
v-loading="dataListLoading" |
|||
size="mini" |
|||
style="width: 100%;"> |
|||
<el-table-column prop="year" label="年份" width="80" header-align="center" align="center" /> |
|||
<el-table-column prop="month" label="月份" width="80" header-align="center" align="center" /> |
|||
<el-table-column prop="poNumber" label="PONumber" min-width="120" show-overflow-tooltip /> |
|||
<el-table-column prop="vendorName" label="VendorName" min-width="220" show-overflow-tooltip /> |
|||
<el-table-column prop="supplierNo" label="供应商编码" min-width="110" show-overflow-tooltip /> |
|||
<el-table-column prop="issuedDate" label="Issued_Date" min-width="150" header-align="center" align="center" /> |
|||
<el-table-column prop="itemCode" label="ItemCode" min-width="140" show-overflow-tooltip /> |
|||
<el-table-column prop="unitPrice" label="UnitPrice" min-width="100" header-align="center" align="right" /> |
|||
<el-table-column prop="receivedDate" label="Received_Date" min-width="150" header-align="center" align="center" /> |
|||
<el-table-column prop="needByDate" label="need_by_date" min-width="150" header-align="center" align="center" /> |
|||
<el-table-column prop="qty" label="Qty" min-width="100" header-align="center" align="right" /> |
|||
<el-table-column prop="oldPrice" label="OldPrice" min-width="100" header-align="center" align="right" /> |
|||
<el-table-column prop="variance" label="Variance" min-width="100" header-align="center" align="right" /> |
|||
<el-table-column prop="extAmount" label="ExtAmount" min-width="110" header-align="center" align="right" /> |
|||
<el-table-column prop="createBy" label="导入人" min-width="100" show-overflow-tooltip /> |
|||
<el-table-column prop="createDate" label="导入时间" min-width="150" header-align="center" align="center" /> |
|||
</el-table> |
|||
|
|||
<el-pagination |
|||
@size-change="sizeChangeHandle" |
|||
@current-change="currentChangeHandle" |
|||
:current-page="pageIndex" |
|||
:page-sizes="[20, 50, 100, 200, 500]" |
|||
:page-size="pageSize" |
|||
:total="totalPage" |
|||
layout="total, sizes, prev, pager, next, jumper" /> |
|||
|
|||
<el-dialog |
|||
title="Savings报表导入" |
|||
v-drag |
|||
:visible.sync="dialogVisible" |
|||
width="1250px" |
|||
top="5vh" |
|||
:show-close="!busy" |
|||
:close-on-click-modal="false" |
|||
:close-on-press-escape="!busy" |
|||
@closed="handleDialogClosed"> |
|||
<div class="dialog-toolbar"> |
|||
<span class="toolbar-label">年份</span> |
|||
<el-select v-model="importYear" :disabled="busy" placeholder="请选择年份" class="year-select"> |
|||
<el-option v-for="year in yearOptions" :key="year" :label="year" :value="year" /> |
|||
</el-select> |
|||
<span class="toolbar-label">月份</span> |
|||
<el-select v-model="importMonth" :disabled="busy" placeholder="请选择月份" class="month-select"> |
|||
<el-option v-for="month in monthOptions" :key="month" :label="month + ' 月'" :value="month" /> |
|||
</el-select> |
|||
<el-button |
|||
type="primary" |
|||
icon="el-icon-download" |
|||
:loading="templateDownloading" |
|||
:disabled="busy" |
|||
@click="handleDownloadTemplate"> |
|||
下载导入模板 |
|||
</el-button> |
|||
<el-upload |
|||
ref="savingsImportUpload" |
|||
action="#" |
|||
accept=".xls,.xlsx" |
|||
:auto-upload="false" |
|||
:show-file-list="false" |
|||
:limit="1" |
|||
:disabled="busy" |
|||
:on-change="handleFileChange" |
|||
:on-exceed="handleFileExceed"> |
|||
<el-button |
|||
type="primary" |
|||
icon="el-icon-upload2" |
|||
:loading="previewLoading" |
|||
:disabled="busy"> |
|||
选择导入文件 |
|||
</el-button> |
|||
</el-upload> |
|||
<span class="file-name" :title="fileName">{{ fileName || '未选择文件' }}</span> |
|||
<span v-if="invalidCount" class="invalid-hint">存在校验失败行,请修正文件后重新导入</span> |
|||
<span class="preview-count"> |
|||
已读取 {{ previewRows.length }} 行 |
|||
<span v-if="invalidCount">,其中 {{ invalidCount }} 行校验失败</span> |
|||
<span v-if="skippedCount">,{{ skippedCount }} 行未收货将跳过</span> |
|||
</span> |
|||
</div> |
|||
|
|||
<el-table |
|||
v-loading="previewLoading" |
|||
:data="previewRows" |
|||
border |
|||
height="430" |
|||
size="mini" |
|||
empty-text="请选择Excel文件进行预览" |
|||
:row-class-name="previewRowClassName" |
|||
class="savings-import-preview"> |
|||
<el-table-column |
|||
prop="validationMessage" |
|||
label="错误信息" |
|||
min-width="240" |
|||
fixed="left" |
|||
align="left" |
|||
show-overflow-tooltip /> |
|||
<el-table-column prop="excelRowNo" label="Excel行号" width="90" fixed="left" align="center" /> |
|||
<el-table-column |
|||
v-for="column in previewColumns" |
|||
:key="column.prop" |
|||
:prop="column.prop" |
|||
:label="column.label" |
|||
:min-width="column.width" |
|||
:align="column.align || 'left'" |
|||
show-overflow-tooltip /> |
|||
</el-table> |
|||
|
|||
<div slot="footer" class="dialog-footer"> |
|||
<el-button |
|||
type="primary" |
|||
icon="el-icon-check" |
|||
:loading="saving" |
|||
:disabled="saveDisabled" |
|||
@click="handleSave"> |
|||
保存 |
|||
</el-button> |
|||
<el-button :disabled="busy" @click="dialogVisible = false">关闭</el-button> |
|||
</div> |
|||
</el-dialog> |
|||
</div> |
|||
</template> |
|||
|
|||
<script> |
|||
import { |
|||
countSavingsReport, |
|||
downloadSavingsTemplate, |
|||
previewSavingsReport, |
|||
saveSavingsReport, |
|||
searchSavingsReportPage |
|||
} from '@/api/order/srmSavingsReport' |
|||
|
|||
export default { |
|||
name: 'SrmSavingsReportImport', |
|||
data () { |
|||
const currentYear = new Date().getFullYear() |
|||
return { |
|||
height: 200, |
|||
// ===== 主页面列表 ===== |
|||
searchData: { |
|||
year: '', |
|||
month: '', |
|||
poNumber: '', |
|||
vendorName: '' |
|||
}, |
|||
yearOptions: [currentYear - 4, currentYear - 3, currentYear - 2, currentYear - 1, currentYear], |
|||
monthOptions: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], |
|||
dataList: [], |
|||
dataListLoading: false, |
|||
pageIndex: 1, |
|||
pageSize: 20, |
|||
totalPage: 0, |
|||
// ===== 导入弹窗 ===== |
|||
dialogVisible: false, |
|||
importYear: currentYear, |
|||
importMonth: new Date().getMonth() + 1, |
|||
importFile: null, |
|||
fileName: '', |
|||
previewRows: [], |
|||
previewLoading: false, |
|||
saving: false, |
|||
templateDownloading: false, |
|||
previewColumns: [ |
|||
{ prop: 'poNumber', label: 'PONumber', width: 120 }, |
|||
{ prop: 'vendorName', label: 'VendorName', width: 220 }, |
|||
{ prop: 'issuedDate', label: 'Issued_Date', width: 150 }, |
|||
{ prop: 'itemCode', label: 'ItemCode', width: 140 }, |
|||
{ prop: 'unitPrice', label: 'UnitPrice', width: 100, align: 'right' }, |
|||
{ prop: 'receivedDate', label: 'Received_Date', width: 150 }, |
|||
{ prop: 'needByDate', label: 'need_by_date', width: 150 }, |
|||
{ prop: 'qty', label: 'Qty', width: 100, align: 'right' }, |
|||
{ prop: 'oldPrice', label: 'OldPrice', width: 100, align: 'right' }, |
|||
{ prop: 'variance', label: 'Variance', width: 100, align: 'right' }, |
|||
{ prop: 'extAmount', label: 'ExtAmount', width: 110, align: 'right' } |
|||
] |
|||
} |
|||
}, |
|||
computed: { |
|||
busy () { |
|||
return this.previewLoading || this.saving || this.templateDownloading |
|||
}, |
|||
invalidCount () { |
|||
return this.previewRows.filter(row => row && row.valid === false).length |
|||
}, |
|||
skippedCount () { |
|||
return this.previewRows.filter(row => row && row.valid !== false && row.skipped === true).length |
|||
}, |
|||
saveDisabled () { |
|||
return this.busy || !this.importYear || !this.importMonth || !this.previewRows.length || this.invalidCount > 0 |
|||
} |
|||
}, |
|||
created () { |
|||
this.getDataList() |
|||
}, |
|||
mounted () { |
|||
this.$nextTick(() => { |
|||
this.height = window.innerHeight - 200 |
|||
}) |
|||
}, |
|||
methods: { |
|||
// ==================== 主页面列表 ==================== |
|||
searchList () { |
|||
this.pageIndex = 1 |
|||
this.getDataList() |
|||
}, |
|||
getDataList () { |
|||
this.dataListLoading = true |
|||
const params = { |
|||
...this.searchData, |
|||
page: this.pageIndex, |
|||
limit: this.pageSize |
|||
} |
|||
searchSavingsReportPage(params).then(({ data }) => { |
|||
if (data && data.code === 0) { |
|||
const pageData = data.page |
|||
this.dataList = pageData && pageData.list ? pageData.list : [] |
|||
this.pageIndex = pageData && pageData.currPage ? pageData.currPage : 1 |
|||
this.pageSize = pageData && pageData.pageSize ? pageData.pageSize : this.pageSize |
|||
this.totalPage = pageData && pageData.totalCount ? pageData.totalCount : 0 |
|||
} else { |
|||
this.$message.error((data && data.msg) || '获取数据失败') |
|||
} |
|||
}).catch(err => { |
|||
this.$message.error((err && err.message) || '获取数据失败') |
|||
}).finally(() => { |
|||
this.dataListLoading = false |
|||
}) |
|||
}, |
|||
sizeChangeHandle (val) { |
|||
this.pageSize = val |
|||
this.pageIndex = 1 |
|||
this.getDataList() |
|||
}, |
|||
currentChangeHandle (val) { |
|||
this.pageIndex = val |
|||
this.getDataList() |
|||
}, |
|||
// ==================== 导入弹窗 ==================== |
|||
openImportDialog () { |
|||
this.dialogVisible = true |
|||
this.importYear = this.searchData.year || new Date().getFullYear() |
|||
this.importMonth = this.searchData.month || (new Date().getMonth() + 1) |
|||
this.previewRows = [] |
|||
this.clearSelectedFile() |
|||
}, |
|||
handleDialogClosed () { |
|||
this.previewRows = [] |
|||
this.previewLoading = false |
|||
this.saving = false |
|||
this.clearSelectedFile() |
|||
}, |
|||
handleFileChange (file) { |
|||
if (this.busy) { |
|||
return |
|||
} |
|||
const name = (file && file.name) || '' |
|||
if (!/\.(xls|xlsx)$/i.test(name)) { |
|||
this.$message.error('仅支持 .xls / .xlsx 格式的Excel文件') |
|||
this.clearSelectedFile() |
|||
return |
|||
} |
|||
const rawFile = file.raw || file |
|||
this.importFile = rawFile |
|||
this.fileName = name |
|||
this.previewRows = [] |
|||
this.doPreview(rawFile) |
|||
}, |
|||
handleFileExceed () { |
|||
this.$message.warning('一次只能导入一个文件,请先移除已选文件') |
|||
}, |
|||
/** |
|||
* 下载与 CNREPORT.xlsx 列结构一致的导入模板,减少表头错位导致的整单报错。 |
|||
*/ |
|||
handleDownloadTemplate () { |
|||
this.templateDownloading = true |
|||
downloadSavingsTemplate().then(response => { |
|||
const blob = new Blob([response.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }) |
|||
const url = window.URL.createObjectURL(blob) |
|||
const link = document.createElement('a') |
|||
link.href = url |
|||
link.download = 'Savings报表导入模板.xlsx' |
|||
document.body.appendChild(link) |
|||
link.click() |
|||
document.body.removeChild(link) |
|||
window.URL.revokeObjectURL(url) |
|||
}).catch(err => { |
|||
this.$message.error((err && err.message) || '模板下载失败,请稍后重试') |
|||
}).finally(() => { |
|||
this.templateDownloading = false |
|||
}) |
|||
}, |
|||
doPreview (rawFile) { |
|||
const site = this.$store.state.user.site |
|||
if (!site) { |
|||
this.$message.error('当前登录用户没有Site') |
|||
this.clearSelectedFile() |
|||
return |
|||
} |
|||
this.previewLoading = true |
|||
previewSavingsReport(rawFile, site).then(({ data }) => { |
|||
if (data.code === 0) { |
|||
this.previewRows = data.data || [] |
|||
if (this.invalidCount) { |
|||
this.$message.warning(`Excel共${this.previewRows.length}行,${this.invalidCount}行校验失败,请查看黄色行错误信息`) |
|||
} else if (this.skippedCount) { |
|||
this.$message.success(`Excel读取成功,共${this.previewRows.length}行,其中${this.skippedCount}行未收货将跳过`) |
|||
} else { |
|||
this.$message.success(`Excel读取成功,共${this.previewRows.length}行`) |
|||
} |
|||
} else { |
|||
this.showImportError(data.msg || 'Excel读取失败') |
|||
this.clearSelectedFile() |
|||
} |
|||
}).catch(error => { |
|||
const message = error && error.response && error.response.data && error.response.data.msg |
|||
? error.response.data.msg |
|||
: 'Excel读取失败,请检查文件格式' |
|||
this.showImportError(message) |
|||
this.clearSelectedFile() |
|||
}).finally(() => { |
|||
this.previewLoading = false |
|||
}) |
|||
}, |
|||
/** |
|||
* 保存流程:先查该年月是否已有数据;已有数据时让用户选择覆盖/新增(关闭弹窗则放弃导入), |
|||
* 无数据直接按新增保存。后端保存时会重新校验,不信任前端 valid。 |
|||
*/ |
|||
handleSave () { |
|||
if (this.saveDisabled) { |
|||
return |
|||
} |
|||
const site = this.$store.state.user.site |
|||
if (!site) { |
|||
this.$message.error('当前登录用户没有Site') |
|||
return |
|||
} |
|||
this.saving = true |
|||
countSavingsReport(this.importYear, this.importMonth).then(({ data }) => { |
|||
if (data.code !== 0) { |
|||
throw new Error(data.msg || '查询已有数据失败') |
|||
} |
|||
const count = data.count || 0 |
|||
if (count > 0) { |
|||
return this.chooseImportMode(count) |
|||
} |
|||
return this.doSave(site, 'append') |
|||
}).then(() => { |
|||
this.getDataList() |
|||
}).catch(error => { |
|||
if (error !== 'abort') { |
|||
this.showImportError(this.resolveErrorMessage(error, '保存失败')) |
|||
} |
|||
}).finally(() => { |
|||
this.saving = false |
|||
}) |
|||
}, |
|||
/** |
|||
* 覆盖/新增选择:确定=覆盖导入,取消按钮=新增导入,右上角关闭=放弃本次导入。 |
|||
*/ |
|||
chooseImportMode (count) { |
|||
return this.$confirm( |
|||
`${this.importYear}年${this.importMonth}月已存在 ${count} 条导入数据,请选择本次导入方式:覆盖将删除原有数据后重新导入,新增则在原有数据上追加。`, |
|||
'选择导入方式', |
|||
{ |
|||
confirmButtonText: '覆盖', |
|||
cancelButtonText: '新增', |
|||
type: 'warning', |
|||
distinguishCancellationReason: true, |
|||
customClass: 'savings-import-mode-box' |
|||
} |
|||
).then(() => { |
|||
const site = this.$store.state.user.site |
|||
return this.doSave(site, 'overwrite') |
|||
}).catch(reason => { |
|||
if (reason === 'cancel') { |
|||
const site = this.$store.state.user.site |
|||
return this.doSave(site, 'append') |
|||
} |
|||
return Promise.reject('abort') |
|||
}) |
|||
}, |
|||
doSave (site, mode) { |
|||
const payload = { |
|||
year: this.importYear, |
|||
month: this.importMonth, |
|||
mode, |
|||
site, |
|||
rows: this.previewRows |
|||
} |
|||
return saveSavingsReport(payload).then(({ data }) => { |
|||
if (data.code === 0) { |
|||
this.$message.success(`导入成功 ${data.savedCount} 条,跳过 ${data.skippedCount} 条`) |
|||
this.dialogVisible = false |
|||
} else { |
|||
return Promise.reject(new Error(data.msg || '保存失败')) |
|||
} |
|||
}) |
|||
}, |
|||
resolveErrorMessage (error, fallback) { |
|||
const responseData = error && error.response && error.response.data |
|||
if (responseData && responseData.msg) { |
|||
return responseData.msg |
|||
} |
|||
return (error && error.message) || fallback |
|||
}, |
|||
/** |
|||
* 导入失败必须弹确认框,避免 $message 几秒后消失看不清。 |
|||
*/ |
|||
showImportError (message) { |
|||
const text = message || '操作失败' |
|||
const content = this.$createElement( |
|||
'div', |
|||
{ style: { maxHeight: '360px', overflowY: 'auto', whiteSpace: 'pre-wrap', wordBreak: 'break-all', lineHeight: '1.6', textAlign: 'left' } }, |
|||
text |
|||
) |
|||
this.$alert(content, 'Savings报表导入提示', { |
|||
confirmButtonText: '确定', |
|||
type: 'error', |
|||
customClass: 'savings-import-error-alert' |
|||
}).catch(() => {}) |
|||
}, |
|||
previewRowClassName ({ row }) { |
|||
if (row && row.valid === false) { |
|||
return 'savings-import-warning-row' |
|||
} |
|||
if (row && row.skipped === true) { |
|||
return 'savings-import-skipped-row' |
|||
} |
|||
return '' |
|||
}, |
|||
clearSelectedFile () { |
|||
this.fileName = '' |
|||
this.importFile = null |
|||
if (this.$refs.savingsImportUpload) { |
|||
this.$refs.savingsImportUpload.clearFiles() |
|||
} |
|||
} |
|||
} |
|||
} |
|||
</script> |
|||
|
|||
<style scoped> |
|||
.mod-srm-savings-report /deep/ .cell { |
|||
height: auto; |
|||
line-height: 1.5; |
|||
} |
|||
|
|||
.dialog-toolbar { |
|||
display: flex; |
|||
align-items: center; |
|||
flex-wrap: wrap; |
|||
min-height: 40px; |
|||
margin-bottom: 12px; |
|||
gap: 10px; |
|||
} |
|||
|
|||
.toolbar-label { |
|||
color: #606266; |
|||
font-size: 13px; |
|||
} |
|||
|
|||
.year-select { |
|||
width: 110px; |
|||
} |
|||
|
|||
.month-select { |
|||
width: 110px; |
|||
} |
|||
|
|||
.file-name { |
|||
display: inline-block; |
|||
max-width: 260px; |
|||
overflow: hidden; |
|||
color: #606266; |
|||
text-overflow: ellipsis; |
|||
white-space: nowrap; |
|||
} |
|||
|
|||
.invalid-hint { |
|||
color: #e6a23c; |
|||
font-size: 13px; |
|||
} |
|||
|
|||
.preview-count { |
|||
margin-left: auto; |
|||
color: #606266; |
|||
font-variant-numeric: tabular-nums; |
|||
} |
|||
|
|||
.savings-import-preview { |
|||
width: 100%; |
|||
} |
|||
|
|||
.savings-import-preview /deep/ .savings-import-warning-row > td { |
|||
background-color: #fff7d6 !important; |
|||
} |
|||
|
|||
.savings-import-preview /deep/ .savings-import-warning-row:hover > td { |
|||
background-color: #fff0b3 !important; |
|||
} |
|||
|
|||
.savings-import-preview /deep/ .savings-import-skipped-row > td { |
|||
background-color: #f0f0f0 !important; |
|||
color: #909399; |
|||
} |
|||
|
|||
.savings-import-preview /deep/ .savings-import-skipped-row:hover > td { |
|||
background-color: #e8e8e8 !important; |
|||
} |
|||
|
|||
.dialog-footer { |
|||
text-align: right; |
|||
} |
|||
</style> |
|||
|
|||
<style> |
|||
/* MessageBox 挂到 body,不能写 scoped,否则超长错误信息会撑破弹框。 */ |
|||
.savings-import-error-alert .el-message-box__message { |
|||
max-height: 360px; |
|||
overflow-y: auto; |
|||
white-space: pre-wrap; |
|||
word-break: break-all; |
|||
line-height: 1.6; |
|||
text-align: left; |
|||
} |
|||
</style> |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue