RecordVC_New.m 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. //
  2. // RecordVC_New.m
  3. // jiaPei
  4. //
  5. // Created by EchoShacolee on 2018/3/26.
  6. // Copyright © 2018年 JCZ. All rights reserved.
  7. //
  8. #import "RecordVC_New.h"
  9. #import "HolderView.h"
  10. #import "RecordCell_New.h"
  11. #import "NSArray+ex.h"
  12. #import <MJRefresh.h>
  13. typedef NS_ENUM(NSInteger, MyGetDataType) {
  14. //正常请求数据
  15. MyGetDataTypeNomal=0,
  16. //下拉刷新请求数据
  17. MyGetDataTypeHeaderRefresh,
  18. //上拉加载更多请求数据
  19. MyGetDataTypeFooterRefresh
  20. };
  21. @interface RecordVC_New ()
  22. {
  23. HolderView *holderV;
  24. NSArray *teachTypes;
  25. NSMutableArray *rArray;
  26. NSInteger currentPage;
  27. MyGetDataType _getDataType;//加载类型
  28. BOOL _IS_LOADING;//正在加载的状态
  29. }
  30. @end
  31. @implementation RecordVC_New
  32. - (void)viewDidLoad {
  33. [super viewDidLoad];
  34. self.title = @"培训记录";
  35. self.tableView.backgroundColor = backGroundColor;
  36. self.tableView.tableFooterView = [UIView new];
  37. [self configNavigationBar];
  38. holderV = [[HolderView alloc] initWithFrame:self.tableView.bounds];
  39. [self.view addSubview:holderV];
  40. currentPage = 1;
  41. _IS_LOADING = NO;
  42. _getDataType = MyGetDataTypeNomal;
  43. rArray = [NSMutableArray new];
  44. teachTypes = [NSArray array];
  45. [self getTeachTypes];
  46. }
  47. - (void)didReceiveMemoryWarning {
  48. [super didReceiveMemoryWarning];
  49. // Dispose of any resources that can be recreated.
  50. }
  51. #pragma mark - 下拉刷新,上拉加载 -
  52. -(void)setRefreshAction{
  53. // 下拉加载更多
  54. __weak typeof(self) weakSelf = self;
  55. MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  56. [weakSelf headerRefresh];
  57. }];
  58. self.tableView.mj_header = header;
  59. MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  60. [weakSelf footerRefresh];
  61. }];
  62. self.tableView.mj_footer = footer;
  63. }
  64. -(void)headerRefresh{
  65. //设置获取数据的方式
  66. _getDataType=MyGetDataTypeHeaderRefresh;
  67. //加载数据
  68. [self getMyTeachLogs];
  69. [self.tableView.mj_header endRefreshing];
  70. }
  71. -(void)footerRefresh{
  72. //设置获取数据的方式
  73. _getDataType=MyGetDataTypeFooterRefresh;
  74. //加载数据
  75. [self getMyTeachLogs];
  76. [self.tableView.mj_footer endRefreshing];
  77. }
  78. #pragma mark - Table view data source
  79. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  80. return 1;
  81. }
  82. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  83. return rArray.count;
  84. }
  85. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  86. RecordCell_New *cell = [tableView dequeueReusableCellWithIdentifier:@"reuseId"];
  87. if (!cell) {
  88. cell = [[[NSBundle mainBundle]loadNibNamed:@"RecordCell_New" owner:nil options:nil] lastObject];
  89. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  90. }
  91. NSDictionary *dic = rArray[indexPath.row];
  92. NSString *teachStyle;
  93. if (teachTypes.count != 0) {
  94. teachStyle = [teachTypes h_safeObjectAtIndex:[dic[@"TL_TEACH_ID"] integerValue] - 1];
  95. }
  96. NSString *remarkS = [NSString stringWithFormat:@"%d、[%@]",(int)indexPath.row + 1,teachStyle];
  97. NSMutableAttributedString * aString = [[NSMutableAttributedString alloc] initWithString:remarkS];
  98. [aString addAttribute:NSForegroundColorAttributeName
  99. value:[UIColor orangeColor]
  100. range:NSMakeRange(2, 1)];
  101. [aString addAttribute:NSForegroundColorAttributeName
  102. value:[UIColor orangeColor]
  103. range:NSMakeRange(remarkS.length - 1, 1)];
  104. cell.titleLab.attributedText = aString;
  105. NSString *km = [dic[@"TL_SUBJECT"] isEqualToString:@"2"]?@"科二":@"科三";
  106. cell.subjectLab.text = km;
  107. NSString *dateString = dic[@"TL_CRDATE"];
  108. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  109. formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
  110. [formatter setDateFormat:@"yyyy-MM-dd"];
  111. NSDate *cDate = [formatter dateFromString:dateString];
  112. [formatter setDateFormat:@"MM.dd.yyyy"];
  113. dateString = [formatter stringFromDate:cDate];
  114. cell.timeLab.text = dateString;
  115. cell.contentLab.text = @"";
  116. if ([dic[@"TL_REMARK"] length] > 0) {
  117. cell.contentLab.text = [NSString stringWithFormat:@"备注: %@",dic[@"TL_REMARK"]];
  118. }
  119. if (cell.contentLab.text.length > 0) {
  120. NSString *remarkString = cell.contentLab.text;
  121. NSMutableAttributedString * aAttributedString = [[NSMutableAttributedString alloc] initWithString:remarkString];
  122. [aAttributedString addAttribute:NSForegroundColorAttributeName
  123. value:[UIColor orangeColor]
  124. range:NSMakeRange(0, 3)];
  125. [aAttributedString addAttribute:NSForegroundColorAttributeName
  126. value:contentTextColor
  127. range:NSMakeRange(3, remarkString.length - 3)];
  128. cell.contentLab.attributedText = aAttributedString;
  129. }
  130. return cell;
  131. }
  132. #pragma mark - 网络请求
  133. -(void)getTeachTypes
  134. {
  135. if (![Util connectedToNetWork]) {
  136. showMsgUnconnect();
  137. return;
  138. }
  139. NSMutableArray *arr=[NSMutableArray array];
  140. [arr addPro:@"subject" Value:@""];
  141. [arr addPro:@"type" Value:@"1"];
  142. NSString* method = @"getTeachTypes";
  143. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  144. //NSLog(@"类型---->%@----->%@",arr,root);
  145. if (!root) {
  146. [LoadingView showMsg:@"请求失败"];
  147. return;
  148. }
  149. if ([root[@"code"] isEqualToString:@"1"]) {
  150. [LoadingView showMsg:root[@"body"]];
  151. return;
  152. }
  153. NSMutableArray *types = [NSMutableArray array];
  154. for (NSDictionary *dic in root[@"body"]) {
  155. [types addObject:dic[@"TC_TEACH_TYPE"]];
  156. }
  157. teachTypes = [NSArray arrayWithArray:types];
  158. [self getMyTeachLogs];
  159. }];
  160. }
  161. -(void)getMyTeachLogs
  162. {
  163. //判断当前是否正在加载数据。如果正在加载数据,直接return。
  164. if (_IS_LOADING) {
  165. return;
  166. }
  167. _IS_LOADING=YES;
  168. if (_getDataType==MyGetDataTypeHeaderRefresh) {
  169. currentPage = 1;
  170. }
  171. NSMutableArray *arr=[NSMutableArray array];
  172. [arr addPro:@"queryValue" Value:defUser.userDict[@"outId"]];
  173. [arr addPro:@"isPage" Value:@"1"];
  174. [arr addPro:@"pageSize" Value:@"10"];
  175. [arr addPro:@"currentPage" Value:[NSString stringWithFormat:@"%d",(int)currentPage]];
  176. NSString* method = @"getMyTeachLogs";
  177. [MBProgressHUD showLoadToView:self.view];
  178. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  179. _IS_LOADING=NO;
  180. [MBProgressHUD hideHUDForView:self.view];
  181. holderV.hidden = NO;
  182. if (!root) {
  183. [LoadingView showMsg:@"操作失败"];
  184. return;
  185. }
  186. if ([root[@"code"] isEqualToString:@"1"]) {
  187. [LoadingView showMsg:root[@"body"]];
  188. return;
  189. }
  190. if (currentPage == 1) {
  191. rArray = [NSMutableArray arrayWithArray:root[@"body"]];
  192. }else{
  193. [rArray addObjectsFromArray:root[@"body"]];
  194. }
  195. if (rArray.count != 0) {
  196. [holderV setHidden:YES];
  197. }
  198. if ([root[@"body"] count] == 0) {
  199. ShowMsg(@"已加载全部数据");
  200. return;
  201. }else{
  202. currentPage += 1;
  203. }
  204. [self.tableView reloadData];
  205. }];
  206. }
  207. @end