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>
|
2022-11-18 18:48:15 +00:00
|
|
|
<b-form-group class="ms-2 col-md-6" label="End date" label-for="dp_dateTo">
|
2021-05-24 09:34:48 +00:00
|
|
|
<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>
|
2022-10-30 13:26:23 +00:00
|
|
|
<label class="text-start">
|
2021-05-24 09:34:48 +00:00
|
|
|
Timerange: <b>{{ timeRange }}</b>
|
|
|
|
</label>
|
|
|
|
</div>
|
2020-07-11 17:55:47 +00:00
|
|
|
</template>
|
|
|
|
|
2022-12-10 12:39:53 +00:00
|
|
|
<script setup lang="ts">
|
2020-12-05 18:32:37 +00:00
|
|
|
import { dateFromString, dateStringToTimeRange, timestampToDateString } from '@/shared/formatters';
|
2022-12-10 12:39:53 +00:00
|
|
|
import { ref, computed, onMounted, watch } from 'vue';
|
2020-07-11 17:55:47 +00:00
|
|
|
|
|
|
|
const now = new Date();
|
|
|
|
|
2022-12-10 12:39:53 +00:00
|
|
|
const props = defineProps({
|
|
|
|
modelValue: { required: true, type: String },
|
|
|
|
});
|
|
|
|
const emit = defineEmits(['update:modelValue']);
|
|
|
|
const dateFrom = ref<string>('');
|
|
|
|
const dateTo = ref<string>('');
|
2020-12-05 18:32:37 +00:00
|
|
|
|
2022-12-10 12:39:53 +00:00
|
|
|
const timeRange = computed(() => {
|
|
|
|
if (dateFrom.value !== '' || dateTo.value !== '') {
|
|
|
|
return `${dateStringToTimeRange(dateFrom.value)}-${dateStringToTimeRange(dateTo.value)}`;
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
});
|
2020-07-11 17:55:47 +00:00
|
|
|
|
2022-12-10 12:39:53 +00:00
|
|
|
const updated = () => {
|
|
|
|
emit('update:modelValue', timeRange.value);
|
|
|
|
};
|
2021-07-04 14:25:41 +00:00
|
|
|
|
2022-12-10 12:39:53 +00:00
|
|
|
const updateInput = () => {
|
|
|
|
const tr = props.modelValue.split('-');
|
|
|
|
if (tr[0]) {
|
|
|
|
dateFrom.value = timestampToDateString(dateFromString(tr[0], 'yyyyMMdd'));
|
|
|
|
}
|
|
|
|
if (tr.length > 1 && tr[1]) {
|
|
|
|
dateTo.value = timestampToDateString(dateFromString(tr[1], 'yyyyMMdd'));
|
|
|
|
}
|
|
|
|
updated();
|
|
|
|
};
|
2021-07-04 14:25:41 +00:00
|
|
|
|
2022-12-10 12:39:53 +00:00
|
|
|
watch(
|
|
|
|
() => timeRange.value,
|
|
|
|
() => updated(),
|
|
|
|
);
|
2020-07-11 17:55:47 +00:00
|
|
|
|
2022-12-10 12:39:53 +00:00
|
|
|
onMounted(() => {
|
|
|
|
if (!props.modelValue) {
|
|
|
|
dateFrom.value = timestampToDateString(new Date(now.getFullYear(), now.getMonth() - 1, 1));
|
|
|
|
} else {
|
|
|
|
updateInput();
|
|
|
|
}
|
|
|
|
emit('update:modelValue', timeRange.value);
|
2022-04-21 04:37:57 +00:00
|
|
|
});
|
2020-07-11 17:55:47 +00:00
|
|
|
</script>
|
|
|
|
|
2021-05-24 09:03:36 +00:00
|
|
|
<style scoped></style>
|