ClassTheoryList.m 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. //
  2. // ClassTheoryList.m
  3. // JSJPCoach
  4. //
  5. // Created by EchoShacolee on 2017/7/15.
  6. // Copyright © 2017年 Danson. All rights reserved.
  7. //
  8. #import "ClassTheoryList.h"
  9. #import "TheoryTrainVC.h"
  10. #import "ClsTheoryListCell.h"
  11. #import "MJRefresh.h"
  12. @interface ClassTheoryList ()<UITableViewDataSource,UITableViewDelegate>
  13. {
  14. UITableView *_tableView;
  15. NSMutableArray *_dataurce;
  16. HolderView *holderV;
  17. NSInteger _currentPageNum; //记录页书
  18. MyGetDataType _getDataType; //加载数据的类型
  19. BOOL _IS_LOADING; //正在加载的状态
  20. }
  21. @end
  22. @implementation ClassTheoryList
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. [self.view setBackgroundColor:backGroundColor];
  26. self.navigationController.navigationBar.translucent = NO;
  27. [self setTitle:@"带班信息列表"];
  28. [self configNavBar];
  29. [self myInit];
  30. [self setRefreshAction];
  31. [self getStudentClassesList];
  32. }
  33. -(void)myInit{
  34. _IS_LOADING = NO;
  35. _getDataType = MyGetDataTypeNomal;
  36. _dataurce = [[NSMutableArray alloc]init];
  37. _tableView = [[UITableView alloc]initWithFrame:kFrame style:UITableViewStyleGrouped];
  38. _tableView.backgroundColor = backGroundColor;
  39. _tableView.delegate = self;
  40. _tableView.dataSource = self;
  41. _tableView.rowHeight = 90;
  42. _tableView.tableFooterView = [UIView new];
  43. [self.view addSubview:_tableView];
  44. holderV = [[HolderView alloc] initWithFrame:_tableView.frame];
  45. holderV.height += 64;
  46. [holderV freshBlock:^{
  47. [self getStudentClassesList];
  48. }];
  49. [self addV:holderV];
  50. [holderV setHidden:YES];
  51. }
  52. #pragma mark - 下拉刷新,上拉加载 -
  53. -(void)setRefreshAction{
  54. // 下拉加载更多
  55. __weak typeof(self) weakSelf = self;
  56. MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  57. [weakSelf headerRefresh];
  58. }];
  59. _tableView.mj_header = header;
  60. MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  61. [weakSelf footerRefresh];
  62. }];
  63. _tableView.mj_footer = footer;
  64. }
  65. -(void)headerRefresh{
  66. //设置获取数据的方式
  67. _getDataType=MyGetDataTypeHeaderRefresh;
  68. //加载数据
  69. [self getStudentClassesList];
  70. [_tableView.mj_header endRefreshing];
  71. }
  72. -(void)footerRefresh{
  73. //设置获取数据的方式
  74. _getDataType=MyGetDataTypeFooterRefresh;
  75. //加载数据
  76. [self getStudentClassesList];
  77. [_tableView.mj_footer endRefreshing];
  78. }
  79. #pragma mark tableview代理相关
  80. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  81. return _dataurce.count;
  82. }
  83. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  84. return 1;
  85. }
  86. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  87. ClsTheoryListCell *cell = [ClsTheoryListCell cellForTableView:tableView];
  88. cell.dic = _dataurce[indexPath.row];
  89. return cell;
  90. }
  91. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  92. return 0.1f;
  93. }
  94. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  95. return 10;
  96. }
  97. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  98. NSDictionary *dic = _dataurce[indexPath.row];
  99. if (![[NSString stringWithFormat:@"%@",dic[@"TR_AUDIT_STATUS"]] isEqualToString:@"1"]) {
  100. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:@"提醒" message:@"所选班级未通过审核,不允许带教" preferredStyle:UIAlertControllerStyleAlert];
  101. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  102. }]];
  103. [self presentViewController:alertFind animated:true completion:nil];
  104. return;
  105. }
  106. TheoryTrainVC *vc = [[TheoryTrainVC alloc]init];
  107. vc.classId = _dataurce[indexPath.row][@"TSC_ID"];
  108. vc.schoolId = _dataurce[indexPath.row][@"TSC_SCHOOL_ID"];
  109. vc.startTime = _dataurce[indexPath.row][@"TR_STARTTIME"];
  110. vc.endTime = _dataurce[indexPath.row][@"TR_ENDTIME"];
  111. vc.isNotification = NO;
  112. if ([[NSString stringWithFormat:@"%@",dic[@"TSC_TYPE"]] isEqualToString:@"1"]) {
  113. vc.title = @"理论学习";
  114. }else{
  115. vc.title = @"模拟学习";
  116. }
  117. [self.navigationController pushViewController:vc animated:YES];
  118. }
  119. #pragma mark 网络请求
  120. -(void)getStudentClassesList{
  121. //判断当前是否正在加载数据。如果正在加载数据,直接return。
  122. if (_IS_LOADING) {
  123. return;
  124. }
  125. _IS_LOADING=YES;
  126. //获取第一页数据
  127. NSInteger needLoadPage;
  128. needLoadPage=_currentPageNum+1;
  129. if (_getDataType==MyGetDataTypeHeaderRefresh) {
  130. needLoadPage=1;
  131. }
  132. [LoadingView showHUD];
  133. NSMutableArray *arr = [[NSMutableArray alloc]init];
  134. [arr addPro:@"coachOutid" Value:defUser.userDict[@"outId"]];
  135. [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]];
  136. [arr addPro:@"subject" Value:@""];
  137. [arr addPro:@"type" Value:@""];//类型(1集中理论 2 集中模拟)
  138. [arr addPro:@"isPage" Value:@"1"];
  139. [arr addPro:@"pageSize" Value:@"10"];
  140. [arr addPro:@"currentPage" Value:[NSString stringWithFormat:@"%ld",(long)needLoadPage]];
  141. NSString *method = @"getStudentClassesList";
  142. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  143. RemoveHUD();
  144. holderV.hidden = NO;
  145. _IS_LOADING=NO;
  146. if (!root) {
  147. ShowMsg(@"数据请求失败,请重试");
  148. return;
  149. }
  150. if ([root[@"code"] integerValue] != 0) {
  151. ShowMsg(root[@"msg"]);
  152. return;
  153. }
  154. //处理数据
  155. //如果获取到了数据,而且是下拉刷新,清空数组。
  156. if (_getDataType==MyGetDataTypeHeaderRefresh){
  157. [_dataurce removeAllObjects];
  158. }
  159. //追加数据
  160. [_dataurce addObjectsFromArray:root[@"body"]];
  161. if (_dataurce.count != 0) {
  162. holderV.hidden = YES;
  163. //计数器+1
  164. if ([root[@"body"] count] != 0) {
  165. _currentPageNum=needLoadPage;
  166. //刷新界面
  167. [_tableView reloadData];
  168. }
  169. }
  170. //恢复初始状态。
  171. _getDataType=MyGetDataTypeNomal;
  172. if (_dataurce.count > 0) {
  173. holderV.hidden = YES;
  174. }
  175. [_tableView reloadData];
  176. }];
  177. }
  178. - (void)didReceiveMemoryWarning {
  179. [super didReceiveMemoryWarning];
  180. // Dispose of any resources that can be recreated.
  181. }
  182. /*
  183. #pragma mark - Navigation
  184. // In a storyboard-based application, you will often want to do a little preparation before navigation
  185. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  186. // Get the new view controller using [segue destinationViewController].
  187. // Pass the selected object to the new view controller.
  188. }
  189. */
  190. @end