exportExcel-NMMS.vue
6.2 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
<template>
<!-- $t is vue-i18n global function to translate lang -->
<div class="app-container">
<!--工具条-->
<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
<el-form :inline="true" :model="searchText">
<el-form-item>
<el-date-picker v-model="searchText.startdate" value-format="yyyy-MM-dd" type="date"
placeholder="开始航班日期"
></el-date-picker>
</el-form-item>
<el-form-item>
<el-date-picker v-model="searchText.enddate" value-format="yyyy-MM-dd" type="date"
placeholder="结束航班日期"
></el-date-picker>
</el-form-item>
<el-form-item>
<el-input v-model="searchText.flightno" placeholder="航班号" ></el-input>
</el-form-item>
<el-form-item>
<el-button :loading="listLoading" style="margin:0 0 20px 20px;" type="primary" icon="document" @click="fetchData">查询</el-button>
</el-form-item>
<el-tag
:key="note.message"
:type="note.type">
{{note.message}}
</el-tag>
</el-form>
</el-col>
<div>
<FilenameOption v-model="filename" />
<AutoWidthOption v-model="autoWidth" />
<BookTypeOption v-model="bookType" />
<el-button :loading="downloadLoading" style="margin:0 0 20px 20px;" type="primary" icon="document" @click="handleDownload">导出 Excel</el-button>
</div>
<el-table v-loading="listLoading" element-loading-text="拼命加载中" border fit highlight-current-row>
<el-table-column align="center" label="Id" width="95">
<template slot-scope="scope">
{{ scope.$index }}
</template>
</el-table-column>
<el-table-column label="运单号">
<template slot-scope="scope">
{{ scope.row.waybillnomaster }}
</template>
</el-table-column>
<el-table-column label="航班号" width="115" align="center">
<template slot-scope="scope">
{{ scope.row.flightno }}
</template>
</el-table-column>
<el-table-column align="center" label="航班日期" width="220" :formatter="dateFormat">
<template slot-scope="scope">
<i class="el-icon-time"/>
<span>{{ scope.row.flightDate | parseTime('{y}-{m}-{d}')}}</span>
</template>
</el-table-column>
<el-table-column label="航段" width="110" align="center">
<template slot-scope="scope">
<el-tag>{{ scope.row.segment }}</el-tag>
</template>
</el-table-column>
</el-table>
</div>
</template>
<script>
import { getNmmsAnalysisList } from '@/api/agent-excel'
import { parseTime } from '@/utils'
// options components
import FilenameOption from './components/FilenameOption'
import AutoWidthOption from './components/AutoWidthOption'
import BookTypeOption from './components/BookTypeOption'
import Export2Excel from '@/vendor/Export2Excel'
export default {
name: 'ExportExcelNMMS',
components: { FilenameOption, AutoWidthOption, BookTypeOption },
data() {
return {
list: [],
fetchList: [],
listLoading: false,
downloadLoading: false,
filename: '',
autoWidth: true,
bookType: 'xlsx',
searchText: {
startdate: undefined,
enddate: undefined,
flightno: undefined
},
note: {
type: 'info',
message: ''
}
}
},
created() {
// this.fetchData()
},
filters: {
parseTime: parseTime
},
methods: {
dateFormat:function(row,column){
var t=new Date(row.updateTime);//row 表示一行数据, updateTime 表示要格式化的字段名称
return t.getFullYear()+"-"+(t.getMonth()+1)+"-"+t.getDate();
},
fetchData() {
this.listLoading = true
getNmmsAnalysisList(this.searchText).then(response => {
this.list = response.data.data
this.listLoading = false
this.$message({
message: '数据查询成功,可以下载excel',
type: 'success'
});
this.note.message = '数据查询成功,可以下载excel;共'+this.list.length+'条数据';
this.note.type = 'success';
})
},
handleDownload() {
this.downloadLoading = true
import('@/vendor/Export2Excel').then(excel => {
const tHeader = [
'航班号',
'航班日期',
'航段',
'主运单号',
'分单号',
'运单件数',
'运单重量',
'舱单件数',
'舱单重量',
'品名',
'航班起始站',
'航班起始站中文',
'航班目的站',
'航班目的站中文',
'运单起始站',
'运单起始站中文',
'运单目的站',
'运单目的站中文',
'发货人国家',
'发货人国家中文',
'发货人区域'
]
const filterVal = [
'flightno',
'flightDate',
'segment',
'waybillnomaster',
'waybillnosecondary',
'totalpiece',
'totalweight',
'manifesttotalpiece',
'manifesttotalweight',
'productname',
'originatingstation',
'originatingstationcn',
'destinationstation',
'destinationstationcn',
'originatingstationBill',
'originatingstationbillcn',
'destinationstationBill',
'destinationstationbillcn',
'shipperCountrycode',
'countrydescchn',
'areadescchn'
]
const list = this.list
const data = this.formatJson(filterVal, list)
excel.export_json_to_excel({
header: tHeader,
data,
filename: this.filename,
autoWidth: this.autoWidth,
bookType: this.bookType
})
this.downloadLoading = false
})
},
formatJson(filterVal, jsonData) {
return jsonData.map(v => filterVal.map(j => {
if (j === 'timeamp') {
return parseTime(v[j])
} else {
return v[j]
}
}))
}
}
}
</script>
<style>
.radio-label {
font-size: 14px;
color: #606266;
line-height: 40px;
padding: 0 12px 0 30px;
}
</style>