select-time.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <div class="time-select">
  3. <div
  4. v-for="i in timeList"
  5. :key="i.id"
  6. class="time-tap"
  7. :class="activeId === i.id && 'active'"
  8. @click="handleTimeSelct(i)"
  9. >
  10. {{ i.content }}
  11. </div>
  12. <el-date-picker
  13. v-model="time"
  14. type="daterange"
  15. range-separator="至"
  16. start-placeholder="开始日期"
  17. end-placeholder="结束日期"
  18. format="yyyy-MM-dd"
  19. value-format="yyyy-MM-dd"
  20. />
  21. </div>
  22. </template>
  23. <script>
  24. import loopEchart from '../mixins/index'
  25. export default {
  26. mixins: [loopEchart],
  27. props: {
  28. timeList: {
  29. type: Array,
  30. default: () => [
  31. {
  32. id: 1,
  33. content: '昨天'
  34. },
  35. {
  36. id: 2,
  37. content: '近1月'
  38. },
  39. {
  40. id: 3,
  41. content: '近6月'
  42. },
  43. {
  44. id: 4,
  45. content: '近1年'
  46. },
  47. {
  48. id: 0,
  49. content: '全部'
  50. }
  51. ]
  52. },
  53. activeLinkId: {
  54. type: Number,
  55. default: 1
  56. }
  57. },
  58. data() {
  59. return {
  60. time: [],
  61. activeId: 1
  62. }
  63. },
  64. watch: {
  65. activeId: {
  66. handler(e) {
  67. const obj = {
  68. 1: () => this.getYesterDay(1),
  69. 2: () => this.getMonths(1),
  70. 3: () => this.getMonths(6),
  71. 4: () => this.getYears(1),
  72. 0: () => {
  73. this.time = []
  74. },
  75. 5: () => this.getWeeks(1)
  76. }
  77. this.time = e !== 0 ? [obj[e](), this.getDay()] : ['', '']
  78. },
  79. immediate: true
  80. },
  81. time: {
  82. handler(e) {
  83. this.$emit('handleSelectTime', e)
  84. },
  85. immediate: true
  86. },
  87. activeLinkId: {
  88. handler(val) {
  89. if (val) {
  90. this.activeId = val
  91. }
  92. },
  93. immediate: true
  94. }
  95. },
  96. methods: {
  97. handleTimeSelct($event) {
  98. this.activeId = $event.id
  99. }
  100. }
  101. }
  102. </script>
  103. <style lang="scss">
  104. .time-select {
  105. display: flex;
  106. align-items: center;
  107. padding: 0.5vw 0;
  108. .time-tap {
  109. margin-right: 1vw;
  110. font-size: 14px;
  111. color: #ccc;
  112. cursor: pointer;
  113. &.active {
  114. color: rgb(0, 174, 255);
  115. }
  116. }
  117. }
  118. .el-picker-panel {
  119. z-index: 9999999 !important;
  120. }
  121. </style>