// // ApplyQuit.m // LN_School // // Created by EchoShacolee on 2017/4/20. // Copyright © 2017年 Danson. All rights reserved. // #import "ApplyQuit.h" #import "applyCell.h" #import "QuitTextViewCell.h" @interface ApplyQuit () { UITableView * _tableView; NSArray *_titles; NSArray *_dataArr; NSMutableArray *_sheetsArray; NSArray *_auditUserInfo; NSArray *_placeholders; } @end @implementation ApplyQuit - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title = @"退学申请"; self.navigationController.navigationBar.translucent = NO; self.view.backgroundColor = KBackGroundColor; [self goBackByNavigation]; [self myInit]; [self getAuditUserInfo]; } -(void)myInit{ //@RQ-MARK 1.0.2修改:“退学申请”模块审核人移除 _titles = @[@[@"学员证件号",@"报名费用",@"已收金额",@"应退款金额"],@[@"退学原因"]]; _dataArr = @[[NSMutableArray arrayWithArray:@[@"请输入学员证件号",@"请填写报名费用",@"请填写已收金额",@"请填写应退款金额"]], [NSMutableArray arrayWithArray:@[@""]]//请输入退学原因 ]; _placeholders = [NSArray arrayWithArray:_dataArr[0]]; _sheetsArray = [NSMutableArray arrayWithArray:@[@"无"]]; _auditUserInfo = [NSArray array]; _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kSize.width, kSize.height-kNavOffSet) style:UITableViewStyleGrouped]; _tableView.dataSource = self; _tableView.delegate = self; _tableView.estimatedSectionHeaderHeight = 0; _tableView.estimatedSectionFooterHeight = 0; [self.view addSubview:_tableView]; UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 100)]; UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(10, 25, kSize.width - 20, 50)]; btn.backgroundColor = RQMianColor; [btn borderCornorRadios:5]; [btn setTitle:@"提交" textColor:[UIColor whiteColor] font:Font18 fotState:UIControlStateNormal]; [btn target:self Tag:1]; [view addSubview:btn]; _tableView.tableFooterView = view; } - (void)btnClick:(UIButton *)sender { [self.view endEditing:YES]; [self quitSchool]; } #pragma mark tableview代理方法 -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return _titles.count; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [_titles[section] count]; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.section == 1) { return 106; } return 44; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { //textView if (indexPath.section == 1) { QuitTextViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellID"]; if (!cell) { cell = [[[NSBundle mainBundle]loadNibNamed:@"QuitTextViewCell" owner:nil options:nil]lastObject]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } cell.textView.delegate = self; return cell; } applyCell* cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; if (cell == nil) { cell = [[applyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } [cell.titLabel setText:[_titles[indexPath.section] objectAtIndex:indexPath.row]]; NSArray *detailArray = _dataArr[indexPath.section]; cell.detailField.delegate = self; cell.detailField.keyboardType = UIKeyboardTypeNumberPad; cell.detailField.tag = indexPath.section * 10 + indexPath.row; if (indexPath.section == 0) { cell.detailField.userInteractionEnabled = YES; if ([_placeholders containsObject:detailArray[indexPath.row]]) { cell.detailField.placeholder = detailArray[indexPath.row]; }else { cell.detailField.textColor = KTitleColor; cell.detailField.text = detailArray[indexPath.row]; } } return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self.view endEditing:YES]; } -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return .1; } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 25; } -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { //NSLog(@"1"); [self.view endEditing:YES]; } #pragma mark textField -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField { NSIndexPath *indexpath = indexpath= [NSIndexPath indexPathForRow:textField.tag%10 inSection:textField.tag/10];; //获取当前cell在tableview中的位置 CGRect rectintableview=[_tableView rectForRowAtIndexPath:indexpath]; [_tableView setContentOffset:CGPointMake(_tableView.contentOffset.x,rectintableview.origin.y-25) animated:YES]; return YES; } -(BOOL)textFieldShouldEndEditing:(UITextField *)textField { NSString *textString = textField.text; if (textString.length < 1) { textString = _placeholders[textField.tag]; } NSMutableArray *array = _dataArr[textField.tag/10]; [array replaceObjectAtIndex:textField.tag%10 withObject:textString]; [_tableView reloadData]; return YES; } -(BOOL)textFieldShouldReturn:(UITextField *)textField { [textField endEditing:YES]; return YES; } #pragma mark textview代理 -(BOOL)textViewShouldBeginEditing:(UITextView *)textView{ NSIndexPath *indexpath= [NSIndexPath indexPathForRow:0 inSection:2]; //获取当前cell在tableview中的位置 CGRect rectintableview=[_tableView rectForRowAtIndexPath:indexpath]; [_tableView setContentOffset:CGPointMake(_tableView.contentOffset.x,rectintableview.origin.y-25)]; return YES; } - (BOOL)textViewShouldEndEditing:(UITextView *)textView{ NSString * str = textView.text; [_dataArr[1] replaceObjectAtIndex:0 withObject:str]; return YES; } - (void)textViewDidChange:(UITextView *)textView{ NSString * str = textView.text; [_dataArr[1] replaceObjectAtIndex:0 withObject:str]; return; } #pragma mark 网络请求 -(void)getAuditUserInfo{ // if (![NetManager connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableDictionary * dic = [NSMutableDictionary new]; [dic setObject:defUser.userDict[@"school"] forKey:@"schoolId"]; [NetManager requestAnythingWithURL:@"getAuditUserInfo" dictionary:dic dataArray:nil completion:^(NSDictionary *root) { if (!root) { ShowErrorMsg(@"请求失败!"); return; } if ([root[@"code"] isEqualToString:@"1"]) { ShowErrorMsg(root[@"msg"]); NSLog(@"%@",root[@"msg"]); return; } _auditUserInfo = root[@"body"]; [_sheetsArray removeAllObjects]; for (NSDictionary * dic in _auditUserInfo) { [_sheetsArray addObject:dic[@"text"]]; } }]; } -(void)quitSchool{ for (NSString *str in _dataArr[0]) { if (str.length == 0 || [_placeholders containsObject:str]) { ShowMsg(@"请填写完整信息"); return; } } for (NSString *str in _dataArr[1]) { if (str.length == 0) { ShowMsg(@"请填写完整信息"); return; } } // if (![NetManager connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableDictionary *dic = [NSMutableDictionary dictionary]; [dic setObject:defUser.userDict[@"id"] forKey:@"userId"]; [dic setObject:_dataArr[0][0] forKey:@"idcard"]; [dic setObject:_dataArr[0][1] forKey:@"price"]; [dic setObject:_dataArr[0][2] forKey:@"priceIn"]; [dic setObject:_dataArr[0][3] forKey:@"priceOut"]; [dic setObject:_dataArr[1][0] forKey:@"reason"]; // [dic setObject:@"" forKey:@"auditUser"]; [NetManager requestAnythingWithURL:@"quitSchool" dictionary:dic dataArray:nil completion:^(NSDictionary *root) { if (!root) { ShowErrorMsg(@"请求失败!"); return; } if ([root[@"code"] isEqualToString:@"1"]) { ShowErrorMsg(root[@"msg"]); NSLog(@"%@",root[@"msg"]); return; } ShowMsg(@"登记成功"); if (self.blcok) { self.blcok(); } [self.navigationController popViewControllerAnimated:YES]; }]; } #pragma mark - 限制输入字符 -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{ if (textField.tag == 0 && range.location >= 18) { return NO; } if (textField.tag != 0 && range.location >= 5) { return NO; } return YES; } @end