TeachLogsVC.m 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. //
  2. // TeachLogsVC.m
  3. // LNManager
  4. //
  5. // Created by EchoShacolee on 2017/6/14.
  6. // Copyright © 2017年 lee. All rights reserved.
  7. //
  8. #import "TeachLogsVC.h"
  9. #import "TeachLogCell.h"
  10. #import "MinRescord.h"
  11. #import "MJRefresh.h"
  12. @interface TeachLogsVC ()<UITableViewDelegate,UITableViewDataSource>
  13. {
  14. UITableView *mainTableView;
  15. NSMutableArray *dataArray;
  16. int subject;
  17. int currentPage;
  18. MyGetDataType _getDataType;//加载类型
  19. BOOL _IS_LOADING;//正在加载的状态
  20. UISegmentedControl *_segementCtr;
  21. }
  22. @property (nonatomic,strong)HolderView *holderV;
  23. @end
  24. @implementation TeachLogsVC
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. self.navigationItem.title = @"教学日志";
  28. [self myInit];
  29. }
  30. -(void)myInit{
  31. //四个分类列表的处理
  32. NSArray *items = @[@"科一",@"科二",@"科三",@"科四"];
  33. _segementCtr = [[UISegmentedControl alloc] initWithItems:items];
  34. _segementCtr.frame = CGRectMake(0, kNavOffSet, kSize.width, 40);
  35. _segementCtr.backgroundColor = [UIColor whiteColor];
  36. _segementCtr.tintColor = COLOR_THEME;
  37. _segementCtr.selectedSegmentIndex = 1;
  38. [_segementCtr addTarget:self action:@selector(changeSubject) forControlEvents:UIControlEventValueChanged];
  39. [self.view addSubview:_segementCtr];
  40. //默认显示科目二信息
  41. subject = 2;
  42. currentPage = 1;
  43. dataArray = [NSMutableArray array];
  44. mainTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kNavOffSet + 40, kSize.width, kSize.height - kNavOffSet - 40 - SafeAreaBottomHeight) style:UITableViewStylePlain];
  45. mainTableView.delegate = self;
  46. mainTableView.dataSource = self;
  47. mainTableView.rowHeight = 145;
  48. mainTableView.tableFooterView = [UIView new];
  49. [self.view addSubview:mainTableView];
  50. self.holderV = [[HolderView alloc] initWithFrame:mainTableView.frame];
  51. [self.holderV freshBlock:^{
  52. [self headerRefresh];
  53. }];
  54. [self.view addSubview:self.holderV];
  55. [self setRefreshAction];//设置刷新
  56. [self getTrainTimesRecords];
  57. }
  58. - (void)changeSubject {
  59. currentPage = 1;
  60. subject = (int)_segementCtr.selectedSegmentIndex + 1;
  61. [self getTrainTimesRecords];
  62. }
  63. #pragma mark - 下拉刷新,上拉加载 -
  64. -(void)setRefreshAction{
  65. // 下拉加载更多
  66. __weak typeof(self) weakSelf = self;
  67. MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  68. [weakSelf headerRefresh];
  69. }];
  70. mainTableView.mj_header = header;
  71. MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  72. [weakSelf footerRefresh];
  73. }];
  74. mainTableView.mj_footer = footer;
  75. }
  76. -(void)headerRefresh{
  77. //设置获取数据的方式
  78. _getDataType=MyGetDataTypeHeaderRefresh;
  79. //加载数据
  80. [self getTrainTimesRecords];
  81. [mainTableView.mj_header endRefreshing];
  82. }
  83. -(void)footerRefresh{
  84. //设置获取数据的方式
  85. _getDataType=MyGetDataTypeFooterRefresh;
  86. //加载数据
  87. [self getTrainTimesRecords];
  88. [mainTableView.mj_footer endRefreshing];
  89. }
  90. #pragma mark tableview代理相关
  91. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  92. return dataArray.count;
  93. }
  94. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  95. TeachLogCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellTeach"];
  96. if (!cell) {
  97. //加载xib文件创建cell
  98. cell = [[[NSBundle mainBundle] loadNibNamed:@"TeachLogCell" owner:nil options:nil] lastObject];
  99. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  100. }
  101. [cell setDataWithDic:dataArray[indexPath.row]];
  102. return cell;
  103. }
  104. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  105. if (subject != 2 && subject != 3) {
  106. return;
  107. }
  108. //查看分钟学时&照片 轨迹延后做
  109. MinRescord * mvc = [[MinRescord alloc]init];
  110. mvc.stuDic = dataArray[indexPath.row];
  111. [self.navigationController pushViewController:mvc animated:YES];
  112. }
  113. #pragma mark 请求数据
  114. -(void)getTrainTimesRecords{
  115. //判断当前是否正在加载数据。如果正在加载数据,直接return。
  116. if (_IS_LOADING) {
  117. return;
  118. }
  119. _IS_LOADING=YES;
  120. if (_getDataType==MyGetDataTypeHeaderRefresh) {
  121. currentPage = 1;
  122. }
  123. NSMutableDictionary *mdic = [[NSMutableDictionary alloc]init];
  124. [mdic setValue:[NSString stringWithFormat:@"%@",_schDic[@"TSI_DQBH"]] forKey:@"dqbh"];
  125. [mdic setValue:[NSString stringWithFormat:@"%@",_schDic[@"TSI_QXBH"]] forKey:@"qxbh"];
  126. [mdic setValue:[NSString stringWithFormat:@"%@",_schDic[@"TSI_INSCODE"]] forKey:@"inscode"];
  127. [mdic setValue:@"" forKey:@"stunum"];
  128. [mdic setValue:@"" forKey:@"studentName"];
  129. [mdic setValue:[NSString stringWithFormat:@"%d",subject] forKey:@"subject"];
  130. [mdic setValue:@"" forKey:@"idcard"];
  131. [mdic setValue:@"1" forKey:@"isPage"];
  132. [mdic setValue:@"10" forKey:@"pageSize"];
  133. [mdic setValue:[NSString stringWithFormat:@"%d",currentPage] forKey:@"currentPage"];
  134. //判断网络是否连接
  135. if (![NetworkManager connectedToNetWork]) {
  136. [self showMsgByAlertVCWithString:@"网络连接异常"];
  137. return;
  138. }
  139. [MBProgressHUD hideHUDForView:self.view animated:NO];
  140. [MBProgressHUD showHUDAddedTo:self.view animated:NO];
  141. [NetworkManager requestWithMethod:@"trainTimesRecords" parameters:mdic type:0 handler:^(NSDictionary *successDic, NSString *failureStr) {
  142. _IS_LOADING=NO;
  143. _holderV.hidden = NO;
  144. [MBProgressHUD hideHUDForView:self.view animated:YES];
  145. if (failureStr) {
  146. [self showMsgByAlertVCWithString:failureStr];
  147. return;
  148. }
  149. if ([successDic[@"code"] isEqualToString:@"1"]) {
  150. [self showMsgByAlertVCWithString:successDic[@"msg"]];
  151. return;
  152. }
  153. if (currentPage == 1) {
  154. //如果是首页 就要删除之前的数据
  155. [dataArray removeAllObjects];
  156. }
  157. [dataArray addObjectsFromArray:successDic[@"body"]];
  158. if ([successDic[@"body"] count] > 0) {
  159. currentPage++;
  160. }
  161. if ([dataArray count] > 0) {
  162. _holderV.hidden = YES;
  163. }else {
  164. if (currentPage == 1) {
  165. _holderV.hidden = NO;
  166. }
  167. }
  168. dispatch_async(dispatch_get_main_queue(), ^{
  169. [mainTableView reloadData];
  170. });
  171. _getDataType=MyGetDataTypeNomal;
  172. }];
  173. }
  174. - (void)didReceiveMemoryWarning {
  175. [super didReceiveMemoryWarning];
  176. // Dispose of any resources that can be recreated.
  177. }
  178. /*
  179. #pragma mark - Navigation
  180. // In a storyboard-based application, you will often want to do a little preparation before navigation
  181. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  182. // Get the new view controller using [segue destinationViewController].
  183. // Pass the selected object to the new view controller.
  184. }
  185. */
  186. @end