/* * @Author: Badguy * @Date: 2022-03-04 11:41:55 * @LastEditTime: 2022-05-03 15:14:10 * @LastEditors: your name * @Description: 航站视图通用部分 * have a nice day! */ import { CurrentAirportQuery, RelatedAirportQuery, AirCompanyQuery, CraftTypeQuery, FlightAttrQuery, IntegratedQuery, IntegratedQueryTransfer } from '@/api/flight' export default { data() { return { // 表格数据 tableData: [], spanArr: [], pos: 0, loading: false } }, created() { this.currentAirportQuery() }, methods: { // 数据处理 formatData(arr) { arr.forEach(item => { item['name'] = item['name'] + item['code3'] item.builds && item.builds.forEach(p => { p['code3'] = p.name }) }) return arr }, // 表格数据格式化 tableFormat(row, column, cellValue) { if (cellValue || cellValue === 0) { switch (column.property) { case 'FlightDate': return cellValue.split('-').slice(1).join('-') case 'PlanLandingTime': case 'PlanDepartureTime': case 'PrePlanLandingTime': case 'TransferFlightPlanDepartureTime': return cellValue.split('T')[1].split(':').slice(0, 2).join(':') default: return cellValue } } else { return '' } }, // 合计行 summaryMethod({ columns, data }) { const sums = [] if (columns.length > 0) { columns.forEach((column, index) => { if (index === 0) { sums[index] = '合计' } else if ( // 需要计算的列 [ 'passagernum', 'checkin', 'not_actived', 'expect_load', 'security_all', 'fenj', 'loadcar', 'loadflight', 'waitfanj', 'hasfanj', 'delbag', 'no_bsm', 'transfer_all', 'reach', 'did_not_arrive', 'special', 'claim', 'uninstalled', 'to_be_uninstalled', 'terminateArrive', 'terminatedNotArrived', 'delivered', 'not_shipped', 'container', 'bulk' ].includes(column.property) ) { const values = data.map(item => Number(item[column.property])) if (values.some(value => !isNaN(value))) { sums[index] = values.reduce((prev, curr) => { const value = Number(curr) if (!isNaN(value)) { return Number(prev) + Number(curr) } else { return Number(prev) } }, 0) } else { sums[index] = 0 } } else { // 过滤某些字段不参与计算 sums[index] = '-' } }) } return sums }, // 表格行点击跳转 rowClick(row, column, event) { this.$router.push({ path: `/${this.$route.path.split('/').slice(1, -1).join('/')}/flightView`, query: row }) }, // 全部机场查询 async currentAirportQuery() { const params = { startDate: this.startDate, endDate: this.endDate } try { const res = await CurrentAirportQuery(params) if (res.code === 0) { if (res.returnData.length) { const datas = this.formatData(res.returnData) const datasCopy = this._.cloneDeep(datas) this.currentAirportOptions = datas const defaultData = datasCopy[0] // this.formData.currentAirport = [[defaultData.code3, defaultData.builds[0].code3]] // this.formData.currentAirport = [[defaultData.code3]] this.formData.currentAirport = [defaultData.code3] params.currentAirport = this.currentAirport this.getFormData(params) this.getTableData({ ...params, world: this.formData.search }) } } else { this.$message.error(res.message) } } catch (error) { console.log('出错了', error) } }, // 目的站/始飞站查询 async relatedAirportQuery(params = {}) { try { const res = await RelatedAirportQuery(params) if (res.code === 0) { const datas = this.formatData(res.returnData) this.relatedAirportOptions = datas } else { this.$message.error(res.message) } } catch (error) { console.log('出错了', error) } }, // 航司查询 async inboundCarrierQuery(params = {}) { try { const res = await AirCompanyQuery({ ...params, type: 'IN' }) if (res.code === 0) { this.inboundCarrierOptions = res.returnData } else { this.$message.error(res.message) } } catch (error) { console.log('出错了', error) } }, // 航司查询 async outgoingAirlineQuery(params = {}) { try { const res = await AirCompanyQuery({ ...params, type: 'OUT' }) if (res.code === 0) { this.outgoingAirlineOptions = res.returnData } else { this.$message.error(res.message) } } catch (error) { console.log('出错了', error) } }, // 机型查询 async craftTypeQuery(params = {}) { try { const res = await CraftTypeQuery(params) if (res.code === 0) { this.craftTypeOptions = res.returnData.map(item => ({ code3: item, name: item })) } else { this.$message.error(res.message) } } catch (error) { console.log('出错了', error) } }, // 航线查询 async flightAttrQuery(params = {}) { try { const res = await FlightAttrQuery(params) if (res.code === 0) { this.flightAttrOptions = res.returnData } else { this.$message.error(res.message) } } catch (error) { console.log('出错了', error) } }, // 综合查询 async integratedQuery(params = {}) { try { this.loading = true const res = await IntegratedQuery(params) if (res.code === 0) { const tableData = res.returnData this.initTableData(tableData) this.loading = false } else { this.$message.error(res.message) this.loading = false } } catch (error) { console.log('出错了', error) this.loading = false } }, // 中转综合查询 async integratedQueryTransfer(params = {}) { try { this.loading = true const res = await IntegratedQueryTransfer(params) if (res.code === 0) { const tableData = res.returnData this.initTableData(tableData) this.loading = false } else { this.$message.error(res.message) this.loading = false } } catch (error) { console.log('出错了', error) this.loading = false } } } }