season.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <div>
  3. <span @click="showDoubleMonth">
  4. <el-input v-model="choseQuarter" prefix-icon="el-icon-date" placeholder="请选择" />
  5. </span>
  6. <div v-show="showTime1a" class="show1">
  7. <p>
  8. <button type="button" aria-label="前一年" class="el-picker-panel__icon-btn el-date-picker__prev-btn el-icon-d-arrow-left"
  9. @click="prev" />
  10. <span role="button" class="span-year">{{ year }}年</span>
  11. <button type="button" aria-label="后一年" class="el-picker-panel__icon-btn el-date-picker__next-btn el-icon-d-arrow-right"
  12. @click="next" />
  13. </p>
  14. <div>
  15. <span v-for="(item,index) in fullMonth" :key="index" class="selectMonth" @click="selectQuarter(item)">
  16. {{ item }}
  17. </span>
  18. </div>
  19. </div>
  20. </div>
  21. </template>
  22. <script>
  23. export default {
  24. name: 'season',
  25. data() {
  26. return {
  27. value: '',
  28. showTime2: false,
  29. showTime1a: false,
  30. year: new Date().getFullYear(),
  31. fullMonth: ['第一季度', '第二季度', '第三季度', '第四季度'],
  32. choseQuarter: '',
  33. choseQuarter1: ''
  34. }
  35. },
  36. props:{
  37. isActive:{
  38. type:Boolean,
  39. default:false
  40. }
  41. },
  42. mounted() {
  43. if(!this.isActive){
  44. var date=new Date().getMonth()+1;
  45. var arrs=this.fullMonth;
  46. var str=""
  47. if(date<=3){
  48. str=arrs[0]
  49. }else if(date<=6){
  50. str=arrs[1]
  51. }else if(date<=9){
  52. str=arrs[2]
  53. }else{
  54. str=arrs[3]
  55. }
  56. this.selectQuarter(str);
  57. }
  58. },
  59. methods: {
  60. // 点击季度按钮
  61. quarterTime() {
  62. this.showTime2 = true
  63. this.choseQuarter = ''
  64. this.fullMonth = ['第一季度', '第二季度', '第三季度', '第四季度']
  65. },
  66. // 点击input框
  67. showDoubleMonth() {
  68. this.showTime1a = true
  69. },
  70. // 上一年
  71. prev() {
  72. this.year = this.year * 1 - 1
  73. },
  74. // 下一年
  75. next() {
  76. this.year = this.year * 1 + 1
  77. },
  78. // 点击选项事件
  79. selectQuarter(item) {
  80. switch (item) {
  81. case '第一季度':
  82. this.choseQuarter1 = this.year + '1'
  83. this.choseQuarter = this.year + '年 第一季度'
  84. break
  85. case '第二季度':
  86. this.choseQuarter1 = this.year + '2'
  87. this.choseQuarter = this.year + '年 第二季度'
  88. break
  89. case '第三季度':
  90. this.choseQuarter1 = this.year + '3'
  91. this.choseQuarter = this.year + '年 第三季度'
  92. break
  93. case '第四季度':
  94. this.choseQuarter1 = this.year + '4'
  95. this.choseQuarter = this.year + '年 第四季度'
  96. break
  97. }
  98. this.$emit('confirm', this.choseQuarter1)
  99. this.showTime1a = false
  100. }
  101. }
  102. }
  103. </script>
  104. <style scoped>
  105. * {
  106. margin: 0;
  107. padding: 0;
  108. list-style: none;
  109. }
  110. .show1 {
  111. width: 320px;
  112. margin-top: 5px;
  113. position: absolute;
  114. z-index: 2;
  115. height: auto;
  116. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, .1);
  117. background: #fff;
  118. padding: 5px;
  119. padding-right: 20px;
  120. }
  121. .show1 p:nth-child(1) {
  122. width: 100%;
  123. height: 40px;
  124. border-bottom: 1px solid #f5f5f5;
  125. display: flex;
  126. align-items: center;
  127. justify-content: end;
  128. padding: 0 10px;
  129. }
  130. .show1>div {
  131. width: 100%;
  132. height: auto;
  133. }
  134. .show1>div span {
  135. width: 50%;
  136. }
  137. .selectMonth {
  138. display: inline-block;
  139. float: left;
  140. width: 78px;
  141. height: 40px;
  142. line-height: 40px;
  143. text-align: center;
  144. }
  145. .selectMonth:hover {
  146. background: rgba(19, 131, 255, 0.052);
  147. }
  148. .span-year {
  149. width: 90%;
  150. margin: 0 auto;
  151. display: inline-block;
  152. text-align: center;
  153. line-height: 40px;
  154. }
  155. </style>