EvaluationListVC.m 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. //
  2. // EvaluationListVC.m
  3. // LNManager
  4. //
  5. // Created by EchoShacolee on 2017/5/31.
  6. // Copyright © 2017年 lee. All rights reserved.
  7. //
  8. #import "EvaluationListVC.h"
  9. #import "MJRefresh.h"
  10. #import "EvaListCell.h"
  11. #import "NSString+ex.h"
  12. #import "NSArray+ex.h"
  13. #import "MengBanView.h"
  14. @interface EvaluationListVC ()
  15. {
  16. //记录页书
  17. NSInteger _currentPageNum;
  18. //加载数据的类型
  19. MyGetDataType _getDataType;
  20. //缓存cell高度
  21. NSMutableArray *_heightArr;
  22. MengBanView *_mengBanView;
  23. NSString * _status;
  24. UISegmentedControl *_seg;
  25. //权限
  26. BOOL _permissonSch;
  27. BOOL _permissonCoa;
  28. NSString *_failureStrSch;
  29. NSString *_failureStrCoa;
  30. }
  31. @end
  32. @implementation EvaluationListVC
  33. - (void)viewDidLoad {
  34. [super viewDidLoad];
  35. // [self customRightBtn];
  36. //@lee 2018/2/9 处理下啦刷新显示问题
  37. if (iOS11) {
  38. }else {
  39. self.automaticallyAdjustsScrollViewInsets = NO;// Defaults to YES
  40. }
  41. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  42. _currentPageNum = 0;
  43. _getDataType = MyGetDataTypeNomal;
  44. _status = @"1";
  45. _permissonSch = NO;
  46. _permissonCoa = NO;
  47. _failureStrSch = @"";
  48. _failureStrCoa = @"";
  49. //
  50. _seg = [[UISegmentedControl alloc]initWithItems:@[@"机构评价",@"教练评价"]];
  51. _seg.frame = CGRectMake(10, kNavOffSet, kSize.width-20, 40);
  52. _seg.backgroundColor = [UIColor whiteColor];
  53. _seg.selectedSegmentIndex = 0;
  54. _seg.tintColor = COLOR_THEME;
  55. [_seg addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged];
  56. [self.view addSubview:_seg];
  57. self.tableView.frame = CGRectMake(0, kNavOffSet+40, kSize.width, kSize.height-kNavOffSet-40-SafeAreaBottomHeight);
  58. [self setRefreshAction];//设置刷新
  59. [self getPermisson];
  60. __weak typeof(self) weakSelf = self;
  61. self.block = ^{
  62. _currentPageNum = 0;
  63. [weakSelf getData];
  64. };
  65. }
  66. -(void)change:(UISegmentedControl *)seg{
  67. _status = [NSString stringWithFormat:@"%ld",seg.selectedSegmentIndex+1];
  68. [_heightArr removeAllObjects];
  69. [self.dataurce removeAllObjects];
  70. [self.tableView reloadData];
  71. [self headerRefresh];
  72. }
  73. -(void)customRightBtn{
  74. UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithTitle:@"筛选" style:UIBarButtonItemStylePlain target:self action:@selector(setMengbanView)];
  75. item.tintColor = COLOR_THEME;
  76. self.navigationItem.rightBarButtonItem = item;
  77. }
  78. -(void)setMengbanView{
  79. if (_mengBanView) {
  80. [_mengBanView showView];
  81. return;
  82. }
  83. NSArray * btnarr = @[@"机构评价",@"教练评价"];
  84. _mengBanView = [[MengBanView alloc]initWithTitileStr:nil buttonsArray:@[btnarr] block:^(NSArray *array) {
  85. if ([array[0] isEqualToString:@"机构评价"]) {
  86. _status = @"1";
  87. }else if ([array[0] isEqualToString:@"教练评价"]){
  88. _status = @"2";
  89. }
  90. [_heightArr removeAllObjects];
  91. [self.tableView setContentOffset:CGPointMake(0, -kNavOffSet) animated:NO];
  92. [self headerRefresh];
  93. }];
  94. [_mengBanView showView];
  95. }
  96. #pragma mark - 下拉刷新,上拉加载 -
  97. -(void)setRefreshAction{
  98. // 下拉加载更多
  99. __weak typeof(self) weakSelf = self;
  100. MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  101. [weakSelf headerRefresh];
  102. }];
  103. self.tableView.mj_header = header;
  104. MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  105. [weakSelf footerRefresh];
  106. }];
  107. self.tableView.mj_footer = footer;
  108. }
  109. -(void)headerRefresh{
  110. //设置获取数据的方式
  111. _getDataType=MyGetDataTypeHeaderRefresh;
  112. //加载数据
  113. [self getData];
  114. [self.tableView.mj_header endRefreshing];
  115. }
  116. -(void)footerRefresh{
  117. //设置获取数据的方式
  118. _getDataType=MyGetDataTypeFooterRefresh;
  119. //加载数据
  120. [self getData];
  121. [self.tableView.mj_footer endRefreshing];
  122. }
  123. #pragma mark - 网络加载
  124. -(void)getPermisson{
  125. //驾校
  126. [Tools permissionValidationWithID:@"700" result:^(BOOL isCan, NSString *failureStr) {
  127. if (!isCan) {
  128. if (failureStr) {
  129. [self showMsgByMBWithString:failureStr];
  130. _failureStrSch = failureStr;
  131. }
  132. return;
  133. }
  134. _permissonSch = YES;
  135. [self getData];
  136. }];
  137. //教练
  138. [Tools permissionValidationWithID:@"26" result:^(BOOL isCan, NSString *failureStr) {
  139. if (!isCan) {
  140. if (failureStr) {
  141. // [self showMsgByMBWithString:failureStr];
  142. _failureStrCoa = failureStr;
  143. }
  144. return;
  145. }
  146. _permissonCoa = YES;
  147. }];
  148. }
  149. -(void)getData{
  150. BOOL permisson = [_status integerValue]==1?_permissonSch:_permissonCoa;
  151. if (!permisson) {
  152. NSString *str = [_status integerValue]==1?_failureStrSch:_failureStrCoa;
  153. if (str.length != 0) {
  154. [self showMsgByAlertVCWithString:str];
  155. }
  156. return;
  157. }
  158. //判断当前是否正在加载数据。如果正在加载数据,直接return。
  159. if (_IS_LOADING) {
  160. return;
  161. }
  162. _IS_LOADING=YES;
  163. //获取第一页数据
  164. NSInteger needLoadPage;
  165. needLoadPage=_currentPageNum+1;
  166. if (_getDataType==MyGetDataTypeHeaderRefresh) {
  167. needLoadPage=1;
  168. }
  169. NSMutableDictionary * mDic = [NSMutableDictionary new];
  170. [mDic setObject:_status forKey:@"type"];//1机构2教练
  171. [mDic setObject:MYAPPDELEGATE.userDic[@"dqbh"] forKey:@"dqbh"];
  172. [mDic setObject:MYAPPDELEGATE.userDic[@"qxbh"] forKey:@"qxbh"];
  173. [mDic setObject:@"1" forKey:@"isPage"];
  174. [mDic setObject:@"10" forKey:@"pageSize"];
  175. [mDic setObject:[NSString stringWithFormat:@"%ld",(long)needLoadPage] forKey:@"currentPage"];
  176. __weak typeof(self) weakSelf = self;
  177. [self getDataWithDic:mDic method:@"getEvals" block:^(NSDictionary *successDic) {
  178. //处理数据
  179. //如果获取到了数据,而且是下拉刷新,清空数组。
  180. if (_getDataType==MyGetDataTypeHeaderRefresh){
  181. [weakSelf.dataurce removeAllObjects];
  182. }
  183. //追加数据
  184. [weakSelf.dataurce addObjectsFromArray:successDic[@"body"]];
  185. if (weakSelf.dataurce.count != 0) {
  186. weakSelf.holderV.hidden = YES;
  187. }
  188. //计数器+1
  189. _currentPageNum=needLoadPage;
  190. //刷新界面
  191. [weakSelf.tableView reloadData];
  192. //恢复初始状态。
  193. _getDataType=MyGetDataTypeNomal;
  194. }];
  195. }
  196. #pragma mark tableView代理方法
  197. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  198. return self.dataurce.count;
  199. }
  200. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  201. EvaListCell * cell = [EvaListCell cellForTabelView:tableView];
  202. [cell updateWithDic:self.dataurce[indexPath.row]];
  203. return cell;
  204. }
  205. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  206. //缓存高度
  207. NSNumber *cellHeight = [_heightArr h_safeObjectAtIndex:indexPath.row];
  208. if (cellHeight) {
  209. return [cellHeight floatValue];
  210. }else{
  211. NSDictionary * dic = self.dataurce[indexPath.row];
  212. CGFloat h1 = [dic[@"SRVMANNER"] length] ? 17 : 0;
  213. CGFloat h2 = [self getHeightWithString:dic[@"TEACHLEVEL"]];
  214. CGFloat h3 = [self getHeightWithString:dic[@"COACHNAME"]];
  215. CGFloat H = 74+h1+h2+h3;//74为其它固定高度
  216. [_heightArr addObject:@(H)];
  217. return H;
  218. }
  219. }
  220. #pragma mark 计算高度
  221. -(CGFloat)getHeightWithString:(NSString *)str{
  222. if (str.length == 0) {
  223. return 0;
  224. }
  225. NSString * newStr = [NSString stringWithFormat:@"评价管理 :%@",str];
  226. CGFloat w = self.tableView.frame.size.width-40;
  227. CGFloat h1 = [newStr heightForWid:w Font:14];
  228. return h1+5;//5是间隔
  229. }
  230. - (void)didReceiveMemoryWarning {
  231. [super didReceiveMemoryWarning];
  232. // Dispose of any resources that can be recreated.
  233. }
  234. @end