EvaluationListVC.m 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. //
  2. // EvaluationListVC.m
  3. // LN_School
  4. //
  5. // Created by EchoShacolee on 2017/6/15.
  6. // Copyright © 2017年 Danson. All rights reserved.
  7. //
  8. #import "EvaluationListVC.h"
  9. #import "EvaListCell.h"
  10. #import "MJRefresh.h"
  11. #import "MengBanView.h"
  12. typedef NS_ENUM(NSInteger, MyGetDataType) {
  13. //正常请求数据
  14. MyGetDataTypeNomal=0,
  15. //下拉刷新请求数据
  16. MyGetDataTypeHeaderRefresh,
  17. //上拉加载更多请求数据
  18. MyGetDataTypeFooterRefresh
  19. };
  20. @interface EvaluationListVC ()<UITableViewDataSource,UITableViewDelegate>
  21. {
  22. //记录页书
  23. NSInteger _currentPageNum;
  24. //正在加载的状态
  25. BOOL _IS_LOADING;
  26. //加载数据的类型
  27. MyGetDataType _getDataType;
  28. //缓存cell高度
  29. NSMutableArray *_heightArr;
  30. //1机构2教练
  31. NSString * _status;
  32. //
  33. HolderView *_holderV;
  34. //
  35. MengBanView *_mengBanView;
  36. UISegmentedControl *_seg;
  37. }
  38. @property(nonatomic,strong)NSMutableArray * dataurce;
  39. @property(nonatomic,strong)UITableView *tableView;
  40. @end
  41. @implementation EvaluationListVC
  42. - (void)viewDidLoad {
  43. [super viewDidLoad];
  44. self.navigationItem.title = @"评价管理";
  45. self.view.backgroundColor = KBackGroundColor;
  46. self.navigationController.navigationBar.translucent = NO;
  47. _dataurce = [[NSMutableArray alloc]init];
  48. _heightArr = [[NSMutableArray alloc]init];
  49. _currentPageNum = 0;
  50. _IS_LOADING = NO;
  51. _getDataType = MyGetDataTypeNomal;
  52. _status = @"1";
  53. //
  54. _seg = [[UISegmentedControl alloc]initWithItems:@[@"机构评价",@"教练评价"]];
  55. _seg.frame = CGRectMake(0, 0, kSize.width, 40);
  56. _seg.backgroundColor = [UIColor whiteColor];
  57. _seg.selectedSegmentIndex = 0;
  58. _seg.tintColor = defGreen;
  59. [_seg addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged];
  60. [self.view addSubview:_seg];
  61. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 40, kSize.width, kSize.height-CGRectGetMaxY(_seg.frame)-kNavOffSet)];
  62. _tableView.backgroundColor = KBackGroundColor;
  63. _tableView.dataSource = self;
  64. _tableView.delegate = self;
  65. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  66. [self.view addSubview:_tableView];
  67. self.tableView.tableFooterView = [UIView new];
  68. // [self customRightBtn];
  69. [self goBackByNavigation];
  70. [self setRefreshAction];//设置刷新
  71. [self getData];
  72. _holderV = [[HolderView alloc] initWithFrame:_tableView.frame];
  73. [_holderV freshBlock:^{
  74. [self headerRefresh];
  75. }];
  76. [self.view addSubview:_holderV];
  77. }
  78. -(void)change:(UISegmentedControl *)seg{
  79. _status = [NSString stringWithFormat:@"%ld",seg.selectedSegmentIndex+1];
  80. [_heightArr removeAllObjects];
  81. [self headerRefresh];
  82. }
  83. #pragma mark 导航栏右键
  84. -(void)customRightBtn{
  85. UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
  86. btn.frame = CGRectMake(0, 0, 43, 44);
  87. btn.titleLabel.font = [UIFont systemFontOfSize:17];
  88. [btn setTitle:@"筛选" forState:UIControlStateNormal];
  89. [btn setTitleColor:defGreen forState:UIControlStateNormal];
  90. [btn addTarget:self action:@selector(setMengbanView) forControlEvents:UIControlEventTouchUpInside];
  91. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
  92. }
  93. -(void)setMengbanView{
  94. if (_mengBanView) {
  95. [_mengBanView showView];
  96. return;
  97. }
  98. NSArray * btnarr = @[@"机构投诉",@"教练投诉"];
  99. NSArray * buttonsArray = @[btnarr];
  100. _mengBanView = [[MengBanView alloc]initWithTitileStr:nil buttonsArray:buttonsArray isAllbtn:YES block:^(NSArray *array) {
  101. if ([array[0] isEqualToString:@"机构投诉"]) {
  102. _status = @"1";
  103. }else if ([array[0] isEqualToString:@"教练投诉"]){
  104. _status = @"2";
  105. }
  106. [_heightArr removeAllObjects];
  107. [self.tableView setContentOffset:CGPointMake(0, -kNavOffSet) animated:NO];
  108. [self headerRefresh];
  109. }];
  110. [_mengBanView showView];
  111. }
  112. #pragma mark tableView代理方法
  113. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  114. return self.dataurce.count;
  115. }
  116. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  117. EvaListCell * cell = [EvaListCell cellForTabelView:tableView];
  118. [cell updateWithDic:self.dataurce[indexPath.row]];
  119. return cell;
  120. }
  121. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  122. //缓存高度
  123. NSNumber *cellHeight = [_heightArr h_safeObjectAtIndex:indexPath.row];
  124. if (cellHeight) {
  125. return [cellHeight floatValue];
  126. }else{
  127. NSDictionary * dic = self.dataurce[indexPath.row];
  128. CGFloat h1 = [dic[@"EI_SRVMANNER"] length] ? 17 : 0;
  129. CGFloat h2 = [self getHeightWithString:dic[@"EI_TEACHLEVEL"]];
  130. CGFloat h3 = [self getHeightWithString:dic[@"OBJNAME"]];
  131. CGFloat H = 74+h1+h2+h3;//74为其它固定高度
  132. [_heightArr addObject:@(H)];
  133. return H;
  134. }
  135. }
  136. #pragma mark 计算高度
  137. -(CGFloat)getHeightWithString:(NSString *)str{
  138. if (str.length == 0) {
  139. return 0;
  140. }
  141. NSString * newStr = [NSString stringWithFormat:@"评价管理 :%@",str];
  142. CGFloat w = self.tableView.frame.size.width-40;
  143. CGFloat h1 = [newStr heightForWid:w Font:14];
  144. return h1+5;//5是间隔
  145. }
  146. #pragma mark - 下拉刷新,上拉加载 -
  147. -(void)setRefreshAction{
  148. // 下拉刷新
  149. __weak typeof(self) weakSelf = self;
  150. MJRefreshNormalHeader *mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  151. [weakSelf headerRefresh];
  152. }];
  153. _tableView.mj_header = mj_header;
  154. MJRefreshBackNormalFooter *mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  155. [weakSelf footerRefresh];
  156. }];
  157. _tableView.mj_footer = mj_footer;
  158. }
  159. #pragma mark - 数据加载更多和刷新 -
  160. -(void)headerRefresh{
  161. //设置获取数据的方式
  162. _getDataType=MyGetDataTypeHeaderRefresh;
  163. //加载数据
  164. [self getData];
  165. [_tableView.mj_header endRefreshing];
  166. }
  167. -(void)footerRefresh{
  168. //设置获取数据的方式
  169. _getDataType=MyGetDataTypeFooterRefresh;
  170. //加载数据
  171. [self getData];
  172. [_tableView.mj_footer endRefreshing];
  173. }
  174. -(void)getData{
  175. //1机构2教练
  176. NSString *theID = [_status isEqualToString:@"1"] ? @"77":@"78";
  177. [Tools permissionValidationWithID:theID view:self.view result:^(BOOL isCan, NSString *failureStr) {
  178. if (!isCan) {
  179. if (failureStr) {
  180. showMsgByAlert(self, failureStr);
  181. }
  182. return;
  183. }
  184. [self getDataReally];
  185. }];
  186. }
  187. -(void)getDataReally{
  188. //判断当前是否正在加载数据。如果正在加载数据,直接return。
  189. if (_IS_LOADING) {
  190. return;
  191. }
  192. if (![NetManager connectedToNetWork]) {
  193. showMsgUnconnect();
  194. return;
  195. }
  196. _IS_LOADING=YES;
  197. //获取第一页数据
  198. NSInteger needLoadPage;
  199. needLoadPage=_currentPageNum+1;
  200. if (_getDataType==MyGetDataTypeHeaderRefresh) {
  201. needLoadPage=1;
  202. }
  203. /*
  204. id = 1062;
  205. roleId = 1040;
  206. school = 2101000003;
  207. logind = bcs;
  208. */
  209. NSMutableDictionary * mDic = [NSMutableDictionary new];
  210. [mDic setObject:_status forKey:@"type"];//1机构2教练
  211. [mDic setObject:defUser.userDict[@"school"] forKey:@"objectId"];
  212. [mDic setObject:@"1" forKey:@"isPage"];
  213. [mDic setObject:@"10" forKey:@"pageSize"];
  214. [mDic setObject:[NSString stringWithFormat:@"%ld",(long)needLoadPage] forKey:@"currentPage"];
  215. __weak typeof(self) weakSelf = self;
  216. [MBProgressHUD showLoadToView:self.view];
  217. [NetManager requestAnythingWithURL:@"getEvals" dictionary:mDic dataArray:nil completion:^(NSDictionary *root) {
  218. [MBProgressHUD hideHUDForView:self.view];
  219. _holderV.hidden = NO;
  220. //设置加载状态
  221. _IS_LOADING=NO;
  222. if (!root) {
  223. ShowErrorMsg(@"请求失败!");
  224. return;
  225. }
  226. if ([root[@"code"] isEqualToString:@"1"]) {
  227. ShowErrorMsg(root[@"msg"]);
  228. return;
  229. }
  230. //处理数据
  231. //如果获取到了数据,而且是下拉刷新,清空数组。
  232. if (_getDataType==MyGetDataTypeHeaderRefresh){
  233. [weakSelf.dataurce removeAllObjects];
  234. }
  235. //追加数据
  236. [weakSelf.dataurce addObjectsFromArray:root[@"body"]];
  237. if (weakSelf.dataurce.count != 0) {
  238. _holderV.hidden = YES;
  239. }
  240. //计数器+1
  241. _currentPageNum=needLoadPage;
  242. //刷新界面
  243. [weakSelf.tableView reloadData];
  244. //恢复初始状态。
  245. _getDataType=MyGetDataTypeNomal;
  246. }];
  247. }
  248. - (void)didReceiveMemoryWarning {
  249. [super didReceiveMemoryWarning];
  250. // Dispose of any resources that can be recreated.
  251. }
  252. /*
  253. #pragma mark - Navigation
  254. // In a storyboard-based application, you will often want to do a little preparation before navigation
  255. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  256. // Get the new view controller using [segue destinationViewController].
  257. // Pass the selected object to the new view controller.
  258. }
  259. */
  260. @end