// // CommitMessage_VC.m // Haishenghai-master // // Created by GG on 2019/1/7. // Copyright © 2019年 Haishenghai intelligence network technology. All rights reserved. // #import "CommitMessage_VC.h" #import "Header.h" #import "THDatePickerView.h" @interface CommitMessage_VC () { UIButton *searchTypeBtn; UIButton *searchTimeBtn; UIButton *firebtn; UIButton *faultBtn; UIButton *OtherBtn; NSMutableArray *typeArr; NSString *showStr; NSString *beginStr; NSString *endsStr; UILabel *beginlb; UILabel *endlb; }@end @implementation CommitMessage_VC - (void)viewDidLoad { [super viewDidLoad]; // // showStr = @"0"; beginStr = @"0"; endsStr = @"0"; typeArr = [[NSMutableArray alloc] init]; self.view.backgroundColor = [UIColor whiteColor]; self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:60/255.0 green:114/255.0 blue:255/255.0 alpha:1]; [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}]; UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [backBtn setImage:[UIImage imageNamed:@"hsh_return"] forState:UIControlStateNormal]; backBtn.frame = CGRectMake(0, 0, 44, 44); [backBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside]; backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn]; [self setupUI]; } -(void)backClick{ [self.navigationController popViewControllerAnimated:YES]; } -(void)setupUI{ UIView *searchTypeView = [[UIView alloc] init]; [self.view addSubview:searchTypeView]; searchTypeView.backgroundColor =[UIColor colorWithRed:227/255.0 green:227/255.0 blue:227/255.0 alpha:1]; [searchTypeView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(kTopHeight); make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.height.mas_equalTo(40); }]; searchTypeBtn = [UIButton buttonWithType:UIButtonTypeCustom]; searchTypeBtn.tag = 1; [searchTypeBtn setImage:[UIImage imageNamed:@"hsh_news_choice_transforma"] forState:UIControlStateNormal]; [searchTypeBtn setImage:[UIImage imageNamed:@"hsh_news_choice"] forState:UIControlStateSelected]; [searchTypeBtn setTitle:@"类型搜索" forState:UIControlStateNormal]; searchTypeBtn.imageEdgeInsets = UIEdgeInsetsMake(10, -10, 10, 0); searchTypeBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0); [searchTypeBtn addTarget:self action:@selector(searchClick:) forControlEvents:UIControlEventTouchUpInside]; searchTypeBtn.titleLabel.font = [UIFont systemFontOfSize:18]; [searchTypeView addSubview:searchTypeBtn]; [searchTypeBtn setTitleColor:SXUIColorFromRGB(0x333333) forState:UIControlStateNormal]; [searchTypeBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(0); make.left.mas_equalTo(20); make.height.mas_equalTo(40); make.width.mas_equalTo(95); }]; UIView *fireView = [[UIView alloc] init]; fireView.backgroundColor = SXUIColorFromRGB(0xffffff); [self.view addSubview:fireView]; [fireView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(searchTypeView.mas_bottom); make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.height.mas_equalTo(80); }]; faultBtn = [UIButton buttonWithType:UIButtonTypeCustom]; faultBtn.tag = 3; [faultBtn setImage:[UIImage imageNamed:@"hsh_news_choice_transforma"] forState:UIControlStateNormal]; [faultBtn setImage:[UIImage imageNamed:@"hsh_news_choice"] forState:UIControlStateSelected]; [faultBtn setTitle:@"显示故障" forState:UIControlStateNormal]; [faultBtn setTitleColor:SXUIColorFromRGB(0x333333) forState:UIControlStateNormal]; faultBtn.imageEdgeInsets = UIEdgeInsetsMake(10, -10, 10, 0); faultBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0); [fireView addSubview:faultBtn]; faultBtn.titleLabel.font = [UIFont systemFontOfSize:18]; [faultBtn addTarget:self action:@selector(faultClick:) forControlEvents:UIControlEventTouchUpInside]; [faultBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(0); make.center.mas_equalTo(fireView.center); make.height.mas_equalTo(40); make.width.mas_equalTo(95); }]; firebtn = [UIButton buttonWithType:UIButtonTypeCustom]; firebtn.tag = 2; [firebtn setImage:[UIImage imageNamed:@"hsh_news_choice_transforma"] forState:UIControlStateNormal]; [firebtn setImage:[UIImage imageNamed:@"hsh_news_choice"] forState:UIControlStateSelected]; [firebtn setTitle:@"显示火警" forState:UIControlStateNormal]; [firebtn setTitleColor:SXUIColorFromRGB(0x333333) forState:UIControlStateNormal]; firebtn.imageEdgeInsets = UIEdgeInsetsMake(10, -10, 10, 0); firebtn.titleEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0); [fireView addSubview:firebtn]; [firebtn addTarget:self action:@selector(fireClick:) forControlEvents:UIControlEventTouchUpInside]; [firebtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(0); make.right.mas_equalTo(faultBtn.mas_left).offset(-25); make.centerY.mas_equalTo(fireView.mas_centerY); make.height.mas_equalTo(40); make.width.mas_equalTo(95); }]; OtherBtn = [UIButton buttonWithType:UIButtonTypeCustom]; OtherBtn.tag = 4; [OtherBtn setImage:[UIImage imageNamed:@"hsh_news_choice_transforma"] forState:UIControlStateNormal]; [OtherBtn setImage:[UIImage imageNamed:@"hsh_news_choice"] forState:UIControlStateSelected]; [OtherBtn setTitle:@"显示其他" forState:UIControlStateNormal]; [OtherBtn setTitleColor:SXUIColorFromRGB(0x333333) forState:UIControlStateNormal]; OtherBtn.imageEdgeInsets = UIEdgeInsetsMake(10, -10, 10, 0); OtherBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0); [fireView addSubview:OtherBtn]; OtherBtn.titleLabel.font = [UIFont systemFontOfSize:18]; [OtherBtn addTarget:self action:@selector(otherClick:) forControlEvents:UIControlEventTouchUpInside]; [OtherBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(0); make.left.mas_equalTo(faultBtn.mas_right).offset(25); make.centerY.mas_equalTo(fireView.mas_centerY); make.height.mas_equalTo(40); make.width.mas_equalTo(95); }]; UIView *searchTimeView = [[UIView alloc] init]; [self.view addSubview:searchTimeView]; searchTimeView.backgroundColor =[UIColor colorWithRed:227/255.0 green:227/255.0 blue:227/255.0 alpha:1]; [searchTimeView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(fireView.mas_bottom); make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.height.mas_equalTo(40); }]; searchTimeBtn = [UIButton buttonWithType:UIButtonTypeCustom]; searchTimeBtn.tag = 5; [searchTimeBtn setImage:[UIImage imageNamed:@"hsh_news_choice_transforma"] forState:UIControlStateNormal]; [searchTimeBtn setImage:[UIImage imageNamed:@"hsh_news_choice"] forState:UIControlStateSelected]; [searchTimeBtn setTitle:@"时间搜索" forState:UIControlStateNormal]; searchTimeBtn.imageEdgeInsets = UIEdgeInsetsMake(10, -10, 10, 0); searchTimeBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0); [searchTimeView addSubview:searchTimeBtn]; searchTimeBtn.titleLabel.font = [UIFont systemFontOfSize:18]; [searchTimeBtn setTitleColor:SXUIColorFromRGB(0x333333) forState:UIControlStateNormal]; [searchTimeBtn addTarget:self action:@selector(timeClick:) forControlEvents:UIControlEventTouchUpInside]; [searchTimeBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(0); make.left.mas_equalTo(20); make.height.mas_equalTo(40); make.width.mas_equalTo(95); }]; UILabel *beginLB = [[UILabel alloc]init]; beginLB.text = @"起始时间:"; beginLB.font = [UIFont systemFontOfSize:18]; beginLB.textAlignment = NSTextAlignmentLeft; [self.view addSubview:beginLB]; [beginLB mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(searchTimeView.mas_bottom).offset(20); make.left.mas_equalTo(20); make.height.mas_equalTo(40); make.width.mas_equalTo(80); }]; UILabel *stopLB = [[UILabel alloc]init]; stopLB.text = @"结束时间:"; stopLB.font = [UIFont systemFontOfSize:18]; stopLB.textAlignment = NSTextAlignmentLeft; [self.view addSubview:stopLB]; [stopLB mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(beginLB.mas_bottom).offset(20); make.left.mas_equalTo(20); make.height.mas_equalTo(40); make.width.mas_equalTo(80); }]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSDate *datenow = [NSDate date]; //获取前一天时间 NSDate *lastDay = [NSDate dateWithTimeInterval:-24*60*60 sinceDate:datenow]; NSString *lastTimeString = [formatter stringFromDate:lastDay]; //当前时间 NSString *currentTimeString = [formatter stringFromDate:datenow]; //获取后一天时间 NSDate *nextday = [NSDate dateWithTimeInterval:24*60*60 sinceDate:datenow]; NSString *nextTimeString = [formatter stringFromDate:nextday]; _starttimeBtn = [UIButton buttonWithType:UIButtonTypeCustom]; // [_starttimeBtn setTitle:currentTimeString forState:UIControlStateNormal]; _starttimeBtn.layer.cornerRadius = 6; _starttimeBtn.layer.borderWidth = 0.5; _starttimeBtn.layer.borderColor = [UIColor colorWithRed:227/255.0 green:227/255.0 blue:227/255.0 alpha:1].CGColor; _starttimeBtn.titleLabel.font = [UIFont systemFontOfSize:18]; [_starttimeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [_starttimeBtn addTarget:self action:@selector(starttimeClick:) forControlEvents:UIControlEventTouchUpInside]; _starttimeBtn.tag =100; [self.view addSubview:_starttimeBtn]; [_starttimeBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(searchTimeView.mas_bottom).offset(20); make.left.mas_equalTo(beginLB.mas_right).offset(20); make.right.mas_equalTo(-20); make.height.mas_equalTo(40); }]; beginlb = [[UILabel alloc] init]; beginlb.text =lastTimeString; beginlb.font = [UIFont systemFontOfSize:18]; beginlb.textAlignment = NSTextAlignmentCenter; beginlb.textColor = SXUIColorFromRGB(0x333333); [_starttimeBtn addSubview:beginlb]; [beginlb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(0); make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.height.mas_equalTo(40); make.centerX.mas_equalTo(_starttimeBtn.mas_centerX); }]; _endtimeBtn = [UIButton buttonWithType:UIButtonTypeCustom]; // [_endtimeBtn setTitle:currentTimeString forState:UIControlStateNormal]; _endtimeBtn.layer.cornerRadius = 6; _endtimeBtn.layer.borderWidth = 0.5; _endtimeBtn.layer.borderColor = [UIColor colorWithRed:227/255.0 green:227/255.0 blue:227/255.0 alpha:1].CGColor; _endtimeBtn.tag=101; _endtimeBtn.titleLabel.font = [UIFont systemFontOfSize:18]; [_endtimeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [_endtimeBtn addTarget:self action:@selector(endtimenClick:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:_endtimeBtn]; [_endtimeBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(_starttimeBtn.mas_bottom).offset(20); make.left.mas_equalTo(stopLB.mas_right).offset(20); make.right.mas_equalTo(-20); make.height.mas_equalTo(40); }]; endlb = [[UILabel alloc] init]; endlb.text =currentTimeString; endlb.font = [UIFont systemFontOfSize:18]; endlb.textAlignment = NSTextAlignmentCenter; endlb.textColor = SXUIColorFromRGB(0x333333); [_endtimeBtn addSubview:endlb]; [endlb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(0); make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.height.mas_equalTo(40); make.centerX.mas_equalTo(_endtimeBtn.mas_centerX); }]; /** 提交 */ UIButton *commitBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [commitBtn setBackgroundImage:[UIImage imageNamed:@"blue"] forState:UIControlStateNormal]; [commitBtn setTitle:@"提交" forState:UIControlStateNormal]; [commitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; commitBtn.titleLabel.font = [UIFont systemFontOfSize:18]; commitBtn.titleLabel.textAlignment = NSTextAlignmentCenter; [commitBtn addTarget:self action:@selector(commitBtnClick) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:commitBtn]; [commitBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(stopLB.mas_bottom).offset(30); make.left.mas_equalTo(20); make.height.mas_equalTo(40); make.right.mas_equalTo(-20); }]; [typeArr addObject:@"0"]; [typeArr addObject:@"1"]; [typeArr addObject:@"2"]; THDatePickerView *dateView = [[THDatePickerView alloc] initWithFrame:CGRectMake(0, HEIGHT, WIDTH, 300)]; dateView.delegate = self; [self.view addSubview:dateView]; self.beginDateView = dateView; THDatePickerView *endDateView = [[THDatePickerView alloc] initWithFrame:CGRectMake(0, HEIGHT, WIDTH, 300)]; endDateView.delegate = self; [self.view addSubview:endDateView]; self.endDateView = endDateView; } - (void)datePickerViewSaveBtnClickDelegate:(NSString *)timer { NSLog(@"保存点击"); if ([showStr isEqualToString:@"1"]) { beginlb.text = timer; beginStr = @"0"; }else{ endlb.text = timer; endsStr = @"0"; } [UIView animateWithDuration:0.3 animations:^{ self.beginDateView.frame = CGRectMake(0, HEIGHT, WIDTH, 300); self.endDateView.frame = CGRectMake(0,HEIGHT, WIDTH, 300); }]; } - (void)datePickerViewCancelBtnClickDelegate { NSLog(@"取消点击"); [UIView animateWithDuration:0.3 animations:^{ self.beginDateView.frame = CGRectMake(0, HEIGHT, WIDTH, 300); self.endDateView.frame = CGRectMake(0,HEIGHT, WIDTH, 300); }]; } -(void)starttimeClick:(UIButton *)btn{ showStr = @"1"; [UIView animateWithDuration:0.3 animations:^{ self.beginDateView.frame = CGRectMake(0, HEIGHT - 300, WIDTH, 300); [self.beginDateView show]; }]; } -(void)endtimenClick:(UIButton *)btn{ showStr = @"0"; [UIView animateWithDuration:0.3 animations:^{ self.endDateView.frame = CGRectMake(0, HEIGHT - 300, WIDTH, 300); [self.endDateView show]; }]; } -(void)searchClick:(UIButton *)btn{ btn.selected = !btn.selected; if(!btn.selected){ typeArr = [NSMutableArray array]; [typeArr addObject:@"0"]; [typeArr addObject:@"1"]; [typeArr addObject:@"2"]; firebtn.selected=NO; faultBtn.selected=NO; OtherBtn.selected=NO; }else{ [typeArr removeObject:@"0"]; [typeArr removeObject:@"1"]; [typeArr removeObject:@"2"]; firebtn.selected=YES; faultBtn.selected=YES; OtherBtn.selected=YES; } } -(void)fireClick:(UIButton *)btn{ btn.selected = !btn.selected; if(btn.selected){ [typeArr removeObject:@"1"]; }else{ [typeArr addObject:@"1"]; } if(!firebtn.selected||!faultBtn.selected||!OtherBtn.selected){ searchTypeBtn.selected = NO; }else{ searchTypeBtn.selected = YES; } } -(void)faultClick:(UIButton *)btn{ btn.selected = !btn.selected; if(btn.selected){ [typeArr removeObject:@"0"]; }else{ [typeArr addObject:@"0"]; } if(!firebtn.selected||!faultBtn.selected||!OtherBtn.selected){ searchTypeBtn.selected = NO; }else{ searchTypeBtn.selected = YES; } } -(void)otherClick:(UIButton *)btn{ btn.selected = !btn.selected; if(btn.selected){ [typeArr removeObject:@"2"]; }else{ [typeArr addObject:@"2"]; } if(!firebtn.selected||!faultBtn.selected||!OtherBtn.selected){ searchTypeBtn.selected = NO; }else{ searchTypeBtn.selected = YES; } } -(void)timeClick:(UIButton *)btn{ btn.selected = !btn.selected; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ -(void)commitBtnClick{ NSString *jsonString = [typeArr componentsJoinedByString:@","];; if(!searchTimeBtn.selected){ [DataSourceManager gettroubledeviceWithUrlPagesize:100 Page:1 fromTime:beginlb.text toTime:endlb.text Type:jsonString completionBlock:^(NSMutableArray *array) { //回调传值要把array回传 //回调筛选 NSLog(@"----------0-%@",array); NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:array,@"array", nil]; [[NSNotificationCenter defaultCenter]postNotificationName:@"search" object:nil userInfo: dic]; [self.navigationController popViewControllerAnimated:YES]; }]; }else{ [DataSourceManager gettroubledeviceWithUrlPagesize:100 Page:1 fromTime:@"" toTime:@"" Type:jsonString completionBlock:^(NSMutableArray *array) { //回调传值要把array回传 //回调筛选 NSLog(@"-----------2%@",array); NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:array,@"array", nil]; [[NSNotificationCenter defaultCenter]postNotificationName:@"search" object:nil userInfo: dic]; [self.navigationController popViewControllerAnimated:YES]; }]; } } @end