ComplaintsListVC.m 8.8 KB

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