selectDate.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <div class="selectDate">
  3. <div
  4. v-for="(itm) in btns"
  5. :key="itm.val"
  6. :class="{ active: itm.val === checkId, disabled: itm.disabled }"
  7. @click="changeFn(itm.val)"
  8. >
  9. {{ itm.label }}
  10. </div>
  11. </div>
  12. </template>
  13. <script setup lang="ts">
  14. import { ref } from 'vue'
  15. const emit = defineEmits<{(evt: 'dateChange', type: number): void
  16. }>()
  17. const checkId = ref(1)
  18. const btns = [
  19. { val: 4, label: '总', disabled: true },
  20. { val: 3, label: '年', disabled: false },
  21. { val: 2, label: '月', disabled: false },
  22. { val: 1, label: '日', disabled: false }
  23. ]
  24. function changeFn(id: number) {
  25. checkId.value = id
  26. emit('dateChange', checkId.value)
  27. }
  28. </script>
  29. <style lang="scss" scoped>
  30. .selectDate {
  31. position: absolute;
  32. height: 30px;
  33. border-radius: 30px;
  34. border: solid 1px #2185E8;
  35. left: 50%;
  36. transform: translate(-50%, 0);
  37. top: 10px;
  38. z-index: 2;
  39. display: flex;
  40. cursor: not-allowed;
  41. &>div {
  42. width: 90px;
  43. color: white;
  44. font-size: 16px;
  45. text-align: center;
  46. cursor: pointer;
  47. line-height: 30px;
  48. &:not(:first-child) {
  49. border-left: solid 1px #2185E8;
  50. }
  51. &.disabled {
  52. cursor: not-allowed;
  53. pointer-events: none;
  54. // background: #ccc;
  55. }
  56. &:first-child {
  57. border-radius: 30px 0 0 30px;
  58. }
  59. &:last-child {
  60. border-radius: 0 30px 30px 0;
  61. }
  62. }
  63. .active {
  64. background: #2185e860;
  65. }
  66. }
  67. </style>