Browse Source

[新增]导出excel表格

dev
邵佳豪 3 years ago
parent
commit
d90f6823e4
  1. 2
      src/app/pages/oil-station-info/oil-station-info.component.html
  2. 31
      src/app/pages/oil-station-info/oil-station-info.component.ts

2
src/app/pages/oil-station-info/oil-station-info.component.html

@ -424,7 +424,7 @@
</div>
<div class="btnbox">
<button [nzLoading]="isLoadingSave" nz-button type="submit">保存</button>
<button nz-button type="button"><img style="vertical-align: top;margin-right: 6px;"
<button (click)="exportExcel()" nz-button type="button"><img style="vertical-align: top;margin-right: 6px;"
src="../../../assets/images/excel.png" alt=""> 导出Excel</button>
</div>
</form>

31
src/app/pages/oil-station-info/oil-station-info.component.ts

@ -78,6 +78,7 @@ export class OilStationInfoComponent implements OnInit {
oilLicensevalidityTime: any = []//成品油有效期
//获取油站信息
gallery
gasStationId
getInfo() {
this.http.get('/api/services/app/GasStation/Get', {
params: {
@ -86,6 +87,7 @@ export class OilStationInfoComponent implements OnInit {
}).subscribe((data: any) => {
console.log('油站信息', data)
this.httpBody = data.result
this.gasStationId = data.result.id
if (!data.result.govUnitDetail) {
this.httpBody.govUnitDetail = {
policeStation: {},
@ -93,9 +95,9 @@ export class OilStationInfoComponent implements OnInit {
fireBrigade: {}
}
} else {
this.httpBody.govUnitDetail = JSON.parse(data.result.govUnitDetail)
console.log('走这里了',data.result.govUnitDetail)
console.log('走这里了', data.result.govUnitDetail)
this.policeStation = data.result.govUnitDetail.policeStation
this.hospital = data.result.govUnitDetail.hospital
this.fireBrigade = data.result.govUnitDetail.fireBrigade
@ -132,7 +134,26 @@ export class OilStationInfoComponent implements OnInit {
})
}
exportExcel() {
const httpOptions = {
responseType: 'blob' as 'json'
};
this.http.get(`/api/services/app/GasStation/ExportExcelFile?gasStationId=${this.gasStationId}`, httpOptions).subscribe((data: any) => {
// console.log('导出成功')
// 文件名中有中文 则对文件名进行转码
const link = document.createElement('a');
const blob = new Blob([data], { type: 'application/vnd.ms-excel' });
link.setAttribute('href', window.URL.createObjectURL(blob));
link.setAttribute('download', '统计信息' + '.xls');
link.style.visibility = 'hidden';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
this.message.create('success', '导出成功!');
}, err => {
this.message.create('error', '导出失败!');
})
}
policeStation = {
name: '',
@ -192,8 +213,8 @@ export class OilStationInfoComponent implements OnInit {
submitForm() {
console.log(this.validateForm)
console.log(this.httpBody)
// console.log(this.validateForm)
// console.log(this.httpBody)
if (this.validateForm.valid) {
this.isLoadingSave = true
this.httpBody.openTime = moment(this.httpBody.openTime).format('YYYY-MM-MM')//开业时间格式化

Loading…
Cancel
Save