// // TCSListVC.m // LN_School // // Created by apple on 2017/12/12. // Copyright © 2017年 Danson. All rights reserved. // #import "TCSListVC.h" #import "RegionsCell.h" #import "NewTrainSiteVC.h" #import "NewClassroomVC.h" #import "NewSignUpPointVC.h" #import "TrainDetailVC.h" #import "ClassDetailVC.h" #import "SignDetailVC.h" @interface TCSListVC () { NSMutableDictionary * _requsetDic; UITableView * _tableView; NSMutableArray *_dataSurce; HolderView * holderV; } @end @implementation TCSListVC - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; if ([_vcType isEqualToString:@"T"]) { self.navigationItem.title = @"训练场地列表"; [Tools permissionValidationWithID:@"2042" view:self.view result:^(BOOL isCan, NSString *failureStr) { if (isCan) { [self customRightBtn]; } }]; }else if ([_vcType isEqualToString:@"C"]) { self.navigationItem.title = @"理论教室列表"; [Tools permissionValidationWithID:@"1246" view:self.view result:^(BOOL isCan, NSString *failureStr) { if (isCan) { [self customRightBtn]; } }]; }else if ([_vcType isEqualToString:@"S"]) { self.navigationItem.title = @"报名点列表"; [Tools permissionValidationWithID:@"1147" view:self.view result:^(BOOL isCan, NSString *failureStr) { if (isCan) { [self customRightBtn]; } }]; } self.navigationController.navigationBar.translucent = NO; [self goBackByNavigation]; _dataSurce = [NSMutableArray new]; _requsetDic = [NSMutableDictionary new]; [self myInit]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self getData]; } -(void)myInit{ _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kSize.width, kSize.height-kNavOffSet)]; _tableView.dataSource = self; _tableView.delegate = self; _tableView.rowHeight = 75; _tableView.tableFooterView = [UIView new]; [self.view addSubview:_tableView]; holderV = [[HolderView alloc]initWithFrame:_tableView.frame]; [holderV freshBlock:^{ [self getData]; }]; [self.view addSubview:holderV]; } -(void)customRightBtn{ UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem]; btn.frame = CGRectMake(0, 0, 43, 44); btn.titleLabel.font = [UIFont systemFontOfSize:17]; [btn setTitle:@"新增" forState:UIControlStateNormal]; [btn setTitleColor:defGreen forState:UIControlStateNormal]; [btn addTarget:self action:@selector(addMoreAction) forControlEvents:UIControlEventTouchUpInside]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn]; } - (void)addMoreAction { // if (!myDelegate.isSchool) { // ShowMsg(@"驾校管理员才可以新增操作"); // return; // } if ([_vcType isEqualToString:@"T"]) { NewTrainSiteVC *vc = [[NewTrainSiteVC alloc] init]; [self.navigationController pushViewController:vc animated:YES]; }else if ([_vcType isEqualToString:@"C"]) { NewClassroomVC *vc = [[NewClassroomVC alloc] init]; [self.navigationController pushViewController:vc animated:YES]; }else if ([_vcType isEqualToString:@"S"]) { NewSignUpPointVC *vc = [[NewSignUpPointVC alloc] init]; [self.navigationController pushViewController:vc animated:YES]; } } #pragma mark tableview代理方法 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return _dataSurce.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath{ RegionsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"]; if (!cell) { cell = [[[NSBundle mainBundle] loadNibNamed:@"RegionsCell" owner:nil options:nil]lastObject]; cell.statusLab.hidden = YES; } [cell upDataWithDic:_dataSurce[indexPath.row]]; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ if ([_vcType isEqualToString:@"T"]) { TrainDetailVC *vc = [[TrainDetailVC alloc] init]; vc.dataSource = _dataSurce[indexPath.row]; [self navPushHideTabbarToVC:vc]; }else if ([_vcType isEqualToString:@"C"]) { ClassDetailVC *vc = [[ClassDetailVC alloc] init]; vc.dataSource = _dataSurce[indexPath.row]; [self navPushHideTabbarToVC:vc]; }else if ([_vcType isEqualToString:@"S"]) { SignDetailVC *vc = [[SignDetailVC alloc] init]; vc.dataSource = _dataSurce[indexPath.row]; [self navPushHideTabbarToVC:vc]; } } #pragma mark 数据请求 - (void)getData{ //判断网络是否连接 if (![NetManager connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableDictionary * mdic = [NSMutableDictionary new]; [mdic setValue:defUser.userDict[@"id"] forKey:@"userId"]; [mdic setValue:defUser.userDict[@"school"] forKey:@"schoolId"]; [mdic setValue:defUser.userDict[@"dqbh"] forKey:@"dqbh"]; [mdic setValue:defUser.userDict[@"qxbh"] forKey:@"qxbh"]; [mdic setValue:@"" forKey:@"isPage"]; [mdic setValue:@"" forKey:@"pageSize"]; [mdic setValue:@"" forKey:@"currentPage"]; NSString *method = @""; if ([_vcType isEqualToString:@"T"]) { [mdic setValue:@"" forKey:@"name"]; method = @"trainingFieldList"; }else if ([_vcType isEqualToString:@"C"]) { [mdic setValue:@"" forKey:@"trName"]; [mdic setValue:@"" forKey:@"trAddress"]; [mdic setValue:@"" forKey:@"type"]; [mdic setValue:@"" forKey:@"auditStatus"]; method = @"theoryRoomList"; }else if ([_vcType isEqualToString:@"S"]) { [mdic setValue:@"" forKey:@"name"]; [mdic setValue:@"" forKey:@"address"]; [mdic setValue:@"" forKey:@"logout"]; method = @"schoolPointList"; } _requsetDic = mdic; [MBProgressHUD showLoadToView:self.view]; [NetManager requestAnythingWithURL:method dictionary:mdic dataArray:nil completion:^(NSDictionary *root) { [MBProgressHUD hideHUDForView:self.view]; holderV.hidden = NO; if (!root) { ShowMsg(@"数据请求失败,请重试"); return; } if ([root[@"code"] integerValue] == 1) { ShowMsg(root[@"msg"]); return; } _dataSurce = root[@"body"]; if (_dataSurce.count > 0) { holderV.hidden = YES; } [_tableView reloadData]; }]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } @end