3 changed files with 153 additions and 121 deletions
-
3src/api/orderIssure/soIssueNotify.js
-
6src/views/modules/orderIssure/newSoIssueNotify.vue
-
265src/views/modules/orderIssure/walmart_upload_excel.vue
@ -1,156 +1,181 @@ |
|||||
<template> |
<template> |
||||
<div class="customer-css"> |
<div class="customer-css"> |
||||
<el-dialog :title="titleCon" :close-on-click-modal="false" :visible.sync="visible" width="390px" style="height: 520px;" class="customer-dialog" @close="deleteFile"> |
|
||||
|
<el-dialog :title="titleCon" :close-on-click-modal="false" :visible.sync="visible" width="390px" style="height: 520px;" class="customer-dialog" @close="handleDialogClose" :show-close="!uploading"> |
||||
<el-form :inline="true" label-position="top" label-width="80px"> |
<el-form :inline="true" label-position="top" label-width="80px"> |
||||
<el-row> |
<el-row> |
||||
<el-form-item label=" "> |
<el-form-item label=" "> |
||||
<el-button type="primary" @click="downloadFile()">下载文件模板</el-button> |
|
||||
|
<el-button type="primary" @click="downloadFile()" :disabled="uploading">下载文件模板</el-button> |
||||
</el-form-item> |
</el-form-item> |
||||
</el-row> |
</el-row> |
||||
<el-row> |
<el-row> |
||||
<el-col :span="24"> |
<el-col :span="24"> |
||||
<el-upload class="customer-upload" drag action="javascript:void(0);" ref="uploadFile" :limit="1" accept=".xlsx,.xls" |
<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;"> |
|
||||
|
:before-upload="beforeUploadHandle" :on-change="onChange" :auto-upload="false" :disabled="uploading" style="text-align: left;"> |
||||
<i class="el-icon-upload"></i> |
<i class="el-icon-upload"></i> |
||||
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div> |
|
||||
|
<div class="el-upload__text"> |
||||
|
{{ uploading ? '正在上传中,请稍候...' : '将文件拖到此处,或点击上传' }} |
||||
|
</div> |
||||
</el-upload> |
</el-upload> |
||||
</el-col> |
</el-col> |
||||
</el-row> |
</el-row> |
||||
</el-form> |
</el-form> |
||||
<span slot="footer" class="dialog-footer"> |
<span slot="footer" class="dialog-footer"> |
||||
<el-button type="primary" @click="saveUploadFile">保存</el-button> |
|
||||
<el-button type="primary" @click="closeDialog">关闭</el-button> |
|
||||
|
<el-button type="primary" @click="saveUploadFile" :loading="uploading" :disabled="uploading"> |
||||
|
{{ uploading ? '上传中...' : '保存' }} |
||||
|
</el-button> |
||||
|
<el-button type="primary" @click="closeDialog" :disabled="uploading">关闭</el-button> |
||||
</span> |
</span> |
||||
</el-dialog> |
</el-dialog> |
||||
</div> |
</div> |
||||
</template> |
</template> |
||||
|
|
||||
<script> |
<script> |
||||
/* import {queryFileId} from "@/api/qc/qc.js" |
|
||||
import {saveWalMartOrderByExcel} from '@/api/ecss/ecss.js' |
|
||||
import {downLoadObjectFile} from '@/api/eam/eam_object_list.js' */ |
|
||||
import {saveIssureNotifyByExcel} from '@/api/orderIssure/soIssueNotify.js' |
|
||||
export default { |
|
||||
name: 'bomComponentUpload', |
|
||||
data() { |
|
||||
return { |
|
||||
buList: [], |
|
||||
titleCon: '文件导入', |
|
||||
visible: false, |
|
||||
fileList: [], |
|
||||
pageData: { |
|
||||
site: '', |
|
||||
buNo: '', |
|
||||
createBy: this.$store.state.user.name, |
|
||||
|
import { uploadNotifyExcel } from '@/api/orderIssure/soIssueNotify.js' |
||||
|
|
||||
}, |
|
||||
|
export default { |
||||
|
name: 'bomComponentUpload', |
||||
|
data() { |
||||
|
return { |
||||
|
buList: [], |
||||
|
titleCon: '文件导入', |
||||
|
visible: false, |
||||
|
fileList: [], |
||||
|
pageData: { |
||||
|
site: '', |
||||
|
buNo: '', |
||||
|
createBy: this.$store.state.user.name, |
||||
|
}, |
||||
|
notifyData:{ |
||||
|
site: '', |
||||
|
notifyNo: '', |
||||
|
}, |
||||
|
uploading: false, // 上传状态标志 |
||||
|
} |
||||
|
}, |
||||
|
methods: { |
||||
|
|
||||
|
// 初始化组件的参数 |
||||
|
init (data) { |
||||
|
this.fileList = [] |
||||
|
this.uploading = false // 重置上传状态 |
||||
|
// 打开页面 |
||||
|
this.visible = true |
||||
|
this.notifyData=JSON.parse(JSON.stringify(data)) |
||||
|
}, |
||||
|
|
||||
|
// 上传之前 |
||||
|
beforeUploadHandle (file) { |
||||
|
let extName = file.name.substring(file.name.lastIndexOf('.')).toLowerCase() |
||||
|
if (!(extName === '.xlsx' || extName === '.xls')) { |
||||
|
this.$message.error('数据导入失败,请选择正确的xlsx或xls格式的Excel文件') |
||||
|
return false |
||||
} |
} |
||||
|
return true |
||||
}, |
}, |
||||
methods: { |
|
||||
|
|
||||
// 初始化组件的参数 |
|
||||
init () { |
|
||||
this.fileList = [] |
|
||||
// 打开页面 |
|
||||
this.visible = true |
|
||||
}, |
|
||||
|
// 选择上传文件时 |
||||
|
onChange (file) { |
||||
|
// 清空之前的文件列表,确保只有一个文件 |
||||
|
this.fileList = [] |
||||
|
this.fileList.push(file) |
||||
|
}, |
||||
|
|
||||
// 上传之前 |
|
||||
beforeUploadHandle (file) { |
|
||||
let extName = file[0].name.substring(file[0].name.lastIndexOf('.')).toLowerCase() |
|
||||
if (!(extName === '.xlsx' || extName === '.xls')) { |
|
||||
this.$message.error('数据导入失败,请选择正确的xlsx模板文件') |
|
||||
return false |
|
||||
} |
|
||||
}, |
|
||||
|
// 关闭modal |
||||
|
closeDialog () { |
||||
|
// 如果正在上传,不允许关闭 |
||||
|
if (this.uploading) { |
||||
|
this.$message.warning('正在上传中,请稍候...') |
||||
|
return false |
||||
|
} |
||||
|
this.deleteFile() |
||||
|
// 关闭当前的页面 |
||||
|
this.visible = false |
||||
|
}, |
||||
|
|
||||
// 选择上传文件时 |
|
||||
onChange (file) { |
|
||||
this.fileList.push(file) |
|
||||
}, |
|
||||
|
// 处理弹窗关闭事件(包括右上角X按钮) |
||||
|
handleDialogClose () { |
||||
|
if (this.uploading) { |
||||
|
this.$message.warning('正在上传中,请稍候...') |
||||
|
return |
||||
|
} |
||||
|
this.deleteFile() |
||||
|
}, |
||||
|
|
||||
// 关闭modal |
|
||||
closeDialog () { |
|
||||
this.deleteFile() |
|
||||
// 关闭当前的页面 |
|
||||
this.visible = false |
|
||||
}, |
|
||||
deleteFile(){ |
|
||||
this.fileList = [] |
|
||||
// 清空文件上传记录 |
|
||||
this.$refs.uploadFile.clearFiles() |
|
||||
// 刷新报工的页面 |
|
||||
this.$emit('refreshTable') |
|
||||
|
deleteFile(){ |
||||
|
this.fileList = [] |
||||
|
this.uploading = false // 重置上传状态 |
||||
|
// 清空文件上传记录 |
||||
|
this.$refs.uploadFile.clearFiles() |
||||
|
// 刷新报工的页面 |
||||
|
this.$emit('refreshTable') |
||||
|
}, |
||||
|
|
||||
}, |
|
||||
|
// 保存当前的数据 |
||||
|
saveUploadFile () { |
||||
|
// 判断文件是否上传 |
||||
|
if (null == this.fileList || 0 === this.fileList.length) { |
||||
|
this.$message.error("请先上传文件!") |
||||
|
return false |
||||
|
} |
||||
|
|
||||
// 保修当前的数据 |
|
||||
saveUploadFile () { |
|
||||
// 判断文件是否上传 |
|
||||
if (null == this.fileList || 0 === this.fileList.length) { |
|
||||
this.$message.error("请先上传文件!") |
|
||||
return false |
|
||||
} |
|
||||
const formData = new FormData() |
|
||||
formData.append("buNo",'03-RFID') |
|
||||
formData.append("username",this.$store.state.user.name) |
|
||||
formData.append("file", this.fileList[0].raw) |
|
||||
saveIssureNotifyByExcel(formData).then(({data}) => { |
|
||||
if (data.code === 0) { |
|
||||
if (data.errorMsg) { |
|
||||
this.$message.warning(data.errorMsg) |
|
||||
} else { |
|
||||
this.$message.success(data.msg) |
|
||||
} |
|
||||
// 关闭窗口并刷新页面 |
|
||||
this.closeDialog() |
|
||||
} else { |
|
||||
this.$message.error(data.msg) |
|
||||
} |
|
||||
}) |
|
||||
}, |
|
||||
|
// 再次校验文件格式 |
||||
|
const file = this.fileList[0].raw |
||||
|
const fileName = file.name |
||||
|
const fileExtension = fileName.substring(fileName.lastIndexOf('.')).toLowerCase() |
||||
|
|
||||
// 下载 |
|
||||
async downloadFile () { |
|
||||
let file = { |
|
||||
id: 0, |
|
||||
fileName: '' |
|
||||
} |
|
||||
let tempData = { |
|
||||
orderRef1: 'ecss', |
|
||||
orderRef2: 'upLoadWalMart' |
|
||||
|
if (!('.xls' === fileExtension || '.xlsx' === fileExtension)) { |
||||
|
this.$message.error('文件格式不正确,只支持.xls和.xlsx格式的Excel文件') |
||||
|
return false |
||||
|
} |
||||
|
|
||||
|
// 设置上传状态 |
||||
|
this.uploading = true |
||||
|
|
||||
|
// 创建FormData对象 |
||||
|
const formData = new FormData() |
||||
|
formData.append("file", file) |
||||
|
formData.append("site", this.notifyData.site) |
||||
|
formData.append("notifyNo", this.notifyData.notifyNo) |
||||
|
|
||||
|
// 调用新的上传接口 |
||||
|
uploadNotifyExcel(formData).then(({ data }) => { |
||||
|
if (data.code === 0) { |
||||
|
this.$message.success(data.msg || 'Excel文件上传成功') |
||||
|
// 关闭窗口并刷新页面 |
||||
|
this.closeDialog() |
||||
|
} else { |
||||
|
this.$message.error(data.msg || 'Excel文件上传失败') |
||||
} |
} |
||||
await queryFileId(tempData).then(({data}) => { |
|
||||
if (data && data.code === 0) { |
|
||||
file.id = data.data.id |
|
||||
file.fileName = data.data.fileName |
|
||||
} else { |
|
||||
this.$alert(data.msg, '错误', { |
|
||||
confirmButtonText: '确定' |
|
||||
}) |
|
||||
} |
|
||||
}) |
|
||||
|
}).catch(error => { |
||||
|
console.error('Excel上传异常:', error) |
||||
|
this.$message.error('Excel文件上传异常,请检查文件格式和内容') |
||||
|
}).finally(() => { |
||||
|
// 无论成功还是失败,都重置上传状态 |
||||
|
this.uploading = false |
||||
|
}) |
||||
|
}, |
||||
|
|
||||
await downLoadObjectFile(file).then(({data}) => { |
|
||||
// 不限制文件下载类型 |
|
||||
const blob = new Blob([data], {type: "application/octet-stream"}) |
|
||||
// 下载文件名称 |
|
||||
const fileName = file.fileName |
|
||||
// a标签下载 |
|
||||
const linkNode = document.createElement('a') |
|
||||
// a标签的download属性规定下载文件的名称 |
|
||||
linkNode.download = fileName |
|
||||
linkNode.style.display = 'none' |
|
||||
// 生成一个Blob URL |
|
||||
linkNode.href = URL.createObjectURL(blob) |
|
||||
document.body.appendChild(linkNode) |
|
||||
// 模拟在按钮上的一次鼠标单击 |
|
||||
linkNode.click() |
|
||||
// 释放URL 对象 |
|
||||
URL.revokeObjectURL(linkNode.href) |
|
||||
document.body.removeChild(linkNode) |
|
||||
}) |
|
||||
}, |
|
||||
} |
|
||||
|
// 下载模板文件 |
||||
|
async downloadFile () { |
||||
|
// 这里可以根据需要实现模板下载功能 |
||||
|
// 暂时提示用户模板格式 |
||||
|
this.$alert( |
||||
|
'模板格式说明:\n' + |
||||
|
'第1列:工厂编码(site)\n' + |
||||
|
'第2列:订单号(orderNo)\n' + |
||||
|
'第3列:发布号(releaseNo)\n' + |
||||
|
'第4列:序列号(sequenceNo)\n' + |
||||
|
'第5列:BOM行号(bomLineNo,必须为正整数)\n' + |
||||
|
'第6列:物料编码(materialPartNo)\n' + |
||||
|
'第7列:需求日期(needDate,格式:YYYY-MM-DD)\n' + |
||||
|
'第8列:数量(qty,必须为数字)', |
||||
|
'模板格式说明', |
||||
|
{ |
||||
|
confirmButtonText: '确定', |
||||
|
type: 'info' |
||||
|
} |
||||
|
) |
||||
|
}, |
||||
} |
} |
||||
|
} |
||||
</script> |
</script> |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue