index.vue
6.33 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<template>
<div style="margin: 20px">
<el-form :inline="true" :model="form" class="demo-form-inline" size="small">
<el-form-item label="商品名">
<el-input
v-model="form.skuCode"
placeholder="根据Hscode查询"
></el-input>
</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"
v-hasPermi="['base:flightImport:importFlight']"
>
<el-button icon="el-icon-upload2" type="primary">点击上传</el-button>
</el-upload>
</el-form-item>
<el-form-item>
<el-button
type="primary"
icon="el-icon-download"
@click="downloadTempleate"
v-hasPermi="['base:flightImport:exportExcel']"
>下载模板
</el-button>
</el-form-item>
</el-form>
<div style="font-size: 12px; font-weight: 700; margin-bottom: 15px">
提示:<span style="color: #1890ff">以下为所提交的数据或出错信息</span>
</div>
<div class="btn-wrap">
<el-button
type="danger"
size="mini"
icon="el-icon-delete"
@click="deleteRow"
>删除</el-button
>
</div>
<el-table
ref="filterTable"
class="mt10"
:data="tableData"
size="small"
border
@selection-change="handleSelectionChange"
>
<el-table-column type="selection" width="55"></el-table-column>
<el-table-column label="行号" prop="line" width="50" align="center">
</el-table-column>
<el-table-column label="错误信息" prop="errorMessage" 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>
<template v-for="(value, key) in this.tableData[0]">
<el-table-column
:key="key"
v-if="key != 'errorMessage' && key != 'line'"
:label="key"
:prop="key"
></el-table-column>
</template>
</el-table>
<ModleView ref="modleView" />
</div>
</template>
<script>
import {
filghtKindData,
downLoadTemplate,
importFlight,
} from "@/api/flightInfoImport";
import ModleView from "./components/ModleView";
export default {
name: "FlightInformationImport",
components: {
ModleView,
},
data() {
return {
flightType: [],
form: {
skuCode: "",
},
fileList: [],
tableData: [],
multipleSelection: [],
};
},
methods: {
typeData() {
filghtKindData().then((response) => {
if (response.code != 200) {
this.msgError(response.msg);
}
this.flightType = response.data;
this.form.type = response.data[0].code;
});
},
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;
importFlight(file, this.form.type).then((res) => {
if (res.code != 200) {
if (res.code == 603) {
this.$alert(res.msg, "提示", {
confirmButtonText: "确定",
type: "warning",
});
} else {
this.$confirm("是否查看错误信息列表?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
center: true,
}).then(() => {
console.log(this.$refs.modleView);
this.$refs.modleView.dialogOpenEvent(res.data)
})
.catch(() => {});
this.$message.warning(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);
},
handleSelectionChange(val) {
this.multipleSelection = val;
},
deleteRow() {
this.$confirm("是否确认删除?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
center: true,
})
.then(() => {
this.msgSuccess("删除成功!");
})
.catch(() => {});
},
},
created() {
this.typeData();
},
activated() {
this.typeData();
},
};
</script>
<style rel="stylesheet/scss" lang="scss">
.upload-demo {
float: right;
}
.el-upload-list {
display: inline-block;
margin-left: 10px;
vertical-align: top;
}
</style>