SchoolListVC.m 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. //
  2. // SchoolListVC.m
  3. // LNManager
  4. //
  5. // Created by EchoShacolee on 2017/4/7.
  6. // Copyright © 2017年 lee. All rights reserved.
  7. //
  8. #import "SchoolListVC.h"
  9. #import "DBManager.h"
  10. #import "AssessorList.h"
  11. #import "CarList.h"
  12. #import "SchoolDetail.h"
  13. #import "CoachListVC.h"
  14. #import "SafeList.h"
  15. #import "StudentList.h"
  16. #import "CarList.h"
  17. #import "TeachLogsVC.h"
  18. #import "TerminalVC.h"
  19. #import "SYBaseCell.h"
  20. @interface SchoolListVC ()<UIPickerViewDelegate,UIPickerViewDataSource,UIGestureRecognizerDelegate>
  21. {
  22. //选择城市相关
  23. UIPickerView *_pickerView;
  24. //地市数据库数据
  25. NSMutableArray * _pickVList1;
  26. NSMutableArray * _pickVList2;
  27. NSMutableArray * _pickDataArr;
  28. NSString *_pickStr;//最后被选中的地区
  29. NSInteger _proIndex;//记录选中城市的行数
  30. NSString *_lastTitle;//(判断再次选取城市)
  31. //
  32. UIView * _mengBanView;
  33. UIToolbar * _toolBar;
  34. //记录当前地市
  35. NSString * _dqbh;
  36. NSString * _qxbh;
  37. }
  38. @end
  39. @implementation SchoolListVC
  40. - (void)viewDidLoad {
  41. [super viewDidLoad];
  42. self.dataArr = [NSMutableArray new];
  43. _searchController.searchBar.placeholder = @"请输入驾校名称";
  44. if (self.type == 8) {//通知下发 移除搜索框
  45. self.tableView.tableHeaderView.height = 0;
  46. }
  47. [self customRightBtn];
  48. _dqbh = MYAPPDELEGATE.userDic[@"dqbh"];
  49. _qxbh = MYAPPDELEGATE.userDic[@"qxbh"];
  50. [self getData];
  51. __weak typeof(self) weakSelf = self;
  52. _block = ^{
  53. [weakSelf getData];
  54. };
  55. [self.tableView registerNib:[UINib nibWithNibName:@"SYBaseCell" bundle:nil] forCellReuseIdentifier:@"SYBaseCellId"];
  56. }
  57. -(void)customRightBtn{
  58. UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithTitle:@"选择地市" style:UIBarButtonItemStylePlain target:self action:@selector(setMengbanView:)];
  59. item.tintColor = COLOR_THEME;
  60. NSString *userType = [NSString stringWithFormat:@"%@",MYAPPDELEGATE.userDic[@"userType"]];
  61. //从数据库加载地市
  62. NSMutableArray * sqliteArr = [[DBManager sharedManager]getDqbhAndCtiyNameFromSqlite];
  63. switch ([userType integerValue]) {
  64. case 1:
  65. {
  66. //省级
  67. _pickVList1 = sqliteArr[0];
  68. _pickVList2 = sqliteArr[1];
  69. _pickDataArr = sqliteArr[2];
  70. [_pickVList1 insertObject:@"全省" atIndex:0];
  71. for (int i=0; i<_pickVList2.count; i++) {
  72. [_pickVList2[i] insertObject:@"全市" atIndex:0];
  73. }
  74. [_pickVList2 insertObject:[NSMutableArray new] atIndex:0];//对应全省
  75. self.navigationItem.rightBarButtonItem = item;
  76. }
  77. break;
  78. case 2:
  79. {
  80. //市级
  81. NSString * cityName = @"";
  82. for (NSDictionary * dic in sqliteArr[2]) {
  83. if ([dic[@"code"] isEqualToString:MYAPPDELEGATE.userDic[@"dqbh"]]) {
  84. cityName = dic[@"name"];
  85. }
  86. }
  87. NSUInteger index = [sqliteArr[0] indexOfObject:cityName];
  88. _pickVList1 = [NSMutableArray arrayWithArray:@[cityName]];
  89. _pickVList2 = [NSMutableArray arrayWithArray:@[sqliteArr[1][index]]];
  90. _pickDataArr = sqliteArr[2];
  91. [_pickVList2[0] insertObject:@"全市" atIndex:0];
  92. self.navigationItem.rightBarButtonItem = item;
  93. }
  94. break;
  95. default:
  96. break;
  97. }
  98. }
  99. #pragma mark 地市选择视图
  100. -(void)setMengbanView:(UIBarButtonItem *)sender{
  101. UIWindow * window = [UIApplication sharedApplication].windows[0];
  102. if (_mengBanView) {
  103. _mengBanView.alpha = 1.0;
  104. [window addSubview:_mengBanView];
  105. return;
  106. }
  107. /*创建灰色背景*/
  108. _mengBanView = [[UIView alloc] initWithFrame:KWINDOW.bounds];
  109. _mengBanView.backgroundColor = [UIColor colorWithWhite:.01 alpha:.4];
  110. [window addSubview:_mengBanView];
  111. /*添加手势事件,移除View*/
  112. UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissContactView:)];
  113. tapGesture.cancelsTouchesInView = NO;
  114. tapGesture.delegate = self;
  115. [_mengBanView addGestureRecognizer:tapGesture];
  116. //
  117. UIView *contentView = [[UIView alloc]initWithFrame:CGRectMake(kSize.width/3.0, kNavOffSet, kSize.width*2.0/3, 200+44)];
  118. contentView.layer.cornerRadius = 10;
  119. contentView.layer.masksToBounds = YES;
  120. [_mengBanView addSubview:contentView];
  121. //toolbar
  122. UIToolbar *pickerDateToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, kSize.width*2.0/3, 44)];
  123. pickerDateToolbar.barStyle = UIBarStyleDefault;
  124. _toolBar = pickerDateToolbar;
  125. // [pickerDateToolbar sizeToFit];
  126. //
  127. UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(toolBarCanelClick)];
  128. cancelBtn.tintColor = COLOR_THEME;
  129. //
  130. UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(toolBarDoneClick)];
  131. doneBtn.tintColor = COLOR_THEME;
  132. //
  133. UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
  134. [pickerDateToolbar setItems:@[flexSpace,cancelBtn,flexSpace,flexSpace,flexSpace,flexSpace,doneBtn,flexSpace] animated:YES];
  135. [contentView addSubview:pickerDateToolbar];
  136. // 选择框
  137. _pickerView = [[UIPickerView alloc] init];
  138. _pickerView.frame = CGRectMake(0, 44, kSize.width*2.0/3, 200);
  139. _pickerView.backgroundColor = RGB_COLOR(246, 246, 246);
  140. _pickerView.showsSelectionIndicator=YES;
  141. _pickerView.dataSource = self;
  142. _pickerView.delegate = self;
  143. _proIndex = 0;//第一列默认选中第0行
  144. [contentView addSubview:_pickerView];
  145. }
  146. -(void)toolBarCanelClick{
  147. [self dismissContactViewWithIsSure:NO];
  148. }
  149. -(void)toolBarDoneClick{
  150. [self dismissContactViewWithIsSure:YES];
  151. //其实这一块可以放上面那行方法里面,不过为了让它看起来不那么复杂,就放这里吧
  152. if (_pickStr) {
  153. self.navigationItem.rightBarButtonItem.title = _pickStr;
  154. }else{
  155. self.navigationItem.rightBarButtonItem.title = _pickVList1[0];
  156. return;//_pickstr不存在,即没有滑动
  157. }
  158. if ([_lastTitle isEqualToString:_pickStr]) {
  159. return;
  160. }
  161. if ([_pickStr isEqualToString:@"全省"]) {
  162. _dqbh = @"";//2100作为dqbh会报错 辽宁
  163. _qxbh = @"";
  164. [self getData];
  165. }else if ([_pickVList1 containsObject:_pickStr]){//全市
  166. for (NSMutableDictionary *dic in _pickDataArr) {
  167. if ([dic[@"name"] isEqualToString:_pickStr]) {
  168. _dqbh = dic[@"code"];
  169. _qxbh = @"";
  170. [self getData];
  171. return;
  172. }
  173. }
  174. }else{
  175. for (NSMutableDictionary *dic in _pickDataArr) {
  176. if ([dic[@"name"] isEqualToString:_pickStr]) {
  177. _dqbh = dic[@"parent_code"];
  178. _qxbh = dic[@"code"];
  179. [self getData];
  180. }
  181. }
  182. }
  183. return;
  184. }
  185. #pragma mark - tap手势代理方法
  186. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
  187. {
  188. CGPoint location = [touch locationInView:self.view];
  189. CGRect frame1 = [self.view convertRect:_toolBar.frame fromView:_mengBanView.subviews[0]];
  190. CGRect frame2 = [self.view convertRect:frame1 fromView:_mengBanView];
  191. if(CGRectContainsPoint(frame2, location))
  192. {
  193. return NO;
  194. }
  195. return YES;
  196. }
  197. #pragma mark - 手势点击事件,移除View
  198. - (void)dismissContactView:(UITapGestureRecognizer *)tapGesture{
  199. [self dismissContactViewWithIsSure:NO];
  200. }
  201. -(void)dismissContactViewWithIsSure:(BOOL)sure
  202. {
  203. //如果是取消
  204. if (!sure) {
  205. //取消(取消之前恢复pickerview原状态)
  206. //作相应处理
  207. _pickStr = _lastTitle;
  208. if ([_lastTitle isEqualToString:@"全省"] || !_lastTitle) {
  209. _proIndex = 0;
  210. [_pickerView reloadAllComponents];
  211. [_pickerView selectRow:0 inComponent:0 animated:NO];
  212. [_pickerView selectRow:0 inComponent:1 animated:NO];
  213. }else if ([_pickVList1 containsObject:_lastTitle]){//全市
  214. _proIndex = [_pickVList1 indexOfObject:_lastTitle];
  215. [_pickerView reloadAllComponents];
  216. [_pickerView selectRow:_proIndex inComponent:0 animated:NO];
  217. [_pickerView selectRow:0 inComponent:1 animated:NO];
  218. }else{
  219. //在第二列的位置
  220. NSInteger index2 = 0;
  221. for (int i=0; i<_pickVList2.count; i++) {
  222. if ([_pickVList2[i] containsObject:_lastTitle]) {
  223. _proIndex = i;//第一列位置
  224. index2 = [_pickVList2[i] indexOfObject:_lastTitle];//第二列位置
  225. break;
  226. }
  227. }
  228. [_pickerView reloadAllComponents];
  229. [_pickerView selectRow:_proIndex inComponent:0 animated:NO];
  230. [_pickerView selectRow:index2 inComponent:1 animated:NO];
  231. }
  232. }
  233. [UIView animateWithDuration:0.5 animations:^{
  234. _mengBanView.alpha = 0;
  235. } completion:^(BOOL finished) {
  236. [_mengBanView removeFromSuperview];
  237. }];
  238. }
  239. #pragma mark 数据请求
  240. -(void)getData{
  241. NSMutableDictionary * mdic = [NSMutableDictionary new];
  242. [mdic setValue:_dqbh forKey:@"dqbh"];
  243. [mdic setValue:_qxbh forKey:@"qxbh"];
  244. [mdic setValue:@"" forKey:@"inscode"];//驾校编号
  245. [mdic setValue:@"" forKey:@"jxmc"];
  246. [mdic setValue:@"" forKey:@"isPage"];
  247. [mdic setValue:@"" forKey:@"pageSize"];
  248. [mdic setValue:@"" forKey:@"currentPage"];
  249. [mdic setValue:@"1" forKey:@"auditStatus"];
  250. _requsetDic = mdic;
  251. [self getDataWithDic:mdic method:@"schools" block:^(NSDictionary *successdic) {
  252. _lastTitle = _pickStr;//记录当前已确定地市
  253. //
  254. [_sectionTitles removeAllObjects];
  255. [self.dataArr removeAllObjects];
  256. [_dataSource removeAllObjects];
  257. NSMutableArray * mArr = [NSMutableArray new];//这里不直接对self.dataarr操作是减少子类重写set方法时的频繁调用
  258. NSArray * arr = successdic[@"body"];
  259. if (arr.count != 0) {
  260. self.holderV.hidden = YES;
  261. }
  262. for (NSDictionary * dic in arr) {
  263. if (![_sectionTitles containsObject:dic[@"ZM"]]) {
  264. [_sectionTitles addObject:dic[@"ZM"]];
  265. [mArr addObject:[NSMutableArray new]];
  266. }
  267. [[mArr lastObject] addObject:dic];
  268. }
  269. self.dataArr = mArr;//子类用
  270. _dataSource = mArr;//父类用
  271. [self.tableView reloadData];
  272. }];
  273. }
  274. #pragma mark UIPickerViewDataSource
  275. // pickerView 列数
  276. - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
  277. return 2;
  278. }
  279. // pickerView 每列个数
  280. - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
  281. if (component == 0) {
  282. return _pickVList1.count;
  283. }
  284. return [_pickVList2[_proIndex] count];
  285. }
  286. #pragma mark UIPickerViewDelegate
  287. // 每列宽度
  288. - (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
  289. if (component == 0) {
  290. return 70;
  291. }
  292. return 130;
  293. }
  294. // 返回选中的行
  295. - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
  296. {
  297. // NSLog(@"%ld,%ld",(long)component,(long)row);
  298. if (component == 0) {
  299. _proIndex = row;
  300. [pickerView reloadComponent:1];
  301. [_pickerView selectRow:0 inComponent:1 animated:NO];
  302. if (row == 0) {
  303. _pickStr = @"全省";
  304. }else{
  305. _pickStr = _pickVList1[_proIndex];
  306. }
  307. }
  308. if ((_proIndex != 0 && component == 1)|| _pickVList1.count == 1) {
  309. if (row != 0) {
  310. _pickStr = _pickVList2[_proIndex][row];
  311. }else{
  312. _pickStr = _pickVList1[_proIndex];
  313. }
  314. }
  315. }
  316. //设置风格
  317. -(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
  318. //设置分割线的颜色
  319. for(UIView *singleLine in pickerView.subviews)
  320. {
  321. if (singleLine.frame.size.height < 1)
  322. {
  323. singleLine.backgroundColor = [UIColor blackColor];
  324. }
  325. }
  326. //设置文字的属性
  327. UILabel *genderLabel = [UILabel new];
  328. genderLabel.textAlignment = NSTextAlignmentCenter;
  329. if (component == 0) {
  330. genderLabel.text = [_pickVList1 objectAtIndex:row];
  331. }else{
  332. genderLabel.text = [_pickVList2[_proIndex] objectAtIndex:row];
  333. }
  334. genderLabel.textColor = [UIColor redColor];
  335. return genderLabel;
  336. }
  337. #pragma mark 重写Cell出列方法
  338. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  339. {
  340. SYBaseCell * cell = [tableView dequeueReusableCellWithIdentifier:@"SYBaseCellId" forIndexPath:indexPath];
  341. NSDictionary * dic;
  342. if (_hasSearch) {
  343. dic = _resultArray[indexPath.row][0];
  344. }else{
  345. dic = _dataSource[indexPath.section][indexPath.row];
  346. }
  347. cell.nameLab.text = dic[@"TSI_SHORTNAME"];
  348. NSString *str = [NSString stringWithFormat:@"%@",dic[@"TSI_LOCK_STATUS"]];
  349. cell.lockingImgV.hidden = [str intValue]==0;
  350. return cell;
  351. }
  352. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  353. NSDictionary * dic;
  354. NSIndexPath *correctIndexP;
  355. if (_hasSearch) {
  356. dic = _resultArray[indexPath.row][0];
  357. correctIndexP = _resultArray[indexPath.row][1];
  358. }else{
  359. dic = _dataSource[indexPath.section][indexPath.row];
  360. correctIndexP = indexPath;
  361. }
  362. //驾校编号
  363. NSString * inscode = dic[@"TSI_INSCODE"];
  364. switch (self.type) {
  365. case 0:
  366. {
  367. //驾校详情
  368. SchoolDetail * vc = [[SchoolDetail alloc]init];
  369. vc.lockBlock = ^(NSDictionary *data) {
  370. [self.dataArr[correctIndexP.section] replaceObjectAtIndex:correctIndexP.row withObject:data];
  371. [self.tableView reloadData];
  372. };
  373. [_requsetDic setValue:inscode forKey:@"inscode"];
  374. vc.requesetDic = _requsetDic;
  375. [self.navigationController pushViewController:vc animated:YES];
  376. }
  377. break;
  378. case 1:
  379. {
  380. //教练
  381. CoachListVC * vc = [[CoachListVC alloc]init];
  382. vc.shcDic = dic;
  383. [self.navigationController pushViewController:vc animated:YES];
  384. }
  385. break;
  386. case 2:
  387. {
  388. //考核员
  389. AssessorList * vc = [[AssessorList alloc]init];
  390. vc.shcDic = dic;
  391. [self.navigationController pushViewController:vc animated:YES];
  392. }
  393. break;
  394. case 3:
  395. {
  396. //安全员
  397. SafeList * vc = [[SafeList alloc]init];
  398. vc.shcDic = dic;
  399. [self.navigationController pushViewController:vc animated:YES];
  400. }
  401. break;
  402. case 4:
  403. {
  404. //学员
  405. StudentList * vc = [[StudentList alloc]init];
  406. vc.shcDic = dic;
  407. [self.navigationController pushViewController:vc animated:YES];
  408. }
  409. break;
  410. case 5:
  411. {
  412. //车辆
  413. CarList * vc = [[CarList alloc]init];
  414. vc.shcDic = dic;
  415. [self.navigationController pushViewController:vc animated:YES];
  416. }
  417. break;
  418. case 6:
  419. {
  420. //学时审核
  421. // XueShiCheckList * vc = [[XueShiCheckList alloc]init];
  422. // vc.shcDic = dic;
  423. // [self.navigationController pushViewController:vc animated:YES];
  424. }
  425. break;
  426. case 7:
  427. {
  428. //教学日志
  429. TeachLogsVC * vc = [[TeachLogsVC alloc]init];
  430. vc.schDic = dic;
  431. [self.navigationController pushViewController:vc animated:YES];
  432. }
  433. break;
  434. case 8:
  435. {
  436. //通知下发 初始化判断
  437. //选取驾校发送通知
  438. }
  439. break;
  440. case 9:
  441. {
  442. //终端管理
  443. TerminalVC * vc = [[TerminalVC alloc]init];
  444. vc.shcDic = dic;
  445. [self.navigationController pushViewController:vc animated:YES];
  446. }
  447. break;
  448. default:
  449. break;
  450. }
  451. }
  452. #pragma mark - 搜索代理
  453. - (void)updateSearchResultsForSearchController:(UISearchController *)searchController
  454. {
  455. NSString *searchString = _searchController.searchBar.text;
  456. // NSLog(@"searchString-->%@",searchString);
  457. _hasSearch = NO;
  458. if (searchString.length > 0) {
  459. [_resultArray removeAllObjects];
  460. // if ([searchString integerValue] == 0)
  461. // {//汉字
  462. int i = 0, j = 0;
  463. for (NSArray *sectionArr in _dataSource)
  464. {
  465. j=0;
  466. for (NSDictionary *dic in sectionArr)
  467. {
  468. if ([dic[@"TSI_NAME"] rangeOfString:searchString].location != NSNotFound)
  469. {
  470. [_resultArray addObject:@[dic,[NSIndexPath indexPathForRow:j inSection:i]]];
  471. }
  472. j++;
  473. }
  474. i++;
  475. }
  476. // }
  477. // else{
  478. //
  479. // for (NSArray *sectionArr in _dataSource)
  480. // {j=0;
  481. // for (NSDictionary *dic in sectionArr)
  482. // {
  483. // BOOL isTrue1 = [[NSString stringWithFormat:@"%@",dic[@"TSI_PHONE"]] rangeOfString:searchString].location != NSNotFound;
  484. // if (isTrue1)
  485. // {
  486. // [_resultArray addObject:];
  487. // }
  488. // }
  489. // }
  490. // }
  491. _hasSearch = YES;
  492. }
  493. [self.tableView reloadData];
  494. }
  495. - (void)didReceiveMemoryWarning {
  496. [super didReceiveMemoryWarning];
  497. // Dispose of any resources that can be recreated.
  498. }
  499. /*
  500. #pragma mark - Navigation
  501. // In a storyboard-based application, you will often want to do a little preparation before navigation
  502. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  503. // Get the new view controller using [segue destinationViewController].
  504. // Pass the selected object to the new view controller.
  505. }
  506. */
  507. @end