4 changed files with 240 additions and 2 deletions
-
14src/api/qc/Inbound_notification.js
-
41src/utils/httpRequest.js
-
32src/views/modules/qc/inboundNotification.vue
-
155src/views/modules/qc/label_import_upload.vue
@ -0,0 +1,155 @@ |
|||||
|
<template> |
||||
|
<div class="customer-css"> |
||||
|
<el-dialog :title="titleCon" :close-on-click-modal="false" :visible.sync="visible" width="420px" style="height: 520px;" class="customer-dialog"> |
||||
|
<el-form :inline="true" label-position="top" label-width="80px"> |
||||
|
<el-button type="primary" @click="downloadTemplate()">下载文件模板</el-button> |
||||
|
<el-row style="margin-top: 15px;"> |
||||
|
<el-col :span="24"> |
||||
|
<el-upload class="customer-upload" drag action="javascript:void(0);" ref="uploadFile" :limit="1" accept=".xlsx,.xls" |
||||
|
:before-upload="beforeUploadHandle" :on-change="onChange" :auto-upload="false" style="text-align: left;margin-left: 19px"> |
||||
|
<i class="el-icon-upload"></i> |
||||
|
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div> |
||||
|
<div class="el-upload__tip" slot="tip">只能上传xlsx/xls文件</div> |
||||
|
</el-upload> |
||||
|
</el-col> |
||||
|
</el-row> |
||||
|
</el-form> |
||||
|
<span slot="footer" class="dialog-footer"> |
||||
|
<el-button type="primary" :loading="importLoading" @click="saveUploadFile()">导入</el-button> |
||||
|
<el-button @click="closeDialog">关闭</el-button> |
||||
|
</span> |
||||
|
</el-dialog> |
||||
|
</div> |
||||
|
</template> |
||||
|
|
||||
|
<script> |
||||
|
import { labelImport, downloadLabelTemplate } from "@/api/qc/Inbound_notification.js" |
||||
|
|
||||
|
export default { |
||||
|
data() { |
||||
|
return { |
||||
|
titleCon: '标签导入', |
||||
|
visible: false, |
||||
|
fileList: [], |
||||
|
importLoading: false, |
||||
|
pageData: { |
||||
|
site: '', |
||||
|
buNo: '', |
||||
|
orderNo: '', |
||||
|
orderType: '', |
||||
|
orderStatus: '', |
||||
|
relatedOrderNo: '', |
||||
|
relatedOrderLineNo: '', |
||||
|
partNo: '' |
||||
|
}, |
||||
|
} |
||||
|
}, |
||||
|
methods: { |
||||
|
// 初始化组件的参数 |
||||
|
init (currentRow) { |
||||
|
this.pageData = JSON.parse(JSON.stringify(currentRow)) |
||||
|
this.fileList = [] |
||||
|
this.visible = true |
||||
|
// 清空之前上传的文件 |
||||
|
this.$nextTick(() => { |
||||
|
if (this.$refs.uploadFile) { |
||||
|
this.$refs.uploadFile.clearFiles() |
||||
|
} |
||||
|
}) |
||||
|
}, |
||||
|
|
||||
|
// 上传之前 |
||||
|
beforeUploadHandle (file) { |
||||
|
let extName = file.name.substring(file.name.lastIndexOf('.')).toLowerCase() |
||||
|
if (!(extName === '.xlsx' || extName === '.xls')) { |
||||
|
this.$message.error('数据导入失败,请选择正确的xlsx或xls模板文件') |
||||
|
return false |
||||
|
} |
||||
|
return true |
||||
|
}, |
||||
|
|
||||
|
// 选择上传文件时 |
||||
|
onChange (file, fileList) { |
||||
|
this.fileList = fileList |
||||
|
}, |
||||
|
|
||||
|
// 关闭modal |
||||
|
closeDialog () { |
||||
|
this.fileList = [] |
||||
|
if (this.$refs.uploadFile) { |
||||
|
this.$refs.uploadFile.clearFiles() |
||||
|
} |
||||
|
this.visible = false |
||||
|
}, |
||||
|
|
||||
|
// 保存上传的数据 |
||||
|
saveUploadFile () { |
||||
|
// 判断文件是否上传 |
||||
|
if (this.fileList == null || this.fileList.length === 0) { |
||||
|
this.$message.error("请先上传文件!") |
||||
|
return false |
||||
|
} |
||||
|
|
||||
|
const formData = new FormData() |
||||
|
formData.append("file", this.fileList[0].raw) |
||||
|
formData.append("site", this.pageData.site) |
||||
|
formData.append("buNo", this.pageData.buNo) |
||||
|
formData.append("orderNo", this.pageData.orderNo) |
||||
|
formData.append("orderType", this.pageData.orderType) |
||||
|
formData.append("orderStatus", this.pageData.orderStatus) |
||||
|
formData.append("relatedOrderNo", this.pageData.relatedOrderNo) |
||||
|
formData.append("relatedOrderLineNo", this.pageData.relatedOrderLineNo) |
||||
|
formData.append("partNo", this.pageData.partNo) |
||||
|
|
||||
|
this.importLoading = true |
||||
|
labelImport(formData).then(({data}) => { |
||||
|
if (data.code === 0) { |
||||
|
this.$message.success(data.msg || '导入成功') |
||||
|
// 清空文件上传记录 |
||||
|
this.$refs.uploadFile.clearFiles() |
||||
|
this.fileList = [] |
||||
|
this.visible = false |
||||
|
// 刷新父组件数据 |
||||
|
this.$emit('refreshPageTables') |
||||
|
} else { |
||||
|
this.$alert(data.msg || '导入失败', '错误', { |
||||
|
confirmButtonText: '确定', |
||||
|
dangerouslyUseHTMLString: true |
||||
|
}) |
||||
|
} |
||||
|
}).catch((error) => { |
||||
|
this.$message.error('导入失败,请检查文件格式是否正确') |
||||
|
}).finally(() => { |
||||
|
this.importLoading = false |
||||
|
}) |
||||
|
}, |
||||
|
|
||||
|
// 下载模板 |
||||
|
downloadTemplate () { |
||||
|
downloadLabelTemplate().then((response) => { |
||||
|
const blob = new Blob([response.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }) |
||||
|
const fileName = '标签导入模板.xlsx' |
||||
|
const linkNode = document.createElement('a') |
||||
|
linkNode.download = fileName |
||||
|
linkNode.style.display = 'none' |
||||
|
linkNode.href = URL.createObjectURL(blob) |
||||
|
document.body.appendChild(linkNode) |
||||
|
linkNode.click() |
||||
|
URL.revokeObjectURL(linkNode.href) |
||||
|
document.body.removeChild(linkNode) |
||||
|
}).catch((error) => { |
||||
|
this.$message.error('下载模板失败,请联系管理员') |
||||
|
}) |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
</script> |
||||
|
|
||||
|
<style scoped lang="scss"> |
||||
|
.customer-upload { |
||||
|
width: 100%; |
||||
|
} |
||||
|
/deep/ .el-upload-dragger { |
||||
|
width: 350px; |
||||
|
} |
||||
|
</style> |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue