informationDialog.vue
5.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<template>
<div>
<glsx-dialog :show="showDialog" :title="!showResult?'批量操作':'提示'" width="560px" @close="closeDialog()">
<div>
<div class="upload_box" v-show="!showResult">
<div class="input_box">
<el-input v-model="uploadFile.name" placeholder="未选择任何文件..." class="a_input" size="small" readonly></el-input>
<el-upload ref="elUpload" :action="IMPORT_FAKEOFFLINE_FILES" :headers="uploadHeaders" :accept="acceptFile" :show-file-list="false" :auto-upload="false" :file-list="fileList" :on-change="onFileChange" :on-success="onSuccess">
<el-button size="small" type="primary">浏览</el-button>
</el-upload>
</div>
<div class="tips">*请选择需要导入的条件模板*</div>
<div>
<el-button type="primary" size="small" v-if="!showResult" @click="downloadTemplate()">SN号导入模板</el-button>
<el-button type="primary" size="small" v-if="!showResult" @click="downloadTemplate()">工单号导入模板</el-button>
<el-button type="primary" size="small" v-if="!showResult" @click="downloadTemplate()">车架号导入模板</el-button>
</div>
</div>
<div class="upload_result" v-show="showResult && !exportDialog">
<div class="cell">
<span class="num">{{uploadResult.succNum}}</span>
<span>成功记录</span>
</div>
<div class="cell">
<span class="num cred">{{uploadResult.failNum}}</span>
<span>失败记录</span>
</div>
</div>
<div class="upload_result" v-show="exportDialog">
<el-alert
type="warning"
description="请等待解析结果,解析完成后将自动为您下载,请勿关闭当前浏览器!"
:closable="false"
show-icon>
</el-alert>
</div>
</div>
<div slot="footer">
<div class="dialog_links">
<div>
<el-button type="primary" size="small" v-if="showResult && uploadResult.failFile" @click="downloadFail()">导出失败记录</el-button>
</div>
<div>
<el-button type="primary" size="small" :loading="aloading" :disabled="!uploadFile.name" v-if="!showResult" @click="saveFile()">确认</el-button>
<el-button type="default" size="small" @click="closeDialog()" v-if="!exportDialog">{{!showResult?'取消':'关闭'}}</el-button>
<el-button type="default" size="small" @click="closeDialog()" v-if="exportDialog"><i class="el-icon-loading" v-show="exportDialog"></i>完成</el-button>
</div>
</div>
</div>
</glsx-dialog>
</div>
</template>
<script>
import { IMPORT_FAKEOFFLINE_FILES } from "services/report";
import GlsxDialog from "@/components/dialog";
export default {
name:"informationDialog",
components: {
GlsxDialog
},
data() {
return {
showDialog: false,
showResult: false,
uploadFile: {},
IMPORT_FAKEOFFLINE_FILES,
acceptFile: ".xlsx,.xls",
fileList: [],
uploadResult: {},
aloading: false,
}
},
props: {
uploadHeaders: Object,
// 导出按钮互动参数
exportDialog: {
type: Boolean,
default: false
}
},
methods: {
openDialog() {
this.showDialog = true
},
// 监听文件导入
onFileChange(file, fileList) {
console.log(file);
if (!file.response) {
this.uploadFile = file;
this.fileList = [file];
}
},
// 监听文件上传成功
onSuccess(response, file, fileList) {
this.aloading = false;
if (response.code != 200) {
showToast({
message: response.message,
});
this.uploadFile = {};
this.$refs.elUpload.clearFiles();
return false;
}
this.uploadResult = response.data;
this.showResult = true;
// this.getList(); 刷新表格
this.$emit("successData", true)
},
// 确认上传文件
saveFile() {
let o = this.uploadFile;
console.log(o);
if (!this.uploadFile.name) {
showToast({
message: "请选择上传文件",
});
return false;
}
let list = o.name.split(".");
let acceptFile = this.acceptFile;
let _type = list[list.length - 1];
console.log(_type);
let idx = acceptFile.includes(_type);
if (!idx) {
showToast({
message: `导入文件只支持${acceptFile}`,
});
return false;
}
this.aloading = true;
this.$refs.elUpload.submit();
},
// 下载失败模板
downloadFail() {
let o = this.uploadResult;
window.open(o.failFile);
},
// 关闭弹框
closeDialog() {
this.showDialog = false;
this.uploadFile = {};
this.uploadResult = {};
this.showResult = false;
},
}
}
</script>
<style lang="scss" scoped>
@import "@/styles/offline.scss";
.upload_result ::v-deep.el-alert .el-alert__description {
margin: 0;
}
</style>