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.

81 lines
2.2 KiB

2 years ago
  1. <template>
  2. <div class="tw-flex tw-flex-col-reverse md:tw-flex-row md:tw-items-center">
  3. <button
  4. class="select-date tw-transition tw-w-fit tw-btn-md tw-border tw-border-solid tw-border-secondary-default tw-text-secondary-default tw-bg-white tw-px-[16px] tw-py-[10px] tw-rounded-xl hover:tw-bg-secondary-default hover:tw-text-white">
  5. <client-only>
  6. <a-date-picker v-model="time1" placeholder="Select Time" :disabled-date="disabledDate" format="YYYY.MM.DD"
  7. @change="onChange" @ok="onOk">
  8. <span class="tw-text-secondary-default hover:tw-text-white tw-cursor-pointer">{{ $t("Select Date") }}</span>
  9. </a-date-picker>
  10. </client-only>
  11. </button>
  12. <!-- <a-range-picker v-model="time2">
  13. <span>
  14. {{ time2 ? time2 : "请选择" }}
  15. </span>
  16. </a-range-picker> -->
  17. <div v-show="time1" class="tw-text-secondary-dark tw-body-4 tw-font-medium tw-mb-[15px] md:tw-mb-0 md:tw-ml-[20px]">
  18. {{ $t("Selected: ") }}{{ startDate }}
  19. </div>
  20. </div>
  21. </template>
  22. <script>
  23. import moment from "moment";
  24. export default {
  25. props: {
  26. start: {
  27. type: String
  28. },
  29. end: {
  30. type: String
  31. }
  32. },
  33. data() {
  34. return {
  35. time1: undefined,
  36. time2: undefined,
  37. };
  38. },
  39. computed: {
  40. startDate() {
  41. return moment(this.time1).format("YYYY.MM.DD");
  42. },
  43. endDate() {
  44. return moment(this.time2).format("YYYY.MM.DD");
  45. },
  46. },
  47. methods: {
  48. onChange(value, dateString) {
  49. console.log("Selected Time: ", value);
  50. console.log("Formatted Selected Time: ", dateString);
  51. this.$emit('selected', dateString);
  52. },
  53. onOk(value) {
  54. console.log("onOk: ", value);
  55. },
  56. clearTime() {
  57. this.time1 = undefined;
  58. this.$emit('selected', '');
  59. },
  60. disabledDate(current) {
  61. // const today = new Date();
  62. // today.setHours(0, 0, 0, 0);
  63. const startDate = new Date(this.start);
  64. const endDate = new Date(this.end);
  65. startDate.setHours(0, 0, 0, 0);
  66. endDate.setHours(0, 0, 0, 0);
  67. endDate.setDate(endDate.getDate() + 1);
  68. return current < startDate || current > endDate;
  69. },
  70. },
  71. };
  72. </script>
  73. <style lang="scss" scoped>
  74. .select-date {
  75. &:hover {
  76. span {
  77. color: #fefefe !important;
  78. }
  79. }
  80. }
  81. </style>