index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <div class="date-picker">
  3. <div class="date-picker-box">
  4. <vc-date-picker
  5. ref="Calendar"
  6. class="calendar"
  7. v-model="date"
  8. :disabled-dates='disabledDates'
  9. @transition-start="queryMoth"
  10. @dayclick="onDayClick">
  11. </vc-date-picker>
  12. </div>
  13. <van-divider @click="foldBox">
  14. <van-icon v-if="showPicker" name="arrow-up" color="#ccc" size="20"/>
  15. <van-icon v-else name="arrow-down" color="#ccc" size="20"/>
  16. </van-divider>
  17. <!-- <p class="hide-line" @click="foldBox">-->
  18. <!-- <span>-->
  19. <!-- <van-icon v-if="showPicker" name="arrow-up" color="#ccc" size="20"/>-->
  20. <!-- <van-icon v-else name="arrow-down" color="#ccc" size="20"/>-->
  21. <!-- </span>-->
  22. <!-- </p>-->
  23. </div>
  24. </template>
  25. <script>
  26. import dayjs from "dayjs";
  27. export default {
  28. data(){
  29. let date = dayjs().add(1, 'day').format('YYYY-MM-DD');
  30. return{
  31. date:new Date(),
  32. showPicker:true,
  33. num:0,
  34. height:null,
  35. disabledDates:{
  36. start: date
  37. }
  38. }
  39. },
  40. mounted() {
  41. },
  42. watch:{
  43. // 监听显示状态
  44. showPicker (){
  45. let weeksBox = document.getElementsByClassName('vc-day');
  46. let pickerBox = document.getElementsByClassName('date-picker-box')[0];
  47. if( this.showPicker){
  48. for(let i = 0; i < weeksBox.length;i++){
  49. weeksBox[i].style.transitionDuration = `.5s`;
  50. weeksBox[i].style.transform = `translate(0, 0)`;
  51. }
  52. pickerBox.style.height = `${this.height}px`;
  53. console.log('show')
  54. }else {
  55. this.height = pickerBox.offsetHeight;
  56. for(let i = 0; i < weeksBox.length;i++){
  57. weeksBox[i].style.transitionDuration = `.5s`;
  58. weeksBox[i].style.transform = `translate(0, -${this.num * 32}px)`;
  59. }
  60. pickerBox.style.height = `100px`;
  61. console.log('hide')
  62. }
  63. }
  64. },
  65. methods:{
  66. foldBox(){
  67. let date = this.$refs.Calendar
  68. console.log(date,'this.$refs.Calendar')
  69. this.showPicker = !this.showPicker;
  70. },
  71. // 获取年、月份
  72. queryMoth(){
  73. let Calendar = this.$refs.Calendar;
  74. let year = Calendar.$refs.calendar.pages[0].year;
  75. let month = Calendar.$refs.calendar.pages[0].month;
  76. this.$emit('Mouth',{year,month});
  77. if(!this.showPicker) this.showPicker = true;
  78. },
  79. //点击日期
  80. onDayClick(day){
  81. if(day.isDisabled) return;
  82. console.log(day,'day')
  83. let dayLine = day.classes[7].substring(5);
  84. this.num = dayLine -1;
  85. this.$emit('change',day.id)
  86. },
  87. }
  88. }
  89. </script>
  90. <style lang="scss">
  91. .date-picker {
  92. width: 100%;
  93. background-color: #fff;
  94. box-sizing: border-box;
  95. .calendar {
  96. border: none;
  97. width: 100%;
  98. }
  99. .vc-header{
  100. width: 100%;
  101. background-color: #fff;
  102. position: relative;
  103. z-index:10;
  104. }
  105. .vc-arrow{
  106. position: relative;
  107. z-index:10;
  108. }
  109. .vc-weeks{
  110. overflow: hidden;
  111. transition-duration: .8s;
  112. background-color: #fff;
  113. padding-top: 0;
  114. }
  115. .vc-weekday{
  116. position: relative;
  117. padding-top: 10px;
  118. background-color: #fff;
  119. z-index:10;
  120. }
  121. .vc-day{
  122. transition-duration: .5s;
  123. }
  124. .date-picker-box{
  125. overflow: hidden;
  126. transition-duration: .5s;
  127. }
  128. .hide-line{
  129. box-sizing: border-box;
  130. display: flex;
  131. height: 1px;
  132. width: 100%;
  133. margin: 30px 0;
  134. background-color: #eaeaea;
  135. justify-content: center;
  136. align-items: center;
  137. >span{
  138. display: inline-block;
  139. padding: 6px;
  140. background-color: #fff;
  141. }
  142. }
  143. }
  144. </style>