You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
1.6KB

  1. <template>
  2. <v-menu
  3. v-model="show"
  4. :close-on-content-click="false"
  5. :nudge-right="40"
  6. transition="scale-transition"
  7. offset-y
  8. min-width="290px"
  9. >
  10. <template #activator="{ on }">
  11. <v-text-field
  12. v-model="dateFormatted"
  13. :label="label"
  14. :clearable="clearable"
  15. prepend-icon="mdi-calendar"
  16. readonly
  17. v-on="on"
  18. />
  19. </template>
  20. <v-date-picker
  21. v-model="date"
  22. :first-day-of-week="1"
  23. @input="show = false"
  24. />
  25. </v-menu>
  26. </template>
  27. <script>
  28. export default {
  29. name: 'DateSelector',
  30. props: {
  31. value: {
  32. type: String,
  33. default: '',
  34. },
  35. label: {
  36. type: String,
  37. default: '',
  38. },
  39. clearable: {
  40. type: Boolean,
  41. required: false,
  42. default: false,
  43. },
  44. },
  45. data: () => ({
  46. show: false,
  47. }),
  48. computed: {
  49. dateFormatted: {
  50. get () {
  51. return this.formatDate(this.value)
  52. },
  53. set (val) {
  54. this.$emit('input', this.parseDate(val))
  55. },
  56. },
  57. date: {
  58. get () {
  59. return this.value
  60. },
  61. set (val) {
  62. this.$emit('input', val)
  63. },
  64. },
  65. },
  66. methods: {
  67. formatDate (date) {
  68. if (!date) return null
  69. const [year, month, day] = date.split('-')
  70. return `${day}.${month}.${year}`
  71. },
  72. parseDate (date) {
  73. if (!date) return null
  74. const [day, month, year] = date.split('/')
  75. return `${year}-${month.padStart(2, '0')}-${day.padStart(2, '0')}`
  76. },
  77. },
  78. }
  79. </script>
  80. <style scoped>
  81. </style>