4 changed files with 389 additions and 37 deletions
-
5src/api/orderIssure/noOrderIssueNotify.js
-
211src/views/modules/noOrderIssue/baofei_upload_excel.vue
-
210src/views/modules/noOrderIssue/newNoOrderIssueNotify.vue
-
BINstatic/downLoad/报废领料模板.xlsx
@ -0,0 +1,211 @@ |
|||||
|
<template> |
||||
|
<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="handleDialogClose" :show-close="!uploading"> |
||||
|
<el-form :inline="true" label-position="top" label-width="80px"> |
||||
|
<el-row> |
||||
|
<el-form-item label=" "> |
||||
|
<el-button |
||||
|
type="primary" |
||||
|
icon="el-icon-download" |
||||
|
:disabled="uploading" |
||||
|
@click="downloadPartNoTemplate"> |
||||
|
下载报废模板 |
||||
|
</el-button> |
||||
|
</el-form-item> |
||||
|
</el-row> |
||||
|
<el-row> |
||||
|
<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" :disabled="uploading" style="text-align: left;" :file-list="fileList"> |
||||
|
<i class="el-icon-upload"></i> |
||||
|
<div class="el-upload__text"> |
||||
|
{{ uploading ? '正在上传中,请稍候...' : '将文件拖到此处,或点击上传' }} |
||||
|
</div> |
||||
|
</el-upload> |
||||
|
</el-col> |
||||
|
</el-row> |
||||
|
</el-form> |
||||
|
<span slot="footer" class="dialog-footer"> |
||||
|
<el-button type="primary" @click="saveUploadFile" :loading="uploading" :disabled="uploading"> |
||||
|
{{ uploading ? '上传中...' : '保存' }} |
||||
|
</el-button> |
||||
|
<el-button type="primary" @click="closeDialog" :disabled="uploading">关闭</el-button> |
||||
|
</span> |
||||
|
</el-dialog> |
||||
|
</div> |
||||
|
</template> |
||||
|
|
||||
|
<script> |
||||
|
import { uploadBaoFeiExcel } from '@/api/orderIssure/noOrderIssueNotify.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, // 上传状态标志 |
||||
|
returnData: '', // 返回的数据 |
||||
|
partNoloading: false, // 物料模板下载状态 |
||||
|
} |
||||
|
}, |
||||
|
methods: { |
||||
|
|
||||
|
// 初始化组件的参数 |
||||
|
init (data) { |
||||
|
this.fileList = [] |
||||
|
this.uploading = false // 重置上传状态 |
||||
|
console.log("init data",this.fileList); |
||||
|
|
||||
|
// 打开页面 |
||||
|
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 |
||||
|
}, |
||||
|
|
||||
|
// 选择上传文件时 |
||||
|
onChange (file) { |
||||
|
// 清空之前的文件列表,确保只有一个文件 |
||||
|
this.fileList = [] |
||||
|
this.fileList.push(file) |
||||
|
}, |
||||
|
|
||||
|
// 关闭modal |
||||
|
closeDialog () { |
||||
|
// 如果正在上传,不允许关闭 |
||||
|
if (this.uploading) { |
||||
|
this.$message.warning('正在上传中,请稍候...') |
||||
|
return false |
||||
|
} |
||||
|
this.deleteFile() |
||||
|
// 关闭当前的页面 |
||||
|
this.visible = false |
||||
|
}, |
||||
|
|
||||
|
// 处理弹窗关闭事件(包括右上角X按钮) |
||||
|
handleDialogClose () { |
||||
|
if (this.uploading) { |
||||
|
this.$message.warning('正在上传中,请稍候...') |
||||
|
return |
||||
|
} |
||||
|
this.deleteFile() |
||||
|
}, |
||||
|
|
||||
|
deleteFile(){ |
||||
|
this.fileList = [] |
||||
|
this.visible = false |
||||
|
this.uploading = false // 重置上传状态 |
||||
|
// 清空文件上传记录 |
||||
|
this.$refs.uploadFile.clearFiles() |
||||
|
// 刷新报工的页面 |
||||
|
}, |
||||
|
successCallback(){ |
||||
|
this.fileList = [] |
||||
|
this.visible = false |
||||
|
this.uploading = false // 重置上传状态 |
||||
|
this.$emit('refreshTable',this.returnData) |
||||
|
}, |
||||
|
|
||||
|
// 保存当前的数据 |
||||
|
saveUploadFile () { |
||||
|
// 判断文件是否上传 |
||||
|
if (null == this.fileList || 0 === this.fileList.length) { |
||||
|
this.$message.error("请先上传文件!") |
||||
|
return false |
||||
|
} |
||||
|
|
||||
|
// 再次校验文件格式 |
||||
|
const file = this.fileList[0].raw |
||||
|
const fileName = file.name |
||||
|
const fileExtension = fileName.substring(fileName.lastIndexOf('.')).toLowerCase() |
||||
|
|
||||
|
if (!('.xls' === fileExtension || '.xlsx' === fileExtension)) { |
||||
|
this.$message.error('文件格式不正确,只支持.xls和.xlsx格式的Excel文件') |
||||
|
return false |
||||
|
} |
||||
|
|
||||
|
// 设置上传状态 |
||||
|
this.uploading = true |
||||
|
|
||||
|
// 创建FormData对象 - rqrq |
||||
|
const formData = new FormData() |
||||
|
formData.append("file", file) |
||||
|
formData.append("site", this.notifyData.site) |
||||
|
|
||||
|
// 调用报废Excel上传接口 - rqrq |
||||
|
uploadBaoFeiExcel(formData).then(({ data }) => { |
||||
|
if (data.code === 0) { |
||||
|
this.returnData = data.rows |
||||
|
this.$message.success(data.msg || 'Excel文件上传成功') |
||||
|
// 关闭窗口并刷新页面 |
||||
|
this.successCallback() |
||||
|
} else { |
||||
|
this.$message.error(data.msg || 'Excel文件上传失败') |
||||
|
} |
||||
|
}).catch(error => { |
||||
|
console.error('Excel上传异常:', error) |
||||
|
this.$message.error('Excel文件上传异常,请检查文件格式和内容') |
||||
|
}).finally(() => { |
||||
|
// 无论成功还是失败,都重置上传状态 |
||||
|
this.uploading = false |
||||
|
}) |
||||
|
}, |
||||
|
downloadPartNoTemplate() { |
||||
|
const loading = this.$loading({ |
||||
|
lock: true, |
||||
|
text: '正在下载模板...', |
||||
|
spinner: 'el-icon-loading', |
||||
|
background: 'rgba(0, 0, 0, 0.7)' |
||||
|
}) |
||||
|
|
||||
|
this.$http({ |
||||
|
url: this.$http.adornUrl('/orderIssure/issureNotify/downloadBaoFeiTemplate'), |
||||
|
method: 'get', |
||||
|
responseType: 'blob' |
||||
|
}).then(response => { |
||||
|
loading.close() |
||||
|
|
||||
|
// 创建下载链接 |
||||
|
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 = '报废Excel模板.xlsx' |
||||
|
document.body.appendChild(link) |
||||
|
link.click() |
||||
|
document.body.removeChild(link) |
||||
|
window.URL.revokeObjectURL(url) |
||||
|
|
||||
|
this.$message.success('模板下载成功') |
||||
|
}).catch(error => { |
||||
|
loading.close() |
||||
|
console.error('模板下载失败:', error) |
||||
|
this.$message.error('模板下载失败,请联系管理员') |
||||
|
}) |
||||
|
}, |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
</script> |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue