|
|
|
@ -20,18 +20,11 @@ export class PageTwoTimeComponent implements OnInit {
|
|
|
|
|
@ViewChild('pageTwoName')pageTwoName :PageTwoNameComponent; //父组件中获得子组件的引用
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void { |
|
|
|
|
this.startTime = new FormControl( (new Date()).getFullYear()-10 ) |
|
|
|
|
this.endTime = new FormControl( (new Date()).getFullYear() ) |
|
|
|
|
this.adapter.setLocale('CH') |
|
|
|
|
this.dateInit() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
isQuery:boolean = true; //横纵向查询
|
|
|
|
|
|
|
|
|
|
//查询
|
|
|
|
|
query () { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//shao
|
|
|
|
|
toggleTrue () {
|
|
|
|
|
this.isQuery = true |
|
|
|
@ -44,54 +37,70 @@ export class PageTwoTimeComponent implements OnInit {
|
|
|
|
|
this.echartsData.statefulInspectionToggle = true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
startTime:any; //查询开始时间
|
|
|
|
|
endTime:any; //查询结束时间
|
|
|
|
|
|
|
|
|
|
//选择开始时间
|
|
|
|
|
startEvent (e: MatDatepickerInputEvent<Date>) { |
|
|
|
|
let nowTime = new Date() |
|
|
|
|
if (nowTime < e.value) { |
|
|
|
|
selectType:string = 'month'; //选择当前的 查询类型 按月/年
|
|
|
|
|
|
|
|
|
|
//查询数据
|
|
|
|
|
years:any = [] |
|
|
|
|
selectMonth:any = [1,2,3,4,5,6,7,8,9,10,11,12] |
|
|
|
|
|
|
|
|
|
//日期初始化
|
|
|
|
|
dateInit () { |
|
|
|
|
let date = (new Date()).getFullYear() |
|
|
|
|
for (let i=date; i>=date-10;i--) { |
|
|
|
|
this.years.unshift(i) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
selectOneYear:any = (new Date()).getFullYear() //开始年份
|
|
|
|
|
selectTwoYear:any = (new Date()).getFullYear() //结束年份
|
|
|
|
|
selectStartMonth:any = 1 //开始月份
|
|
|
|
|
selectEndMonth:any = (new Date()).getMonth()+1 //结束月份
|
|
|
|
|
//按月查询
|
|
|
|
|
monthSubmit (e) { |
|
|
|
|
if (e.selectTwoYear > e.selectOneYear) { |
|
|
|
|
let startTime = e.selectOneYear + '-' + e.selectStartMonth + '-' + 1 + ' ' + 0 + ':' + 0 +':'+ 0 |
|
|
|
|
let endTime = e.selectTwoYear + '-' + e.selectEndMonth + '-' + 31 + ' ' + 23 + ':' + 59 +':'+ 59 |
|
|
|
|
console.log(startTime) |
|
|
|
|
console.log(endTime) |
|
|
|
|
} else if (e.selectTwoYear === e.selectOneYear) { |
|
|
|
|
if(e.selectEndMonth >= e.selectStartMonth) { |
|
|
|
|
let startTime = e.selectOneYear + '-' + e.selectStartMonth + '-' + 1 + ' ' + 0 + ':' + 0 +':'+ 0 |
|
|
|
|
let endTime = e.selectTwoYear + '-' + e.selectEndMonth + '-' + 31 + ' ' + 23 + ':' + 59 +':'+ 59 |
|
|
|
|
console.log(startTime) |
|
|
|
|
console.log(endTime) |
|
|
|
|
} else { |
|
|
|
|
const config = new MatSnackBarConfig(); |
|
|
|
|
config.verticalPosition = 'top'; |
|
|
|
|
config.duration = 3000 |
|
|
|
|
this.snackBar.open('请选择正确时间区段','确定',config); |
|
|
|
|
} |
|
|
|
|
}else { |
|
|
|
|
const config = new MatSnackBarConfig(); |
|
|
|
|
config.verticalPosition = 'top'; |
|
|
|
|
config.duration = 3000 |
|
|
|
|
this.snackBar.open('选择时间不能大于现在时间段','确定',config); |
|
|
|
|
this.startTime = new FormControl( new Date(new Date().toLocaleDateString()) ) |
|
|
|
|
} else { |
|
|
|
|
this.startTime = new FormControl(e.value) |
|
|
|
|
this.snackBar.open('请选择正确时间区段','确定',config); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//选择结束时间
|
|
|
|
|
endEvent (e: MatDatepickerInputEvent<Date>) { |
|
|
|
|
let oneDay:number = 86399000; //一天的毫秒数
|
|
|
|
|
let selectDay = (e.value).toLocaleDateString() //选择的年月日
|
|
|
|
|
let newDay = (new Date()).toLocaleDateString() //现在的年月日
|
|
|
|
|
let nowTime = new Date() //现在的时间
|
|
|
|
|
|
|
|
|
|
if (nowTime < e.value && selectDay!=newDay) { //选择时间段大于现在时间段时
|
|
|
|
|
|
|
|
|
|
selectStartYear:any = (new Date()).getFullYear() //开始年份
|
|
|
|
|
selectEndYear:any = (new Date()).getFullYear() //结束年份
|
|
|
|
|
//按年查询
|
|
|
|
|
yearSubmit (e) { |
|
|
|
|
if (e.selectEndYear >= e.selectStartYear) { |
|
|
|
|
let startTime = e.selectStartYear + '-' + 1 + '-' + 1 + ' ' + 0 + ':' + 0 +':'+ 0 |
|
|
|
|
let endTime = e.selectEndYear + '-' + 12 + '-' + 31 + ' ' + 23 + ':' + 59 +':'+ 59 |
|
|
|
|
console.log(startTime) |
|
|
|
|
console.log(endTime) |
|
|
|
|
} else { |
|
|
|
|
const config = new MatSnackBarConfig(); |
|
|
|
|
config.verticalPosition = 'top'; |
|
|
|
|
config.duration = 3000 |
|
|
|
|
this.snackBar.open('选择时间不能大于现在时间段','确定',config); |
|
|
|
|
this.endTime = new FormControl( new Date() ) |
|
|
|
|
} else if (nowTime > e.value && selectDay!=newDay) { //正常情况下 时间+1天
|
|
|
|
|
this.endTime = new FormControl( new Date(e.value.getTime()+oneDay) ) |
|
|
|
|
} else if ( selectDay == newDay ) { //选择时间段是今天时
|
|
|
|
|
this.endTime = new FormControl( new Date() ) |
|
|
|
|
this.snackBar.open('请选择正确时间区段','确定',config); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//处理时间 传入 new Date()格式
|
|
|
|
|
getTime(date){ |
|
|
|
|
let year = date.getFullYear(); //年
|
|
|
|
|
let month = date.getMonth() + 1; //月
|
|
|
|
|
let day = date.getDate(); //日
|
|
|
|
|
let hour = date.getHours() //时
|
|
|
|
|
let min = date.getMinutes(); //分
|
|
|
|
|
let seconds = date.getSeconds(); //秒
|
|
|
|
|
return year+'-'+month+'-'+ day + " "+ hour +':'+ min +':'+ seconds; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|