SelectMonth.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <div class="select_time" :class="setHeight">
  3. <div class="select_label">选择时间:</div>
  4. <div class="select_week_time">
  5. <div class="select_right">
  6. <div class="op_week_year">
  7. <div class="week_year" v-for="(item, index) in listYear" :key="index">{{item}}年</div>
  8. </div>
  9. <ul class="week_many">
  10. <li class="option_week" v-for="(item, index) in listWeek" :key="index">
  11. <span class="list_span" v-for="(data, i) in item" :class='{active:i==isActive&&index==isIndexActive, getlastmonth:i==lastIndex}' :key="i" @click="getWeek(index, i, data)">{{data}}月</span>
  12. <!-- <span class="list_span" v-for="(data, i) in item" :class='{active:i==isActive&&index==isIndexActive}' :key="i" @click="getWeek(index, i, data)">{{data}}月</span> -->
  13. </li>
  14. </ul>
  15. <div class="putaway" @click="getManyTimes()" v-if="isMany">
  16. <span class="put_text">{{btnText}}</span>
  17. <span class="put_icon" :class="iconClass"></span>
  18. </div>
  19. </div>
  20. </div>
  21. </div>
  22. </template>
  23. <script>
  24. import { dateFormatter } from '@/utils/globalFunctions'
  25. import { getReportStartTime } from '@/api/modules'
  26. import { Icon } from 'element-ui'
  27. export default {
  28. name: 'select_time',
  29. components: {
  30. [Icon.name]: name
  31. },
  32. props: {
  33. queryDate: {
  34. type: Object
  35. },
  36. getTypeTime: {
  37. type: Object,
  38. default () {
  39. return {
  40. judgeTime: ''
  41. }
  42. }
  43. }
  44. },
  45. data () {
  46. return {
  47. listYear: [],
  48. listWeek: [],
  49. setHeight: 'setHeight',
  50. isActive: 0, // 年份坐标月份坐标
  51. isIndexActive: 0, // 年份坐标
  52. isMany: false, // 是否显示更多按钮
  53. btnText: '更多',
  54. iconClass: 'el-icon-arrow-down',
  55. week_starttime: '', // 第一个周报的时间
  56. month_starttime: '', // 第一个月报的时间
  57. lastIndex: 0
  58. }
  59. },
  60. created () {
  61. this.getFirst()
  62. },
  63. methods: {
  64. changeActive (time) {},
  65. getFirst () {
  66. getReportStartTime().then((res) => {
  67. if (res.data) {
  68. if (res.data.month_firsttime !== 0) {
  69. this.month_starttime = res.data.month_firsttime
  70. this.getTimes(res.data.month_firsttime)
  71. } else if (res.data.week_firsttime !== 0) {
  72. this.week_starttime = res.data.week_firsttime
  73. this.getTimes(res.data.week_firsttime)
  74. }
  75. }
  76. })
  77. },
  78. getTimes (date) {
  79. // 处理月份
  80. var week
  81. const aloneWeek = []
  82. const nowweek = dateFormatter(new Date(), 'M')
  83. date = date + ''
  84. if (date.slice(4, 5) === '0') {
  85. week = date.slice(5, 6)
  86. } else {
  87. week = date.slice(4, 6)
  88. }
  89. for (let a = week; a <= 12; a++) {
  90. var weeks = a
  91. aloneWeek.push(weeks + '')
  92. }
  93. // 月报不需要展示当月,加class隐藏
  94. const _this = this
  95. // aloneWeek.forEach(function (time, i) {
  96. // console.log(time, nowweek)
  97. // if (nowweek === time) {
  98. // _this.lastIndex = i
  99. // }
  100. // })
  101. // 处理年份、添加12月
  102. const nowyear = dateFormatter(new Date(), 'yyyy')
  103. let year = date.slice(0, 4)
  104. // 如果第一个月报时间是现在的时间,不显示更多按钮
  105. if (nowyear === year) {
  106. this.isMany = false
  107. } else {
  108. this.isMany = true
  109. }
  110. this.listYear.push(nowyear)
  111. var newArr = []
  112. for (var i = year; i < nowyear; i++) {
  113. // year = year - 1
  114. this.listYear.push(year)
  115. for (var tw = 1; tw <= 12; tw++) {
  116. var twM = tw
  117. twM = '' + twM
  118. newArr.push(twM)
  119. }
  120. this.listWeek.push(newArr)
  121. }
  122. this.listWeek.push(aloneWeek)
  123. this.listWeek[0].forEach(function (item, index) {
  124. if (item === nowweek) {
  125. _this.lastIndex = index
  126. _this.listWeek[0] = _this.listWeek[0].splice(0, index + 1)
  127. }
  128. })
  129. // 高亮处理
  130. const tempData = {
  131. year: 0,
  132. month: 0
  133. }
  134. if (this.queryDate && Object.keys(this.queryDate).length) {
  135. tempData.year = this.listYear.indexOf(this.queryDate.year) || 0
  136. tempData.month = this.listWeek[tempData.year].indexOf(this.queryDate.month)
  137. if (tempData.month === -1) {
  138. tempData.month = (this.listWeek[tempData.year].length - ((this.getTypeTime.judgeTime === 'month') ? 2 : 1))
  139. }
  140. } else {
  141. tempData.year = 0
  142. tempData.month = (this.listWeek[tempData.year].length - ((this.getTypeTime.judgeTime === 'month') ? 2 : 1))
  143. }
  144. console.log('temp', tempData)
  145. this.isActive = tempData.month
  146. this.isIndexActive = tempData.year
  147. },
  148. getWeek (index, i, month) {
  149. this.isActive = i
  150. this.isIndexActive = index
  151. if (month < 10) {
  152. month = '0' + month
  153. }
  154. this.$emit('selectYear', this.listYear[index])
  155. this.$emit('selectYm', this.listYear[index] + month)
  156. },
  157. // 更多、收起
  158. getManyTimes () {
  159. if (this.btnText === '更多') {
  160. this.btnText = '收起'
  161. this.iconClass = 'el-icon-arrow-up'
  162. this.setHeight = ''
  163. } else {
  164. this.btnText = '更多'
  165. this.iconClass = 'el-icon-arrow-down'
  166. this.setHeight = 'setHeight'
  167. }
  168. }
  169. }
  170. }
  171. </script>
  172. <style lang="scss" scoped>
  173. .select_time{
  174. position: relative;
  175. display: flex;
  176. justify-content: flex-start;
  177. margin: 0 auto;
  178. padding: 30px 40px 0;
  179. height: auto;
  180. border-bottom: 1px solid #ececec;
  181. .select_label{
  182. width: 70px;
  183. height: 24px;
  184. opacity: 1;
  185. font-size: 14px;
  186. font-family: Microsoft YaHei, Microsoft YaHei-Regular;
  187. font-weight: 400;
  188. text-align: LEFT;
  189. color: #1d1d1d;
  190. line-height: 24px;
  191. }
  192. .select_week_time{
  193. flex: 1;
  194. margin-left: 32px;
  195. .select_right{
  196. display: flex;
  197. .week_year{
  198. display: flex;
  199. margin-bottom: 16px;
  200. height: 30px;
  201. opacity: 1;
  202. font-size: 13px;
  203. font-weight: 400;
  204. color: #999999;
  205. line-height: 20px;
  206. }
  207. .week_many{
  208. flex: 1;
  209. display: flex;
  210. flex-direction: column;
  211. margin-left: 32px;
  212. .option_week{
  213. height: 30px;
  214. margin-bottom: 16px;
  215. .list_span{
  216. margin-right: 24px;
  217. font-size: 13px;
  218. font-family: Microsoft YaHei, Microsoft YaHei-Regular;
  219. font-weight: 400;
  220. text-align: LEFT;
  221. color: #1d1d1d;
  222. line-height: 20px;
  223. cursor: pointer;
  224. }
  225. .active{
  226. color: #2CB7CA;
  227. }
  228. }
  229. }
  230. }
  231. }
  232. }
  233. .putaway{
  234. position: absolute;
  235. right: 40px;
  236. bottom: 16px;
  237. color: #2cb7ca;
  238. cursor: pointer;
  239. .put_text{
  240. opacity: 1;
  241. font-size: 12px;
  242. font-weight: 400;
  243. line-height: 20px;
  244. }
  245. .put_icon{
  246. margin-left: 4px;
  247. font-size: 16px;
  248. }
  249. }
  250. </style>