123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615 |
- //
- // SchoolListVC.m
- // LNManager
- //
- // Created by EchoShacolee on 2017/4/7.
- // Copyright © 2017年 lee. All rights reserved.
- //
- #import "SchoolListVC.h"
- #import "DBManager.h"
- #import "AssessorList.h"
- #import "CarList.h"
- #import "SchoolDetail.h"
- #import "CoachListVC.h"
- #import "SafeList.h"
- #import "StudentList.h"
- #import "CarList.h"
- #import "TeachLogsVC.h"
- #import "TerminalVC.h"
- #import "SYBaseCell.h"
- @interface SchoolListVC ()<UIPickerViewDelegate,UIPickerViewDataSource,UIGestureRecognizerDelegate>
- {
- //选择城市相关
- UIPickerView *_pickerView;
-
- //地市数据库数据
- NSMutableArray * _pickVList1;
- NSMutableArray * _pickVList2;
- NSMutableArray * _pickDataArr;
-
- NSString *_pickStr;//最后被选中的地区
- NSInteger _proIndex;//记录选中城市的行数
- NSString *_lastTitle;//(判断再次选取城市)
-
- //
- UIView * _mengBanView;
- UIToolbar * _toolBar;
-
- //记录当前地市
- NSString * _dqbh;
- NSString * _qxbh;
- }
- @end
- @implementation SchoolListVC
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.dataArr = [NSMutableArray new];
-
- _searchController.searchBar.placeholder = @"请输入驾校名称";
- if (self.type == 8) {//通知下发 移除搜索框
- self.tableView.tableHeaderView.height = 0;
- }
- [self customRightBtn];
-
- _dqbh = MYAPPDELEGATE.userDic[@"dqbh"];
- _qxbh = MYAPPDELEGATE.userDic[@"qxbh"];
- [self getData];
-
- __weak typeof(self) weakSelf = self;
- _block = ^{
- [weakSelf getData];
- };
-
- [self.tableView registerNib:[UINib nibWithNibName:@"SYBaseCell" bundle:nil] forCellReuseIdentifier:@"SYBaseCellId"];
- }
- -(void)customRightBtn{
-
- UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithTitle:@"选择地市" style:UIBarButtonItemStylePlain target:self action:@selector(setMengbanView:)];
- item.tintColor = COLOR_THEME;
-
- NSString *userType = [NSString stringWithFormat:@"%@",MYAPPDELEGATE.userDic[@"userType"]];
-
- //从数据库加载地市
- NSMutableArray * sqliteArr = [[DBManager sharedManager]getDqbhAndCtiyNameFromSqlite];
- switch ([userType integerValue]) {
- case 1:
- {
- //省级
- _pickVList1 = sqliteArr[0];
- _pickVList2 = sqliteArr[1];
- _pickDataArr = sqliteArr[2];
-
- [_pickVList1 insertObject:@"全省" atIndex:0];
- for (int i=0; i<_pickVList2.count; i++) {
- [_pickVList2[i] insertObject:@"全市" atIndex:0];
- }
- [_pickVList2 insertObject:[NSMutableArray new] atIndex:0];//对应全省
-
- self.navigationItem.rightBarButtonItem = item;
- }
- break;
- case 2:
- {
- //市级
- NSString * cityName = @"";
- for (NSDictionary * dic in sqliteArr[2]) {
- if ([dic[@"code"] isEqualToString:MYAPPDELEGATE.userDic[@"dqbh"]]) {
- cityName = dic[@"name"];
- }
- }
-
- NSUInteger index = [sqliteArr[0] indexOfObject:cityName];
- _pickVList1 = [NSMutableArray arrayWithArray:@[cityName]];
- _pickVList2 = [NSMutableArray arrayWithArray:@[sqliteArr[1][index]]];
- _pickDataArr = sqliteArr[2];
-
- [_pickVList2[0] insertObject:@"全市" atIndex:0];
-
- self.navigationItem.rightBarButtonItem = item;
- }
- break;
- default:
- break;
- }
- }
- #pragma mark 地市选择视图
- -(void)setMengbanView:(UIBarButtonItem *)sender{
-
- UIWindow * window = [UIApplication sharedApplication].windows[0];
- if (_mengBanView) {
- _mengBanView.alpha = 1.0;
-
- [window addSubview:_mengBanView];
- return;
- }
-
- /*创建灰色背景*/
- _mengBanView = [[UIView alloc] initWithFrame:KWINDOW.bounds];
- _mengBanView.backgroundColor = [UIColor colorWithWhite:.01 alpha:.4];
- [window addSubview:_mengBanView];
-
- /*添加手势事件,移除View*/
- UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissContactView:)];
- tapGesture.cancelsTouchesInView = NO;
- tapGesture.delegate = self;
- [_mengBanView addGestureRecognizer:tapGesture];
-
- //
- UIView *contentView = [[UIView alloc]initWithFrame:CGRectMake(kSize.width/3.0, kNavOffSet, kSize.width*2.0/3, 200+44)];
- contentView.layer.cornerRadius = 10;
- contentView.layer.masksToBounds = YES;
- [_mengBanView addSubview:contentView];
-
- //toolbar
- UIToolbar *pickerDateToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, kSize.width*2.0/3, 44)];
- pickerDateToolbar.barStyle = UIBarStyleDefault;
- _toolBar = pickerDateToolbar;
- // [pickerDateToolbar sizeToFit];
-
- //
- UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(toolBarCanelClick)];
- cancelBtn.tintColor = COLOR_THEME;
- //
- UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(toolBarDoneClick)];
- doneBtn.tintColor = COLOR_THEME;
- //
- UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
-
- [pickerDateToolbar setItems:@[flexSpace,cancelBtn,flexSpace,flexSpace,flexSpace,flexSpace,doneBtn,flexSpace] animated:YES];
- [contentView addSubview:pickerDateToolbar];
-
- // 选择框
- _pickerView = [[UIPickerView alloc] init];
- _pickerView.frame = CGRectMake(0, 44, kSize.width*2.0/3, 200);
- _pickerView.backgroundColor = RGB_COLOR(246, 246, 246);
- _pickerView.showsSelectionIndicator=YES;
- _pickerView.dataSource = self;
- _pickerView.delegate = self;
-
- _proIndex = 0;//第一列默认选中第0行
- [contentView addSubview:_pickerView];
- }
- -(void)toolBarCanelClick{
- [self dismissContactViewWithIsSure:NO];
- }
- -(void)toolBarDoneClick{
- [self dismissContactViewWithIsSure:YES];
-
- //其实这一块可以放上面那行方法里面,不过为了让它看起来不那么复杂,就放这里吧
- if (_pickStr) {
- self.navigationItem.rightBarButtonItem.title = _pickStr;
- }else{
- self.navigationItem.rightBarButtonItem.title = _pickVList1[0];
- return;//_pickstr不存在,即没有滑动
- }
-
- if ([_lastTitle isEqualToString:_pickStr]) {
- return;
- }
- if ([_pickStr isEqualToString:@"全省"]) {
- _dqbh = @"";//2100作为dqbh会报错 辽宁
- _qxbh = @"";
- [self getData];
-
- }else if ([_pickVList1 containsObject:_pickStr]){//全市
-
- for (NSMutableDictionary *dic in _pickDataArr) {
- if ([dic[@"name"] isEqualToString:_pickStr]) {
- _dqbh = dic[@"code"];
- _qxbh = @"";
- [self getData];
- return;
- }
- }
-
- }else{
-
- for (NSMutableDictionary *dic in _pickDataArr) {
- if ([dic[@"name"] isEqualToString:_pickStr]) {
- _dqbh = dic[@"parent_code"];
- _qxbh = dic[@"code"];
- [self getData];
- }
- }
- }
- return;
- }
- #pragma mark - tap手势代理方法
- - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
- {
- CGPoint location = [touch locationInView:self.view];
-
- CGRect frame1 = [self.view convertRect:_toolBar.frame fromView:_mengBanView.subviews[0]];
- CGRect frame2 = [self.view convertRect:frame1 fromView:_mengBanView];
-
- if(CGRectContainsPoint(frame2, location))
-
- {
- return NO;
- }
- return YES;
- }
- #pragma mark - 手势点击事件,移除View
- - (void)dismissContactView:(UITapGestureRecognizer *)tapGesture{
-
- [self dismissContactViewWithIsSure:NO];
- }
- -(void)dismissContactViewWithIsSure:(BOOL)sure
- {
- //如果是取消
- if (!sure) {
- //取消(取消之前恢复pickerview原状态)
- //作相应处理
- _pickStr = _lastTitle;
-
- if ([_lastTitle isEqualToString:@"全省"] || !_lastTitle) {
-
- _proIndex = 0;
- [_pickerView reloadAllComponents];
- [_pickerView selectRow:0 inComponent:0 animated:NO];
- [_pickerView selectRow:0 inComponent:1 animated:NO];
-
- }else if ([_pickVList1 containsObject:_lastTitle]){//全市
-
- _proIndex = [_pickVList1 indexOfObject:_lastTitle];
- [_pickerView reloadAllComponents];
- [_pickerView selectRow:_proIndex inComponent:0 animated:NO];
- [_pickerView selectRow:0 inComponent:1 animated:NO];
-
- }else{
-
- //在第二列的位置
- NSInteger index2 = 0;
- for (int i=0; i<_pickVList2.count; i++) {
- if ([_pickVList2[i] containsObject:_lastTitle]) {
- _proIndex = i;//第一列位置
- index2 = [_pickVList2[i] indexOfObject:_lastTitle];//第二列位置
- break;
- }
- }
- [_pickerView reloadAllComponents];
- [_pickerView selectRow:_proIndex inComponent:0 animated:NO];
- [_pickerView selectRow:index2 inComponent:1 animated:NO];
-
- }
- }
-
- [UIView animateWithDuration:0.5 animations:^{
- _mengBanView.alpha = 0;
- } completion:^(BOOL finished) {
- [_mengBanView removeFromSuperview];
- }];
-
- }
- #pragma mark 数据请求
- -(void)getData{
-
- NSMutableDictionary * mdic = [NSMutableDictionary new];
- [mdic setValue:_dqbh forKey:@"dqbh"];
- [mdic setValue:_qxbh forKey:@"qxbh"];
- [mdic setValue:@"" forKey:@"inscode"];//驾校编号
- [mdic setValue:@"" forKey:@"jxmc"];
- [mdic setValue:@"" forKey:@"isPage"];
- [mdic setValue:@"" forKey:@"pageSize"];
- [mdic setValue:@"" forKey:@"currentPage"];
- [mdic setValue:@"1" forKey:@"auditStatus"];
-
- _requsetDic = mdic;
-
- [self getDataWithDic:mdic method:@"schools" block:^(NSDictionary *successdic) {
-
- _lastTitle = _pickStr;//记录当前已确定地市
-
- //
- [_sectionTitles removeAllObjects];
- [self.dataArr removeAllObjects];
- [_dataSource removeAllObjects];
-
- NSMutableArray * mArr = [NSMutableArray new];//这里不直接对self.dataarr操作是减少子类重写set方法时的频繁调用
- NSArray * arr = successdic[@"body"];
- if (arr.count != 0) {
- self.holderV.hidden = YES;
- }
-
- for (NSDictionary * dic in arr) {
- if (![_sectionTitles containsObject:dic[@"ZM"]]) {
- [_sectionTitles addObject:dic[@"ZM"]];
- [mArr addObject:[NSMutableArray new]];
- }
- [[mArr lastObject] addObject:dic];
- }
- self.dataArr = mArr;//子类用
- _dataSource = mArr;//父类用
- [self.tableView reloadData];
- }];
- }
- #pragma mark UIPickerViewDataSource
- // pickerView 列数
- - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
- return 2;
- }
- // pickerView 每列个数
- - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
- if (component == 0) {
-
- return _pickVList1.count;
- }
- return [_pickVList2[_proIndex] count];
- }
- #pragma mark UIPickerViewDelegate
- // 每列宽度
- - (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
- if (component == 0) {
- return 70;
- }
- return 130;
- }
- // 返回选中的行
- - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
- {
- // NSLog(@"%ld,%ld",(long)component,(long)row);
- if (component == 0) {
- _proIndex = row;
- [pickerView reloadComponent:1];
- [_pickerView selectRow:0 inComponent:1 animated:NO];
- if (row == 0) {
- _pickStr = @"全省";
- }else{
- _pickStr = _pickVList1[_proIndex];
- }
- }
-
- if ((_proIndex != 0 && component == 1)|| _pickVList1.count == 1) {
- if (row != 0) {
- _pickStr = _pickVList2[_proIndex][row];
- }else{
- _pickStr = _pickVList1[_proIndex];
- }
- }
- }
- //设置风格
- -(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
-
- //设置分割线的颜色
- for(UIView *singleLine in pickerView.subviews)
-
- {
- if (singleLine.frame.size.height < 1)
-
- {
- singleLine.backgroundColor = [UIColor blackColor];
- }
- }
-
- //设置文字的属性
- UILabel *genderLabel = [UILabel new];
- genderLabel.textAlignment = NSTextAlignmentCenter;
- if (component == 0) {
- genderLabel.text = [_pickVList1 objectAtIndex:row];
- }else{
- genderLabel.text = [_pickVList2[_proIndex] objectAtIndex:row];
- }
-
- genderLabel.textColor = [UIColor redColor];
- return genderLabel;
- }
- #pragma mark 重写Cell出列方法
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- SYBaseCell * cell = [tableView dequeueReusableCellWithIdentifier:@"SYBaseCellId" forIndexPath:indexPath];
-
- NSDictionary * dic;
- if (_hasSearch) {
- dic = _resultArray[indexPath.row][0];
- }else{
- dic = _dataSource[indexPath.section][indexPath.row];
- }
-
- cell.nameLab.text = dic[@"TSI_SHORTNAME"];
- NSString *str = [NSString stringWithFormat:@"%@",dic[@"TSI_LOCK_STATUS"]];
- cell.lockingImgV.hidden = [str intValue]==0;
-
-
-
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
-
- NSDictionary * dic;
- NSIndexPath *correctIndexP;
- if (_hasSearch) {
- dic = _resultArray[indexPath.row][0];
- correctIndexP = _resultArray[indexPath.row][1];
- }else{
- dic = _dataSource[indexPath.section][indexPath.row];
- correctIndexP = indexPath;
- }
- //驾校编号
- NSString * inscode = dic[@"TSI_INSCODE"];
- switch (self.type) {
- case 0:
- {
- //驾校详情
- SchoolDetail * vc = [[SchoolDetail alloc]init];
- vc.lockBlock = ^(NSDictionary *data) {
- [self.dataArr[correctIndexP.section] replaceObjectAtIndex:correctIndexP.row withObject:data];
- [self.tableView reloadData];
- };
- [_requsetDic setValue:inscode forKey:@"inscode"];
- vc.requesetDic = _requsetDic;
- [self.navigationController pushViewController:vc animated:YES];
- }
- break;
- case 1:
- {
- //教练
- CoachListVC * vc = [[CoachListVC alloc]init];
- vc.shcDic = dic;
- [self.navigationController pushViewController:vc animated:YES];
- }
- break;
- case 2:
- {
- //考核员
- AssessorList * vc = [[AssessorList alloc]init];
- vc.shcDic = dic;
- [self.navigationController pushViewController:vc animated:YES];
- }
- break;
- case 3:
- {
- //安全员
- SafeList * vc = [[SafeList alloc]init];
- vc.shcDic = dic;
- [self.navigationController pushViewController:vc animated:YES];
- }
- break;
- case 4:
- {
- //学员
- StudentList * vc = [[StudentList alloc]init];
- vc.shcDic = dic;
- [self.navigationController pushViewController:vc animated:YES];
- }
- break;
- case 5:
- {
- //车辆
- CarList * vc = [[CarList alloc]init];
- vc.shcDic = dic;
- [self.navigationController pushViewController:vc animated:YES];
- }
- break;
- case 6:
- {
- //学时审核
- // XueShiCheckList * vc = [[XueShiCheckList alloc]init];
- // vc.shcDic = dic;
- // [self.navigationController pushViewController:vc animated:YES];
- }
- break;
- case 7:
- {
- //教学日志
- TeachLogsVC * vc = [[TeachLogsVC alloc]init];
- vc.schDic = dic;
- [self.navigationController pushViewController:vc animated:YES];
- }
- break;
- case 8:
- {
- //通知下发 初始化判断
- //选取驾校发送通知
-
- }
- break;
- case 9:
- {
- //终端管理
- TerminalVC * vc = [[TerminalVC alloc]init];
- vc.shcDic = dic;
- [self.navigationController pushViewController:vc animated:YES];
- }
- break;
-
- default:
- break;
- }
- }
- #pragma mark - 搜索代理
- - (void)updateSearchResultsForSearchController:(UISearchController *)searchController
- {
- NSString *searchString = _searchController.searchBar.text;
- // NSLog(@"searchString-->%@",searchString);
- _hasSearch = NO;
- if (searchString.length > 0) {
- [_resultArray removeAllObjects];
- // if ([searchString integerValue] == 0)
- // {//汉字
- int i = 0, j = 0;
- for (NSArray *sectionArr in _dataSource)
- {
- j=0;
- for (NSDictionary *dic in sectionArr)
- {
- if ([dic[@"TSI_NAME"] rangeOfString:searchString].location != NSNotFound)
- {
- [_resultArray addObject:@[dic,[NSIndexPath indexPathForRow:j inSection:i]]];
- }
- j++;
- }
- i++;
- }
-
- // }
- // else{
- //
- // for (NSArray *sectionArr in _dataSource)
- // {j=0;
- // for (NSDictionary *dic in sectionArr)
- // {
- // BOOL isTrue1 = [[NSString stringWithFormat:@"%@",dic[@"TSI_PHONE"]] rangeOfString:searchString].location != NSNotFound;
- // if (isTrue1)
- // {
- // [_resultArray addObject:];
- // }
- // }
- // }
- // }
- _hasSearch = YES;
- }
- [self.tableView reloadData];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|