截取年 月 日 的时间格式
getLastDayOfMonth(year, month) {
let cdate = ''
var date = new Date(year, month - 1, '01')
date.setDate(1)
date.setMonth(date.getMonth() + 1)
cdate = new Date(date.getTime() - 1000 * 60 * 60 * 24)
return cdate.getDate()
},
init(page) {
if (page) {
this.page.offset = page
}
const object = this.filter_HW()
for (const key in object) {
if (key === 'time' && object.time) {
object.startTime = object.time[0] + '-01' || ''
object.year = object.time[1].slice(0, 4)
object.month = object.time[1].substring(5)
const endDate = this.getLastDayOfMonth(object.year, object.month)
object.endTime = object.time[1] + '-' + `${endDate}` || ''
delete object.time
}
}
console.log(object)
if (!object.category) {
object.category = ''
}
}
const l = (object['monthData'] || []).length
object['startMonthData'] = (l > 0 && object['monthData'][0] + '-01') || ''
object['endMonthData'] = (l > 1 && this.getFullDate(object['monthData'][1])) || ''
delete object.monthData
const l = (formObject['monthData'] || []).length
formObject['startTime'] = l > 0 && formObject['monthData'][0] || ''
formObject['endTime'] = (l > 1 && this.getFullDate(formObject['monthData'][1])) || ''
if (formObject.startTime !== '' && formObject.lastTime !== '') {
formObject.startTime = formObject.startTime + '-01'
}
getFullDate(date, fullDate = true) {
if (date && fullDate) {
const getYear = date.slice(0, 4)
const getMonth = date.slice(5, 7)
const fullDate = getYear + '-' + getMonth + '-' + new Date(getYear, getMonth, 0).getDate()
return fullDate
} else if (date && !fullDate) {
return new Date(date.slice(0, 4), date.slice(5, 7), 0).getDate()
} else {
return ''
}
},
yaerDate() {
const date = {
year: new Date().getFullYear(),
month: new Date().getMonth() + 1
}
const systemDate = date.year + '-' + (date.month < 10 ? '0' + date.month : date.month)
const sysDate = date.year + '-' + (date.month < 10 ? '0' + date.month : date.month)
const arr = [systemDate, sysDate]
this.$refs.filter.setValue({ key: 'yearPeriod', value: arr })
}