// // CoachListVC.m // LNManager // // Created by EchoShacolee on 2017/4/8. // Copyright © 2017年 lee. All rights reserved. // #import "CoachListVC.h" #import "CoachDetail.h" #import "CoachApplyVC.h" #import "SYBaseCell.h" @interface CoachListVC () @end @implementation CoachListVC - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title = @"教练列表"; [self getData]; __weak typeof(self) weakSelf = self; self.holdervBlock = ^{ [weakSelf getData]; }; [self.tableView registerNib:[UINib nibWithNibName:@"SYBaseCell" bundle:nil] forCellReuseIdentifier:@"SYBaseCellId"]; [Tools permissionValidationWithID:@"21" view:self.view result:^(BOOL isCan, NSString *failureStr) { if (isCan) { [self customRightBtn]; } }]; } -(void)customRightBtn{ UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem]; btn.frame = CGRectMake(0, 0, 80, 44); btn.titleLabel.font = [UIFont systemFontOfSize:17]; [btn setTitle:@"新增教练" forState:UIControlStateNormal]; [btn setTitleColor:defGreen forState:UIControlStateNormal]; [btn addTarget:self action:@selector(addNewCoach) forControlEvents:UIControlEventTouchUpInside]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn]; } -(void)addNewCoach{ // if (!myDelegate.isSchool) { // ShowMsg(@"驾校管理员才可以新增操作"); // return; // } CoachApplyVC *vc = [[CoachApplyVC alloc] init]; vc.block = ^{ [self getData]; }; [self navPushHideTabbarToVC:vc]; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 44; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { SYBaseCell * cell = [tableView dequeueReusableCellWithIdentifier:@"SYBaseCellId" forIndexPath:indexPath]; cell.nameLab.text = _dataSource[indexPath.section][indexPath.row][@"TCI_NAME"]; NSString *str = [NSString stringWithFormat:@"%@",_dataSource[indexPath.section][indexPath.row][@"TCI_LOCK_STATUS"]]; cell.lockingImgV.hidden = [str intValue]==0; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ CoachDetail * coachvc = [[CoachDetail alloc]init]; [_requsetDic setValue:_dataSource[indexPath.section][indexPath.row][@"TCI_IDCARD"] forKey:@"idcard"]; coachvc.requesetDic = _requsetDic; coachvc.coachNum = _dataSource[indexPath.section][indexPath.row][@"TCI_COACHNUM"]; [self navPushHideTabbarToVC:coachvc]; } #pragma mark - 数据请求 -(void)getData{ NSMutableDictionary * mDic = [[NSMutableDictionary alloc]init]; [mDic setValue:defUser.userDict[@"dqbh"] forKey:@"dqbh"]; [mDic setValue:defUser.userDict[@"qxbh"] forKey:@"qxbh"]; [mDic setValue:defUser.userDict[@"school"] forKey:@"schoolId"]; [mDic setValue:@"" forKey:@"name"]; [mDic setValue:@"" forKey:@"idcard"]; [mDic setValue:@"" forKey:@"mobile"]; _requsetDic = mDic; [self getDataWithDic:mDic method:@"coachs" block:^(NSDictionary *successdic) { NSArray * arr = successdic[@"body"]; if (arr.count != 0) { self.holderV.hidden = YES; } for (NSDictionary * dic in arr) { if (![_sectionTitles containsObject:dic[@"ZM"]]) { [_sectionTitles addObject:dic[@"ZM"]]; [_dataSource addObject:[NSMutableArray new]]; } } //排序 [_sectionTitles sortUsingSelector:@selector(compare:)]; for (NSDictionary * dic in arr) { NSInteger location = [_sectionTitles indexOfObject:dic[@"ZM"]]; [_dataSource[location] addObject:dic]; } [self.tableView reloadData]; }]; } @end