|
@@ -392,6 +392,7 @@
|
|
|
<img
|
|
|
class="btn-square btn-shadow"
|
|
|
src="../../../../assets/baggage/ic_export.png"
|
|
|
+ @click="exportToExcel('航班行李列表', 'flightBaggageTable')"
|
|
|
>
|
|
|
<img
|
|
|
class="btn-square btn-shadow"
|
|
@@ -928,6 +929,56 @@ export default {
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
+ exportToExcel(tableName, refName) {
|
|
|
+ const table = this.$refs[refName].$el.cloneNode(true)
|
|
|
+ table.removeChild(table.querySelector('.el-table__fixed'))
|
|
|
+ const tableHeaderCellPopovers = table.querySelectorAll('.table-header-cell-popover')
|
|
|
+ tableHeaderCellPopovers.forEach(node => {
|
|
|
+ node.removeChild(node.querySelector('.el-popover'))
|
|
|
+ })
|
|
|
+ const tableBook = this.$XLSX.utils.table_to_book(table, { raw: true, sheet: tableName })
|
|
|
+ const columnWidths = []
|
|
|
+ function devideGroup(cellName) {
|
|
|
+ const stringArray = cellName.split('')
|
|
|
+ const length = stringArray.length
|
|
|
+ let index = 0
|
|
|
+ for (let i = 0; i < length; i++) {
|
|
|
+ if (isNaN(parseInt(stringArray[i]))) {
|
|
|
+ index += stringArray[i].charCodeAt(0) - 'A'.charCodeAt(0) + i * 26
|
|
|
+ } else {
|
|
|
+ return index
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Object.entries(tableBook.Sheets[tableName]).forEach(cell => {
|
|
|
+ if (!['!rows', '!cols', '!fullref', '!ref'].includes(cell[0])) {
|
|
|
+ const columnIndex = devideGroup(cell[0])
|
|
|
+ const cellTextLength = cell[1].v.split('').reduce((pre, curr) => {
|
|
|
+ const currentSize = curr.charCodeAt(0) > 255 ? 2 : 1
|
|
|
+ return pre + currentSize
|
|
|
+ }, 0)
|
|
|
+ if ((!columnWidths[columnIndex] && cellTextLength > 0) || cellTextLength > columnWidths[columnIndex]) {
|
|
|
+ columnWidths[columnIndex] = cellTextLength
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ tableBook.Sheets[tableName]['!cols'] = columnWidths.map(width => ({
|
|
|
+ wch: width
|
|
|
+ }))
|
|
|
+ const tableWrite = this.$XLSX.write(tableBook, {
|
|
|
+ bookType: 'xlsx',
|
|
|
+ bookSST: true,
|
|
|
+ type: 'array'
|
|
|
+ })
|
|
|
+ try {
|
|
|
+ this.$FileSaver.saveAs(
|
|
|
+ new Blob([tableWrite], { type: 'application/octet-stream' }),
|
|
|
+ `${tableName}-${this.queryData.flightNO}-${this.queryData.flightDate}.xlsx`
|
|
|
+ )
|
|
|
+ } catch (error) {
|
|
|
+ console.log(error.message || error)
|
|
|
+ }
|
|
|
+ },
|
|
|
queryflightInfo(dataContent) {
|
|
|
return myQuery(queryMap.flightInfo, ...dataContent)
|
|
|
},
|