all files / src/datePicker/ calendarYear.vue

0% Statements 0/12
0% Branches 0/2
100% Functions 0/0
0% Lines 0/12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85                                                                                                                                                                         
<template>
<div class="mu-calendar-year-container">
  <div class="mu-calendar-year" ref="container">
    <div class="mu-calendar-year-list">
      <year-button @click="handleClick(year)" v-for="year in years" :key="'yearButton' + year"  :year="year" :selected="year === selectedDate.getFullYear()"/>
    </div>
  </div>
</div>
</template>
 
<script>
import yearButton from './yearButton'
export default {
  props: {
    maxDate: {
      type: Date
    },
    minDate: {
      type: Date
    },
    selectedDate: {
      type: Date
    }
  },
  computed: {
    years () {
      const minYear = this.minDate.getFullYear()
      const maxYear = this.maxDate.getFullYear()
      const years = []
      for (let year = minYear; year <= maxYear; year++) {
        years.push(year)
      }
      return years
    }
  },
  methods: {
    handleClick (year) {
      this.$emit('change', year)
    },
    scrollToSelectedYear (yearButtonNode) {
      const container = this.$refs.container
 
      const containerHeight = container.clientHeight
      const yearButtonNodeHeight = yearButtonNode.clientHeight || 32
 
      const scrollYOffset = (yearButtonNode.offsetTop + yearButtonNodeHeight / 2) - containerHeight / 2
      container.scrollTop = scrollYOffset
    }
  },
  components: {
    'year-button': yearButton
  }
}
</script>
 
<style lang="less">
@import "../styles/import.less";
.mu-calendar-year-container {
  display: flex;
  justify-content: space-between;
  flex-direction: column;
  margin-top: 10px;
  width: 310px;
  height: 272px;
  overflow: hidden;
}
 
.mu-calendar-year {
  background-color: @dialogBackgroundColor;
  height: inherit;
  line-height: 35px;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
}
 
.mu-calendar-year-list {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 100%;
}
</style>