SafeList.m 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. //
  2. // SafeList.m
  3. // LNManager
  4. //
  5. // Created by EchoShacolee on 2017/4/9.
  6. // Copyright © 2017年 lee. All rights reserved.
  7. //
  8. #import "SafeList.h"
  9. #import "SafeDetail.h"
  10. @interface SafeList ()
  11. @end
  12. @implementation SafeList
  13. - (void)viewDidLoad {
  14. [super viewDidLoad];
  15. self.navigationItem.title = @"安全员列表";
  16. [self getData];
  17. __weak typeof(self) weakSelf = self;
  18. _block = ^{
  19. [weakSelf getData];
  20. };
  21. }
  22. -(void)getData{
  23. NSMutableDictionary * mdic = [NSMutableDictionary new];
  24. [mdic setValue:[NSString stringWithFormat:@"%@",_shcDic[@"TSI_DQBH"]] forKey:@"dqbh"];
  25. [mdic setValue:[NSString stringWithFormat:@"%@",_shcDic[@"TSI_QXBH"]] forKey:@"qxbh"];
  26. [mdic setValue:[NSString stringWithFormat:@"%@",_shcDic[@"TSI_INSCODE"]] forKey:@"inscode"];
  27. [mdic setValue:@"" forKey:@"securityguardsName"];
  28. [mdic setValue:@"" forKey:@"idcard"];
  29. [mdic setValue:@"" forKey:@"isPage"];
  30. [mdic setValue:@"" forKey:@"pageSize"];
  31. [mdic setValue:@"" forKey:@"currentPage"];
  32. [mdic setValue:@"" forKey:@"phone"];
  33. [self getDataWithDic:mdic method:@"securityguards" block:^(NSDictionary *successdic) {
  34. NSArray * arr = successdic[@"body"];
  35. if (arr.count != 0) {
  36. self.holderV.hidden = YES;
  37. }
  38. for (NSDictionary * dic in arr) {
  39. if (![_sectionTitles containsObject:dic[@"ZM"]]) {
  40. [_sectionTitles addObject:dic[@"ZM"]];
  41. [_dataSource addObject:[NSMutableArray new]];
  42. }
  43. }
  44. //排序
  45. [_sectionTitles sortUsingSelector:@selector(compare:)];
  46. for (NSDictionary * dic in arr) {
  47. NSInteger location = [_sectionTitles indexOfObject:dic[@"ZM"]];
  48. [_dataSource[location] addObject:dic];
  49. }
  50. [self.tableView reloadData];
  51. }];
  52. }
  53. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  54. {
  55. NSMutableDictionary * dic;
  56. if (_hasSearch) {
  57. dic = _resultArray[indexPath.row];
  58. }else{
  59. dic = _dataSource[indexPath.section][indexPath.row];
  60. }
  61. UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId" forIndexPath:indexPath];
  62. if ([_dataSource[indexPath.section] count] > 0) {
  63. cell.textLabel.text = dic[@"SI_NAME"];
  64. }
  65. return cell;
  66. }
  67. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  68. NSMutableDictionary * dic;
  69. if (_hasSearch) {
  70. dic = _resultArray[indexPath.row];
  71. }else{
  72. dic = _dataSource[indexPath.section][indexPath.row];
  73. }
  74. SafeDetail * vc = [[SafeDetail alloc]init];
  75. vc.dataSource = dic;
  76. [self.navigationController pushViewController:vc animated:YES];
  77. }
  78. #pragma mark - 搜索代理
  79. - (void)updateSearchResultsForSearchController:(UISearchController *)searchController
  80. {
  81. NSString *searchString = _searchController.searchBar.text;
  82. // NSLog(@"searchString-->%@",searchString);
  83. _hasSearch = NO;
  84. if (searchString.length > 0) {
  85. [_resultArray removeAllObjects];
  86. if ([searchString integerValue] == 0)
  87. {//汉字
  88. for (NSArray *sectionArr in _dataSource)
  89. {
  90. for (NSDictionary *dic in sectionArr)
  91. {
  92. if ([dic[@"CI_NAME"] rangeOfString:searchString].location != NSNotFound)
  93. {
  94. [_resultArray addObject:dic];
  95. }
  96. }
  97. }
  98. }else{
  99. for (NSArray *sectionArr in _dataSource)
  100. {
  101. for (NSDictionary *dic in sectionArr)
  102. {
  103. BOOL isTrue1 = [[NSString stringWithFormat:@"%@",dic[@"SI_MOBILE"]] rangeOfString:searchString].location != NSNotFound;
  104. BOOL isTrue2 = [[NSString stringWithFormat:@"%@",dic[@"SI_IDCARD"]] rangeOfString:searchString].location != NSNotFound;
  105. if (isTrue2)
  106. {
  107. [_resultArray addObject:dic];
  108. }else if(isTrue1)
  109. {
  110. [_resultArray addObject:dic];
  111. }
  112. }
  113. }
  114. }
  115. _hasSearch = YES;
  116. }
  117. [self.tableView reloadData];
  118. }
  119. - (void)didReceiveMemoryWarning {
  120. [super didReceiveMemoryWarning];
  121. // Dispose of any resources that can be recreated.
  122. }
  123. /*
  124. #pragma mark - Navigation
  125. // In a storyboard-based application, you will often want to do a little preparation before navigation
  126. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  127. // Get the new view controller using [segue destinationViewController].
  128. // Pass the selected object to the new view controller.
  129. }
  130. */
  131. @end