WaringVC.m 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. //
  2. // WaringVC.m
  3. // LNManager
  4. //
  5. // Created by EchoShacolee on 2017/4/6.
  6. // Copyright © 2017年 lee. All rights reserved.
  7. //
  8. #import "WaringVC.h"
  9. #import "MengBanView.h"
  10. @interface WaringVC ()<UITableViewDelegate,UITableViewDataSource>
  11. {
  12. UITableView * _tableView;
  13. NSMutableArray * _dataArray;//数据源
  14. NSString *_selectedAbility;//记录已选择培训能力搜索条件 车辆数限制/每月限制
  15. NSString *_selectedLowStar;//记录已选择低星级搜索条件 1培训机构,2教练
  16. MengBanView *_mengBanView1;//培训能力
  17. MengBanView *_mengBanView2;//低星级
  18. UIButton * _selectBtn;
  19. UIButton *lastBtn;
  20. }
  21. @property(nonatomic,strong)HolderView *holderV;
  22. @end
  23. @implementation WaringVC
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. self.navigationItem.title = @"预警";
  27. _selectedAbility = @"0";
  28. _selectedLowStar = @"1";
  29. _dataArray = [NSMutableArray arrayWithObjects:@[],@[], nil];
  30. //[self customRightBtn];
  31. [self creatTypeBtnBar];
  32. [self creatTableView];
  33. }
  34. -(void)viewWillAppear:(BOOL)animated{
  35. [super viewWillAppear:animated];
  36. //获取数据
  37. [self getdataWithRule:_selectedAbility];
  38. [self getDataWithType:_selectedLowStar];//1驾校,2教练
  39. }
  40. -(void)customRightBtn{
  41. UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithTitle:@"筛选" style:UIBarButtonItemStylePlain target:self action:@selector(setMengbanView)];
  42. item.tintColor = COLOR_THEME;
  43. self.navigationItem.rightBarButtonItem = item;
  44. }
  45. -(void)setMengbanView{
  46. if (lastBtn.tag == 1) {
  47. if (_mengBanView1) {
  48. [_mengBanView1 showView];
  49. return;
  50. }
  51. NSArray * btnarr = @[@"车辆数*每车限制多少",@"每月限制人数"];
  52. _mengBanView1 = [[MengBanView alloc]initWithTitileStr:@"培训能力预警" buttonsArray:@[btnarr] block:^(NSArray *array) {
  53. BOOL isByCar = [_selectedAbility isEqualToString:@"车辆数*每车限制多少"];
  54. _selectedAbility = isByCar ? @"0" : @"1";
  55. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  56. [self getdataWithRule:_selectedAbility];
  57. }];
  58. [_mengBanView1 showView];
  59. }else if (lastBtn.tag == 2){
  60. if (_mengBanView2) {
  61. [_mengBanView2 showView];
  62. return;
  63. }
  64. NSArray * btnarr = @[@"培训机构",@"教练"];;
  65. _mengBanView2 = [[MengBanView alloc]initWithTitileStr:@"低星级预警" buttonsArray:@[btnarr] block:^(NSArray *array) {
  66. BOOL isBySchool = [_selectedLowStar isEqualToString:@"培训机构"];
  67. _selectedLowStar = isBySchool ? @"1" : @"2";
  68. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  69. [self getDataWithType:_selectedLowStar];
  70. }];
  71. [_mengBanView2 showView];
  72. }
  73. }
  74. - (void)creatTypeBtnBar {
  75. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, kNavOffSet, kSize.width/2.0, 50)];
  76. [btn setTitle:@"培训能力预警" forState:UIControlStateNormal];
  77. [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  78. [btn setTitleColor:COLOR_THEME forState:UIControlStateSelected];
  79. [btn.titleLabel setFont:[UIFont systemFontOfSize:18]];
  80. [btn addTarget:self action:@selector(selectType:) forControlEvents:UIControlEventTouchUpInside];
  81. [self.view addSubview:btn];
  82. btn.tag = 1;
  83. btn.selected = YES;
  84. lastBtn = btn;
  85. btn = [[UIButton alloc] initWithFrame:CGRectMake(kSize.width/2.0, kNavOffSet, kSize.width/2.0, 50)];
  86. [btn setTitle:@"低星级预警" forState:UIControlStateNormal];
  87. [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  88. [btn setTitleColor:COLOR_THEME forState:UIControlStateSelected];
  89. [btn.titleLabel setFont:[UIFont systemFontOfSize:18]];
  90. [btn addTarget:self action:@selector(selectType:) forControlEvents:UIControlEventTouchUpInside];
  91. [self.view addSubview:btn];
  92. btn.tag = 2;
  93. UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(kSize.width/2.0, 5+kNavOffSet, 1, 40)];
  94. lineView.backgroundColor = [UIColor lightGrayColor];
  95. [self.view addSubview:lineView];
  96. lineView = [[UIView alloc] initWithFrame:CGRectMake(0 ,kNavOffSet+50-1, kSize.width, 1)];
  97. lineView.backgroundColor = [UIColor lightGrayColor];
  98. [self.view addSubview:lineView];
  99. }
  100. -(void)creatTableView{
  101. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, kNavOffSet+50, kSize.width, kSize.height - kNavOffSet - 50) style:UITableViewStylePlain];
  102. _tableView.delegate = self;
  103. _tableView.dataSource = self;
  104. _tableView.scrollEnabled = NO;
  105. _tableView.estimatedSectionFooterHeight = 0;
  106. [self.view addSubview:_tableView];
  107. self.holderV = [[HolderView alloc] initWithFrame:_tableView.frame];
  108. [self.holderV freshBlock:^{
  109. if (lastBtn.tag == 1) {
  110. [self getdataWithRule:@""];
  111. }else {
  112. [self getDataWithType:@""];
  113. }
  114. }];
  115. [self.view addSubview:self.holderV];
  116. }
  117. - (void)selectType:(UIButton *)sender {
  118. if (sender.tag == lastBtn.tag) {
  119. return;
  120. }
  121. sender.selected = YES;
  122. lastBtn.selected = NO;
  123. lastBtn = sender;
  124. [_tableView reloadData];
  125. }
  126. #pragma mark tableview的代理方法
  127. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  128. return .1;
  129. }
  130. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  131. return [_dataArray[lastBtn.tag - 1] count];
  132. }
  133. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  134. UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
  135. if (!cell) {
  136. cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cellId"];
  137. }
  138. if (lastBtn.tag == 1) {
  139. cell.textLabel.text = [NSString stringWithFormat:@"机构名称: %@",_dataArray[0][indexPath.row][@"TSI_NAME"]];
  140. cell.detailTextLabel.text = [NSString stringWithFormat:@"超出百分比: %@",_dataArray[0][indexPath.row][@"PERCENT"]];
  141. }else{
  142. cell.textLabel.text = [NSString stringWithFormat:@"%@: %@",[_selectedLowStar integerValue] == 1 ?@"驾校名称":@"教练名字",_dataArray[1][indexPath.row][@"NAME"]];
  143. cell.detailTextLabel.text = [NSString stringWithFormat:@"超出百分比: %@",_dataArray[1][indexPath.row][@"AVGOVERVIEW"]];
  144. }
  145. return cell;
  146. }
  147. #pragma mark 数据请求
  148. -(void)getdataWithRule:(NSString *)rule{
  149. NSMutableDictionary * mdic = [[NSMutableDictionary alloc]init];
  150. [mdic setValue:@"" forKey:@"rule"];
  151. [mdic setValue:@"" forKey:@"inscode"];
  152. [MBProgressHUD hideHUDForView:self.view animated:NO];
  153. [MBProgressHUD showHUDAddedTo:self.view animated:NO];
  154. [NetworkManager requestWithMethod:@"schoolWarning" parameters:mdic type:0 handler:^(NSDictionary *successDic, NSString *failureStr) {
  155. NSArray *arr = _dataArray[1];
  156. if (arr.count == 0) {
  157. _holderV.hidden = NO;
  158. }
  159. [MBProgressHUD hideHUDForView:self.view animated:YES];
  160. if (failureStr) {
  161. [self showMsgByAlertVCWithString:failureStr];
  162. return;
  163. }
  164. if ([successDic[@"code"] isEqualToString:@"1"]) {
  165. [self showMsgByAlertVCWithString:successDic[@"msg"]];
  166. return;
  167. }
  168. if ([successDic[@"body"] count] != 0) {
  169. _holderV.hidden = YES;
  170. }
  171. [_dataArray replaceObjectAtIndex:0 withObject:successDic[@"body"]];
  172. [_tableView reloadData];
  173. }];
  174. }
  175. -(void)getDataWithType:(NSString *)type{
  176. NSMutableDictionary * mdic = [[NSMutableDictionary alloc]init];
  177. [mdic setValue:@"1" forKey:@"type"];
  178. [MBProgressHUD hideHUDForView:self.view animated:NO];
  179. [MBProgressHUD showHUDAddedTo:self.view animated:NO];
  180. [NetworkManager requestWithMethod:@"evalWarning" parameters:mdic type:0 handler:^(NSDictionary *successDic, NSString *failureStr) {
  181. NSArray *arr = _dataArray[0];
  182. if (arr.count == 0) {
  183. _holderV.hidden = NO;
  184. }
  185. [MBProgressHUD hideHUDForView:self.view animated:YES];
  186. if (failureStr) {
  187. [self showMsgByAlertVCWithString:failureStr];
  188. return;
  189. }
  190. if ([successDic[@"code"] isEqualToString:@"1"]) {
  191. [self showMsgByAlertVCWithString:successDic[@"msg"]];
  192. return;
  193. }
  194. if ([successDic[@"body"] count] != 0) {
  195. _holderV.hidden = YES;
  196. }
  197. [_dataArray replaceObjectAtIndex:1 withObject:successDic[@"body"]];
  198. [_tableView reloadData];
  199. }];
  200. }
  201. - (void)didReceiveMemoryWarning {
  202. [super didReceiveMemoryWarning];
  203. // Dispose of any resources that can be recreated.
  204. }
  205. /*
  206. #pragma mark - Navigation
  207. // In a storyboard-based application, you will often want to do a little preparation before navigation
  208. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  209. // Get the new view controller using [segue destinationViewController].
  210. // Pass the selected object to the new view controller.
  211. }
  212. */
  213. @end