123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- //
- // 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 ()<UITableViewDataSource,UITableViewDelegate>
- {
- 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
|