WeekDays.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <div class="week-days-content">
  3. <span class="day-item" v-for="(item, index) in weekdays" @click="itemClick(item,index)">
  4. <span :class="['weekday-name',active == index ?'today-active':'']">{{item.weekdayName}}</span>
  5. <span :class="['day-date',active == index ?'date-active':'']">{{item.day}}</span>
  6. <span class="day-has-suit"></span>
  7. </span>
  8. </div>
  9. </template>
  10. <script>
  11. import * as dateUtils from '../utils/dateUtils'
  12. export default {
  13. name: 'WeekDays',
  14. data() {
  15. return {
  16. active: -1
  17. }
  18. },
  19. computed:{
  20. weekdays:function() {
  21. let arr = dateUtils.getWeekDays(this.start,this.end)
  22. let findIndex = arr.findIndex(t=>t.isActive)
  23. if(findIndex > -1){
  24. arr[findIndex].isActive = false
  25. }
  26. this.active = findIndex
  27. return arr
  28. }
  29. },
  30. mounted () {
  31. },
  32. props:{
  33. 'start': {
  34. type: Date,
  35. default: new Date()
  36. },
  37. 'end': {
  38. type: Date,
  39. default: new Date()
  40. }
  41. },
  42. methods:{
  43. itemClick(item,index) {
  44. this.weekdays.forEach(t=>t.isActive = false)
  45. this.active = index
  46. this.$emit('on-item-click',item)
  47. }
  48. }
  49. }
  50. </script>
  51. <style scoped>
  52. .week-days-content {
  53. width: 100%;
  54. display: flex;
  55. }
  56. .day-item{
  57. display: flex;
  58. flex-direction: column;
  59. justify-content: center;
  60. align-items: center;
  61. flex: 1;
  62. }
  63. .day-item span {
  64. width: 100%;
  65. text-align: center;
  66. }
  67. .weekday-name {
  68. flex: 1;
  69. font-size: 0.5em;
  70. color: rgba(0,0,0,0.54);
  71. margin-bottom: 10px;
  72. }
  73. .day-has-suit{
  74. display: block;
  75. width: 6px !important;
  76. height: 6px !important;
  77. background-color: #31CA8A;
  78. border-radius: 100px;
  79. margin-top: 10px;
  80. }
  81. .today-active{
  82. color: black;
  83. font-weight: 600;
  84. }
  85. .date-active{
  86. border-radius: 100px;
  87. background-color: #7D72F2;
  88. color: white;
  89. }
  90. .day-date{
  91. font-size: 1em;
  92. display: block;
  93. width: 5vw !important;
  94. height: 5vw;
  95. line-height: 5vw;
  96. border-radius: 100px;
  97. }
  98. </style>