MinRescord.m 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. //
  2. // MinRescord.m
  3. // LNManager
  4. //
  5. // Created by EchoShacolee on 2017/4/14.
  6. // Copyright © 2017年 lee. All rights reserved.
  7. //
  8. #import "MinRescord.h"
  9. #import "MinRecordeCell.h"
  10. @interface MinRescord ()
  11. {
  12. // UIButton *trainbtn;
  13. // UIButton *photoBtn;
  14. //
  15. // UIView *photoView;
  16. //记录页书
  17. NSInteger _currentPageNum;
  18. //加载数据的类型
  19. MyGetDataType _getDataType;
  20. }
  21. @end
  22. @implementation MinRescord
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. self.navigationItem.title = @"电子日志详细";
  26. // self.automaticallyAdjustsScrollViewInsets = NO;
  27. // UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20, kNavOffSet + 10, kSize.width/2.0 - 30, 40)];
  28. // [btn setTitle:@"分钟学时" textColor:COLOR_THEME font:FontTitle fotState:UIControlStateNormal];
  29. // [btn borderColor:COLOR_THEME width:1 cornorRadios:3];
  30. // [btn addTarget:self action:@selector(trainAction) forControlEvents:UIControlEventTouchUpInside];
  31. // [self.view addSubview:btn];
  32. // trainbtn = btn;
  33. //
  34. // btn = [[UIButton alloc] initWithFrame:CGRectMake(kSize.width/2.0 + 10, kNavOffSet + 10, kSize.width/2.0 - 30, 40)];
  35. // [btn setTitle:@"训练照片" textColor:RGB_COLOR(136,136,136) font:FontTitle fotState:UIControlStateNormal];
  36. // [btn borderColor:RGB_COLOR(136,136,136) width:1 cornorRadios:3];
  37. // [btn addTarget:self action:@selector(photoAction) forControlEvents:UIControlEventTouchUpInside];
  38. // [self.view addSubview:btn];
  39. // photoBtn = btn;
  40. //
  41. // UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(10, kNavOffSet + 60, kSize.width - 20, 1)];
  42. // line.backgroundColor = RGB_COLOR(136,136,136);
  43. // [self.view addSubview:line];
  44. //
  45. // self.tableView.y = kNavOffSet + 61;
  46. // self.tableView.height = kSize.height - kNavOffSet - 61;
  47. //
  48. // //添加一个图片轮播器在这里 设置在屏幕右边
  49. // photoView = [[UIView alloc] initWithFrame:self.tableView.frame];
  50. // photoView.x = kSize.width;
  51. // photoView.backgroundColor = [UIColor redColor];
  52. // [self.view addSubview:photoView];
  53. [self getData];
  54. [self setRefreshAction];
  55. //点击刷新的回调
  56. __weak typeof(self) weakSelf = self;
  57. self.block = ^{
  58. _currentPageNum = 0;
  59. [weakSelf headerRefresh];
  60. };
  61. }
  62. //- (void)trainAction {
  63. // [trainbtn setTitleColor:COLOR_THEME forState:UIControlStateNormal];
  64. // trainbtn.layer.borderColor = COLOR_THEME.CGColor;
  65. //
  66. // [photoBtn setTitleColor:RGB_COLOR(136,136,136) forState:UIControlStateNormal];
  67. // photoBtn.layer.borderColor = RGB_COLOR(136, 136, 136).CGColor;
  68. // if (self.tableView.x != 0) {
  69. // [UIView animateWithDuration:.4 animations:^{
  70. // self.tableView.x = 0;
  71. // photoView.x = kSize.width;
  72. // }];
  73. // }
  74. //}
  75. //
  76. //- (void)photoAction {
  77. // [trainbtn setTitleColor:RGB_COLOR(136,136,136) forState:UIControlStateNormal];
  78. // trainbtn.layer.borderColor = RGB_COLOR(136, 136, 136).CGColor;
  79. //
  80. // [photoBtn setTitleColor:COLOR_THEME forState:UIControlStateNormal];
  81. // photoBtn.layer.borderColor = COLOR_THEME.CGColor;
  82. // if (photoView.x != 0) {
  83. // [UIView animateWithDuration:.4 animations:^{
  84. // self.tableView.x = -kSize.width;
  85. // photoView.x = 0;
  86. // }];
  87. // }
  88. //}
  89. #pragma mark tableview代理相关
  90. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  91. return self.dataurce.count;
  92. }
  93. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  94. return 100;
  95. }
  96. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  97. MinRecordeCell * cell = [tableView dequeueReusableCellWithIdentifier:@"minRecordCellId"];
  98. if (!cell) {
  99. cell = [[[NSBundle mainBundle] loadNibNamed:@"MinRecordeCell" owner:nil options:nil] lastObject];
  100. }
  101. [cell upDataWithDic:self.dataurce[indexPath.row]];
  102. return cell;
  103. }
  104. #pragma mark - 下拉刷新,上拉加载 -
  105. -(void)setRefreshAction{
  106. // 下拉加载更多
  107. __weak typeof(self) weakSelf = self;
  108. MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  109. [weakSelf headerRefresh];
  110. }];
  111. self.tableView.mj_header = header;
  112. MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  113. [weakSelf footerRefresh];
  114. }];
  115. self.tableView.mj_footer = footer;
  116. }
  117. -(void)headerRefresh{
  118. //设置获取数据的方式
  119. _getDataType=MyGetDataTypeHeaderRefresh;
  120. //加载数据
  121. [self getData];
  122. [self.tableView.mj_header endRefreshing];
  123. }
  124. -(void)footerRefresh{
  125. //设置获取数据的方式
  126. _getDataType=MyGetDataTypeFooterRefresh;
  127. //加载数据
  128. [self getData];
  129. [self.tableView.mj_footer endRefreshing];
  130. }
  131. -(void)getData{
  132. //判断当前是否正在加载数据。如果正在加载数据,直接return。
  133. if (_IS_LOADING) {
  134. return;
  135. }
  136. _IS_LOADING=YES;
  137. //获取第一页数据
  138. NSInteger needLoadPage;
  139. needLoadPage=_currentPageNum+1;
  140. if (_getDataType==MyGetDataTypeHeaderRefresh) {
  141. needLoadPage=1;
  142. }
  143. NSMutableDictionary *mdic = [[NSMutableDictionary alloc]init];
  144. [mdic setValue:self.stuDic[@"STUNUM"] forKey:@"stunum"];
  145. [mdic setValue:self.stuDic[@"CLASSID"] forKey:@"classId"];
  146. [mdic setValue:@"1" forKey:@"isPage"];
  147. [mdic setValue:@"10" forKey:@"pageSize"];
  148. [mdic setValue:[NSString stringWithFormat:@"%ld",(long)needLoadPage] forKey:@"currentPage"];
  149. __weak typeof(self) weakSelf = self;
  150. [self getDataWithDic:mdic method:@"trainTimesRecordMins" block:^(NSDictionary *successDic) {
  151. //处理数据
  152. //如果获取到了数据,而且是下拉刷新,清空数组。
  153. if (_getDataType==MyGetDataTypeHeaderRefresh){
  154. [weakSelf.dataurce removeAllObjects];
  155. }
  156. //追加数据
  157. [weakSelf.dataurce addObjectsFromArray:successDic[@"body"]];
  158. if (weakSelf.dataurce.count != 0) {
  159. weakSelf.holderV.hidden = YES;
  160. }
  161. if ([successDic[@"body"] count] != 0) {
  162. //计数器+1
  163. _currentPageNum=needLoadPage;
  164. }
  165. //刷新界面
  166. [weakSelf.tableView reloadData];
  167. //恢复初始状态。
  168. _getDataType=MyGetDataTypeNomal;
  169. }];
  170. }
  171. - (void)didReceiveMemoryWarning {
  172. [super didReceiveMemoryWarning];
  173. // Dispose of any resources that can be recreated.
  174. }
  175. @end