You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
446 lines
14 KiB
446 lines
14 KiB
// |
|
// NewTrackVC.m |
|
// tongxin |
|
// |
|
// Created by weichao on 2019/8/23. |
|
// Copyright © 2019 xTT. All rights reserved. |
|
// |
|
|
|
#import "NewTrackVC.h" |
|
#import "TrackInfoViewController.h" |
|
#import "TrackViewController.h" |
|
#import "VRGCalendarView.h" |
|
#import "Track.h" |
|
|
|
#define SHOWMAPoffsetY ScreenHeight-getRectNavAndStatusHight-50 |
|
|
|
|
|
@interface NewTrackVC ()<VRGCalendarViewDelegate,UIScrollViewDelegate> |
|
{ |
|
VRGCalendarView *calendar; |
|
UIControl *_overlayView; |
|
} |
|
|
|
/** |
|
是否正在加载 |
|
*/ |
|
@property (assign, nonatomic) BOOL isLoading; |
|
|
|
/** |
|
对应的 日期的轨迹列表 |
|
*/ |
|
@property (strong, nonatomic) NSMutableArray *trackListDate; |
|
|
|
/** |
|
是否是显示地图 子 VC |
|
*/ |
|
@property (assign, nonatomic) BOOL isShowMap; |
|
|
|
|
|
/** |
|
当前选择的Model |
|
*/ |
|
@property (strong, nonatomic) Track *selectTrack; |
|
|
|
/** |
|
显示时间轴的 控制器 |
|
*/ |
|
@property (strong, nonatomic) TrackViewController *showMessageVC; |
|
/** |
|
显示地图页面的 控制器 |
|
*/ |
|
@property (strong, nonatomic) TrackInfoViewController *mapInfoVC; |
|
|
|
@end |
|
|
|
@implementation NewTrackVC |
|
|
|
-(NSMutableArray *)trackListDate{ |
|
if(!_trackListDate){ |
|
_trackListDate = [NSMutableArray array]; |
|
} |
|
return _trackListDate; |
|
} |
|
|
|
- (void)viewDidLoad { |
|
[super viewDidLoad]; |
|
[self initView]; |
|
[self loadMoreDataWithTrack:nil]; |
|
[self.zx_navRightBtn setTitle:@"地图查看" forState:UIControlStateNormal]; |
|
[self.zx_navRightBtn setTitle:@"轨迹查看" forState:UIControlStateSelected]; |
|
[self.zx_navRightBtn setTitleColor:KKWhiteColorColor forState:0]; |
|
[self zx_rightClickedBlock:^(ZXNavItemBtn * _Nonnull btn) { |
|
self.zx_navRightBtn.selected = !self.zx_navRightBtn.selected; |
|
[self rightBarItemClick]; |
|
}]; |
|
} |
|
|
|
- (void)loadMoreDataWithTrack:(Track *)track{ |
|
WEAKSELF |
|
NSString *ID ; |
|
if (track) { |
|
ID = track.id; |
|
} |
|
|
|
[Track getObjsWithID:ID success:^(NSMutableArray *arr) { |
|
if(arr.count > 0 ) |
|
{ |
|
if(weakSelf.trackListDate.count > 0) |
|
{ |
|
[weakSelf.trackListDate removeAllObjects]; |
|
} |
|
[weakSelf.trackListDate addObjectsFromArray:arr]; |
|
} |
|
else |
|
{ |
|
//为 0 的情况 |
|
[weakSelf.trackListDate removeAllObjects]; |
|
} |
|
//MARK: 加载完数据 刷新一下 当前日期的数据 |
|
[weakSelf getCurrentTrackDate]; |
|
|
|
} failure:^(NSError *error){ |
|
|
|
}]; |
|
} |
|
|
|
|
|
- (void)initView{ |
|
[self setDayTimeLabelText:@"今天"]; |
|
[self.dayTimeBtn setTitleColor:mainColor forState:0]; |
|
|
|
self.beforeDayBtn.layer.cornerRadius = 3; |
|
self.beforeDayBtn.layer.masksToBounds = YES; |
|
[self.beforeDayBtn setBackgroundColor:mainColor]; |
|
|
|
self.afterDayBtn.layer.cornerRadius = 3; |
|
self.afterDayBtn.layer.masksToBounds = YES; |
|
[self.afterDayBtn setBackgroundColor:mainColor]; |
|
|
|
//默认后一天的按钮不能按 |
|
[self setBtnBadRoGoodFlag:NO WithBtn:self.afterDayBtn]; |
|
|
|
[self.topView mas_remakeConstraints:^(MASConstraintMaker *make) { |
|
make.left.right.equalTo(self.view); |
|
make.top.equalTo(self.view).offset(iPhoneX_NavHeight); |
|
make.height.mas_equalTo(50); |
|
}]; |
|
//设置 容器View |
|
self.collectionView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, iPhoneX_NavHeight+50, ScreenWidth, ScreenHeight-getRectNavAndStatusHight-50)]; |
|
[self.view addSubview:self.collectionView]; |
|
self.collectionView.bounces = NO; |
|
self.collectionView.contentSize = CGSizeMake(self.collectionView.bounds.size.width, self.collectionView.bounds.size.height*2); |
|
self.collectionView.showsVerticalScrollIndicator = NO; |
|
self.collectionView.showsHorizontalScrollIndicator = NO; |
|
self.collectionView.pagingEnabled = YES; |
|
self.collectionView.scrollEnabled = NO; |
|
self.collectionView.delegate = self; |
|
|
|
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; |
|
|
|
self.showMessageVC = [sb instantiateViewControllerWithIdentifier:@"TrackViewController"]; |
|
//MARK: 删除数据回调 |
|
WEAKSELF |
|
self.showMessageVC.delectBlockCall = ^{ |
|
|
|
[weakSelf loadMoreDataWithTrack:nil]; |
|
}; |
|
[self addChildViewController:self.showMessageVC]; |
|
self.showMessageVC.view.frame = CGRectMake(0, 0, ScreenWidth, SHOWMAPoffsetY-60); |
|
//这个60 是轨迹页面还有个头部 |
|
self.showMessageVC.tableViewHeightNSLC.constant = SHOWMAPoffsetY-60; |
|
[self.collectionView addSubview:self.showMessageVC.view]; |
|
|
|
|
|
self.mapInfoVC = [sb instantiateViewControllerWithIdentifier:@"TrackInfoViewController"]; |
|
[self addChildViewController:self.mapInfoVC]; |
|
self.mapInfoVC.view.frame = CGRectMake(0, SHOWMAPoffsetY, ScreenWidth, SHOWMAPoffsetY); |
|
self.mapInfoVC.mapViewHeightNSLC.constant = SHOWMAPoffsetY; |
|
[self.collectionView addSubview:self.mapInfoVC.view]; |
|
|
|
} |
|
|
|
|
|
- (void)rightBarItemClick |
|
{ |
|
if(self.collectionView.contentOffset.y == 0 || |
|
self.collectionView.contentOffset.y == SHOWMAPoffsetY) |
|
{ |
|
|
|
// [self setBtnBadRoGoodFlag:NO WithBtn:self.rightBarButton]; |
|
[self reloadChildVC]; |
|
|
|
}else{ |
|
//如果还在运动中就狂点,不做操作 |
|
return; |
|
} |
|
} |
|
|
|
- (void)reloadChildVC |
|
{ |
|
WEAKSELF |
|
// if(self.zx_navRightBtn) |
|
// { |
|
if(self.zx_navRightBtn.selected) |
|
{ |
|
[self.collectionView setContentOffset:CGPointMake(0, SHOWMAPoffsetY) animated:YES]; |
|
[self.mapInfoVC loadWithInfoTrack:self.selectTrack Back:^{ |
|
//[weakSelf setBtnBadRoGoodFlag:YES WithBtn:weakSelf.rightBarButton]; |
|
weakSelf.isLoading = NO; |
|
}]; |
|
|
|
} |
|
else |
|
{ |
|
[self.collectionView setContentOffset:CGPointMake(0, 0) animated:YES]; |
|
[self.showMessageVC loadWithInfoTrack:self.selectTrack Back:^{ |
|
//[weakSelf setBtnBadRoGoodFlag:YES WithBtn:weakSelf.rightBarButton]; |
|
weakSelf.isLoading = NO; |
|
}]; |
|
} |
|
// } |
|
// else |
|
// { |
|
// //恢复成 文字轨迹页面 |
|
// [self.collectionView setContentOffset:CGPointMake(0, 0) animated:YES]; |
|
// [self.showMessageVC loadWithInfoTrack:self.selectTrack Back:^{ |
|
// // [weakSelf setBtnBadRoGoodFlag:YES WithBtn:weakSelf.rightBarButton]; |
|
// weakSelf.isLoading = NO; |
|
// }]; |
|
// } |
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
//MARK:----点击日期标题,显示日历的方法 |
|
*/ |
|
- (IBAction)dayTimeBtnAction{ |
|
[self dismissCalendarView]; |
|
_overlayView = [[UIControl alloc]initWithFrame:self.view.bounds]; |
|
[_overlayView addTarget:self action:@selector(dismissCalendarView) forControlEvents:UIControlEventTouchUpInside]; |
|
calendar = [[VRGCalendarView alloc] init]; |
|
calendar.limitDay = 60; |
|
// CGRect c = calendar.frame; |
|
// c.origin.y = iPhoneX_NavHeight+50; |
|
// calendar.frame = c; |
|
|
|
calendar.frame = CGRectMake(0, iPhoneX_NavHeight+50, ScreenWidth, calendar.frame.size.height); |
|
calendar.delegate=self; |
|
|
|
NSDate *selectDate; |
|
if([self.dayTimeBtn.titleLabel.text isEqualToString:@"今天"]){ |
|
//今天 |
|
selectDate = [NSDate dateWithTimeIntervalSince1970:[NSDate date].timeIntervalSince1970]; |
|
}else if([self.dayTimeBtn.titleLabel.text isEqualToString:@"昨天"]){ |
|
//昨天 |
|
selectDate = [NSDate dateWithTimeIntervalSince1970:[NSDate date].timeIntervalSince1970 - 60*60*24]; |
|
}else{ |
|
NSDateFormatter * dateF = [[NSDateFormatter alloc]init]; |
|
[dateF setCalendar:[[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian]]; |
|
[dateF setDateFormat:@"yyyy-MM-dd"]; |
|
NSDate *date =[dateF dateFromString:self.dayTimeBtn.titleLabel.text]; |
|
selectDate = date; |
|
} |
|
//今天 |
|
// selectDate = [NSDate dateWithTimeIntervalSince1970:[NSDate date].timeIntervalSince1970]; |
|
calendar.selectedDate = selectDate; |
|
|
|
calendar.alpha = 1; |
|
[self.view addSubview:_overlayView]; |
|
[self.view addSubview:calendar]; |
|
} |
|
|
|
- (void)dismissCalendarView{ |
|
if(_overlayView){ |
|
[_overlayView removeFromSuperview]; |
|
_overlayView = nil; |
|
[UIView animateWithDuration:0.35 animations:^{ |
|
calendar.alpha = 0; |
|
}completion:^(BOOL finished) { |
|
[calendar removeFromSuperview]; |
|
}]; |
|
[self.dayTimeIconBtn setImage:[UIImage imageNamed:@"icon_drop-down"] forState:0]; |
|
} |
|
} |
|
#pragma mark - 日期选择Delegate |
|
-(void)calendarView:(VRGCalendarView *)calendarView switchedToMonth:(int)month targetHeight:(float)targetHeight animated:(BOOL)animated { |
|
|
|
} |
|
|
|
-(void)calendarView:(VRGCalendarView *)calendarView dateSelected:(NSDate *)date { |
|
|
|
NSString *selectDay = [myHelper getDateFormatWithStr:@"yyyy-MM-dd" date:date]; |
|
//对比昨天和今天 |
|
//昨天 |
|
NSString *yesterday = [myHelper getDateFormatWithStr:@"yyyy-MM-dd" timeInterval:[NSDate date].timeIntervalSince1970 - 60*60*24]; |
|
//今天 |
|
NSString *today = [myHelper getDateFormatWithStr:@"yyyy-MM-dd" timeInterval:[NSDate date].timeIntervalSince1970]; |
|
if([selectDay isEqualToString:yesterday]){ |
|
[self setDayTimeLabelText:@"昨天"]; |
|
|
|
}else if([selectDay isEqualToString:today]){ |
|
[self setDayTimeLabelText:@"今天"]; |
|
}else{ |
|
[self setDayTimeLabelText:selectDay]; |
|
} |
|
|
|
[self getCurrentTrackDate]; |
|
[self dismissCalendarView]; |
|
} |
|
|
|
- (IBAction)dayBtnAction:(UIButton *)sender { |
|
if(self.isLoading){ |
|
return; |
|
} |
|
self.isLoading = YES; |
|
NSMutableDictionary * params = [NSMutableDictionary dictionary]; |
|
self.zx_navRightBtn.selected = NO; |
|
if([sender isEqual:self.beforeDayBtn]) |
|
{ //按了前一天的按钮 |
|
NSString *paramsDay; |
|
if([self.dayTimeBtn.titleLabel.text isEqualToString:@"今天"]){ |
|
//昨天 |
|
paramsDay = [myHelper getDateFormatWithStr:@"yyyy-MM-dd" timeInterval:[NSDate date].timeIntervalSince1970 - 60*60*24]; |
|
|
|
[self setDayTimeLabelText: @"昨天"]; |
|
}else if([self.dayTimeBtn.titleLabel.text isEqualToString:@"昨天"]){ |
|
|
|
paramsDay = [myHelper getDateFormatWithStr:@"yyyy-MM-dd" timeInterval:[NSDate date].timeIntervalSince1970 - 2 * 60*60*24]; |
|
|
|
[self setDayTimeLabelText: paramsDay]; |
|
}else{ |
|
//当前位置的天数转换成的时间戳 |
|
NSTimeInterval tempTime = [myHelper getDateWithStr:self.dayTimeBtn.titleLabel.text dateFormat:@"yyyy-MM-dd"].timeIntervalSince1970; |
|
paramsDay = [myHelper getDateFormatWithStr:@"yyyy-MM-dd" timeInterval:tempTime - 60*60*24]; |
|
|
|
[self setDayTimeLabelText: paramsDay]; |
|
} |
|
|
|
[params setValue:paramsDay forKey:@"date"]; |
|
|
|
} |
|
else if([sender isEqual:self.afterDayBtn]) |
|
{ |
|
if([self.dayTimeBtn.titleLabel.text isEqualToString:@"今天"]){ |
|
return; |
|
} |
|
//后一天 |
|
if([self.dayTimeBtn.titleLabel.text isEqualToString:@"昨天"]){ |
|
[self setDayTimeLabelText:@"今天"]; |
|
params = nil; |
|
|
|
}else{ |
|
//当前位置的天数转换成的时间戳 |
|
NSTimeInterval tempTime = [myHelper getDateWithStr:self.dayTimeBtn.titleLabel.text dateFormat:@"yyyy-MM-dd"].timeIntervalSince1970; |
|
NSString *paramsDay = [myHelper getDateFormatWithStr:@"yyyy-MM-dd" timeInterval:tempTime + 60*60*24]; |
|
//对比昨天和今天 |
|
//昨天 |
|
NSString *yesterday = [myHelper getDateFormatWithStr:@"yyyy-MM-dd" timeInterval:[NSDate date].timeIntervalSince1970 - 60*60*24]; |
|
//今天 |
|
NSString *today = [myHelper getDateFormatWithStr:@"yyyy-MM-dd" timeInterval:[NSDate date].timeIntervalSince1970]; |
|
if([paramsDay isEqualToString:yesterday]){ |
|
[self setDayTimeLabelText:@"昨天"]; |
|
|
|
}else if([paramsDay isEqualToString:today]){ |
|
[self setDayTimeLabelText:@"今天"]; |
|
}else{ |
|
[self setDayTimeLabelText:paramsDay]; |
|
} |
|
[params setValue:paramsDay forKey:@"date"]; |
|
} |
|
|
|
} |
|
else |
|
{ |
|
params = nil; |
|
} |
|
|
|
[self getCurrentTrackDate]; |
|
|
|
} |
|
-(void)setDayTimeLabelText:(NSString*)day{ |
|
[self.dayTimeBtn setTitle:day forState:0]; |
|
|
|
} |
|
/** |
|
查询 当前日期 的轨迹数据 |
|
*/ |
|
-(void)getCurrentTrackDate{ |
|
// 查询轨迹数据 |
|
NSString *currenDateStr = @""; |
|
|
|
if([self.dayTimeBtn.titleLabel.text isEqualToString:@"今天"]){ |
|
//今天 |
|
NSString *today = [myHelper getDateFormatWithStr:@"yyyy-MM-dd" timeInterval:[NSDate date].timeIntervalSince1970]; |
|
//[params setValue:today forKey:@"date"]; |
|
currenDateStr = today; |
|
|
|
[self setBtnBadRoGoodFlag:NO WithBtn:self.afterDayBtn]; |
|
}else if([self.dayTimeBtn.titleLabel.text isEqualToString:@"昨天"]){ |
|
//昨天 |
|
|
|
NSString *yesterday = [myHelper getDateFormatWithStr:@"yyyy-MM-dd" timeInterval:[NSDate date].timeIntervalSince1970 - 60*60*24]; |
|
// [params setValue:yesterday forKey:@"date"]; |
|
currenDateStr = yesterday; |
|
[self setBtnBadRoGoodFlag:YES WithBtn:self.afterDayBtn]; |
|
}else{ |
|
// [params setValue:self.dayTimeBtn.titleLabel.text forKey:@"date"]; |
|
currenDateStr = self.dayTimeBtn.titleLabel.text; |
|
[self setBtnBadRoGoodFlag:YES WithBtn:self.afterDayBtn]; |
|
} |
|
|
|
self.selectTrack = nil; |
|
for(int i = 0; i < self.trackListDate.count; i++){ |
|
Track *item = self.trackListDate[i]; |
|
if([item.date isEqualToString:currenDateStr]){ |
|
self.selectTrack = item; |
|
} |
|
} |
|
self.zx_navRightBtn.hidden = self.selectTrack ? NO : YES; |
|
|
|
// MARK: 选择的日历时触发 |
|
[self reloadChildVC]; |
|
|
|
} |
|
|
|
/** |
|
设置按钮不可选且半透明 |
|
@param flag Bad is NO , Good is YES |
|
@param button button |
|
*/ |
|
-(void)setBtnBadRoGoodFlag:(BOOL)flag WithBtn:(id) button{ |
|
if(flag){ |
|
if([button isKindOfClass:[UIButton class]]){ |
|
[button setAlpha:1]; |
|
} |
|
[button setEnabled:YES]; |
|
}else{ |
|
if([button isKindOfClass:[UIButton class]]){ |
|
[button setAlpha:0.5]; |
|
} |
|
[button setEnabled:NO]; |
|
} |
|
} |
|
|
|
|
|
////MARK: UIScorllView 代理 ----- |
|
//-(void)scrollViewDidScroll:(UIScrollView *)scrollView{ |
|
// if ([scrollView isEqual:self.collectionView]) |
|
// { |
|
// if (scrollView.contentOffset.y <= 0 ) |
|
// { |
|
// if(self.selectTrack) |
|
// { |
|
// [self setRightBarBtnTitle:@"地图查看" RoImage:nil]; |
|
// } |
|
// } |
|
// if (scrollView.contentOffset.y >= SHOWMAPoffsetY){ |
|
// [self setRightBarBtnTitle:@"轨迹查看" RoImage:nil]; |
|
// } |
|
// } |
|
//} |
|
|
|
@end
|
|
|