123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- //
- // WaringVC.m
- // LNManager
- //
- // Created by EchoShacolee on 2017/4/6.
- // Copyright © 2017年 lee. All rights reserved.
- //
- #import "WaringVC.h"
- #import "MengBanView.h"
- @interface WaringVC ()<UITableViewDelegate,UITableViewDataSource>
- {
- 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
|