DataTimingRange.vue 2.8 KB

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