3 changed files with 643 additions and 1 deletions
-
11src/api/ecss/ecss.js
-
412src/views/modules/ecss/codelnotify.vue
-
221src/views/modules/ecss/upc_upload_excel.vue
@ -0,0 +1,221 @@ |
|||
<template> |
|||
<div class="customer-css"> |
|||
<el-dialog title="UPC导入" :close-on-click-modal="false" :visible.sync="visible" width="390px" style="height: 520px;" class="customer-dialog" @close="deleteFile"> |
|||
<el-form :inline="true" label-position="top" label-width="80px"> |
|||
<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" style="text-align: left;"> |
|||
<i class="el-icon-upload"></i> |
|||
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div> |
|||
</el-upload> |
|||
</el-col> |
|||
</el-row> |
|||
<el-row style="margin-top: 10px;"> |
|||
<el-col :span="24"> |
|||
<el-alert |
|||
title="导入说明" |
|||
type="info" |
|||
description="发票号需与当前选中的发货通知单发票号一致" |
|||
:closable="false" |
|||
show-icon> |
|||
</el-alert> |
|||
</el-col> |
|||
</el-row> |
|||
</el-form> |
|||
<span slot="footer" class="dialog-footer"> |
|||
<el-button type="primary" :loading="saveLoading" :disabled="saveLoading" @click="saveUploadFile">保存</el-button> |
|||
<el-button type="primary" @click="closeDialog">关闭</el-button> |
|||
</span> |
|||
</el-dialog> |
|||
</div> |
|||
</template> |
|||
|
|||
<script> |
|||
import {queryFileId} from "@/api/qc/qc.js" |
|||
import {importUpcData} from '@/api/ecss/ecss.js' |
|||
import {downLoadObjectFile} from '@/api/eam/eam_object_list.js' |
|||
import {getBuList}from '@/api/factory/site.js' |
|||
|
|||
export default { |
|||
name: 'upcUploadExcel', |
|||
data() { |
|||
return { |
|||
buList: [], |
|||
visible: false, |
|||
fileList: [], |
|||
saveLoading: false, |
|||
pageData: { |
|||
site: '', |
|||
buNo: '', |
|||
cmcInvoice: '', |
|||
createBy: this.$store.state.user.name, |
|||
}, |
|||
} |
|||
}, |
|||
methods: { |
|||
/** |
|||
* 初始化组件参数 |
|||
* @param {Object} inData - 当前行数据,包含 cmcInvoice 等信息 |
|||
*/ |
|||
init (inData) { |
|||
this.fileList = [] |
|||
let tempData = { |
|||
username: this.$store.state.user.name, |
|||
} |
|||
this.pageData.buNo = inData.buNo |
|||
this.pageData.cmcInvoice = inData.cmcInvoice |
|||
this.pageData.site = inData.site || this.$store.state.user.site |
|||
|
|||
getBuList(tempData).then(({data}) => { |
|||
if (data.code === 0) { |
|||
this.buList = data.row2 |
|||
if(data.row2.length === 1){ |
|||
this.pageData.buNo = data.row2[0].buNo |
|||
} |
|||
} |
|||
}) |
|||
|
|||
// 打开对话框 |
|||
this.visible = true |
|||
}, |
|||
|
|||
/** |
|||
* 上传之前的验证 |
|||
*/ |
|||
beforeUploadHandle (file) { |
|||
let extName = file[0].name.substring(file[0].name.lastIndexOf('.')).toLowerCase() |
|||
if (!(extName === '.xlsx' || extName === '.xls')) { |
|||
this.$message.error('数据导入失败,请选择正确的xlsx模板文件') |
|||
return false |
|||
} |
|||
}, |
|||
|
|||
/** |
|||
* 选择上传文件时 |
|||
*/ |
|||
onChange (file) { |
|||
this.fileList.push(file) |
|||
}, |
|||
|
|||
/** |
|||
* 关闭对话框 |
|||
*/ |
|||
closeDialog () { |
|||
this.deleteFile() |
|||
this.visible = false |
|||
}, |
|||
|
|||
/** |
|||
* 清空文件 |
|||
*/ |
|||
deleteFile(){ |
|||
this.fileList = [] |
|||
// 清空文件上传记录 |
|||
this.$refs.uploadFile.clearFiles() |
|||
// 刷新页面 |
|||
this.$emit('refreshTable') |
|||
}, |
|||
|
|||
/** |
|||
* 保存上传的文件 |
|||
*/ |
|||
saveUploadFile () { |
|||
// 判断文件是否上传 |
|||
if (null == this.fileList || 0 === this.fileList.length) { |
|||
this.$message.error("请先上传文件!") |
|||
return false |
|||
} |
|||
|
|||
// 验证是否选择了发货通知单 |
|||
if (!this.pageData.cmcInvoice) { |
|||
this.$message.error("请先选择一个发货通知单!") |
|||
return false |
|||
} |
|||
|
|||
this.saveLoading = true |
|||
const formData = new FormData() |
|||
formData.append("site", this.pageData.site) |
|||
formData.append("buNo", this.pageData.buNo) |
|||
formData.append("cmcInvoice", this.pageData.cmcInvoice) |
|||
formData.append("username", this.$store.state.user.name) |
|||
formData.append("file", this.fileList[0].raw) |
|||
|
|||
importUpcData(formData).then(({data}) => { |
|||
if (data.code === 0) { |
|||
this.$message.success(data.msg || 'UPC数据导入成功') |
|||
// 关闭窗口并刷新页面 |
|||
this.closeDialog() |
|||
} else { |
|||
this.$alert(data.msg || '导入失败', '错误', { |
|||
confirmButtonText: '确定' |
|||
}) |
|||
} |
|||
}).catch((error) => { |
|||
console.error('UPC导入失败:', error) |
|||
this.$message.error('导入失败,请重试') |
|||
}).finally(() => { |
|||
this.saveLoading = false |
|||
}) |
|||
}, |
|||
|
|||
/** |
|||
* 下载UPC导入模板 |
|||
*/ |
|||
async downloadFile () { |
|||
let file = { |
|||
id: 0, |
|||
fileName: '' |
|||
} |
|||
let tempData = { |
|||
orderRef1: 'ecss', |
|||
orderRef2: 'upcImportTemplate' |
|||
} |
|||
|
|||
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: '确定' |
|||
}) |
|||
return |
|||
} |
|||
}) |
|||
|
|||
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) |
|||
}).catch(() => { |
|||
this.$message.error('模板下载失败') |
|||
}) |
|||
}, |
|||
} |
|||
} |
|||
</script> |
|||
|
|||
<style scoped> |
|||
.customer-css { |
|||
/* 自定义样式 */ |
|||
} |
|||
|
|||
.el-alert { |
|||
font-size: 12px; |
|||
} |
|||
</style> |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue