导入物料

This commit is contained in:
张江玮
2023-02-14 14:16:23 +08:00
parent 6131d1fa12
commit 8a75334053
6 changed files with 213 additions and 7 deletions

View File

@@ -55,4 +55,12 @@ export function getProductSeries() {
})
}
export default { add, edit, del, getMaterOptType, isAlongMaterType, synchronize, getProductSeries }
export function excelImport(data) {
return request({
url: 'api/Materialbase/excelImport',
method: 'post',
data
})
}
export default { add, edit, del, getMaterOptType, isAlongMaterType, synchronize, getProductSeries, excelImport }

View File

@@ -0,0 +1,116 @@
<template>
<el-dialog
title="导入Excel文件"
append-to-body
:visible.sync="dialogVisible"
destroy-on-close
width="400px"
:show-close="true"
@close="close"
@open="open"
>
<el-upload
ref="upload"
class="upload-demo"
action=""
drag
:on-exceed="is_one"
:limit="1"
:auto-upload="false"
:multiple="false"
:show-file-list="true"
:on-change="uploadByJsqd"
:file-list="fileList"
accept=".xlsx,.xls"
>
<i class="el-icon-upload" />
<div class="el-upload__text">
将文件拖到此处
<em>点击上传</em>
</div>
<div slot="tip" class="el-upload__tip">只能上传Excel文件且不超过10MB</div>
</el-upload>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false"> </el-button>
<el-button type="primary" @click="submit"> </el-button>
</span>
</el-dialog>
</template>
<script>
import crudMaterialbase from '@/api/wms/basedata/materialbase'
import CRUD, { crud } from '@crud/crud'
export default {
name: 'UploadDialog',
mixins: [crud()],
components: {},
props: {
dialogShow: {
type: Boolean,
default: false
},
openParam: {
type: String
}
},
data() {
return {
dialogVisible: false,
fileList: [],
file1: ''
}
},
watch: {
dialogShow: {
handler(newValue, oldValue) {
this.dialogVisible = newValue
}
},
openParam: {
handler(newValue, oldValue) {
this.opendtlParam = newValue
}
}
},
methods: {
open() {
},
close() {
this.$emit('update:dialogShow', false)
},
is_one() {
this.crud.notify('只能上传一个excel文件', CRUD.NOTIFICATION_TYPE.WARNING)
},
// 文件校验方法
beforeAvatarUpload(file) {
// 不能导入大小超过2Mb的文件
if (file.size > 10 * 1024 * 1024) {
return false
}
return true
},
// 文件发生改变就会触发的事件
uploadByJsqd(file) {
this.file1 = file
},
submit() {
if (this.beforeAvatarUpload(this.file1)) {
this.fileList.name = this.file1.name
this.fileList.url = ''
var formdata = new FormData()
formdata.append('file', this.file1.raw)
// excelImport请求接口 formdata传递参数
crudMaterialbase.excelImport(formdata).then((res) => {
this.crud.notify('导入成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
this.$emit('tableChanged3', '')
this.$emit('update:dialogShow', false)
})
} else {
this.crud.notify('文件过大请上传小于10MB的文件〜', CRUD.NOTIFICATION_TYPE.WARNING)
}
}
}
}
</script>

View File

@@ -58,16 +58,26 @@
</el-row>
<!--如果想在工具栏加入更多按钮可以使用插槽方式 slot = 'left' or 'right'-->
<crudOperation :permission="permission">
<!-- <el-button-->
<!-- v-if="false"-->
<!-- slot="right"-->
<!-- class="filter-item"-->
<!-- type="success"-->
<!-- icon="el-icon-position"-->
<!-- size="mini"-->
<!-- @click="synchronize()"-->
<!-- >-->
<!-- 同步-->
<!-- </el-button>-->
<el-button
v-if="false"
slot="right"
class="filter-item"
type="success"
icon="el-icon-position"
type="warning"
icon="el-icon-upload2"
size="mini"
@click="synchronize()"
@click="uploadShow = true"
>
同步
导入
</el-button>
</crudOperation>
<!--表单组件-->
@@ -227,6 +237,7 @@
</el-table>
<!--分页组件-->
<pagination />
<UploadDialog :dialog-show.sync="uploadShow" @tableChanged3="tableChanged3" />
</div>
</div>
</template>
@@ -242,6 +253,7 @@ import Treeselect, { LOAD_CHILDREN_OPTIONS } from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import crudClassstandard from '@/api/wms/basedata/classstandard'
import crudMdPbMeasureunit from '@/api/wms/basedata/mdPbMeasureunit'
import UploadDialog from '@/views/wms/basedata/material/UploadDialog.vue'
const defaultForm = {
material_id: null,
@@ -284,7 +296,7 @@ export default {
name: 'Materialbase',
// 数据字典
dicts: ['is_used'],
components: { pagination, crudOperation, rrOperation, udOperation, Treeselect },
components: { UploadDialog, pagination, crudOperation, rrOperation, udOperation, Treeselect },
mixins: [presenter(), header(), form(defaultForm), crud()],
cruds() {
return CRUD({
@@ -305,6 +317,7 @@ export default {
measure_unit: [],
productSeries: [],
permission: {},
uploadShow: false,
rules: {
material_id: [
{ required: true, message: '物料号不能为空', trigger: 'blur' }
@@ -346,6 +359,9 @@ export default {
[CRUD.HOOK.beforeRefresh]() {
return true
},
tableChanged3() {
this.crud.toQuery()
},
initClass1() {
const param = {
parent_class_code: '09'