// // StudentList.m // LNManager // // Created by EchoShacolee on 2017/4/8. // Copyright © 2017年 lee. All rights reserved. // #import "StudentList.h" #import "StudentDetail.h" #import "StudentListCell.h" #import "DateView.h" @interface StudentList () { UITableView *mainTableView; HolderView *holderView; NSInteger currentPage; //查询条件 UIView *backView; UIButton *item; UIButton *subjectBtn,*trainTypeBtn,*oldStuBtn,*beginTimeBtn,*endTimeBtn; UITextField *nameField,*identityNumField,*telPhoneField; UITableView *carTypeTable; NSMutableArray *dataArray; NSArray *carTypeArray; NSMutableArray *selectCarTypeArray; NSString *subject; NSString *trainType; NSString *oldStu; NSString *beginTime; NSString *endTime; NSString *name; NSString *identityNum; NSString *telPhone; } @end @implementation StudentList - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title = @"学员列表"; [self goBackByNavigation]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem]; item = btn; 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(clickToSearch) forControlEvents:UIControlEventTouchUpInside]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn]; currentPage = 1; dataArray = [NSMutableArray array]; selectCarTypeArray = [NSMutableArray array]; carTypeArray = @[@"A1",@"A2",@"A3",@"B1",@"B2",@"C1",@"C2",@"C3",@"C4",@"C5",@"D",@"E",@"F",@"M",@"N",@"p"]; subject = trainType = oldStu = beginTime = endTime = name = identityNum = telPhone = @""; mainTableView = [[UITableView alloc] initWithFrame:kFrame style:UITableViewStylePlain]; mainTableView.height -= kNavOffSet + SafeAreaBottomHeight; mainTableView.delegate = self; mainTableView.dataSource = self; mainTableView.tableFooterView = [UIView new]; // UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 50)]; // headerView.backgroundColor = [UIColor whiteColor]; // CGFloat wid = kSize.width/4.0 - 4.0; // NSArray *titleArray = @[@"姓名",@"性别",@"车型",@"报名日期"]; // for (int i = 0; i < 4; i ++) { // UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(wid * i, 0, wid, 50)]; // label.font = [UIFont systemFontOfSize:18 weight:14]; // label.textAlignment = NSTextAlignmentCenter; // label.text = titleArray[i]; // label.textColor = KTitleColor; // [headerView addSubview:label]; // } // mainTableView.tableHeaderView = headerView; mainTableView.rowHeight = 44; [self.view addSubview:mainTableView]; // [mainTableView registerNib:[UINib nibWithNibName:@"StudentListCell" bundle:nil] forCellReuseIdentifier:@"studentListCell"]; __weak typeof(self) weakSelf = self; MJRefreshBackNormalFooter *mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{ //加载数据 [weakSelf getData]; [mainTableView.mj_footer endRefreshing]; }]; mainTableView.mj_footer = mj_footer; holderView = [[HolderView alloc] initWithFrame:mainTableView.frame]; [holderView freshBlock:^{ [self getData]; }]; [self.view addSubview:holderView]; [self getData]; } - (void)clickToSearch { item.enabled = NO; backView = [[UIView alloc] initWithFrame:kFrame]; backView.backgroundColor = [UIColor colorWithWhite:.1 alpha:.5]; [self.view addSubview:backView]; CGFloat x, y, w, h, bd; x = 20; w = kSize.width - 2*x; h = 460; y = (kSize.height - h - kNavOffSet)/2.0; UIView *searchView = [[UIView alloc] KSetxywh]; searchView.backgroundColor = KBackGroundColor; [searchView borderCornorRadios:5]; [backView addSubview:searchView]; x = y = bd = 10; w = searchView.width - 30; h = 40; NSArray *titles = @[@"学员姓名:",@"证件号:",@"手机号:",@"培训科目:",@"培训车型",@"历史学员",@"开始时间:",@"结束时间:"]; NSArray *textArray = @[name,identityNum,telPhone]; NSString *nameStr = @"输入学员姓名查找"; NSString *identityStr = @"输入学员证件号查找"; NSString *telStr = @"输入学员手机号查找"; NSString *subjectStr = @"请选择培训科目"; switch ([subject integerValue]) { case 1: subjectStr = @"科目一"; break; case 2: subjectStr = @"科目二"; break; case 3: subjectStr = @"科目三"; break; case 4: subjectStr = @"科目四"; break; default: break; } NSString *carTypeStr = @"请选择培训车型"; if (trainType.length > 0) { carTypeStr = trainType; } NSString *oldStuStr = @"查看全部学员"; if ([oldStu isEqualToString:@"0"]) { oldStuStr = @"查看新增学员"; } if ([oldStu isEqualToString:@"1"]) { oldStuStr = @"查看历史学员"; } NSString *beginStr = beginTime; if (beginStr.length < 1) { beginStr = @"请选择开始时间"; } NSString *endStr = endTime; if (endStr.length < 1) { endStr = @"请选择结束时间"; } NSArray *btnTitles = @[nameStr,identityStr,telStr,subjectStr,carTypeStr,oldStuStr,beginStr,endStr]; NSMutableArray *btns = [NSMutableArray array]; for (int i = 0; i < btnTitles.count; i ++) { UIView *backV = [[UIView alloc] initWithFrame:CGRectMake(x, y + i*(h + bd) , w, h)]; [backV borderColor:kLineColor width:2 cornorRadios:5]; [searchView addSubview:backV]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x + bd, y + i*(h + bd) , 100, h)]; [label setText:titles[i] Font:Font16 TextColor:KContentTextColor Alignment:NSTextAlignmentLeft]; [searchView addSubview:label]; if (i < 3) { UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(x + bd + 110, y + i*(h + bd) , w - x - bd - 110, h)]; tf.font = [UIFont scaleSize:Font16]; [tf setReturnKeyType:UIReturnKeyDone]; tf.placeholder = btnTitles[i]; NSString *str = textArray[i]; if (str.length > 0) { tf.text = str; } tf.delegate = self; [searchView addSubview:tf]; [btns addObject:tf]; [tf addViewWithRect:CGRectMake(x + bd + 100, y + i*(h + bd) + 30 , w - x - bd - 100, 1.5) Color:kLineColor]; }else{ UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(x + bd + 100, y + i*(h + bd) , w - x - bd - 100, h)]; [button setTitle:btnTitles[i] textColor:KContentTextColor font:Font16 fotState:UIControlStateNormal]; button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; [button target:self Tag:i - 2]; [searchView addSubview:button]; [btns addObject:button]; } } nameField = btns[0]; identityNumField = btns[1]; telPhoneField = btns[2]; subjectBtn = btns[3]; trainTypeBtn = btns[4]; oldStuBtn = btns[5]; beginTimeBtn = btns[6]; endTimeBtn = btns[7]; y += titles.count*(h + bd); w = (w - 2*bd)/2.0; NSArray *titleArrays = @[@"取消",@"查询"]; for (int i = 0; i < 2; i ++) { UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(x + i*(w + 2*bd), y , w, h)]; [button setTitle:titleArrays[i] textColor:defGreen font:Font16 fotState:UIControlStateNormal]; [button borderColor:kLineColor width:2 cornorRadios:5]; [button target:self Tag:i + titles.count - 2];//6 7 [searchView addSubview:button]; } } - (void)btnClick:(UIButton *)sender { [backView endEditing:YES]; UIButton *btn = (UIButton *)sender; switch (btn.tag) { case 1://科目 { UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"选择培训科目" message:nil preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction * oneAction = [UIAlertAction actionWithTitle:@"科目一" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { subject = @"1"; [btn setTitle:@"科目一" forState:UIControlStateNormal]; }]; UIAlertAction * twoAction = [UIAlertAction actionWithTitle:@"科目二" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { subject = @"2"; [btn setTitle:@"科目二" forState:UIControlStateNormal]; }]; UIAlertAction * threeAction = [UIAlertAction actionWithTitle:@"科目三" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { subject = @"3"; [btn setTitle:@"科目三" forState:UIControlStateNormal]; }]; UIAlertAction * fourAction = [UIAlertAction actionWithTitle:@"科目四" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { subject = @"4"; [btn setTitle:@"科目四" forState:UIControlStateNormal]; }]; UIAlertAction * allAction = [UIAlertAction actionWithTitle:@"全部科目" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { subject = @""; [btn setTitle:@"全部科目" forState:UIControlStateNormal]; }]; [alert addAction:oneAction]; [alert addAction:twoAction]; [alert addAction:threeAction]; [alert addAction:fourAction]; [alert addAction:allAction]; [self presentViewController:alert animated:YES completion:nil]; } break; case 2://车型 { if (!carTypeTable) { carTypeTable = [[UITableView alloc] initWithFrame:CGRectMake(20, (kSize.height - 460 - kNavOffSet)/2.0, kSize.width - 40, 460) style:UITableViewStylePlain]; carTypeTable.delegate = self; carTypeTable.dataSource = self; carTypeTable.rowHeight = 44; //[carTypeTable setEditing:YES]; UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSize.width - 40, 50)]; carTypeTable.tableHeaderView = view; UILabel *label = [[UILabel alloc] initWithFrame:view.frame]; [label setText:@"车型选择" Font:Font18 TextColor:KTitleColor Alignment:NSTextAlignmentCenter]; [view addSubview:label]; // UIButton *doneBtn = [[UIButton alloc] initWithFrame:CGRectMake(kSize.width - 40 - 100, 0, 100, 50)]; // [doneBtn setTitle:@"完成" textColor:defGreen font:Font16 fotState:UIControlStateNormal]; // [doneBtn target:self Tag:10]; // [view addSubview:doneBtn]; } [backView addSubview:carTypeTable]; } break; case 3://历史学员 { UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"是否历史学员" message:nil preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction * oneAction = [UIAlertAction actionWithTitle:@"查看新增学员" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { oldStu = @"0"; [btn setTitle:@"查看新增学员" forState:UIControlStateNormal]; }]; UIAlertAction * twoAction = [UIAlertAction actionWithTitle:@"查看历史学员" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { oldStu = @"1"; [btn setTitle:@"查看历史学员" forState:UIControlStateNormal]; }]; UIAlertAction * threeAction = [UIAlertAction actionWithTitle:@"查看全部学员" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { oldStu = @""; [btn setTitle:@"查看全部学员" forState:UIControlStateNormal]; }]; [alert addAction:oneAction]; [alert addAction:twoAction]; [alert addAction:threeAction]; [self presentViewController:alert animated:YES completion:nil]; } break; case 4://开始时间 { DateView *dateV = [[DateView alloc] init]; [dateV setStyle:0]; [dateV showWithComplete:^(NSString * result) { beginTime = result; [beginTimeBtn setTitle:beginTime forState:UIControlStateNormal]; }]; } break; case 5://结束时间 { DateView *dateV = [[DateView alloc] init]; [dateV setStyle:0]; [dateV showWithComplete:^(NSString * result) { endTime = result; [endTimeBtn setTitle:endTime forState:UIControlStateNormal]; }]; } break; case 6://取消 { if (backView) { [backView removeFromSuperview]; } item.enabled = YES; } break; case 7://查询 { if (backView) { [backView removeFromSuperview]; } item.enabled = YES; currentPage = 1; [dataArray removeAllObjects]; [self getData]; } break; case 10://完成车型选择 { [carTypeTable removeFromSuperview]; trainType = @""; for (NSString *carType in selectCarTypeArray) { trainType = [trainType stringByAppendingString:[NSString stringWithFormat:@"%@,",carType]]; } if (trainType.length > 0) { trainType = [trainType substringToIndex:trainType.length - 1]; } [trainTypeBtn setTitle:trainType forState:UIControlStateNormal]; } break; default: break; } } #pragma mark 数据 -(void)getData{ NSMutableDictionary * mdic = [NSMutableDictionary new]; if (nameField.text.length > 0) { name = nameField.text; }else{ name = @""; } if (identityNumField.text.length > 0) { identityNum = identityNumField.text; }else{ identityNum = @""; } if (telPhoneField.text.length > 0) { telPhone = telPhoneField.text; }else{ telPhone = @""; } [mdic setValue:@"1" forKey:@"isPage"]; [mdic setValue:@"20" forKey:@"pageSize"]; [mdic setValue:[NSString stringWithFormat:@"%d",(int)currentPage] forKey:@"currentPage"]; [mdic setValue:defUser.userDict[@"id"] forKey:@"userId"]; [mdic setValue:defUser.userDict[@"dqbh"] forKey:@"dqbh"]; [mdic setValue:defUser.userDict[@"qxbh"] forKey:@"qxbh"]; [mdic setValue:defUser.userDict[@"school"] forKey:@"school"]; [mdic setValue:@"" forKey:@"isActive"]; [mdic setValue:@"" forKey:@"logout"]; [mdic setValue:@"" forKey:@"sex"]; [mdic setValue:subject forKey:@"subject"]; [mdic setValue:trainType forKey:@"trainType"]; [mdic setValue:name forKey:@"name"]; [mdic setValue:identityNum forKey:@"idcard"]; [mdic setValue:telPhone forKey:@"phone"]; [mdic setValue:beginTime forKey:@"startTime"]; [mdic setValue:endTime forKey:@"endTime"]; [mdic setValue:oldStu forKey:@"historyStu"]; [MBProgressHUD showLoadToView:self.view]; [NetManager requestAnythingWithURL:@"students" dictionary:mdic dataArray:nil completion:^(NSDictionary *root) { [MBProgressHUD hideHUDForView:self.view]; if (!root) { ShowMsg(@"获取学员列表失败,请重试!"); return; } if ([root[@"code"] integerValue] == 1) { ShowMsg(root[@"msg"]); return; } if ([root[@"body"] count] < 1) { if (currentPage > 1) { ShowMsg(@"没有更多数据"); }else { holderView.hidden = NO; } return; } holderView.hidden = YES; currentPage += 1; [dataArray addObjectsFromArray:root[@"body"]]; [mainTableView reloadData]; }]; } #pragma mark tf delegate -(BOOL)textFieldShouldReturn:(UITextField *)textField { [backView endEditing:YES]; return YES; } #pragma mark tableView delegate - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { return UITableViewCellEditingStyleDelete|UITableViewCellEditingStyleInsert; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (tableView == carTypeTable) { return carTypeArray.count; } return dataArray.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if (tableView == carTypeTable) { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; cell.textLabel.textAlignment = NSTextAlignmentCenter; } cell.textLabel.text = carTypeArray[indexPath.row]; return cell; } // StudentListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"studentListCell" forIndexPath:indexPath]; // cell.dataDic = dataArray[indexPath.row]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"]; if (!cell) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellId"]; } cell.textLabel.text = [NSString stringWithFormat:@"%@",dataArray[indexPath.row][@"TSO_NAME"]]; cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",dataArray[indexPath.row][@"TSO_IDCARD"]]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ if (tableView == carTypeTable) {//选中 // if (![selectCarTypeArray containsObject:carTypeArray[indexPath.row]]) { // [selectCarTypeArray addObject:carTypeArray[indexPath.row]]; // } trainType = carTypeArray[indexPath.row]; [trainTypeBtn setTitle:trainType forState:UIControlStateNormal]; [carTypeTable removeFromSuperview]; return; } StudentDetail * vc = [[StudentDetail alloc]init]; vc.dataSource = dataArray[indexPath.row];//传入不再请求数据 [self navPushHideTabbarToVC:vc]; } -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath { if (tableView == carTypeTable) {//移除 if ([selectCarTypeArray containsObject:carTypeArray[indexPath.row]]) { [selectCarTypeArray removeObject:carTypeArray[indexPath.row]]; } return; } } - (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