123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- <template>
- <div class="select_time" :class="setHeight">
- <div class="select_label">选择时间:</div>
- <div class="select_week_time">
- <div class="select_right">
- <div class="op_week_year">
- <div class="week_year" v-for="(item, index) in listYear" :key="index">{{item}}年</div>
- </div>
- <ul class="week_many">
- <li class="option_week" v-for="(item, index) in listWeek" :key="index">
- <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>
- <!-- <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> -->
- </li>
- </ul>
- <div class="putaway" @click="getManyTimes()" v-if="isMany">
- <span class="put_text">{{btnText}}</span>
- <span class="put_icon" :class="iconClass"></span>
- </div>
- </div>
- </div>
- </div>
- </template>
- <script>
- import { dateFormatter } from '@/utils/globalFunctions'
- import { getReportStartTime } from '@/api/modules'
- import { Icon } from 'element-ui'
- export default {
- name: 'select_time',
- components: {
- [Icon.name]: name
- },
- props: {
- queryDate: {
- type: Object
- },
- getTypeTime: {
- type: Object,
- default () {
- return {
- judgeTime: ''
- }
- }
- }
- },
- data () {
- return {
- listYear: [],
- listWeek: [],
- setHeight: 'setHeight',
- isActive: 0, // 年份坐标月份坐标
- isIndexActive: 0, // 年份坐标
- isMany: false, // 是否显示更多按钮
- btnText: '更多',
- iconClass: 'el-icon-arrow-down',
- week_starttime: '', // 第一个周报的时间
- month_starttime: '', // 第一个月报的时间
- lastIndex: 0
- }
- },
- created () {
- this.getFirst()
- },
- methods: {
- changeActive (time) {},
- getFirst () {
- getReportStartTime().then((res) => {
- if (res.data) {
- if (res.data.month_firsttime !== 0) {
- this.month_starttime = res.data.month_firsttime
- this.getTimes(res.data.month_firsttime)
- } else if (res.data.week_firsttime !== 0) {
- this.week_starttime = res.data.week_firsttime
- this.getTimes(res.data.week_firsttime)
- }
- }
- })
- },
- getTimes (date) {
- // 处理月份
- var week
- const aloneWeek = []
- const nowweek = dateFormatter(new Date(), 'M')
- date = date + ''
- if (date.slice(4, 5) === '0') {
- week = date.slice(5, 6)
- } else {
- week = date.slice(4, 6)
- }
- for (let a = week; a <= 12; a++) {
- var weeks = a
- aloneWeek.push(weeks + '')
- }
- // 月报不需要展示当月,加class隐藏
- const _this = this
- // aloneWeek.forEach(function (time, i) {
- // console.log(time, nowweek)
- // if (nowweek === time) {
- // _this.lastIndex = i
- // }
- // })
- // 处理年份、添加12月
- const nowyear = dateFormatter(new Date(), 'yyyy')
- let year = date.slice(0, 4)
- // 如果第一个月报时间是现在的时间,不显示更多按钮
- if (nowyear === year) {
- this.isMany = false
- } else {
- this.isMany = true
- }
- this.listYear.push(nowyear)
- var newArr = []
- for (var i = year; i < nowyear; i++) {
- // year = year - 1
- this.listYear.push(year)
- for (var tw = 1; tw <= 12; tw++) {
- var twM = tw
- twM = '' + twM
- newArr.push(twM)
- }
- this.listWeek.push(newArr)
- }
- this.listWeek.push(aloneWeek)
- this.listWeek[0].forEach(function (item, index) {
- if (item === nowweek) {
- _this.lastIndex = index
- _this.listWeek[0] = _this.listWeek[0].splice(0, index + 1)
- }
- })
- // 高亮处理
- const tempData = {
- year: 0,
- month: 0
- }
- if (this.queryDate && Object.keys(this.queryDate).length) {
- tempData.year = this.listYear.indexOf(this.queryDate.year) || 0
- tempData.month = this.listWeek[tempData.year].indexOf(this.queryDate.month)
- if (tempData.month === -1) {
- tempData.month = (this.listWeek[tempData.year].length - ((this.getTypeTime.judgeTime === 'month') ? 2 : 1))
- }
- } else {
- tempData.year = 0
- tempData.month = (this.listWeek[tempData.year].length - ((this.getTypeTime.judgeTime === 'month') ? 2 : 1))
- }
- console.log('temp', tempData)
- this.isActive = tempData.month
- this.isIndexActive = tempData.year
- },
- getWeek (index, i, month) {
- this.isActive = i
- this.isIndexActive = index
- if (month < 10) {
- month = '0' + month
- }
- this.$emit('selectYear', this.listYear[index])
- this.$emit('selectYm', this.listYear[index] + month)
- },
- // 更多、收起
- getManyTimes () {
- if (this.btnText === '更多') {
- this.btnText = '收起'
- this.iconClass = 'el-icon-arrow-up'
- this.setHeight = ''
- } else {
- this.btnText = '更多'
- this.iconClass = 'el-icon-arrow-down'
- this.setHeight = 'setHeight'
- }
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .select_time{
- position: relative;
- display: flex;
- justify-content: flex-start;
- margin: 0 auto;
- padding: 30px 40px 0;
- height: auto;
- border-bottom: 1px solid #ececec;
- .select_label{
- width: 70px;
- height: 24px;
- opacity: 1;
- font-size: 14px;
- font-family: Microsoft YaHei, Microsoft YaHei-Regular;
- font-weight: 400;
- text-align: LEFT;
- color: #1d1d1d;
- line-height: 24px;
- }
- .select_week_time{
- flex: 1;
- margin-left: 32px;
- .select_right{
- display: flex;
- .week_year{
- display: flex;
- margin-bottom: 16px;
- height: 30px;
- opacity: 1;
- font-size: 13px;
- font-weight: 400;
- color: #999999;
- line-height: 20px;
- }
- .week_many{
- flex: 1;
- display: flex;
- flex-direction: column;
- margin-left: 32px;
- .option_week{
- height: 30px;
- margin-bottom: 16px;
- .list_span{
- margin-right: 24px;
- font-size: 13px;
- font-family: Microsoft YaHei, Microsoft YaHei-Regular;
- font-weight: 400;
- text-align: LEFT;
- color: #1d1d1d;
- line-height: 20px;
- cursor: pointer;
- }
- .active{
- color: #2CB7CA;
- }
- }
- }
- }
- }
- }
- .putaway{
- position: absolute;
- right: 40px;
- bottom: 16px;
- color: #2cb7ca;
- cursor: pointer;
- .put_text{
- opacity: 1;
- font-size: 12px;
- font-weight: 400;
- line-height: 20px;
- }
- .put_icon{
- margin-left: 4px;
- font-size: 16px;
- }
- }
- </style>
|