season.vue 4.4 KB

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