EvaluationListVC.m 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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 = RQMianColor;
  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",(long)seg.selectedSegmentIndex+1];
  80. [_heightArr removeAllObjects];
  81. [self headerRefresh];
  82. }
  83. #pragma mark 导航栏右键
  84. -(void)customRightBtn{
  85. UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithTitle:@"筛选" style:UIBarButtonItemStylePlain target:self action:@selector(setMengbanView)];
  86. item.tintColor = RQMianColor;
  87. self.navigationItem.rightBarButtonItem = item;
  88. }
  89. -(void)setMengbanView{
  90. if (_mengBanView) {
  91. [_mengBanView showView];
  92. return;
  93. }
  94. NSArray * btnarr = @[@"机构投诉",@"教练投诉"];
  95. NSArray * buttonsArray = @[btnarr];
  96. _mengBanView = [[MengBanView alloc]initWithTitileStr:nil buttonsArray:buttonsArray isAllbtn:YES block:^(NSArray *array) {
  97. if ([array[0] isEqualToString:@"机构投诉"]) {
  98. _status = @"1";
  99. }else if ([array[0] isEqualToString:@"教练投诉"]){
  100. _status = @"2";
  101. }
  102. [_heightArr removeAllObjects];
  103. [self.tableView setContentOffset:CGPointMake(0, -kNavOffSet) animated:NO];
  104. [self headerRefresh];
  105. }];
  106. [_mengBanView showView];
  107. }
  108. #pragma mark tableView代理方法
  109. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  110. return self.dataurce.count;
  111. }
  112. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  113. EvaListCell * cell = [EvaListCell cellForTabelView:tableView];
  114. [cell updateWithDic:self.dataurce[indexPath.row]];
  115. return cell;
  116. }
  117. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  118. //缓存高度
  119. NSNumber *cellHeight = [_heightArr h_safeObjectAtIndex:indexPath.row];
  120. if (cellHeight) {
  121. return [cellHeight floatValue];
  122. }else{
  123. NSDictionary * dic = self.dataurce[indexPath.row];
  124. CGFloat h1 = [dic[@"EI_SRVMANNER"] length] ? 17 : 0;
  125. CGFloat h2 = [self getHeightWithString:dic[@"EI_TEACHLEVEL"]];
  126. CGFloat h3 = [self getHeightWithString:dic[@"OBJNAME"]];
  127. CGFloat H = 74+h1+h2+h3;//74为其它固定高度
  128. [_heightArr addObject:@(H)];
  129. return H;
  130. }
  131. }
  132. #pragma mark 计算高度
  133. -(CGFloat)getHeightWithString:(NSString *)str{
  134. if (str.length == 0) {
  135. return 0;
  136. }
  137. NSString * newStr = [NSString stringWithFormat:@"评价管理 :%@",str];
  138. CGFloat w = self.tableView.frame.size.width-40;
  139. CGFloat h1 = [newStr heightForWid:w Font:14];
  140. return h1+5;//5是间隔
  141. }
  142. #pragma mark - 下拉刷新,上拉加载 -
  143. -(void)setRefreshAction{
  144. // 下拉刷新
  145. __weak typeof(self) weakSelf = self;
  146. MJRefreshNormalHeader *mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  147. [weakSelf headerRefresh];
  148. }];
  149. _tableView.mj_header = mj_header;
  150. MJRefreshBackNormalFooter *mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  151. [weakSelf footerRefresh];
  152. }];
  153. _tableView.mj_footer = mj_footer;
  154. }
  155. #pragma mark - 数据加载更多和刷新 -
  156. -(void)headerRefresh{
  157. //设置获取数据的方式
  158. _getDataType=MyGetDataTypeHeaderRefresh;
  159. //加载数据
  160. [self getData];
  161. [_tableView.mj_header endRefreshing];
  162. }
  163. -(void)footerRefresh{
  164. //设置获取数据的方式
  165. _getDataType=MyGetDataTypeFooterRefresh;
  166. //加载数据
  167. [self getData];
  168. [_tableView.mj_footer endRefreshing];
  169. }
  170. -(void)getData{
  171. //判断当前是否正在加载数据。如果正在加载数据,直接return。
  172. if (_IS_LOADING) {
  173. return;
  174. }
  175. if (![NetManager connectedToNetWork]) {
  176. showMsgUnconnect();
  177. return;
  178. }
  179. _IS_LOADING=YES;
  180. //获取第一页数据
  181. NSInteger needLoadPage;
  182. needLoadPage=_currentPageNum+1;
  183. if (_getDataType==MyGetDataTypeHeaderRefresh) {
  184. needLoadPage=1;
  185. }
  186. /*
  187. id = 1062;
  188. roleId = 1040;
  189. school = 2101000003;
  190. logind = bcs;
  191. */
  192. NSMutableDictionary * mDic = [NSMutableDictionary new];
  193. [mDic setObject:_status forKey:@"type"];//1机构2教练
  194. [mDic setObject:defUser.userDict[@"school"] forKey:@"objectId"];
  195. [mDic setObject:@"1" forKey:@"isPage"];
  196. [mDic setObject:@"10" forKey:@"pageSize"];
  197. [mDic setObject:[NSString stringWithFormat:@"%ld",(long)needLoadPage] forKey:@"currentPage"];
  198. __weak typeof(self) weakSelf = self;
  199. [NetManager requestAnythingWithURL:@"getEvals" dictionary:mDic dataArray:nil completion:^(NSDictionary *root) {
  200. _holderV.hidden = NO;
  201. //设置加载状态
  202. _IS_LOADING=NO;
  203. if (!root) {
  204. ShowErrorMsg(@"请求失败!");
  205. return;
  206. }
  207. if ([root[@"code"] isEqualToString:@"1"]) {
  208. ShowErrorMsg(root[@"msg"]);
  209. return;
  210. }
  211. //处理数据
  212. //如果获取到了数据,而且是下拉刷新,清空数组。
  213. if (_getDataType==MyGetDataTypeHeaderRefresh){
  214. [weakSelf.dataurce removeAllObjects];
  215. }
  216. //追加数据
  217. [weakSelf.dataurce addObjectsFromArray:root[@"body"]];
  218. if (weakSelf.dataurce.count != 0) {
  219. _holderV.hidden = YES;
  220. }
  221. //计数器+1
  222. _currentPageNum=needLoadPage;
  223. //刷新界面
  224. [weakSelf.tableView reloadData];
  225. //恢复初始状态。
  226. _getDataType=MyGetDataTypeNomal;
  227. }];
  228. }
  229. - (void)didReceiveMemoryWarning {
  230. [super didReceiveMemoryWarning];
  231. // Dispose of any resources that can be recreated.
  232. }
  233. /*
  234. #pragma mark - Navigation
  235. // In a storyboard-based application, you will often want to do a little preparation before navigation
  236. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  237. // Get the new view controller using [segue destinationViewController].
  238. // Pass the selected object to the new view controller.
  239. }
  240. */
  241. @end