Browse Source

hscode属性导入

java8
han\hanst 1 month ago
parent
commit
cab42d53cd
  1. 3
      src/api/ecss/ecss.js
  2. 19
      src/views/modules/ecss/partHsCode.vue
  3. 259
      src/views/modules/ecss/partHsCodeImport.vue

3
src/api/ecss/ecss.js

@ -144,5 +144,8 @@ export const downloadAllPdf = data => createAPI(`/ecss/coDel/downloadAllPdf`,'po
// 获取物料包装属性(每卷数量、每箱卷数、箱重量)
export const getPartPackageProperties = data => createAPI(`/ecss/coDel/getPartPackageProperties`,'post',data)
// 导入物料包装属性(每卷数量、每箱卷数、每卷重量、箱重量、箱类型)
export const importPartPackageProperties = data => createAPI(`/ecss/coDel/importPartPackageProperties`,'post',data)

19
src/views/modules/ecss/partHsCode.vue

@ -44,6 +44,7 @@
<el-form-item :label="' '">
<el-button @click="searchTable">查询</el-button>
<!-- <el-button type="primary" @click="delModal()">删除</el-button>-->
<el-button type="primary" @click="openImportDialog">导入</el-button>
<download-excel
:fields="fields()"
:data="exportData"
@ -304,6 +305,9 @@
</el-footer>
</el-dialog>
<!-- 导入弹窗 -->
<part-hs-code-import ref="partHsCodeImport" @refreshTable="searchTable"></part-hs-code-import>
</div>
</template>
@ -315,10 +319,12 @@
import {} from "@/api/sysLanguage.js"
import {getBuList}from '@/api/factory/site.js'
import orderAttribute from "./orderProperties"
import partHsCodeImport from "./partHsCodeImport"
export default {
name: "null",
components:{
orderAttribute,
partHsCodeImport,
},
data() {
return {
@ -852,7 +858,12 @@
if(this.currentRow===''||this.currentRow===null){
this.currentRow={site:'',partNo:'',buNo:'',recordType:''}
}
//
if (this.activeName === 'attribute' && this.$refs.dialogAttribute) {
this.$nextTick(() => {
this.$refs.dialogAttribute.getProperties()
})
}
},
async createExportData () {
this.searchData.limit = -1
@ -890,6 +901,12 @@
}
})
},
/**
* 打开导入弹窗
*/
openImportDialog() {
this.$refs.partHsCodeImport.init()
},
hsCodeModel(row){
this.hsCodeModelData=JSON.parse(JSON.stringify(row))
this.hsCodeModelFlag=true

259
src/views/modules/ecss/partHsCodeImport.vue

@ -0,0 +1,259 @@
<template>
<div class="customer-css">
<el-dialog title="物料包装属性导入" :close-on-click-modal="false" :visible.sync="visible"
width="600px" class="customer-dialog">
<el-form label-position="top">
<el-row :gutter="16">
<el-col :span="12">
<el-form-item label="BU">
<el-select v-model="pageData.buNo" placeholder="请选择" style="width: 100%">
<el-option v-for="i in buList" :key="i.buNo" :label="i.buDesc" :value="i.buNo"></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label=" ">
<el-button type="primary" @click="downloadTemplate()">下载导入模板</el-button>
</el-form-item>
</el-col>
<el-col :span="24" style="margin-top: 10px">
<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" :show-file-list="false" style="text-align: left;">
<i class="el-icon-upload"></i>
<div class="el-upload__text">将文件拖到此处<em>点击上传</em></div>
<!-- <div class="el-upload__tip" slot="tip">
模板字段BU物料编码每卷数量每箱卷数每卷重量箱重量kgBox No
</div>-->
</el-upload>
<!-- 已选择的文件名显示 -->
<div v-if="selectedFileName" style="margin-top: 10px; color: #409EFF;">
<i class="el-icon-document"></i> 已选择: {{ selectedFileName }}
</div>
</el-col>
</el-row>
</el-form>
<span slot="footer" class="dialog-footer" style="margin-top: 10px">
<el-button type="primary" @click="saveImport" :loading="saveButtonLoading" :disabled="saveButtonLoading || fileList.length === 0">导入</el-button>
<el-button @click="closeDialog" :disabled="saveButtonLoading">关闭</el-button>
</span>
</el-dialog>
</div>
</template>
<script>
import { getBuList } from '@/api/factory/site.js'
import { importPartPackageProperties } from '@/api/ecss/ecss.js'
import { queryFileId } from '@/api/qc/qc.js'
import { downLoadObjectFile } from '@/api/eam/eam_object_list.js'
export default {
name: 'partHsCodeImport',
data() {
return {
buList: [],
visible: false,
fileList: [],
pageData: {
buNo: '',
createBy: this.$store.state.user.name
},
selectedFileName: '', //
saveButtonLoading: false //
}
},
methods: {
/**
* 初始化组件
*/
init() {
//
this.fileList = []
this.selectedFileName = ''
this.saveButtonLoading = false
//
this.visible = true
//
this.$nextTick(() => {
if (this.$refs.uploadFile) {
this.$refs.uploadFile.clearFiles()
}
})
// BU
let tempData = {
username: this.$store.state.user.name
}
getBuList(tempData).then(({ data }) => {
if (data.code === 0) {
this.buList = data.row2
if (data.row2.length === 1) {
this.pageData.buNo = data.row2[0].buNo
}
}
})
},
/**
* 上传前验证
*/
beforeUploadHandle(file) {
let extName = file[0].name.substring(file[0].name.lastIndexOf('.')).toLowerCase()
if (!(extName === '.xlsx' || extName === '.xls')) {
this.$message.error('请选择正确的Excel文件(xlsx或xls格式)')
return false
}
},
/**
* 文件选择变化
*/
onChange(file) {
this.fileList = [file]
this.selectedFileName = file.name
},
/**
* 确认导入
*/
async saveImport() {
if (!this.pageData.buNo) {
this.$message.error('请先选择BU!')
return
}
if (!this.fileList || this.fileList.length === 0) {
this.$message.error('请先选择文件!')
return
}
this.saveButtonLoading = true
const formData = new FormData()
formData.append('file', this.fileList[0].raw)
formData.append('buNo', this.pageData.buNo)
formData.append('username', this.$store.state.user.name)
formData.append('previewOnly', 'false')
try {
const { data } = await importPartPackageProperties(formData)
if (data.code === 0) {
const successCount = data.successCount || 0
const failCount = data.failCount || 0
let html = `<div style="max-height:380px;overflow:auto;font-size:12px;line-height:1.4;">`
if (successCount > 0) {
html += `<div style="margin-bottom:6px;">
<div style="color:green;font-weight:bold;margin-bottom:3px;">
成功导入 ${successCount} 条记录
</div>
</div>`
}
if (failCount > 0) {
html += `<div>
<div style="color:red;font-weight:bold;margin-bottom:3px;">
失败 ${failCount} 条记录
</div>
</div>`
}
if (data.details && data.details.length > 0) {
html += `<div style="margin-top:10px;">
<table border="1" cellspacing="0" cellpadding="2" style="border-collapse:collapse;width:100%;">`
data.details.forEach(item => {
const color = item.success ? 'green' : 'red'
html += `<tr><td style="color:${color};padding:2px 4px;">${item.message}</td></tr>`
})
html += `</table></div>`
}
html += `</div>`
this.$alert(html, '导入结果', {
confirmButtonText: '确定',
dangerouslyUseHTMLString: true,
callback: () => {
if (successCount > 0) {
this.closeDialog()
this.$emit('refreshTable')
}
}
})
} else {
this.$alert(data.msg || '导入失败', '错误', {
confirmButtonText: '确定'
})
}
} catch (error) {
this.$message.error('导入失败:' + (error.message || '网络异常'))
} finally {
this.saveButtonLoading = false
}
},
/**
* 关闭弹窗
*/
closeDialog() {
//
if (this.$refs.uploadFile) {
this.$refs.uploadFile.clearFiles()
}
this.visible = false
this.fileList = []
this.selectedFileName = ''
},
/**
* 下载导入模板
*/
async downloadTemplate() {
let file = {
id: 0,
fileName: ''
}
let tempData = {
orderRef1: 'ecss',
orderRef2: 'partPackageImport'
}
await queryFileId(tempData).then(({ data }) => {
if (data && data.code === 0) {
file.id = data.data.id
file.fileName = data.data.fileName
} else {
//
this.$alert('模板字段:BU、物料编码、每卷数量、每箱卷数、每卷重量、箱重量(kg)、Box No、长(米)、宽(米)、高(米)', '导入模板说明', {
confirmButtonText: '确定'
})
return
}
})
if (file.id > 0) {
await downLoadObjectFile(file).then(({ data }) => {
const blob = new Blob([data], { type: 'application/octet-stream' })
const fileName = file.fileName
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)
})
}
}
}
}
</script>
<style scoped>
/deep/ .customer-upload .el-upload .el-upload-dragger {
width: 580px;
}
</style>
Loading…
Cancel
Save