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.

198 lines
5.5 KiB

2 years ago
  1. <template>
  2. <v-card outlined class="rounded-xl pl-3">
  3. <v-card-title> {{ $t("Date") }} </v-card-title>
  4. <v-card-subtitle>
  5. <v-dialog v-model="dialog" @click:outside="closeDialog" width="500">
  6. <template v-slot:activator="{ on, attrs }">
  7. <v-btn
  8. class="tw-text-complementary-1 tw-border-solid tw-border-[1px] tw-bg-[#FFFFFF] tw-border-complementary-1 tw-shadow-none remove-upper rounded-lg mt-5"
  9. v-bind="attrs"
  10. v-on="on"
  11. >
  12. {{ $t("Select date") }}
  13. </v-btn>
  14. </template>
  15. <v-card class="rounded-xl pa-4" width="592" height="618">
  16. <v-card-title>
  17. <v-row no-gutters>
  18. <v-col cols="4" class="d-flex justify-start">
  19. <div class="ml-n3">{{ $t("Select Dates") }}</div>
  20. </v-col>
  21. <v-col
  22. cols="8"
  23. class="d-flex justify-end"
  24. @click="dialog = false"
  25. >
  26. X
  27. </v-col>
  28. </v-row>
  29. </v-card-title>
  30. <v-row class="mt-10">
  31. <v-col cols="4">
  32. <v-btn
  33. v-for="(btnText, idx) in btnList"
  34. :key="idx"
  35. width="100%"
  36. text
  37. class="remove-upper justify-start"
  38. :class="{ 'primary--text': idx == selectBtn }"
  39. @click="() => clickRange(idx)"
  40. >
  41. {{ $t(btnText) }}
  42. </v-btn>
  43. </v-col>
  44. <v-col cols="8">
  45. <!-- <v-date-picker v-model="dates" range full-width></v-date-picker> -->
  46. <v-date-picker
  47. :value="dates"
  48. @input="setDates"
  49. :locale="$i18n.locale"
  50. range
  51. full-width
  52. ></v-date-picker>
  53. </v-col>
  54. </v-row>
  55. <v-card-text class="d-flex justify-end align-end mt-8">
  56. <v-btn
  57. text
  58. class="remove-upper primary--text rouned-xl px-8"
  59. @click="setClear([])"
  60. >
  61. {{ $t("Clear") }}
  62. </v-btn>
  63. <v-btn
  64. text
  65. class="remove-upper primary rounded-xl px-8"
  66. @click="closeDialog"
  67. >
  68. {{ $t("Apply") }}
  69. </v-btn>
  70. </v-card-text>
  71. </v-card>
  72. </v-dialog>
  73. </v-card-subtitle>
  74. <v-card-text class="tw-text-complementary-1">
  75. {{ $t("Select") }}:
  76. {{
  77. datesComputed.length == 0
  78. ? $t("All Time")
  79. : datesComputed.length == 1
  80. ? datesComputed[0]
  81. : datesComputed[0] + " ~ " + datesComputed[1]
  82. }}
  83. </v-card-text>
  84. </v-card>
  85. </template>
  86. <script>
  87. import { dateCardFormatDate } from "~/utils/assist";
  88. export default {
  89. props: {
  90. modalChecked: {
  91. type: Array,
  92. default: () => [],
  93. },
  94. },
  95. data() {
  96. return {
  97. dates: [],
  98. btnList: [
  99. "Quick Ranges",
  100. "This month",
  101. "Next month",
  102. "This year",
  103. "Next year",
  104. ],
  105. selectBtn: null,
  106. dialog: false,
  107. clear: false,
  108. };
  109. },
  110. computed: {
  111. datesComputed() {
  112. return this.dates.sort();
  113. },
  114. },
  115. mounted() {
  116. if (this.modalChecked.length > 0) {
  117. this.dates = [...this.modalChecked];
  118. }
  119. },
  120. watch: {
  121. dates(newDates, oldDates) {
  122. if (this.dates.length == 2 || (this.clear && this.dates.length == 0)) {
  123. this.$emit("selectDates", this.dates);
  124. }
  125. },
  126. modalChecked: {
  127. handler: function () {
  128. this.$nextTick(() => {
  129. if (this.modalChecked.length > 0) {
  130. this.dates = [...this.modalChecked];
  131. }
  132. });
  133. },
  134. },
  135. },
  136. methods: {
  137. setDates(dates) {
  138. this.dates = dates;
  139. this.clear = false;
  140. },
  141. setClear(dates) {
  142. this.dates = dates;
  143. this.clear = true;
  144. },
  145. closeDialog() {
  146. this.dialog = !this.dialog;
  147. this.$emit("update", this.datesComputed);
  148. },
  149. clickRange(idx) {
  150. this.selectBtn = idx;
  151. if (idx == 0) {
  152. } else if (idx == 1) {
  153. var thisMonthFirstDay = dateCardFormatDate(
  154. new Date(new Date().getFullYear(), new Date().getMonth(), 1)
  155. );
  156. var thisMonthLastDay = dateCardFormatDate(
  157. new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0)
  158. );
  159. this.setDates([]);
  160. this.$nextTick(() => {
  161. this.setDates([thisMonthFirstDay, thisMonthLastDay]);
  162. });
  163. } else if (idx == 2) {
  164. var nextMonthFirstDay = dateCardFormatDate(
  165. new Date(new Date().getFullYear(), new Date().getMonth() + 1, 1)
  166. );
  167. var nextMonthLastDay = dateCardFormatDate(
  168. new Date(new Date().getFullYear(), new Date().getMonth() + 2, 0)
  169. );
  170. this.setDates([]);
  171. this.$nextTick(() => {
  172. this.setDates([nextMonthFirstDay, nextMonthLastDay]);
  173. });
  174. } else if (idx == 3) {
  175. var thisYearFirstDay = new Date().getFullYear() + "-01-01";
  176. var thisYearLastDay = new Date().getFullYear() + "-12-31";
  177. this.setDates([]);
  178. this.$nextTick(() => {
  179. this.setDates([thisYearFirstDay, thisYearLastDay]);
  180. });
  181. } else if (idx == 4) {
  182. var nextYearFirstDay = new Date().getFullYear() + 1 + "-01-01";
  183. var nextYearLastDay = new Date().getFullYear() + 1 + "-12-31";
  184. this.setDates([]);
  185. this.$nextTick(() => {
  186. this.setDates([nextYearFirstDay, nextYearLastDay]);
  187. });
  188. }
  189. },
  190. },
  191. };
  192. </script>
  193. <style></style>