// // WaringVC.m // LNManager // // Created by EchoShacolee on 2017/4/6. // Copyright © 2017年 lee. All rights reserved. // #import "WaringVC.h" #import "MengBanView.h" @interface WaringVC () { UITableView * _tableView; NSMutableArray * _dataArray;//数据源 NSString *_selectedAbility;//记录已选择培训能力搜索条件 车辆数限制/每月限制 NSString *_selectedLowStar;//记录已选择低星级搜索条件 1培训机构,2教练 MengBanView *_mengBanView1;//培训能力 MengBanView *_mengBanView2;//低星级 UIButton * _selectBtn; UIButton *lastBtn; } @property(nonatomic,strong)HolderView *holderV; @end @implementation WaringVC - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title = @"预警"; _selectedAbility = @"0"; _selectedLowStar = @"1"; _dataArray = [NSMutableArray arrayWithObjects:@[],@[], nil]; //[self customRightBtn]; [self creatTypeBtnBar]; [self creatTableView]; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; //获取数据 [self getdataWithRule:_selectedAbility]; [self getDataWithType:_selectedLowStar];//1驾校,2教练 } -(void)customRightBtn{ UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithTitle:@"筛选" style:UIBarButtonItemStylePlain target:self action:@selector(setMengbanView)]; item.tintColor = COLOR_THEME; self.navigationItem.rightBarButtonItem = item; } -(void)setMengbanView{ if (lastBtn.tag == 1) { if (_mengBanView1) { [_mengBanView1 showView]; return; } NSArray * btnarr = @[@"车辆数*每车限制多少",@"每月限制人数"]; _mengBanView1 = [[MengBanView alloc]initWithTitileStr:@"培训能力预警" buttonsArray:@[btnarr] block:^(NSArray *array) { BOOL isByCar = [_selectedAbility isEqualToString:@"车辆数*每车限制多少"]; _selectedAbility = isByCar ? @"0" : @"1"; [MBProgressHUD showHUDAddedTo:self.view animated:YES]; [self getdataWithRule:_selectedAbility]; }]; [_mengBanView1 showView]; }else if (lastBtn.tag == 2){ if (_mengBanView2) { [_mengBanView2 showView]; return; } NSArray * btnarr = @[@"培训机构",@"教练"];; _mengBanView2 = [[MengBanView alloc]initWithTitileStr:@"低星级预警" buttonsArray:@[btnarr] block:^(NSArray *array) { BOOL isBySchool = [_selectedLowStar isEqualToString:@"培训机构"]; _selectedLowStar = isBySchool ? @"1" : @"2"; [MBProgressHUD showHUDAddedTo:self.view animated:YES]; [self getDataWithType:_selectedLowStar]; }]; [_mengBanView2 showView]; } } - (void)creatTypeBtnBar { UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, kNavOffSet, kSize.width/2.0, 50)]; [btn setTitle:@"培训能力预警" forState:UIControlStateNormal]; [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [btn setTitleColor:COLOR_THEME forState:UIControlStateSelected]; [btn.titleLabel setFont:[UIFont systemFontOfSize:18]]; [btn addTarget:self action:@selector(selectType:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn]; btn.tag = 1; btn.selected = YES; lastBtn = btn; btn = [[UIButton alloc] initWithFrame:CGRectMake(kSize.width/2.0, kNavOffSet, kSize.width/2.0, 50)]; [btn setTitle:@"低星级预警" forState:UIControlStateNormal]; [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [btn setTitleColor:COLOR_THEME forState:UIControlStateSelected]; [btn.titleLabel setFont:[UIFont systemFontOfSize:18]]; [btn addTarget:self action:@selector(selectType:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn]; btn.tag = 2; UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(kSize.width/2.0, 5+kNavOffSet, 1, 40)]; lineView.backgroundColor = [UIColor lightGrayColor]; [self.view addSubview:lineView]; lineView = [[UIView alloc] initWithFrame:CGRectMake(0 ,kNavOffSet+50-1, kSize.width, 1)]; lineView.backgroundColor = [UIColor lightGrayColor]; [self.view addSubview:lineView]; } -(void)creatTableView{ _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, kNavOffSet+50, kSize.width, kSize.height - kNavOffSet - 50) style:UITableViewStylePlain]; _tableView.delegate = self; _tableView.dataSource = self; _tableView.scrollEnabled = NO; _tableView.estimatedSectionFooterHeight = 0; [self.view addSubview:_tableView]; self.holderV = [[HolderView alloc] initWithFrame:_tableView.frame]; [self.holderV freshBlock:^{ if (lastBtn.tag == 1) { [self getdataWithRule:@""]; }else { [self getDataWithType:@""]; } }]; [self.view addSubview:self.holderV]; } - (void)selectType:(UIButton *)sender { if (sender.tag == lastBtn.tag) { return; } sender.selected = YES; lastBtn.selected = NO; lastBtn = sender; [_tableView reloadData]; } #pragma mark tableview的代理方法 -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return .1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [_dataArray[lastBtn.tag - 1] count]; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"]; if (!cell) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cellId"]; } if (lastBtn.tag == 1) { cell.textLabel.text = [NSString stringWithFormat:@"机构名称: %@",_dataArray[0][indexPath.row][@"TSI_NAME"]]; cell.detailTextLabel.text = [NSString stringWithFormat:@"超出百分比: %@",_dataArray[0][indexPath.row][@"PERCENT"]]; }else{ cell.textLabel.text = [NSString stringWithFormat:@"%@: %@",[_selectedLowStar integerValue] == 1 ?@"驾校名称":@"教练名字",_dataArray[1][indexPath.row][@"NAME"]]; cell.detailTextLabel.text = [NSString stringWithFormat:@"超出百分比: %@",_dataArray[1][indexPath.row][@"AVGOVERVIEW"]]; } return cell; } #pragma mark 数据请求 -(void)getdataWithRule:(NSString *)rule{ NSMutableDictionary * mdic = [[NSMutableDictionary alloc]init]; [mdic setValue:@"" forKey:@"rule"]; [mdic setValue:@"" forKey:@"inscode"]; [MBProgressHUD hideHUDForView:self.view animated:NO]; [MBProgressHUD showHUDAddedTo:self.view animated:NO]; [NetworkManager requestWithMethod:@"schoolWarning" parameters:mdic type:0 handler:^(NSDictionary *successDic, NSString *failureStr) { NSArray *arr = _dataArray[1]; if (arr.count == 0) { _holderV.hidden = NO; } [MBProgressHUD hideHUDForView:self.view animated:YES]; if (failureStr) { [self showMsgByAlertVCWithString:failureStr]; return; } if ([successDic[@"code"] isEqualToString:@"1"]) { [self showMsgByAlertVCWithString:successDic[@"msg"]]; return; } if ([successDic[@"body"] count] != 0) { _holderV.hidden = YES; } [_dataArray replaceObjectAtIndex:0 withObject:successDic[@"body"]]; [_tableView reloadData]; }]; } -(void)getDataWithType:(NSString *)type{ NSMutableDictionary * mdic = [[NSMutableDictionary alloc]init]; [mdic setValue:@"1" forKey:@"type"]; [MBProgressHUD hideHUDForView:self.view animated:NO]; [MBProgressHUD showHUDAddedTo:self.view animated:NO]; [NetworkManager requestWithMethod:@"evalWarning" parameters:mdic type:0 handler:^(NSDictionary *successDic, NSString *failureStr) { NSArray *arr = _dataArray[0]; if (arr.count == 0) { _holderV.hidden = NO; } [MBProgressHUD hideHUDForView:self.view animated:YES]; if (failureStr) { [self showMsgByAlertVCWithString:failureStr]; return; } if ([successDic[@"code"] isEqualToString:@"1"]) { [self showMsgByAlertVCWithString:successDic[@"msg"]]; return; } if ([successDic[@"body"] count] != 0) { _holderV.hidden = YES; } [_dataArray replaceObjectAtIndex:1 withObject:successDic[@"body"]]; [_tableView reloadData]; }]; } - (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. } */ @end