|
@@ -50,12 +50,34 @@
|
|
|
v-model="formData[item.prop]"
|
|
|
:size="item.size || 'small'"
|
|
|
type="daterange"
|
|
|
+ format="yyyy-MM-dd"
|
|
|
value-format="yyyy-MM-dd"
|
|
|
+ unlink-panels
|
|
|
range-separator="至"
|
|
|
start-placeholder="开始日期"
|
|
|
end-placeholder="结束日期"
|
|
|
/>
|
|
|
</template>
|
|
|
+ <template v-if="item.inputType === 'monthPicker'">
|
|
|
+ <el-date-picker
|
|
|
+ v-model="formData[item.prop]"
|
|
|
+ :size="item.size || 'small'"
|
|
|
+ type="monthrange"
|
|
|
+ format="yyyy-MM"
|
|
|
+ value-format="yyyy-MM"
|
|
|
+ unlink-panels
|
|
|
+ range-separator="至"
|
|
|
+ start-placeholder="开始月份"
|
|
|
+ end-placeholder="结束月份"
|
|
|
+ />
|
|
|
+ </template>
|
|
|
+ <template v-if="item.inputType === 'yearPicker'">
|
|
|
+ <year-range-picker
|
|
|
+ v-model="formData[item.prop]"
|
|
|
+ :size="item.size || 'small'"
|
|
|
+ range-separator="至"
|
|
|
+ />
|
|
|
+ </template>
|
|
|
<template v-if="item.inputType === 'cascader'">
|
|
|
<el-cascader
|
|
|
v-model="formData[item.prop]"
|
|
@@ -99,8 +121,12 @@
|
|
|
<script>
|
|
|
import { TempQuery } from '@/api/temp'
|
|
|
import { mapGetters } from 'vuex'
|
|
|
+import YearRangePicker from '@/components/YearRangePicker'
|
|
|
+import { parseTime } from '@/utils'
|
|
|
+
|
|
|
export default {
|
|
|
name: 'StatisticsHeader',
|
|
|
+ components: { YearRangePicker },
|
|
|
props: {
|
|
|
title: {
|
|
|
type: String,
|
|
@@ -136,7 +162,7 @@ export default {
|
|
|
formData: {
|
|
|
range: '',
|
|
|
inOrOut: '',
|
|
|
- interval: '',
|
|
|
+ td: '',
|
|
|
air_line: [],
|
|
|
area: '',
|
|
|
airport: [],
|
|
@@ -202,11 +228,10 @@ export default {
|
|
|
options: [],
|
|
|
},
|
|
|
{
|
|
|
- prop: 'interval',
|
|
|
+ prop: 'td',
|
|
|
inputType: 'select',
|
|
|
placeholder: '时间维度',
|
|
|
requiredWarning: '请先选择统计时间维度',
|
|
|
- // clearable: true,
|
|
|
options: [
|
|
|
{
|
|
|
value: '日',
|
|
@@ -216,15 +241,79 @@ export default {
|
|
|
value: '月',
|
|
|
label: '按月统计',
|
|
|
},
|
|
|
- {
|
|
|
- value: '季',
|
|
|
- label: '按季统计',
|
|
|
- },
|
|
|
{
|
|
|
value: '年',
|
|
|
label: '按年统计',
|
|
|
},
|
|
|
],
|
|
|
+ changeHandler(value) {
|
|
|
+ const typeMap = {
|
|
|
+ 日: 'datePicker',
|
|
|
+ 月: 'monthPicker',
|
|
|
+ 年: 'yearPicker',
|
|
|
+ }
|
|
|
+ const dateTimeItem = this.formItems.find(
|
|
|
+ item => item.prop === 'dateTime'
|
|
|
+ )
|
|
|
+ if (dateTimeItem) {
|
|
|
+ dateTimeItem.inputType = typeMap[value]
|
|
|
+ const dateTime = formData.dateTime
|
|
|
+ if (dateTime && dateTime[0] && dateTime[1]) {
|
|
|
+ if (value === '年') {
|
|
|
+ this.formData.dateTime[0] = dateTime[0].split('-')[0]
|
|
|
+ this.formData.dateTime[1] = dateTime[1].split('-')[0]
|
|
|
+ }
|
|
|
+ if (value === '月') {
|
|
|
+ if (oldValue === '年') {
|
|
|
+ this.formData.dateTime[0] = `${
|
|
|
+ dateTime[0].split('-')[0]
|
|
|
+ }-01`
|
|
|
+ this.formData.dateTime[1] = `${
|
|
|
+ dateTime[1].split('-')[0]
|
|
|
+ }-12`
|
|
|
+ }
|
|
|
+ if (oldValue === '日') {
|
|
|
+ this.formData.dateTime[0] = dateTime[0]
|
|
|
+ .split('-')
|
|
|
+ .slice(0, 2)
|
|
|
+ .join('-')
|
|
|
+ this.formData.dateTime[1] = dateTime[1]
|
|
|
+ .split('-')
|
|
|
+ .slice(0, 2)
|
|
|
+ .join('-')
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (value === '日') {
|
|
|
+ if (oldValue === '年') {
|
|
|
+ this.formData.dateTime[0] = `${
|
|
|
+ dateTime[0].split('-')[0]
|
|
|
+ }-01-01`
|
|
|
+ this.formData.dateTime[1] = `${
|
|
|
+ dateTime[1].split('-')[0]
|
|
|
+ }-12-31`
|
|
|
+ }
|
|
|
+ if (oldValue === '月') {
|
|
|
+ this.formData.dateTime[0] = `${dateTime[0]
|
|
|
+ .split('-')
|
|
|
+ .slice(0, 2)
|
|
|
+ .join('-')}-01`
|
|
|
+ let [year, month] = dateTime[1].split('-')
|
|
|
+ if (month === '12') {
|
|
|
+ year = Number(year) + 1
|
|
|
+ month = 1
|
|
|
+ } else {
|
|
|
+ month = Number(month) + 1
|
|
|
+ }
|
|
|
+ const day = 24 * 60 * 60 * 1000
|
|
|
+ this.formData.dateTime[1] = parseTime(
|
|
|
+ new Date(`${year}-${month}-01`) - day * 1,
|
|
|
+ '{y}-{m}-{d}'
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
},
|
|
|
{
|
|
|
prop: 'dateTime',
|
|
@@ -312,7 +401,7 @@ export default {
|
|
|
item.changeHandler &&
|
|
|
String(val[item.prop]) !== String(oldVal[item.prop])
|
|
|
) {
|
|
|
- item.changeHandler.call(this, val[item.prop])
|
|
|
+ item.changeHandler.call(this, val[item.prop], oldVal[item.prop])
|
|
|
}
|
|
|
})
|
|
|
},
|
|
@@ -350,11 +439,12 @@ export default {
|
|
|
},
|
|
|
methods: {
|
|
|
getData() {
|
|
|
+ const formData = this._.cloneDeep(this.formData)
|
|
|
try {
|
|
|
this.formItems.forEach(item => {
|
|
|
if (
|
|
|
item.requiredWarning &&
|
|
|
- (!this.formData[item.prop] || this.formData[item.prop].length === 0)
|
|
|
+ (!formData[item.prop] || formData[item.prop].length === 0)
|
|
|
) {
|
|
|
throw new Error(item.requiredWarning)
|
|
|
}
|
|
@@ -363,20 +453,40 @@ export default {
|
|
|
this.$message.warning(error.message)
|
|
|
return
|
|
|
}
|
|
|
- if (this.formData.range === '航线' && !this.formData.air_line) {
|
|
|
+ if (formData.range === '航线' && !formData.air_line) {
|
|
|
this.$message.warning('请先选择航线')
|
|
|
return
|
|
|
- } else if (this.formData.range === '航站' && !this.formData.airport) {
|
|
|
+ } else if (formData.range === '航站' && !formData.airport) {
|
|
|
this.$message.warning('请先选择航站')
|
|
|
return
|
|
|
- } else if (this.formData.range === '基地分公司' && !this.formData.area) {
|
|
|
+ } else if (formData.range === '基地分公司' && !formData.area) {
|
|
|
this.$message.warning('请先选择基地分公司')
|
|
|
return
|
|
|
}
|
|
|
- this.$emit('getFormData', this.formData)
|
|
|
this.$store.dispatch('savedSettings/saveFormData', {
|
|
|
- formData: this.formData,
|
|
|
+ formData,
|
|
|
})
|
|
|
+ if (formData.td === '月') {
|
|
|
+ formData.dateTime[0] = `${formData.dateTime[0]}-01`
|
|
|
+ let [year, month] = formData.dateTime[1].split('-')
|
|
|
+ if (month === '12') {
|
|
|
+ year = Number(year) + 1
|
|
|
+ month = 1
|
|
|
+ } else {
|
|
|
+ month = Number(month) + 1
|
|
|
+ }
|
|
|
+ const day = 24 * 60 * 60 * 1000
|
|
|
+ formData.dateTime[1] = parseTime(
|
|
|
+ new Date(`${year}-${month}-01`) - day * 1,
|
|
|
+ '{y}-{m}-{d}'
|
|
|
+ )
|
|
|
+ } else if (formData.td === '年') {
|
|
|
+ formData.dateTime = [
|
|
|
+ `${formData.dateTime[0]}-01-01`,
|
|
|
+ `${formData.dateTime[1]}-12-31`,
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ this.$emit('getFormData', formData)
|
|
|
},
|
|
|
exportClickHandler() {
|
|
|
this.$emit('export')
|
|
@@ -520,6 +630,8 @@ export default {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ .el-date-editor--monthrange.el-input,
|
|
|
+ .el-date-editor--monthrange.el-input__inner,
|
|
|
.el-date-editor--daterange.el-input,
|
|
|
.el-date-editor--daterange.el-input__inner,
|
|
|
.el-date-editor--timerange.el-input,
|