2020-07-11 17:55:47 +00:00
|
|
|
<template>
|
2021-05-24 09:34:48 +00:00
|
|
|
<div>
|
|
|
|
<div class="d-flex">
|
|
|
|
<b-form-group class="col-md-6" label="Start date" label-for="dp_dateFrom">
|
|
|
|
<b-input-group>
|
|
|
|
<b-input-group-prepend>
|
|
|
|
<b-form-datepicker v-model="dateFrom" class="mb-1" button-only></b-form-datepicker>
|
|
|
|
</b-input-group-prepend>
|
|
|
|
<b-form-input
|
|
|
|
id="dp_dateFrom"
|
|
|
|
v-model="dateFrom"
|
|
|
|
type="text"
|
|
|
|
placeholder="YYYY-MM-DD"
|
|
|
|
autocomplete="off"
|
|
|
|
></b-form-input>
|
|
|
|
</b-input-group>
|
|
|
|
</b-form-group>
|
|
|
|
<b-form-group class="ml-2 col-md-6" label="End date" label-for="dp_dateTo">
|
|
|
|
<b-input-group>
|
|
|
|
<b-input-group-prepend>
|
|
|
|
<b-form-datepicker v-model="dateTo" class="mb-1" button-only></b-form-datepicker>
|
|
|
|
</b-input-group-prepend>
|
|
|
|
<b-form-input
|
|
|
|
id="dp_dateTo"
|
|
|
|
v-model="dateTo"
|
|
|
|
type="text"
|
|
|
|
placeholder="YYYY-MM-DD"
|
|
|
|
autocomplete="off"
|
|
|
|
></b-form-input>
|
|
|
|
</b-input-group>
|
|
|
|
</b-form-group>
|
|
|
|
</div>
|
|
|
|
<label class="text-left">
|
|
|
|
Timerange: <b>{{ timeRange }}</b>
|
|
|
|
</label>
|
|
|
|
</div>
|
2020-07-11 17:55:47 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-07-04 14:25:41 +00:00
|
|
|
import { Component, Vue, Emit, Prop, Watch } from 'vue-property-decorator';
|
2020-12-05 18:32:37 +00:00
|
|
|
import { dateFromString, dateStringToTimeRange, timestampToDateString } from '@/shared/formatters';
|
2020-07-11 17:55:47 +00:00
|
|
|
|
|
|
|
const now = new Date();
|
|
|
|
@Component({})
|
|
|
|
export default class TimeRangeSelect extends Vue {
|
2020-12-05 18:32:37 +00:00
|
|
|
dateFrom = '';
|
2020-07-11 17:55:47 +00:00
|
|
|
|
|
|
|
dateTo = '';
|
|
|
|
|
2020-12-05 18:32:37 +00:00
|
|
|
@Prop() value!: string;
|
|
|
|
|
2020-07-11 17:55:47 +00:00
|
|
|
@Emit('input')
|
|
|
|
emitTimeRange() {
|
|
|
|
return this.timeRange;
|
|
|
|
}
|
|
|
|
|
2021-07-04 14:25:41 +00:00
|
|
|
@Watch('value')
|
2021-07-17 15:03:45 +00:00
|
|
|
valueChanged(val) {
|
|
|
|
console.log('TimeRange', val);
|
|
|
|
if (val !== this.value) {
|
|
|
|
this.updateInput();
|
|
|
|
}
|
2021-07-04 14:25:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
updateInput() {
|
|
|
|
const tr = this.value.split('-');
|
|
|
|
if (tr[0]) {
|
|
|
|
this.dateFrom = timestampToDateString(dateFromString(tr[0], 'yyyyMMdd'));
|
|
|
|
}
|
|
|
|
if (tr.length > 1 && tr[1]) {
|
|
|
|
this.dateTo = timestampToDateString(dateFromString(tr[1], 'yyyyMMdd'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-11 17:55:47 +00:00
|
|
|
created() {
|
2020-12-05 18:32:37 +00:00
|
|
|
if (!this.value) {
|
|
|
|
this.dateFrom = timestampToDateString(new Date(now.getFullYear(), now.getMonth() - 1, 1));
|
|
|
|
} else {
|
2021-07-04 14:25:41 +00:00
|
|
|
this.updateInput();
|
2020-12-05 18:32:37 +00:00
|
|
|
}
|
2020-07-11 17:55:47 +00:00
|
|
|
this.emitTimeRange();
|
|
|
|
}
|
|
|
|
|
|
|
|
updated() {
|
|
|
|
this.emitTimeRange();
|
|
|
|
}
|
|
|
|
|
|
|
|
get timeRange() {
|
|
|
|
if (this.dateFrom !== '' || this.dateTo !== '') {
|
|
|
|
return `${dateStringToTimeRange(this.dateFrom)}-${dateStringToTimeRange(this.dateTo)}`;
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2021-05-24 09:03:36 +00:00
|
|
|
<style scoped></style>
|