<template>
|
<el-card class="box-card">
|
<div slot="header" class="clearfix">
|
<span>运单更新导入</span>
|
</div>
|
<!-- <el-form ref="form" v-model="formData" label-width="120px">
|
<el-form-item label="选择仓库">
|
<el-select v-model="formData.Storage_Id" placeholder="请选择">
|
<el-option v-for="item in StorageNames" :key="item.Storage_Id" :label="item.StorageName" :value="item.Storage_Id">
|
</el-option>
|
</el-select>
|
</el-form-item>
|
</el-form> -->
|
|
<el-upload ref="upload" :on-preview="handlePreview" :on-remove="handleRemove" :on-success="handleSuccess" :file-list="fileList" :auto-upload="true" :action="upLoadUrl()" :limit="1" class="upload-bill">
|
<el-button slot="trigger" size="small" type="primary">选取文件</el-button>
|
<el-button style="margin-left: 10px;" size="small" type="success" @click="submitImport()">开始导入</el-button>
|
<el-button style="margin-left: 10px;" size="small" type="primary" plain>
|
<a :href="common.ossDomain+'/node-wms/template/运单更新模板.xlsx'" target="_blank" style="color:while;font-size:12px;">下载模板</a>
|
</el-button>
|
<div slot="tip" class="el-upload__tip">只能上传扩展名为.xlsx的excel文件</div>
|
</el-upload>
|
|
<el-scrollbar ref="scrollbar" :noresize="false" :native="false" wrap-class="scrollbar-wrap">
|
<ul class="msg-container">
|
<li v-for="(item, index) in msgList" :key="index" class="msg-item" v-html="item">
|
{{ index + 1 }}、{{ item }}
|
</li>
|
</ul>
|
</el-scrollbar>
|
<div ref="loading"></div>
|
</el-card>
|
</template>
|
|
<script>
|
export default {
|
name: "user-way-package-import",
|
data() {
|
return {
|
fileList: [],
|
fileUrl: null,
|
// 消息内容
|
msgList: [],
|
// 导入获得消息interval handle
|
intervalHandler: null,
|
// 导入key
|
uploadKey: null
|
};
|
},
|
mounted() {
|
this.uploadKey = this.common.getGUID();
|
},
|
methods: {
|
// 开始导入
|
submitImport() {
|
if (!this.fileUrl) {
|
this.$message.error("请上传文件!");
|
return;
|
}
|
this.msgList = []; // 清空消息
|
const url = "/api/tms/waypackageimport/importExcel";
|
const params = {
|
url: this.fileUrl,
|
key: this.uploadKey
|
};
|
var callback = res => {
|
if (res.result) {
|
window.clearTimeout(this.intervalHandler);
|
this.intervalHandler = false;
|
this.getMsg();
|
this.fileList = [];
|
this.fileUrl = null;
|
}
|
};
|
this.common.ajax(url, params, callback, this.$refs.loading);
|
},
|
handleRemove(file, fileList) {
|
this.fileUrl = null;
|
},
|
// 点击文件时的钩子
|
handlePreview(file) {},
|
// 上传附件Url
|
upLoadUrl: function() {
|
var domain = this.common.domain;
|
return domain + "/api/common/uploadSingleFile";
|
},
|
// 上传成功后
|
handleSuccess(res, file) {
|
this.common.showMsg("上传成功!");
|
this.fileUrl = res.data.url;
|
},
|
// 获得导入消息
|
getMsg() {
|
// 获得同步消息
|
const url = "/api/common/getUploadMsg";
|
const params = {
|
key: this.uploadKey
|
};
|
// const ref = this.dataList;
|
var callBack = res => {
|
// 自动滚动到最后一行
|
window.setTimeout(() => {
|
const div = this.$refs.scrollbar.$refs.wrap;
|
div.scrollTop = div.scrollHeight + 1000;
|
}, 1500);
|
if (!res.result) {
|
window.clearTimeout(this.intervalHandler);
|
this.intervalHandler = false;
|
if (Array.isArray(res.data)) {
|
this.msgList = this.msgList.concat(res.data);
|
}
|
return;
|
}
|
if (Array.isArray(res.data)) {
|
this.msgList = this.msgList.concat(res.data.filter(item => item !== "-1"));
|
}
|
if (res.data.indexOf("-1") >= 0) {
|
window.clearTimeout(this.intervalHandler);
|
this.intervalHandler = null;
|
return;
|
}
|
this.intervalHandler = window.setTimeout(this.getMsg, 1000);
|
};
|
this.common.ajax(url, params, callBack, this.$refs.loading);
|
}
|
}
|
};
|
</script>
|
|
<style lang="scss" scoped>
|
.box-card {
|
.upload-bill {
|
width: 480px;
|
.el-upload__tip {
|
margin-top: 20px;
|
}
|
}
|
/deep/ .scrollbar-wrap {
|
max-height: 400px !important;
|
margin-top: 10px;
|
font-size: 14px;
|
.msg-container {
|
margin: 0;
|
padding: 0;
|
.msg-item {
|
margin: 0;
|
padding: 5px 0;
|
word-wrap: break-word;
|
}
|
}
|
}
|
}
|
</style>
|