| | |
| | | <u-button :plain='custom' style="width: 70px;height: 25px;" @click="dateChange('custom')" |
| | | type="primary" shape="circle" text="自定义"></u-button> |
| | | </view> |
| | | |
| | | <view class="head_block" style="height: 80rpx; display: flex;justify-content: space-around;"> |
| | | <u-button :plain='currentQuarter' style="width: 70px;height: 25px;" |
| | | @click="dateChange('currentQuarter')" type="primary" shape="circle" text="本季度"> |
| | | </u-button> |
| | | <u-button :plain='lastQuarter' style="width: 70px;height: 25px;" |
| | | @click="dateChange('lastQuarter')" type="primary" shape="circle" text="上一季度"> |
| | | </u-button> |
| | | |
| | | </view> |
| | | |
| | | </view> |
| | | |
| | | <view v-if="!custom" class="flex_column" |
| | |
| | | today: true, |
| | | month: false, |
| | | custom: true, |
| | | currentQuarter: true, |
| | | lastQuarter: true, |
| | | |
| | | // calendarRange: new Date().toISOString().slice(0, 10) + '~' + new Date().toISOString().slice(0, |
| | | // 10), //系统当前日期 |
| | | calendarRange: new Date().getFullYear() + '-' + (new Date().getMonth() + 1).toString().padStart( |
| | | 2, '0') + '-01' + '~' + new Date().toISOString().slice(0, 10), //当月日期 |
| | | |
| | | // calendarRange: new Date().getFullYear() + '-' + (new Date().getMonth() + 1).toString().padStart( |
| | | // 2, '0') + '-01' + '~' + new Date().toISOString().slice(0, 10), //当月日期 |
| | | calendarRange: '', |
| | | |
| | | |
| | | tagArr: [ |
| | |
| | | } |
| | | }, |
| | | created() { |
| | | |
| | | this.dateChange('currentQuarter') |
| | | }, |
| | | mounted() { |
| | | this.init() |
| | |
| | | this.today = false |
| | | this.month = true |
| | | this.custom = true |
| | | this.currentQuarter = true |
| | | this.lastQuarter = true |
| | | this.calendarRange = new Date().toISOString().slice(0, 10) + '~' + new Date().toISOString().slice(0, |
| | | 10) |
| | | } else if (val === 'month') { |
| | | this.today = true |
| | | this.month = false |
| | | this.custom = true |
| | | |
| | | this.currentQuarter = true |
| | | this.lastQuarter = true |
| | | this.calendarRange = new Date().getFullYear() + '-' + (new Date().getMonth() + 1).toString().padStart( |
| | | 2, '0') + '-01' + '~' + new Date().toISOString().slice(0, 10) |
| | | |
| | |
| | | this.today = true |
| | | this.month = true |
| | | this.custom = false |
| | | this.currentQuarter = true |
| | | this.lastQuarter = true |
| | | this.calendarRange = new Date().getFullYear() + '-' + (new Date().getMonth() + 1).toString().padStart( |
| | | 2, '0') + '-01' + '~' + new Date().toISOString().slice(0, 10) |
| | | } else if (val === 'currentQuarter') { |
| | | this.today = true |
| | | this.month = true |
| | | this.custom = true |
| | | this.currentQuarter = false |
| | | this.lastQuarter = true |
| | | |
| | | this.calendarRange = this.getCurrentQuarter().start + '~' + this.getCurrentQuarter().end |
| | | } else if (val === 'lastQuarter') { |
| | | this.today = true |
| | | this.month = true |
| | | this.custom = true |
| | | this.currentQuarter = true |
| | | this.lastQuarter = false |
| | | this.calendarRange = this.getLastQuarter().start + '~' + this.getLastQuarter().end |
| | | |
| | | } |
| | | }, |
| | | |
| | | |
| | | |
| | | // 获取 本季度 开始、结束日期 |
| | | getCurrentQuarter() { |
| | | const now = new Date() |
| | | const year = now.getFullYear() |
| | | const month = now.getMonth() // 0-11 |
| | | |
| | | // 当前季度 |
| | | const quarter = Math.floor(month / 3) |
| | | const startMonth = quarter * 3 |
| | | const endMonth = startMonth + 2 |
| | | |
| | | const start = new Date(year, startMonth, 1) |
| | | const end = new Date(year, endMonth + 1, 0) // 取当月最后一天 |
| | | |
| | | return { |
| | | start: this.formatDate(start), |
| | | end: this.formatDate(end) |
| | | } |
| | | }, |
| | | |
| | | // 获取 上一季度 开始、结束日期 |
| | | getLastQuarter() { |
| | | const now = new Date() |
| | | const year = now.getFullYear() |
| | | const month = now.getMonth() |
| | | |
| | | let quarter = Math.floor(month / 3) |
| | | let lastQuarter = quarter - 1 |
| | | let lastYear = year |
| | | |
| | | // 如果是第一季度,上季度就是去年第四季度 |
| | | if (lastQuarter < 0) { |
| | | lastQuarter = 3 |
| | | lastYear = year - 1 |
| | | } |
| | | |
| | | const startMonth = lastQuarter * 3 |
| | | const endMonth = startMonth + 2 |
| | | |
| | | const start = new Date(lastYear, startMonth, 1) |
| | | const end = new Date(lastYear, endMonth + 1, 0) |
| | | |
| | | return { |
| | | start: this.formatDate(start), |
| | | end: this.formatDate(end) |
| | | } |
| | | }, |
| | | |
| | | // 日期格式化:yyyy-MM-dd |
| | | formatDate(date) { |
| | | const y = date.getFullYear() |
| | | const m = (date.getMonth() + 1).toString().padStart(2, '0') |
| | | const d = date.getDate().toString().padStart(2, '0') |
| | | return `${y}-${m}-${d}` |
| | | }, |
| | | |
| | | |
| | | // 日历时间点击 |
| | | calendarClick() { |
| | | this.$refs.calendar.open(); |