SelectSchoolVC.m 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. //
  2. // SelectSchoolVC.m
  3. // jiaPei
  4. //
  5. // Created by apple on 2017/1/10.
  6. // Copyright © 2017年 JCZ. All rights reserved.
  7. #import "SelectSchoolVC.h"
  8. #import "HolderView.h"
  9. #import "Tools.h"
  10. #import "AllCoachPlanVC.h"
  11. #import "SchCell.h"
  12. #import "FenceSiteVC.h"
  13. #import <BaiduMapAPI_Map/BMKMapComponent.h>
  14. #import <BMKLocationkit/BMKLocationComponent.h>//引入定位功能所有的头文件(新)
  15. @interface SelectSchoolVC ()<UITableViewDataSource,UITableViewDelegate,UIAlertViewDelegate,UISearchDisplayDelegate,UISearchResultsUpdating,UIPickerViewDataSource,UIPickerViewDelegate,BMKLocationManagerDelegate>
  16. {
  17. HolderView *holderV;
  18. //搜索栏
  19. UITableView *_contactTable;
  20. UISearchBar *_searchBar;
  21. UISearchController *_searchController;
  22. UIBarButtonItem *item;
  23. //索引
  24. NSMutableArray *_letterArray;
  25. NSMutableArray *_resultArray;
  26. NSMutableArray *models;
  27. NSMutableDictionary *groupDic;
  28. NSString *dqbh, *qxbh;
  29. NSString *pickDQBH,*pickQXBH;
  30. //地区选择栏
  31. UIPickerView *picker;
  32. NSInteger currentSlect;
  33. UIView *bgView;
  34. NSArray *areaArray;
  35. NSArray *pickDataArray;
  36. //地图定位
  37. CLLocationCoordinate2D myLocation;
  38. }
  39. @end
  40. @implementation SelectSchoolVC
  41. - (void)viewDidLoad {
  42. [super viewDidLoad];
  43. [self setTitle:@"选择驾校"];
  44. if ([_skipType isEqualToString:@"1"]) {
  45. [self configNavigationBar];
  46. self.navigationController.navigationBar.translucent = NO;
  47. }else{//2 3
  48. [self configNavigationBar];
  49. }
  50. dqbh = defUser.userDict[@"city"];
  51. qxbh = defUser.userDict[@"country"];
  52. //定位
  53. [[MapManager sharedManager] updateLocationWithCompleteBlock:^(BOOL success, CLLocation * _Nonnull location) {
  54. if (success) {
  55. //储存自己当前位置
  56. self->myLocation = location.coordinate;
  57. [self getSchList];
  58. }else {
  59. [self getSchList];
  60. }
  61. }];
  62. _letterArray = [[NSMutableArray alloc] init];
  63. _resultArray = [[NSMutableArray alloc] init];
  64. groupDic = [[NSMutableDictionary alloc] init];
  65. models = [[NSMutableArray alloc] init];
  66. [self loadArea];
  67. //获取26个大写字母
  68. for (int i = 65; i < 91; i ++)
  69. {
  70. NSString * letter = [[NSString alloc] initWithBytes:&i length:1 encoding:NSUTF8StringEncoding];
  71. [_letterArray addObject:letter];
  72. }
  73. //创建一个表
  74. _contactTable = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
  75. _contactTable.height -= kNavOffSet;
  76. [_contactTable setDataSource:self];
  77. [_contactTable setDelegate:self];
  78. _contactTable.rowHeight = 100;
  79. _contactTable.tableFooterView = [UIView new];
  80. //设置sectionIndex
  81. [_contactTable setSectionIndexBackgroundColor:[UIColor clearColor]];
  82. [_contactTable setSectionIndexColor:[UIColor redColor]];
  83. [self.view addSubview:_contactTable];
  84. //切换城市
  85. item = [[UIBarButtonItem alloc] initWithTitle:@"切换城市" style:UIBarButtonItemStyleDone target:self action:@selector(clickToChangeCity)];
  86. [item setTintColor:defGreen];
  87. [self.navigationItem setRightBarButtonItem:item];
  88. if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
  89. {
  90. _searchController =[[UISearchController alloc]initWithSearchResultsController:nil];
  91. [_searchController.searchBar sizeToFit];
  92. _searchController.searchResultsUpdater = self;
  93. //这个是在搜索时候将之前的隐藏 包括表 无法点击 适合弹出新的tableviewcontroller 默认yes
  94. _searchController.dimsBackgroundDuringPresentation = NO;
  95. //这个是搜索时候隐藏导航栏
  96. _searchController.hidesNavigationBarDuringPresentation = NO;
  97. _searchController.searchBar.placeholder=@"请输入驾校名称";
  98. _contactTable.sectionIndexColor = [UIColor blueColor];
  99. _contactTable.tableHeaderView=_searchController.searchBar;
  100. //[self searchBarTextDidBeginEditing:_searchController.searchBar];
  101. //不用弹出 因为没有单独的tableviewcontroller
  102. //[self presentViewController:_searchController animated:YES completion:nil];
  103. }
  104. else
  105. {
  106. //实例化一个搜索框
  107. _searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 40)];
  108. //设置背景色
  109. [_searchBar setBarTintColor:[UIColor grayColor]];
  110. //设置搜索框风格
  111. [_searchBar setSearchBarStyle:UISearchBarStyleProminent];
  112. [_searchBar setPlaceholder:@"请输入驾校名称"];
  113. //设置显示取消按钮
  114. [_searchBar setShowsCancelButton:YES animated:YES];
  115. //改变索引的颜色
  116. _contactTable.sectionIndexColor = [UIColor blueColor];
  117. //改变索引选中的背景颜色
  118. //设置表的表头
  119. [_contactTable setTableHeaderView:_searchBar];
  120. //搜索显示器 Display显示
  121. // UISearchDisplayController * displayController = [[UISearchDisplayController alloc] initWithSearchBar:_searchBar contentsController:self];
  122. // [displayController setDelegate:self];
  123. // [displayController setSearchResultsDataSource:self];
  124. // [displayController setSearchResultsDelegate:self];
  125. }
  126. holderV = [[HolderView alloc] initWithFrame:_contactTable.frame];
  127. [holderV freshBlock:^{
  128. [self getSchList];
  129. }];
  130. [self.view addSubview:holderV];
  131. }
  132. -(void)viewWillDisappear:(BOOL)animated
  133. {
  134. [super viewWillDisappear:animated];
  135. [self.view endEditing:YES];
  136. //这个一定要写 要不然会在退出去下一个页面时候 搜索栏有一定时间的存留
  137. if (_searchController.active) {
  138. _searchController.active = NO;
  139. if (_searchController.searchBar && _searchController.searchBar.superview) {
  140. //NSLog(@"这个也一直执行");
  141. [_searchController.searchBar removeFromSuperview];
  142. }
  143. }
  144. }
  145. - (void)btnClick:(UIButton *)sender
  146. {
  147. if (sender.tag == 1) {
  148. if (bgView) {
  149. [bgView removeFromSuperview];
  150. bgView = nil;
  151. item.title = @"切换城市";
  152. dqbh = pickDQBH;
  153. qxbh = pickQXBH;
  154. }
  155. [self getSchList];
  156. }
  157. }
  158. - (void)clickToChangeCity
  159. {
  160. if (bgView) {
  161. [bgView removeFromSuperview];
  162. bgView = nil;
  163. item.title = @"切换城市";
  164. return;
  165. }
  166. item.title = @"取消";
  167. currentSlect = 0;
  168. //沈阳市 福州市
  169. pickDQBH = @"2101";
  170. pickQXBH = @"";
  171. bgView = [[UIView alloc] initWithFrame:CGRectMake(0, kSize.height - 295 - kNavOffSet-kSafeAreaBottomHeight, kSize.width, 295+kSafeAreaBottomHeight)];
  172. bgView.backgroundColor = backGroundColor;
  173. [self.view addSubview:bgView];
  174. // UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(kSize.width/2.0, 0, kSize.width/2.0 - 20, 40)];
  175. // [label setText:@"完成" Font:Font17 TextColor:defGreen Alignment:NSTextAlignmentRight];
  176. // [bgView addSubview:label];
  177. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(kSize.width-100, 5, 80, 40)];
  178. [btn setTitle:@"完成" forState:UIControlStateNormal];
  179. [btn setTitleColor:defGreen forState:UIControlStateNormal];
  180. btn.layer.cornerRadius = 5;
  181. btn.layer.masksToBounds = YES;
  182. btn.layer.borderWidth = .5;
  183. btn.layer.borderColor = defGreen.CGColor;
  184. [btn target:self tag:1];
  185. [bgView addSubview:btn];
  186. picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 50, kSize.width, 245)];
  187. picker.delegate = self;
  188. picker.dataSource = self;
  189. [bgView addSubview:picker];
  190. [btn addViewWithRect:CGRectMake(0, 50, kSize.width, 1) Color:contentTextColor];
  191. }
  192. - (void)finishBlock:(BlockTypeVo)block {
  193. finishBlock = block;
  194. }
  195. #pragma mark 获取地区信息
  196. -(void)loadArea
  197. {
  198. NSMutableArray *firArr,*secArr;
  199. firArr = [NSMutableArray array];//市name【x市】
  200. secArr = [NSMutableArray array];//区name
  201. areaArray = [DB_Que_Helper queryArea];
  202. for (NSDictionary *dic in areaArray) {
  203. if ([dic[@"parent_code"] isEqualToString:@"2100"]) {
  204. [firArr addObject:dic[@"name"]];
  205. [secArr addObject:[NSMutableArray arrayWithArray:@[@"全市"]]];
  206. }else{
  207. // secArr[firArr.count-1] 它们是有序的
  208. [secArr[firArr.count-1] addObject:dic[@"name"]];
  209. }
  210. }
  211. pickDataArray = @[firArr,secArr];
  212. }
  213. #pragma mark pickerView
  214. -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
  215. {
  216. return pickDataArray.count;
  217. }
  218. //每列对应多少行
  219. -(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
  220. {
  221. if (component == 0) {
  222. return [[pickDataArray firstObject] count];
  223. }else{
  224. NSInteger index = currentSlect;
  225. NSArray *array = [pickDataArray lastObject];
  226. return [array[index] count];
  227. }
  228. }
  229. //每列每行对应显示的数据
  230. -(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
  231. {
  232. NSArray *array;
  233. if (component == 0) {
  234. array = [pickDataArray firstObject];
  235. }else{
  236. NSInteger index = currentSlect;
  237. array = [pickDataArray lastObject][index];
  238. }
  239. return array[row];
  240. }
  241. -(CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
  242. {
  243. return 40;
  244. }
  245. //选中
  246. -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
  247. {
  248. if (component == 0) {
  249. currentSlect = row;
  250. //重新加载第二列的数据
  251. [pickerView reloadComponent:1];
  252. //让第二列归位
  253. [pickerView selectRow:0 inComponent:1 animated:YES];
  254. for (NSDictionary *dic in areaArray) {
  255. if ([dic[@"name"] isEqualToString:[[pickDataArray firstObject] objectAtIndex:row]]) {
  256. pickDQBH = dic[@"code"];
  257. break;
  258. }
  259. }
  260. }else{
  261. NSInteger index = currentSlect;
  262. NSArray *array = [pickDataArray lastObject][index];
  263. for (NSDictionary *dic in areaArray) {
  264. if ([array[row] isEqualToString:@"全市"]) {
  265. pickDQBH = @"";
  266. break;
  267. }else if ([dic[@"name"] isEqualToString:array[row]]) {
  268. pickQXBH = dic[@"code"];
  269. if (pickQXBH.length < 6) {
  270. pickQXBH = @"";
  271. }
  272. break;
  273. }
  274. }
  275. }
  276. }
  277. #pragma mark 设置tableView右边的索引
  278. -(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
  279. {
  280. return _letterArray;
  281. }
  282. //响应点击索引时的委托方法
  283. -(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
  284. {
  285. NSInteger count = 0;
  286. //NSLog(@"%@-%d",title,(int)index);
  287. NSArray *array = [[groupDic allKeys] sortedArrayUsingSelector:@selector(compare:)];
  288. //为了找到索引中没有字目的前一个字母 也是醉了
  289. if (![array containsObject:title]) {
  290. int index = (int)[_letterArray indexOfObject:title];
  291. for (int i = index; i > 0; i --) {
  292. if ([array containsObject:_letterArray[i]]) {
  293. title = _letterArray[i];
  294. break;
  295. }
  296. }
  297. }
  298. for(NSString *character in array)
  299. {
  300. if([character isEqualToString:title])
  301. {
  302. return count;
  303. }
  304. count ++;
  305. }
  306. return 0;
  307. }
  308. -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
  309. {
  310. if (tableView == _contactTable)
  311. {
  312. if (_searchController.searchBar.text.length > 0) {
  313. if (_resultArray.count > 0) {
  314. NSString *str = [[_resultArray firstObject] substringToIndex:1];
  315. for (NSDictionary *dic in models) {
  316. if ([dic[@"STU_NAME"] hasPrefix:str]) {
  317. return dic[@"PY_FIRST"];
  318. }
  319. }
  320. }
  321. //这个永远不会返回 因为 result为空 就不会有这个
  322. return @"A";
  323. }else{
  324. NSArray * array = [[groupDic allKeys] sortedArrayUsingSelector:@selector(compare:)];
  325. return [array objectAtIndex:section];
  326. }
  327. }
  328. else
  329. {
  330. NSString *str = [[_resultArray firstObject] substringToIndex:1];
  331. for (NSDictionary *dic in models) {
  332. if ([dic[@"STU_NAME"] hasPrefix:str]) {
  333. return dic[@"PY_FIRST"];
  334. }
  335. }
  336. }
  337. //这个永远不会返回 因为 result为空 就不会有这个
  338. return @"A";
  339. }
  340. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  341. {
  342. //最外层else 相当于对版本适配了 只有iOS8以下 才会进的方法
  343. if (tableView == _contactTable)
  344. {
  345. if (_searchController.searchBar.text.length > 0) {
  346. if (_resultArray.count > 0) {
  347. return 1;
  348. }else{
  349. return 0;
  350. }
  351. }
  352. return [[groupDic allKeys] count];
  353. }
  354. else
  355. {
  356. if (_resultArray.count > 0) {
  357. return 1;
  358. }else{
  359. return 0;
  360. }
  361. }
  362. }
  363. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  364. {
  365. if (tableView == _contactTable)
  366. {
  367. //sortedArrayUsingSelector 排序
  368. if (_searchController.searchBar.text.length > 0) {
  369. return _resultArray.count;
  370. }
  371. NSArray * array = [[groupDic allKeys] sortedArrayUsingSelector:@selector(compare:)];
  372. return [[groupDic objectForKey:array[section]] count];
  373. }
  374. else
  375. {
  376. //显示搜索的结果
  377. return _resultArray.count;
  378. }
  379. }
  380. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  381. {
  382. SchCell *cell = [SchCell cellWithTableView:tableView];
  383. NSString *p;
  384. if (tableView == _contactTable)
  385. {
  386. if (_searchController.searchBar.text.length > 0) {
  387. p = _resultArray[indexPath.row];
  388. }else{
  389. NSArray * array = [[groupDic allKeys] sortedArrayUsingSelector:@selector(compare:)];
  390. p = [[groupDic objectForKey:[array objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  391. }
  392. }
  393. else
  394. {
  395. p = _resultArray[indexPath.row];
  396. }
  397. //[cell.textLabel setText:p];
  398. for (NSDictionary *dic in models) {
  399. if ([dic[@"SHORTNAME"] isEqualToString:p]) {
  400. cell.selectDic = dic;
  401. }
  402. }
  403. return cell;
  404. }
  405. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  406. {
  407. NSString *showString;
  408. if (tableView == _contactTable)
  409. {
  410. if (_searchController.searchBar.text.length > 0) {
  411. showString = _resultArray[indexPath.row];
  412. }else{
  413. NSArray * array = [[groupDic allKeys] sortedArrayUsingSelector:@selector(compare:)];
  414. showString = [[groupDic objectForKey:[array objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  415. }
  416. }else{
  417. showString = _resultArray[indexPath.row];
  418. }
  419. for (NSDictionary *dic in models) {
  420. if ([dic[@"SHORTNAME"] isEqualToString:showString]) {
  421. if (![_skipType isEqualToString:@"2"]) {
  422. //调绑定接口
  423. [self bindSchoolWithJXBH:dic[@"ID"]];
  424. }else{
  425. //跳转选择训练场地或者选择教练页面
  426. [self getSchPlacesWithDic:dic];
  427. break;
  428. }
  429. }
  430. }
  431. }
  432. #pragma mark UISearchDisplayController 代理方法
  433. ////iOS7搜索的时候 会调用这个方法
  434. //- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
  435. //{
  436. // //NSLog(@"searchString====%@",searchString);
  437. // [_resultArray removeAllObjects];
  438. //
  439. // //按名字查找
  440. // for (NSDictionary *dic in models)
  441. // {
  442. // if ([dic[@"SHORTNAME"] rangeOfString:searchString].location != NSNotFound)
  443. // {
  444. // [_resultArray addObject:dic[@"SHORTNAME"]];
  445. // }
  446. // }
  447. //
  448. // [_contactTable reloadData];
  449. // return YES;
  450. //}
  451. ////点击不同的选择范围的时候调用
  452. //-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption
  453. //{
  454. // [self searchDisplayController:controller shouldReloadTableForSearchString:_searchBar.text];
  455. // return YES;
  456. //}
  457. //iOS8搜索调用的方法
  458. - (void)updateSearchResultsForSearchController:(UISearchController *)searchController
  459. {
  460. //[self searchBarTextDidBeginEditing:_searchController.searchBar];
  461. NSString *searchString = _searchController.searchBar.text;
  462. //NSLog(@"searchString-->%@",searchString);
  463. [_resultArray removeAllObjects];
  464. //按名字查找
  465. for (NSDictionary *dic in models)
  466. {
  467. if ([dic[@"SHORTNAME"] rangeOfString:searchString].location != NSNotFound)
  468. {
  469. [_resultArray addObject:dic[@"SHORTNAME"]];
  470. }
  471. }
  472. //NSLog(@"_resultArray-->%@",_resultArray);
  473. [_contactTable reloadData];
  474. }
  475. #pragma mark 数据请求
  476. - (void)bindSchoolWithJXBH:(NSString *)jxbh
  477. {
  478. if (![Util connectedToNetWork]) {
  479. showMsgUnconnect();
  480. return;
  481. }
  482. NSMutableArray *arr=[NSMutableArray array];
  483. [arr addPro:@"userId" Value:defUser.userDict[@"id"]];
  484. [arr addPro:@"schId" Value:jxbh];
  485. NSString* method = @"bindSchool";
  486. [MBProgressHUD showLoadToView:self.view];
  487. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  488. [MBProgressHUD hideHUDForView:self.view];
  489. //NSLog(@"绑定驾校---->%@,,,,,%@",arr,root);
  490. if (!root) {
  491. ShowMsgFailed();
  492. return;
  493. }
  494. [LoadingView showMsg:root[@"body"]];
  495. if ([root[@"code"] isEqualToString:@"0"]) {
  496. //绑定成功
  497. [LoginViewController reLoginFromViewController:self finishBlock:^{
  498. if (finishBlock) {
  499. finishBlock();
  500. }
  501. }];
  502. [self dismissViewControllerAnimated:YES completion:nil];
  503. }
  504. }];
  505. }
  506. - (void)getSchList
  507. {
  508. if (![Util connectedToNetWork]) {
  509. showMsgUnconnect();
  510. return;
  511. }
  512. NSMutableArray *arr=[NSMutableArray array];
  513. [arr addPro:@"dqbh" Value:dqbh];
  514. [arr addPro:@"qxbh" Value:qxbh];
  515. [arr addPro:@"lat" Value:[NSString stringWithFormat:@"%f",myLocation.latitude]];
  516. [arr addPro:@"lng" Value:[NSString stringWithFormat:@"%f",myLocation.longitude]];
  517. NSString* method = @"getSchList";//经纬度只为了返回jui
  518. [MBProgressHUD showLoadToView:self.view];
  519. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  520. [MBProgressHUD hideHUDForView:self.view];
  521. //NSLog(@"驾校列表---->%@,,,,,%@",arr,root);
  522. [holderV setHidden:NO];
  523. if (!root) {
  524. [LoadingView showMsg:@"查询失败"];
  525. return;
  526. }
  527. NSString* code = root[@"code"];
  528. if (code.intValue > 0)
  529. {
  530. [LoadingView showMsg:root[@"body"]];
  531. return;
  532. }
  533. if ([root[@"body"] count] < 1) {
  534. return;
  535. }
  536. models = root[@"body"];
  537. [self acceptData];
  538. [holderV setHidden:YES];
  539. }];
  540. }
  541. -(void)acceptData
  542. {
  543. if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
  544. {
  545. _searchController.searchBar.placeholder=[NSString stringWithFormat:@"请输入驾校名称(当前共%d家)",(int)models.count];
  546. }else{
  547. [_searchBar setPlaceholder:[NSString stringWithFormat:@"请输入驾校名称(当前共%d家)",(int)models.count]];
  548. }
  549. [groupDic removeAllObjects];
  550. for (NSDictionary *dic in models) {
  551. NSString *letter = [Tools pinYinFromChinese:dic[@"SHORTNAME"]];
  552. if (letter.length < 1) {
  553. continue;
  554. }
  555. letter = [letter substringToIndex:1];
  556. if (![groupDic objectForKey:letter]) {
  557. [groupDic setObject:[NSMutableArray array] forKey:letter];
  558. }
  559. [[groupDic objectForKey:letter] addObject:dic[@"SHORTNAME"]];
  560. }
  561. [_contactTable reloadData];
  562. }
  563. - (void)getSchPlacesWithDic:(NSDictionary *)dic
  564. {
  565. if (!dqbh || dqbh.length==0) {
  566. [self goAllCoachPlanVCWithDic:dic];
  567. return;
  568. }
  569. if (![Util connectedToNetWork]) {
  570. [self goAllCoachPlanVCWithDic:dic];
  571. return;
  572. }
  573. NSMutableArray *arr=[NSMutableArray array];
  574. [arr addPro:@"dqbh" Value:dqbh];
  575. [arr addPro:@"jxbh" Value:dic[@"JXBH"]];
  576. NSString* method = @"getSchPlaces";
  577. [MBProgressHUD showLoadToView:self.view];
  578. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  579. [MBProgressHUD hideHUDForView:self.view];
  580. if (!root) {
  581. [self goAllCoachPlanVCWithDic:dic];
  582. return;
  583. }
  584. if ([root[@"code"] intValue] == 0) {
  585. if ([root[@"body"] count] < 1) {
  586. [self goAllCoachPlanVCWithDic:dic];
  587. }else {
  588. FenceSiteVC *vc = [[FenceSiteVC alloc] init];
  589. vc.dataArray = root[@"body"];
  590. vc.dqbh = dqbh;
  591. [self navPushHideTabbarToVC:vc];
  592. }
  593. }else {
  594. [self goAllCoachPlanVCWithDic:dic];
  595. }
  596. }];
  597. }
  598. - (void)goAllCoachPlanVCWithDic:(NSDictionary *)dic {
  599. AllCoachPlanVC* vc = [[AllCoachPlanVC alloc] init];
  600. vc.searchJXBH = dic[@"JXBH"];
  601. [self navPushHideTabbarToVC:vc];
  602. }
  603. - (void)didReceiveMemoryWarning {
  604. [super didReceiveMemoryWarning];
  605. }
  606. @end