上篇 点击面板触发事件
作者:互联网
------------恢复内容开始------------
async addEvent() { if (this.setClick) return document.querySelector('.el-month-table').addEventListener('click', () => { this.monthChange() }) document.querySelectorAll("[aria-label='下个月'],[aria-label='上个月'],[aria-label='后一年'],[aria-label='前一年']") .forEach(item => item.addEventListener('click', () => { this.monthChange() })) this.setClick = true }, 上面的函数时点击面板是会触发monthChange()这个函数------------恢复内容结束------------
通过日期选择器的ref属性 获取当前面板的月份年份 row
const month = this.$refs['ref'].picker.month + 1 const year = this.$refs['ref'].picker.year const rows = this.$refs['ref'].picker.$children[0].rows // console.log(rows); const nowDate = new Date('') // 是个位数加0 let isOneAddZero = value => { return value < 10 ? '0' + value : value } // 获取年-月 let getY_M = () => { let returnData = ['', year + '-' + isOneAddZero(month) + '-', ''] if (month == 1) { returnData[0] = (parseInt(year, 10) - 1) + '-12-' returnData[2] = year + '-02-' } else if (month == 12) { returnData[0] = year + '-11-' returnData[2] = (parseInt(year, 10) + 1) + '-01-' } else { returnData[0] = year + '-' + isOneAddZero(parseInt(month, 10) - 1) + '-' returnData[2] = year + '-' + isOneAddZero(parseInt(month, 10) + 1) + '-' } return returnData } const Y_M = getY_M() let startDate = (rows[0][0].type == 'prev-month' ? Y_M[0] : Y_M[1]) + isOneAddZero(rows[0][0].text) let endDate = '' if (nowDate.getFullYear() == year && nowDate.getMonth() + 1 == month) endDate = nowDate.getFullYear() + '-' + isOneAddZero(nowDate.getMonth() + 1) + '-' + isOneAddZero(nowDate.getDate()) else if (nowDate.getFullYear() < year || (nowDate.getFullYear() == year && nowDate.getMonth() + 1 < month)) return; else endDate = (rows[5][6].type == 'next-month' ? Y_M[2] : Y_M[1]) + isOneAddZero(rows[5][6].text)let reportData = { item_id: this.item_id, report_date_start: startDate, report_date_end: endDate } // console.log(reportData, Y_M) 请求后台数据 getReportDataDailyList(reportData).then(res => { this.dataList = res.data.list ? res.data.list : [] // console.log(res.data); // console.log(this.dataList); })
标签:触发,const,returnData,isOneAddZero,month,点击,nowDate,year,面板 来源: https://www.cnblogs.com/Natural-numbers/p/14898101.html