Commit 9a89d8b8 authored by xiejb's avatar xiejb

高级搜索时间快捷按钮 今天 7天 30天

parent 5f3d62d9
......@@ -153,15 +153,15 @@ export default {
},
dataType: [
{
name: '本日',
name: '今天',
active: true
},
{
name: '本周',
name: '七天',
active: false
},
{
name: '本月',
name: '30天',
active: false
}
// {
......@@ -427,15 +427,15 @@ export default {
_this.showCustomizeDate = false
_this.getCurrentSeason()
break
case '本月':
case '30天':
_this.showCustomizeDate = false
_this.getCurrentMonth()
break
case '本周':
case '七天':
_this.showCustomizeDate = false
_this.getCurrentWeek()
break
case '本日':
case '今天':
_this.showCustomizeDate = false
_this.getCurrentDate()
break
......@@ -501,67 +501,57 @@ export default {
// 起止日期数组
// var startStop = []
// 获取当前时间
var currentDate = new Date()
// 获得当前月份0-11
var currentMonth = currentDate.getMonth()
// 获得当前年份4位年
var currentYear = currentDate.getFullYear()
// 求出本月第一天
var firstDay = new Date(currentYear, currentMonth, 1)
// var currentDate = new Date()
// // 获得当前月份0-11
// var currentMonth = currentDate.getMonth()
// // 获得当前年份4位年
// var currentYear = currentDate.getFullYear()
// // 求出本月第一天
// var firstDay = new Date(currentYear, currentMonth, 1)
// 当为12月的时候年份需要加1
// 月份需要更新为0 也就是下一年的第一个月
if (currentMonth == 11) {
currentYear++
currentMonth = 0 // 就为
} else {
// 否则只是月份增加,以便求的下一月的第一天
currentMonth++
}
// // 当为12月的时候年份需要加1
// // 月份需要更新为0 也就是下一年的第一个月
// if (currentMonth == 11) {
// currentYear++
// currentMonth = 0 // 就为
// } else {
// // 否则只是月份增加,以便求的下一月的第一天
// currentMonth++
// }
// 一天的毫秒数
var millisecond = 1000 * 60 * 60 * 24
// 下月的第一天
var nextMonthDayOne = new Date(currentYear, currentMonth, 1)
// 求出上月的最后一天
// var lastDay = new Date(nextMonthDayOne.getTime() - millisecond)
var lastDay = new Date()
// 添加至数组中返回
// startStop.push(firstDay)
// startStop.push(lastDay)
this.moreSearchInfo.time.start = getFormateDate(firstDay, 'yyyy-MM-dd')
this.moreSearchInfo.time.end = getFormateDate(lastDay, 'yyyy-MM-dd')
// // 一天的毫秒数
// var millisecond = 1000 * 60 * 60 * 24
// // 下月的第一天
// var nextMonthDayOne = new Date(currentYear, currentMonth, 1)
// // 求出上月的最后一天
// // var lastDay = new Date(nextMonthDayOne.getTime() - millisecond)
// var lastDay = new Date()
// // 添加至数组中返回
// // startStop.push(firstDay)
// // startStop.push(lastDay)
// this.moreSearchInfo.time.start = getFormateDate(firstDay, 'yyyy-MM-dd')
// this.moreSearchInfo.time.end = getFormateDate(lastDay, 'yyyy-MM-dd')
this.moreSearchInfo.time.start = this.getDay(getFormateDate(new Date(), 'yyyy-MM-dd'), -30)
this.moreSearchInfo.time.end = getFormateDate(new Date(), 'yyyy-MM-dd')
// 返回
// return startStop
},
// 获得当前星期的开始与结束日期
getCurrentWeek () {
// 起止日期数组
// var startStop = []
// 获取当前时间
var currentDate = new Date()
// 返回date是一周中的某一天
var week = currentDate.getDay()
// 返回date是一个月中的某一天
// var month = currentDate.getDate()
// var currentDate = new Date()
// // 返回date是一周中的某一天
// var week = currentDate.getDay()
// 一天的毫秒数
var millisecond = 1000 * 60 * 60 * 24
// 减去的天数
var minusDay = week != 0 ? week - 1 : 6
// alert(minusDay);
// 本周 周一
var monday = new Date(currentDate.getTime() - (minusDay * millisecond))
// 本周 周日
// var sunday = new Date(monday.getTime() + (6 * millisecond))
// // 一天的毫秒数
// var millisecond = 1000 * 60 * 60 * 24
// // 减去的天数
// var minusDay = week != 0 ? week - 1 : 6
// // alert(minusDay);
// // 本周 周一
// var monday = new Date(currentDate.getTime() - (minusDay * millisecond))
var sunday = new Date()
// 添加本周时间
// startStop.push(monday) // 本周起始时间
// // 添加本周最后一天时间
// startStop.push(sunday) // 本周终止时间
// 返回
// return startStop
this.moreSearchInfo.time.start = getFormateDate(monday, 'yyyy-MM-dd')
this.moreSearchInfo.time.start = this.getDay(getFormateDate(sunday, 'yyyy-MM-dd'), -7)
this.moreSearchInfo.time.end = getFormateDate(sunday, 'yyyy-MM-dd')
},
// 获取当天的日期
......@@ -579,17 +569,33 @@ export default {
if (month < 3) {
return spring
}
if (month < 6) {
return summer
}
if (month < 9) {
return fall
}
return winter
}
},
getDay(time,day) {  
var today = new Date(time);
var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;  
today.setTime(targetday_milliseconds); //注意,这行是关键代码
  
var tYear = today.getFullYear();  
var tMonth = today.getMonth();  
var tDate = today.getDate();  
tMonth = this.doHandleMonth(tMonth + 1);  
tDate = this.doHandleMonth(tDate);  
return tYear + "-" + tMonth + "-" + tDate;
},
doHandleMonth(month) {  
var m = month;  
if (month.toString().length == 1) {  
m = "0" + month;  
}  
return m;
},
}
}
</script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment