DataTimingRange.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 v-slot: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, useContext, watch, computed, ComputedRef, Ref, WatchStopHandle
  39. } from '@nuxtjs/composition-api'
  40. import { $useMyProfileUpdater } from '~/use/updater/useMyProfileUpdater'
  41. import { $useDirtyForm } from '~/use/form/useDirtyForm'
  42. export default defineComponent({
  43. setup (_, { emit }) {
  44. const { store, $dataPersister } = useContext()
  45. const { markFormAsNotDirty } = $useDirtyForm(store)
  46. const { updateMyProfile, setHistoricalRange, historical } = $useMyProfileUpdater(store, $dataPersister)
  47. const datesRange:ComputedRef<Array<string>> = computed(() => {
  48. return [historical.value.dateStart, historical.value.dateEnd]
  49. })
  50. const show:Ref<boolean> = ref(false)
  51. if (historical.value.dateStart || historical.value.dateEnd) {
  52. show.value = true
  53. emit('showDateTimeRange', true)
  54. }
  55. const unwatch:WatchStopHandle = watch(show, (newValue) => {
  56. emit('showDateTimeRange', newValue)
  57. })
  58. onUnmounted(() => {
  59. unwatch()
  60. })
  61. const updateDateTimeRange = async (dates:Array<string>): Promise<any> => {
  62. setHistoricalRange(dates)
  63. markFormAsNotDirty()
  64. await updateMyProfile()
  65. window.location.reload()
  66. }
  67. return {
  68. show,
  69. datesRange,
  70. updateDateTimeRange
  71. }
  72. }
  73. })
  74. </script>
  75. <style lang="scss">
  76. .v-btn--active .v-icon{
  77. color: #FFF !important;
  78. }
  79. .time-btn{
  80. border-width: 1px 1px 1px 0px;
  81. border-style: solid;
  82. border-color: rgba(0, 0, 0, 0.12) !important;
  83. }
  84. .time-range{
  85. max-height: 20px;
  86. .v-text-field{
  87. padding-top: 0 !important;
  88. margin-top: 0 !important;
  89. }
  90. .v-icon{
  91. font-size: 20px;
  92. }
  93. input{
  94. font-size: 14px;
  95. width: 400px !important;
  96. }
  97. }
  98. </style>