// // ClassTheoryList.m // JSJPCoach // // Created by EchoShacolee on 2017/7/15. // Copyright © 2017年 Danson. All rights reserved. // #import "ClassTheoryList.h" #import "TheoryTrainVC.h" #import "ClsTheoryListCell.h" #import "MJRefresh.h" @interface ClassTheoryList () { UITableView *_tableView; NSMutableArray *_dataurce; HolderView *holderV; NSInteger _currentPageNum; //记录页书 MyGetDataType _getDataType; //加载数据的类型 BOOL _IS_LOADING; //正在加载的状态 } @end @implementation ClassTheoryList - (void)viewDidLoad { [super viewDidLoad]; [self.view setBackgroundColor:backGroundColor]; self.navigationController.navigationBar.translucent = NO; [self setTitle:@"带班信息列表"]; [self configNavBar]; [self myInit]; [self setRefreshAction]; [self getStudentClassesList]; } -(void)myInit{ _IS_LOADING = NO; _getDataType = MyGetDataTypeNomal; _dataurce = [[NSMutableArray alloc]init]; _tableView = [[UITableView alloc]initWithFrame:kFrame style:UITableViewStyleGrouped]; _tableView.backgroundColor = backGroundColor; _tableView.delegate = self; _tableView.dataSource = self; _tableView.rowHeight = 90; _tableView.tableFooterView = [UIView new]; [self.view addSubview:_tableView]; holderV = [[HolderView alloc] initWithFrame:_tableView.frame]; holderV.height += 64; [holderV freshBlock:^{ [self getStudentClassesList]; }]; [self addV:holderV]; [holderV setHidden:YES]; } #pragma mark - 下拉刷新,上拉加载 - -(void)setRefreshAction{ // 下拉加载更多 __weak typeof(self) weakSelf = self; MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ [weakSelf headerRefresh]; }]; _tableView.mj_header = header; MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{ [weakSelf footerRefresh]; }]; _tableView.mj_footer = footer; } -(void)headerRefresh{ //设置获取数据的方式 _getDataType=MyGetDataTypeHeaderRefresh; //加载数据 [self getStudentClassesList]; [_tableView.mj_header endRefreshing]; } -(void)footerRefresh{ //设置获取数据的方式 _getDataType=MyGetDataTypeFooterRefresh; //加载数据 [self getStudentClassesList]; [_tableView.mj_footer endRefreshing]; } #pragma mark tableview代理相关 -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return _dataurce.count; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 1; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ ClsTheoryListCell *cell = [ClsTheoryListCell cellForTableView:tableView]; cell.dic = _dataurce[indexPath.row]; return cell; } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 0.1f; } -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ return 10; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ NSDictionary *dic = _dataurce[indexPath.row]; if (![[NSString stringWithFormat:@"%@",dic[@"TR_AUDIT_STATUS"]] isEqualToString:@"1"]) { UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:@"提醒" message:@"所选班级未通过审核,不允许带教" preferredStyle:UIAlertControllerStyleAlert]; [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]]; [self presentViewController:alertFind animated:true completion:nil]; return; } TheoryTrainVC *vc = [[TheoryTrainVC alloc]init]; vc.classId = _dataurce[indexPath.row][@"TSC_ID"]; vc.schoolId = _dataurce[indexPath.row][@"TSC_SCHOOL_ID"]; vc.startTime = _dataurce[indexPath.row][@"TR_STARTTIME"]; vc.endTime = _dataurce[indexPath.row][@"TR_ENDTIME"]; vc.isNotification = NO; if ([[NSString stringWithFormat:@"%@",dic[@"TSC_TYPE"]] isEqualToString:@"1"]) { vc.title = @"理论学习"; }else{ vc.title = @"模拟学习"; } [self.navigationController pushViewController:vc animated:YES]; } #pragma mark 网络请求 -(void)getStudentClassesList{ //判断当前是否正在加载数据。如果正在加载数据,直接return。 if (_IS_LOADING) { return; } _IS_LOADING=YES; //获取第一页数据 NSInteger needLoadPage; needLoadPage=_currentPageNum+1; if (_getDataType==MyGetDataTypeHeaderRefresh) { needLoadPage=1; } [LoadingView showHUD]; NSMutableArray *arr = [[NSMutableArray alloc]init]; [arr addPro:@"coachOutid" Value:defUser.userDict[@"outId"]]; [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]]; [arr addPro:@"subject" Value:@""]; [arr addPro:@"type" Value:@""];//类型(1集中理论 2 集中模拟) [arr addPro:@"isPage" Value:@"1"]; [arr addPro:@"pageSize" Value:@"10"]; [arr addPro:@"currentPage" Value:[NSString stringWithFormat:@"%ld",(long)needLoadPage]]; NSString *method = @"getStudentClassesList"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) { RemoveHUD(); holderV.hidden = NO; _IS_LOADING=NO; if (!root) { ShowMsg(@"数据请求失败,请重试"); return; } if ([root[@"code"] integerValue] != 0) { ShowMsg(root[@"msg"]); return; } //处理数据 //如果获取到了数据,而且是下拉刷新,清空数组。 if (_getDataType==MyGetDataTypeHeaderRefresh){ [_dataurce removeAllObjects]; } //追加数据 [_dataurce addObjectsFromArray:root[@"body"]]; if (_dataurce.count != 0) { holderV.hidden = YES; //计数器+1 if ([root[@"body"] count] != 0) { _currentPageNum=needLoadPage; //刷新界面 [_tableView reloadData]; } } //恢复初始状态。 _getDataType=MyGetDataTypeNomal; if (_dataurce.count > 0) { holderV.hidden = YES; } [_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