4 changed files with 276 additions and 5 deletions
-
4src/api/orderIssure/noOrderIssueNotify.js
-
92src/views/modules/noOrderIssue/newNoOrderIssueNotify.vue
-
1src/views/modules/noOrderIssue/noOrderNotification.vue
-
184src/views/modules/noOrderIssue/noorder_upload_excel.vue
@ -0,0 +1,184 @@ |
|||
<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" @click="downloadFile()" :disabled="uploading">下载文件模板</el-button>--> |
|||
<a href="/static/downLoad/NotifyUploadModel.xlsx" download="领料申请单导入模板.xlsx"> |
|||
下载 Excel 模板 |
|||
</a> |
|||
</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;"> |
|||
<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 { uploadNoorderNotifyExcel } 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, // 上传状态标志 |
|||
} |
|||
}, |
|||
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 |
|||
}, |
|||
|
|||
// 选择上传文件时 |
|||
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.uploading = false // 重置上传状态 |
|||
// 清空文件上传记录 |
|||
this.$refs.uploadFile.clearFiles() |
|||
// 刷新报工的页面 |
|||
this.$emit('refreshTable') |
|||
}, |
|||
|
|||
// 保存当前的数据 |
|||
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对象 |
|||
const formData = new FormData() |
|||
formData.append("file", file) |
|||
formData.append("site", this.notifyData.site) |
|||
formData.append("notifyNo", this.notifyData.notifyNo) |
|||
|
|||
// 调用新的上传接口 |
|||
uploadNoorderNotifyExcel(formData).then(({ data }) => { |
|||
if (data.code === 0) { |
|||
this.$message.success(data.msg || 'Excel文件上传成功') |
|||
// 关闭窗口并刷新页面 |
|||
this.closeDialog() |
|||
} else { |
|||
this.$message.error(data.msg || 'Excel文件上传失败') |
|||
} |
|||
}).catch(error => { |
|||
console.error('Excel上传异常:', error) |
|||
this.$message.error('Excel文件上传异常,请检查文件格式和内容') |
|||
}).finally(() => { |
|||
// 无论成功还是失败,都重置上传状态 |
|||
this.uploading = false |
|||
}) |
|||
}, |
|||
|
|||
// 下载模板文件 |
|||
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> |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue