index.vue
5.09 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<template>
<div style="margin: 20px">
<el-form :inline="true" :model="form" class="demo-form-inline" size="small">
<el-form-item label="航班种类">
<el-select v-model="form.type" placeholder="航班种类">
<el-option
v-for="item in flightType"
:key="item.id"
:label="item.englishName"
:value="item.code"
>{{ item.englishName }}</el-option
>
</el-select>
</el-form-item>
<el-form-item>
<el-upload
action="/flightInfoImport/importFlight"
name="file"
:http-request="uploadExcel"
:on-remove="handleRemove"
:limit="1"
:on-exceed="handleExceed"
:file-list="fileList"
accept=".xlsx"
class="upload-demo"
>
<el-button type="primary">点击上传</el-button>
</el-upload>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="downloadTempleate"
>下载模板</el-button
>
</el-form-item>
</el-form>
<div style="font-size: 12px; font-weight: 700">
提示:<span style="color: #0000ff">以下为所提交的数据或出错信息</span>
</div>
<el-table
ref="filterTable"
:data="tableData"
style="width: 100%; margin-top: 20px"
size="small"
border
>
<el-table-column label="行号" prop="line" fixed width="50" align="center">
</el-table-column>
<el-table-column label="错误信息" prop="errorMessage" fixed width="200">
<template slot-scope="scope">
<div v-for="(m, key) in scope.row.errorMessage" :key="key">
{{ m }}
</div>
</template>
</el-table-column>
<el-table-column v-if="tableData.length == 0"></el-table-column>
<el-table-column
v-for="(value, key) in this.tableData[0]"
:key="key"
v-if="key != 'errorMessage' && key != 'line'"
:label="key"
:prop="key"
width="120"
></el-table-column>
</el-table>
</div>
</template>
</div>
</template>
<script>
import {
filghtKindData,
downLoadTemplate,
importFlight,
} from "@/api/flightInfoImport";
export default {
data() {
return {
flightType: [],
form: {
type: "",
region: "",
},
fileList: [],
tableData: [],
};
},
methods: {
downloadTempleate() {
let downloadType = "";
let fileName = "";
switch (this.form.type) {
case "flightKind20":
downloadType = "whiteTail";
fileName = "航班信息导入模板WhiteTail.xlsx";
break;
case "flightKind30":
downloadType = "purpleTail";
fileName = "航班信息导入模板PurpleTail.xlsx";
break;
default:
this.$confirm("此类航班暂无模板,请选择其他类型航班", "提示", {
confirmButtonText: "确定",
showCancelButton: false,
type: "warning",
});
}
if (downloadType != "") {
downLoadTemplate(downloadType).then((res) => {
if (res) {
const blob = new Blob([res]);
const link = document.createElement("a"); //创建a标签
link.download = fileName; //a标签添加属性
link.style.display = "none";
link.href = URL.createObjectURL(blob);
document.body.appendChild(link);
link.click(); //执行下载
URL.revokeObjectURL(link.href); //释放url
document.body.removeChild(link); //释放标签
} else {
this.$message.error("下载失败");
}
});
}
},
uploadExcel(option) {
//上传excel
const file = option.file;
console.log(option);
importFlight(file, this.form.type).then((res) => {
if (res.code != 200) {
if (res.code == 401) {
this.$alert(res.msg , "提示", {
confirmButtonText: "确定",
type: "warning",
});
}else {
this.$message.error(res.msg);
this.tableData = res.data;
}
} else {
this.$message.success("导入成功");
this.tableData = res.data;
}
});
},
handleRemove(file, fileList) {
//清掉上传的文件
this.tableData = [];
this.fileList = [];
},
handleExceed(files) {
//重复上传文件
let file = {};
file.file = files[0];
file.name = files[0].name;
this.fileList = [];
this.fileList.push(file);
this.uploadExcel(file);
},
},
created() {
filghtKindData().then((response) => {
if (response.code != 200) {
this.$message({
message: response.msg,
type: "error",
});
}
this.flightType = response.data;
this.form.type = response.data[0].code;
});
},
};
</script>
<style rel="stylesheet/scss" lang="scss">
.upload-demo {
float: right;
}
.el-upload-list {
display: inline-block;
margin-left: 10px;
vertical-align: top;
}
</style>