DataTimingRange.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <main class="d-flex align-baseline">
  3. <div v-if="show" class="d-flex align-baseline">
  4. <span class="mr-2 ot_dark_grey--text font-weight-bold">{{ $t('period_choose') }}</span>
  5. <UiInputDatePicker
  6. class="time-range"
  7. label="date_choose"
  8. :data="datesRange"
  9. :range="true"
  10. :dense="true"
  11. :single-line="true"
  12. @update="updateDateTimeRange"
  13. />
  14. </div>
  15. <v-tooltip bottom>
  16. <template #activator="{ on, attrs }">
  17. <v-btn
  18. class="time-btn"
  19. max-height="25"
  20. v-bind="attrs"
  21. elevation="0"
  22. max-width="10px"
  23. min-width="10px"
  24. v-on="on"
  25. @click="show=!show"
  26. >
  27. <v-icon color="ot_grey" class="font-weight-normal" x-small>
  28. fas fa-history
  29. </v-icon>
  30. </v-btn>
  31. </template>
  32. <span>{{ $t('history_help') }}</span>
  33. </v-tooltip>
  34. </main>
  35. </template>
  36. <script lang="ts">
  37. import {
  38. defineComponent, onUnmounted, ref, watch, computed, ComputedRef, Ref, WatchStopHandle
  39. } from '@nuxtjs/composition-api'
  40. import { useMyProfile } from '~/composables/data/useMyProfile'
  41. import { $useForm } from '~/composables/form/useForm'
  42. export default defineComponent({
  43. setup (_, { emit }) {
  44. const { markFormAsNotDirty } = $useForm()
  45. const { updateMyProfile, setHistoricalRange, historical } = useMyProfile()
  46. const datesRange:ComputedRef<Array<any>> = computed(() => {
  47. return [historical.value.dateStart, historical.value.dateEnd]
  48. })
  49. const show:Ref<boolean> = ref(false)
  50. if (historical.value.dateStart || historical.value.dateEnd) {
  51. show.value = true
  52. emit('showDateTimeRange', true)
  53. }
  54. const unwatch:WatchStopHandle = watch(show, (newValue) => {
  55. emit('showDateTimeRange', newValue)
  56. })
  57. onUnmounted(() => {
  58. unwatch()
  59. })
  60. const updateDateTimeRange = async (dates:Array<string>): Promise<any> => {
  61. setHistoricalRange(dates)
  62. markFormAsNotDirty()
  63. await updateMyProfile()
  64. window.location.reload()
  65. }
  66. return {
  67. show,
  68. datesRange,
  69. updateDateTimeRange
  70. }
  71. }
  72. })
  73. </script>
  74. <style lang="scss">
  75. .v-btn--active .v-icon{
  76. color: #FFF !important;
  77. }
  78. .time-btn{
  79. border-width: 1px 1px 1px 0px;
  80. border-style: solid;
  81. border-color: rgba(0, 0, 0, 0.12) !important;
  82. }
  83. .time-range{
  84. max-height: 20px;
  85. .v-text-field{
  86. padding-top: 0 !important;
  87. margin-top: 0 !important;
  88. }
  89. .v-icon{
  90. font-size: 20px;
  91. }
  92. input{
  93. font-size: 14px;
  94. width: 400px !important;
  95. }
  96. }
  97. </style>