// // WD_Detail_baseVC.m // LNManager // // Created by EchoShacolee on 2017/6/6. // Copyright © 2017年 lee. All rights reserved. // #import "WD_DetailVC.h" #import "WD_DetailCell.h" #import "MJRefresh.h" #import "NSArray+ex.h" #import "NSString+ex.h" #import "WD_Detail_ShenHe.h" #import "WD_DetailSchCell.h" #import "WD_DetailCoaCell.h" #import "WD_DetailCarCell.h" #import "WD_DetailDevCell.h" #import "WD_DetailChangeCell.h" #import "SchoolDetail.h" #import "CoachDetail.h" #import "CarDetail.h" @interface WD_DetailVC () { //记录页书 NSInteger _currentPageNum; //加载数据的类型 MyGetDataType _getDataType; //缓存高度 NSMutableArray * _heightArr; //审核驾校 NSMutableArray *_selectedIndexPathes;//记录选中的cell UIButton * _notifyBtn; UIButton *_allBtn; UIButton *_cancelBtn; } @end @implementation WD_DetailVC - (void)viewDidLoad { [super viewDidLoad]; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; CGRect frame = self.tableView.frame; self.tableView.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height); _currentPageNum = 0; _getDataType = MyGetDataTypeNomal; _selectedIndexPathes = [[NSMutableArray alloc] init]; //审核按钮 NSArray * shenheArr = @[@"3",@"4",@"5",@"6"]; if ([shenheArr containsObject:self.type]) { [self createSelectBtn]; [self setRefreshAction];//设置刷新 } [self getData]; __weak typeof(self) weakSelf = self; self.block = ^{ _currentPageNum = 0; [weakSelf getData]; }; } #pragma mark - 审核相关 -(void)createSelectBtn{ _notifyBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _notifyBtn.backgroundColor = COLOR_THEME; _notifyBtn.frame = CGRectMake(kSize.width-80, kSize.height-90-kNavOffSet, 60, 60); [_notifyBtn setTitle:@"审核" forState:UIControlStateNormal]; [_notifyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; _notifyBtn.titleLabel.numberOfLines = 0; _notifyBtn.layer.masksToBounds = YES; _notifyBtn.layer.cornerRadius = 30; [_notifyBtn addTarget:self action:@selector(notifiBtnClick:) forControlEvents:UIControlEventTouchUpInside]; _notifyBtn.hidden = YES; [self.view addSubview:_notifyBtn]; [self.view bringSubviewToFront:self.holderV]; } -(void)notifiBtnClick:(UIButton *)sender{ if (self.dataurce.count == 0) { return; } if (!self.tableView.editing) { [self.tableView setEditing:YES];//进入编辑模式 [self removeRefreshAction]; [sender setTitle:@"提交\n审核" forState:UIControlStateNormal]; CGRect frame = sender.frame;; _allBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _allBtn.backgroundColor = [UIColor lightGrayColor]; //_allBtn.backgroundColor = COLOR_THEME; _allBtn.frame = CGRectMake(frame.origin.x + 30, frame.origin.y, 0, 30); [_allBtn setTitle:@"全选" forState:UIControlStateNormal]; [_allBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [_allBtn setTitleColor:COLOR_THEME forState:UIControlStateSelected]; [_allBtn addTarget:self action:@selector(allClick:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:_allBtn]; _cancelBtn = [UIButton buttonWithType:UIButtonTypeSystem]; _cancelBtn.backgroundColor = [UIColor lightGrayColor]; _cancelBtn.frame = CGRectMake(frame.origin.x + 30, frame.origin.y + 30, 0, 30); [_cancelBtn setTitle:@"取消" forState:UIControlStateNormal]; [_cancelBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [_cancelBtn addTarget:self action:@selector(cancelClick:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:_cancelBtn]; [UIView animateWithDuration:.4 animations:^{ _allBtn.frame = CGRectMake(frame.origin.x-100, frame.origin.y - 5, 80, 30); _cancelBtn.frame = CGRectMake(frame.origin.x-100, frame.origin.y + 35, 80, 30); }]; return; } NSMutableArray * allId = [NSMutableArray new]; for (NSIndexPath *indexPath in _selectedIndexPathes) { NSString *theKey = @""; switch ([self.type integerValue]) { case 3: theKey = @"TSI_ID"; break; case 4: theKey = @"CI_ID"; break; case 5: theKey = @"TCO_ID"; break; case 6: theKey = @"ID"; break; default: break; } [allId addObject:self.dataurce[indexPath.row][theKey]]; } if (allId.count > 0) { [self.tableView setEditing:NO]; [self setRefreshAction]; [sender setTitle:@"审核" forState:UIControlStateNormal]; [_allBtn removeFromSuperview]; [_cancelBtn removeFromSuperview]; [_selectedIndexPathes removeAllObjects]; [self shenheWithIds:allId]; }else{ [self showMsgByAlertVCWithString:@"请选择驾校"]; } } -(void)allClick:(UIButton *)button{ button.selected = !button.selected; //获取表格视图内容的尺寸 CGSize size = self.tableView.contentSize; CGRect rect = CGRectMake(0, 0, size.width, size.height); //获取指定区域的cell的indexPath NSArray *indexPathes = [self.tableView indexPathsForRowsInRect:rect]; if (button.selected) { for (NSIndexPath *indexPath in indexPathes) { //使用代码方式选中一行 [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; } //更新选中数组 _selectedIndexPathes.array = indexPathes; } else { for (NSIndexPath *indexPath in indexPathes) { //使用代码方式取消选中一行 [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; } //清空选中cell的记录数组 [_selectedIndexPathes removeAllObjects]; } } - (void)cancelClick:(UIButton *)sender { [self.tableView setEditing:NO]; [self setRefreshAction]; [_notifyBtn setTitle:@"审核" forState:UIControlStateNormal]; [_allBtn removeFromSuperview]; [_cancelBtn removeFromSuperview]; [_selectedIndexPathes removeAllObjects]; } -(void)shenheWithIds:(NSArray *)ids{ NSInteger typeId = [self.type integerValue] - 2; //当前vc self.type // 1.系统升级公告 // 2电子围栏审核 // 3驾校审核通知 // 4教练审核通知 // 5教练车审核通知 // 6终端审核通知 // 7管理部门下发通知 /* 审核界面 WD_Detail_ShenHe vc.shenheType 1驾校审核通知 2教练审核通知 3教练车审核通知 4终端审核通知 */ NSString * shenheType = [NSString stringWithFormat:@"%ld",(long)typeId]; WD_Detail_ShenHe *vc = [[WD_Detail_ShenHe alloc]init]; vc.shenheType = shenheType; vc.ids = ids; vc.block = ^{ [self headerRefresh]; }; [self.navigationController pushViewController:vc animated:YES]; } #pragma mark - 下拉刷新,上拉加载 - -(void)setRefreshAction{ // 下拉加载更多 __weak typeof(self) weakSelf = self; MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ [weakSelf headerRefresh]; }]; self.tableView.mj_header = header; MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{ [weakSelf footerRefresh]; }]; self.tableView.mj_footer = footer; } -(void)headerRefresh{ //设置获取数据的方式 _getDataType=MyGetDataTypeHeaderRefresh; //加载数据 [self getData]; [self.tableView.mj_header endRefreshing]; } -(void)footerRefresh{ //设置获取数据的方式 _getDataType=MyGetDataTypeFooterRefresh; //加载数据 [self getData]; [self.tableView.mj_footer endRefreshing]; } -(void)removeRefreshAction{ self.tableView.mj_header = nil; self.tableView.mj_footer = nil; } -(void)getData{ //判断当前是否正在加载数据。如果正在加载数据,直接return。 if (_IS_LOADING) { return; } _IS_LOADING=YES; //获取第一页数据 NSInteger needLoadPage; needLoadPage=_currentPageNum+1; if (_getDataType==MyGetDataTypeHeaderRefresh) { needLoadPage=1; } //对需要审核的做不同的数据请求 NSArray * questArr = [self getQuestDicAndMethodWithType:self.type page:needLoadPage]; __weak typeof(self) weakSelf = self; [self getDataWithDic:questArr[0] method:questArr[1] block:^(NSDictionary *successDic) { //处理数据 if (_getDataType==MyGetDataTypeHeaderRefresh){ [weakSelf.dataurce removeAllObjects]; } [weakSelf.dataurce addObjectsFromArray:successDic[@"body"]]; if (weakSelf.dataurce.count != 0) { weakSelf.holderV.hidden = YES; _notifyBtn.hidden = NO; } _currentPageNum=needLoadPage; [weakSelf.tableView reloadData]; _getDataType=MyGetDataTypeNomal; }]; } -(NSArray *)getQuestDicAndMethodWithType:(NSString *)type page:(NSInteger)page{ NSMutableDictionary * mDic = [NSMutableDictionary new]; NSString * method = @""; // NSString *needLoadPage = [NSString stringWithFormat:@"%ld",(long)page]; switch ([type integerValue]) { case 3: { [mDic setValue:MYAPPDELEGATE.userDic[@"dqbh"] forKey:@"dqbh"]; [mDic setValue:MYAPPDELEGATE.userDic[@"qxbh"] forKey:@"qxbh"]; [mDic setValue:@"" forKey:@"inscode"];//驾校编号 [mDic setValue:@"" forKey:@"jxmc"]; [mDic setValue:@"1" forKey:@"isPage"]; [mDic setValue:@"10" forKey:@"pageSize"]; [mDic setValue:[NSString stringWithFormat:@"%ld",page] forKey:@"currentPage"]; [mDic setValue:@"0" forKey:@"auditStatus"]; method = @"schools"; } break; case 4: { [mDic setValue:MYAPPDELEGATE.userDic[@"dqbh"] forKey:@"dqbh"]; [mDic setValue:MYAPPDELEGATE.userDic[@"qxbh"] forKey:@"qxbh"]; [mDic setValue:@"" forKey:@"inscode"]; [mDic setValue:@"" forKey:@"coachName"]; [mDic setValue:@"" forKey:@"idcard"]; [mDic setValue:@"1" forKey:@"isPage"]; [mDic setValue:@"10" forKey:@"pageSize"]; [mDic setValue:[NSString stringWithFormat:@"%ld",page] forKey:@"currentPage"]; [mDic setValue:@"0" forKey:@"auditStatus"]; [mDic setValue:@"" forKey:@"phone"]; method = @"coachs"; } break; case 5: { [mDic setValue:MYAPPDELEGATE.userDic[@"dqbh"] forKey:@"dqbh"]; [mDic setValue:MYAPPDELEGATE.userDic[@"qxbh"] forKey:@"qxbh"]; [mDic setValue:@"" forKey:@"inscode"]; [mDic setValue:@"" forKey:@"licNum"]; [mDic setValue:@"1" forKey:@"isPage"]; [mDic setValue:@"10" forKey:@"pageSize"]; [mDic setValue:[NSString stringWithFormat:@"%ld",page] forKey:@"currentPage"]; [mDic setValue:@"0" forKey:@"auditStatus"]; method = @"cars"; } break; case 6: { [mDic setValue:MYAPPDELEGATE.userDic[@"dqbh"] forKey:@"dqbh"]; [mDic setValue:MYAPPDELEGATE.userDic[@"qxbh"] forKey:@"qxbh"]; [mDic setValue:@"" forKey:@"inscode"]; [mDic setValue:@"0" forKey:@"auditStatus"]; [mDic setValue:@"1" forKey:@"isPage"]; [mDic setValue:@"10" forKey:@"pageSize"]; [mDic setValue:[NSString stringWithFormat:@"%ld",(long)page] forKey:@"currentPage"]; method = @"devs"; } break; default: { if ([self.type integerValue] == 1) { self.type = @"0"; }else if ([self.type integerValue] == 7) { self.type = @"8"; } [mDic setObject:MYAPPDELEGATE.userDic[@"id"] forKey:@"userId"]; [mDic setObject:self.type forKey:@"type"]; method = @"getMsgs"; } break; } return @[mDic,method]; } #pragma mark tableView代理方法 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.dataurce.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ switch ([self.type integerValue]) { case 3: { //驾校 WD_DetailSchCell *cell = [WD_DetailSchCell cellForTableView:tableView]; cell.dic = self.dataurce[indexPath.row]; return cell; } break; case 4: { //教练 WD_DetailCoaCell *cell = [WD_DetailCoaCell cellForTableView:tableView]; cell.dic = self.dataurce[indexPath.row]; return cell; } break; case 5: { //车辆 WD_DetailCarCell *cell = [WD_DetailCarCell cellForTableView:tableView]; cell.dic = self.dataurce[indexPath.row]; return cell; } break; case 6: { //终端 WD_DetailDevCell *cell = [WD_DetailDevCell cellForTableView:tableView]; cell.dic = self.dataurce[indexPath.row]; return cell; } break; default: { WD_DetailCell *cell = [WD_DetailCell cellForTableView:tableView]; cell.dic = self.dataurce[indexPath.row]; return cell; } break; } } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ //需要审核的消息 switch ([self.type integerValue]) { case 3: return 140; break; case 4: return 165; break; case 5: return 138; break; case 6: return 165; break; default: break; } //不需要审核的消息 //缓存高度 NSNumber *cellHeight = [_heightArr h_safeObjectAtIndex:indexPath.row]; if (cellHeight) { return [cellHeight floatValue]; }else{ NSDictionary * dic = self.dataurce[indexPath.row]; CGFloat w = self.tableView.frame.size.width-60; NSString *str = [NSString stringWithFormat:@"%@",dic[@"MI_CONTENT"]]; CGFloat h1 = [str heightForWid:w Font:14] + 5; NSString *str2 = [NSString stringWithFormat:@"%@",dic[@"MI_TITLE"]]; CGFloat h2 = [str2 heightForWid:w Font:17] + 5; CGFloat H = 46+h1+h2;//46为其它固定高度 [_heightArr addObject:@(H)]; return H; } } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ //普通消息 NSArray * shenheArr = @[@"3",@"4",@"5",@"6"]; if (![shenheArr containsObject:self.type]) { return; } //审核消息 if (self.tableView.editing) { //当选中cell时,记录其indexPath if (![_selectedIndexPathes containsObject:indexPath]) { [_selectedIndexPathes addObject:indexPath]; } return; } switch ([self.type integerValue]) { case 3: { SchoolDetail * vc = [[SchoolDetail alloc]init]; vc.byWillDo = YES; vc.dataSource = self.dataurce[indexPath.row]; vc.shenheBLock = ^{ [self shenheWithIds:@[self.dataurce[indexPath.row][@"TSI_ID"]]]; }; [self.navigationController pushViewController:vc animated:YES]; } break; case 4: { CoachDetail * vc = [[CoachDetail alloc]init]; vc.byWillDo = YES; vc.dataSource = self.dataurce[indexPath.row]; vc.shenheBLock = ^{ [self shenheWithIds:@[self.dataurce[indexPath.row][@"CI_ID"]]]; }; [self.navigationController pushViewController:vc animated:YES]; } break; case 5: { CarDetail * vc = [[CarDetail alloc]init]; vc.byWillDo = YES; vc.dataSource = self.dataurce[indexPath.row]; vc.shenheBLock = ^{ [self shenheWithIds:@[self.dataurce[indexPath.row][@"TCO_ID"]]]; }; [self.navigationController pushViewController:vc animated:YES]; } break; case 6: { [self showMsgByAlertVCWithString:@"点击右下角图标,选择终端进行审核"]; } break; default: break; } } - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath { //当取消选中cell时,从记录的数组中删除其indexPath if ([_selectedIndexPathes containsObject:indexPath] && self.tableView.editing) { [_selectedIndexPathes removeObject:indexPath]; if (_allBtn.selected) { _allBtn.selected = NO; } } } - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { return UITableViewCellEditingStyleInsert |UITableViewCellEditingStyleDelete; } - (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