zhidan.vue
15.5 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
<template>
<div>
<el-row :gutter="24">
<el-col :span="4">
<el-input size="medium" v-model="query.waybill" placeholder="运单号"></el-input>
</el-col>
<el-col :span="9">
<el-date-picker
size="medium"
v-model="value2"
type="datetimerange"
:picker-options="pickerOptions"
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"
align="right">
</el-date-picker>
</el-col>
<el-col :span="2">
<el-button size="medium" @click="getList" type="primary">查询</el-button>
</el-col>
<el-col :span="2">
<el-upload
class="upload-demo"
action=""
:before-upload="beforeUpload"
:http-request="impExcel"
:show-file-list="false">
<el-button size="medium" type="success">导入数据</el-button>
</el-upload>
</el-col>
<el-col :span="2">
<el-upload
class="upload-demo"
action=""
:before-upload="beforeUpload"
:http-request="importPlanExcel"
:show-file-list="false">
<el-button size="medium" type="success">导入计划表</el-button>
</el-upload>
</el-col>
<el-col :span="2">
<el-button size="medium" @click="batchExtExcel" type="success" round>批量导出excel</el-button>
</el-col>
</el-row>
<el-row :gutter="24">
<el-col :span="24">
<el-table
:data="tableData"
border
style="width: 100%"
@selection-change="handleSelectionChange"
>
<el-table-column type="selection" width="55"></el-table-column>
<el-table-column
prop="waybill"
label="运单号"
width="120">
</el-table-column>
<!--<el-table-column
prop="fhl"
label="分单号"
width="120">
</el-table-column>-->
<el-table-column
prop="flightno"
label="航班号"
width="120">
</el-table-column>
<el-table-column
prop="flightdate"
label="航班日期"
width="150">
</el-table-column>
<el-table-column
prop="pcs"
label="件数"
width="120">
</el-table-column>
<el-table-column
prop="weight"
label="重量"
width="120">
</el-table-column>
<el-table-column
prop="feweifht"
label="计费重"
width="120">
</el-table-column>
<el-table-column
prop="vol"
label="体积"
width="120">
</el-table-column>
<el-table-column
prop="descr"
label="品名"
width="120">
</el-table-column>
<el-table-column
fixed="right"
label="操作"
width="160">
<template slot-scope="scope">
<el-button @click="handlePdf(scope.row)" type="text" size="small">下载PDF</el-button>
<el-button @click="handleExcel(scope.row)" type="text" size="small">下载EXCEL</el-button>
<el-button @click="handleDocx(scope.row)" type="text" size="small">下载DOCX</el-button>
</template>
</el-table-column>
</el-table>
</el-col>
<el-col :span="24">
<el-pagination
size="medium"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="query.pageNum"
:page-sizes="[100, 200, 300, 400]"
:page-size="query.pageSize"
layout="total, sizes, prev, pager, next, jumper"
:total="total">
</el-pagination>
</el-col>
</el-row>
</div>
</template>
<script>
import {selectLists,extPdf,extExcel,batchExtExcel,extDocx,importExcel,importPlanExcel} from "../../api/zhidan/zhidan";
export default {
data(){
return{
pickerOptions: {
shortcuts: [
{
text: '最近一周',
onClick(picker) {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
picker.$emit('pick', [start, end]);
}
}, {
text: '最近一个月',
onClick(picker) {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
picker.$emit('pick', [start, end]);
}
}, {
text: '最近三个月',
onClick(picker) {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
picker.$emit('pick', [start, end]);
}
}
]
},
query:{
waybill:'',
starttime:'',
endtime:'',
pageNum:1,
pageSize:20
},
value2:'',
tableData: [],
total:0,
selectedRows: []
}
},
mounted() {
this.getList();
},
methods:{
//导入订单excel
beforeUpload(file) {
// 检查文件类型
const isExcel = file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' || file.type === 'application/vnd.ms-excel';
if (!isExcel) {
this.$message.error('上传文件只能是 Excel 格式!');
return false; // 取消文件上传
}
return true; // 允许上传
},
impExcel({ file, onSuccess, onError }){
// 生成 FormData 对象
const formData = new FormData();
formData.append('file', file);
importExcel(formData).then((response) => {
const res = response.data
if (res.code !== '200') {
return this.$message.error(res.msg);
}
this.$message.success(res.msg);
this.getList();
onSuccess(response.data); // 调用 onSuccess 回调通知上传成功
}).catch(error => {
// 关闭加载
this.$message.error(error.toString())
onError(error); // 调用 onError 回调通知上传失败
})
},
// 导入计划表
importPlanExcel({file, onSuccess, onError}){
// 生成 FormData 对象
const formData = new FormData();
formData.append('file', file);
importPlanExcel(formData).then((response) => {
const res = response.data
if (res.code !== '200') {
return this.$message.error(res.msg);
}
this.$message.success(res.msg);
this.getList();
onSuccess(response.data); // 调用 onSuccess 回调通知上传成功
}).catch(error => {
// 关闭加载
this.$message.error(error.toString())
onError(error); // 调用 onError 回调通知上传失败
})
},
getList(){
if(this.value2 !== null && this.value2 !== ""){
this.query.starttime=this.value2[0];
this.query.endtime=this.value2[1];
}
selectLists(this.query).then((response) => {
const res = response.data
if (res.code !== '200') {
return this.$message.error('获取消息收发记录,失败!')
}
// 获取列表数据
this.tableData = res.data.list
// 获取列表的总记录数
this.total = res.data.total
this.$message.success('获取消息收发记录,成功!');
}).catch(error => {
// 关闭加载
this.$message.error(error.toString())
})
},
handlePdf(row) {
extPdf({id: row.id}).then(response => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', row.waybill+'.pdf'); // 动态设置文件名
document.body.appendChild(link);
link.click();
document.body.removeChild(link); // 清理临时链接
window.URL.revokeObjectURL(url); // 清理URL对象
}).catch(error => {
console.error('Error downloading PDF:', error);
});
},
handleExcel(row) {
extExcel({id: row.id}).then(response => {
if (!response || !response.data) {
console.error('Response data is empty or not a Blob.');
return;
}
const blob = new Blob([response.data], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'});
const tempFile = URL.createObjectURL(blob);
fetch(tempFile)
.then(res => res.blob())
.then(blob => {
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', row.waybill+'.xlsx');
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
})
.catch(error => {
console.error('Error creating temporary file:', error);
});
window.URL.revokeObjectURL(tempFile);
}).catch(error => {
console.error('Error downloading Excel:', error);
});
},
handleDocx(row){
extDocx({id: row.id}).then(response => {
// 创建一个 Blob 对象
const blob = new Blob([response.data], { type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' });
// 创建一个隐藏的可下载链接
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = row.waybill + '.docx'; // 设置下载文件名
// 将链接添加到 DOM 中
document.body.appendChild(link);
// 触发下载
link.click();
// 移除链接
document.body.removeChild(link);
}).catch(error => {
console.error('Error downloading DOCX:', error);
});
},
batchExtExcel(){
if(this.selectedRows.length === 0){
this.$message.error('请选择需要批量导出的数据')
return
}
const ids = this.selectedRows.map(item => item.id)
const idsString = ids.join(',');
console.log(idsString)
batchExtExcel({ids: idsString}).then(response => {
if (!response || !response.data) {
console.error('Response data is empty or not a Blob.');
return;
}
const blob = new Blob([response.data], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'});
const tempFile = URL.createObjectURL(blob);
fetch(tempFile)
.then(res => res.blob())
.then(blob => {
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 主单excel +'.xlsx');
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
})
.catch(error => {
console.error('Error creating temporary file:', error);
});
window.URL.revokeObjectURL(tempFile);
}).catch(error => {
console.error('Error downloading Excel:', error);
});
},
handleSizeChange(val) {
this.query.pageSize=val;
this.getList();
},
handleCurrentChange(val) {
this.query.pageNum=val;
this.getList();
},
//多选
handleSelectionChange(selection) {
this.selectedRows = selection;
}
}
}
</script>