// #import "ApplyVC.h" #import "STButton.h" #import "applyCell.h" //#import @interface ApplyVC () { NSArray* titles; NSArray *sheetsArray; NSInteger sheetNow; UITextField *tfNow; UITextField *carField; UITextField *identField; UITextField *nameField; UITextField *identHMField; UITextField *dhField; UITextField *iponeField; UITextField *addressField; UITextField *submitField; } @end @implementation ApplyVC - (void)viewDidLoad { [super viewDidLoad]; [self myInit]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - -(void)myInit { [self configNavigationBar]; [self.view setBackgroundColor:[UIColor whiteColor]]; [self setTitle:@"报名"]; self.navigationController.navigationBar.translucent = NO; CGFloat x,y,w,h; UITableView* tv = [[UITableView alloc] initWithFrame:kFrame style:UITableViewStyleGrouped]; [tv setContentInset:UIEdgeInsetsMake(0, 0, kSize.height/2, 0)]; tv.height -= kNavOffSet; [self.view addSubview:tv]; [tv setDelegate:self]; [tv setDataSource:self]; tv.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; titles = @[@[@"车型",@"证件类型"],@[@"姓名",@"证件号码",@"电话",@"手机",@"地址"],/*@[@"验证码"]*/]; x = 0; h = 60; w = kSize.width; y = kSize.height - h - kNavOffSet - kSafeAreaBottomHeight; UIView* vi = [[UIView alloc] initWithFrame:CGRectMake(x, y, w, h)]; [vi setBackgroundColor:backGroundColor]; vi.layer.borderWidth = .5; vi.layer.borderColor = KlineColor.CGColor; [self.view addSubview:vi]; STButton* stBtn = [[STButton alloc] initWithFrame:CGRectMake((kSize.width - 100)/2.0, 0, 100, h)]; [stBtn setImage:[UIImage imageNamed:@"question_correct"] withTitle:@"提交" Font:SmallFont forState:UIControlStateNormal]; [stBtn addTarget:self action:@selector(clickToSubmit) forControlEvents:UIControlEventTouchUpInside]; [stBtn setStyle:1]; [stBtn setTitleColor:contentTextColor forState:UIControlStateNormal]; [vi addSubview:stBtn]; } -(void)clickToSubmitNumber { // if ([iponeField.text isEqualToString:@""] || [identHMField.text isEqualToString:@""]) // { // UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"手机号码或者证件号码为空!" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; // [alert show]; // return; // } // // if (![Util connectedToNetWork]) { // showMsgUnconnect(); // return; // } // // //获取验证码 // [MBProgressHUD showLoadToView:self.view]; // [RQ_SHARE_FUNCTION checkMobPolicyOnResult:^(BOOL success) { // //获取验证码 // [SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:iponeField.text zone:@"86" template:nil result:^(NSError *error) { // [MBProgressHUD hideHUDForView:self.view]; // if (error) { // if (error.code == 477) { // ShowMsg(@"当天验证次数已超上限"); // }else{ // ShowMsg(@"请检查手机号码是否正确"); // } // return; // } // [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"验证码已发送" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil completion:nil]; // }]; // }]; } -(void)clickToSubmit { if ([nameField.text isEqualToString:@""] || [identHMField.text isEqualToString:@""] || [addressField.text isEqualToString:@""] || [iponeField.text isEqualToString:@""] || [submitField.text isEqualToString:@""]) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"信息不完整,请您完善信息" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; [alert show]; return; } if ([identField.text containsString:@"身份证"]) { //身份证验证 NSString *regex2 = @"^(^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$)|(^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])((\\d{4})|\\d{3}[Xx])$)$"; NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex2]; if (![regextestmobile evaluateWithObject:identHMField.text]) { ShowMsg(@"请输入正确的身份证号码"); return; } } NSString * mobil = @"^1(3[0-9]|4[579]|5[0-35-9]|7[01356]|8[0-9])\\d{8}$"; NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", mobil]; if (![regextestmobile evaluateWithObject:iponeField.text]) { ShowMsg(@"请输入正确的手机号"); return; } if ([carField.text isEqualToString:@"C1-小型汽车 >"]) { carField.text = @"C1-小型汽车"; } if ([identField.text isEqualToString:@"身份证 >"]) { identField.text = @"身份证"; } [self submit]; // //验证验证码是否过期 // if (![Util connectedToNetWork]) { // showMsgUnconnect(); // return; // } // // //验证验证码 // [MBProgressHUD showLoadToView:self.view]; // [SMSSDK commitVerificationCode:submitField.text phoneNumber:iponeField.text zone:@"86" result:^(NSError *error) { // // [MBProgressHUD hideHUDForView:self.view]; // if (error) { // //NSLog(@"验证码有误"); // ShowMsg(@"请输入正确验证码"); // } else { // //NSLog(@"验证成功"); // [self submit]; // } // }]; } -(void)submit { //NSLog(@"提交报名信息"); NSMutableArray *arr=[NSMutableArray array]; [arr addPro:@"name" Value:nameField.text]; [arr addPro:@"zjlx" Value:identField.text]; [arr addPro:@"zjhm" Value:[identHMField.text uppercaseString]]; [arr addPro:@"pxcx" Value:[carField.text substringToIndex:2]]; [arr addPro:@"lxdz" Value:addressField.text]; [arr addPro:@"mobile" Value:iponeField.text]; [arr addPro:@"tel" Value:dhField.text]; [arr addPro:@"jxbh" Value:self.jxbh]; [arr addPro:@"jxmc" Value:self.jxmc];//已经改了,字段里是name [arr addPro:@"source" Value:@"3"]; [arr addPro:@"code" Value:submitField.text]; NSString* method = @"uploadStuSignInfo"; [MBProgressHUD showLoadToView:self.view]; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) { [MBProgressHUD hideHUDForView:self.view]; if (!root) { ShowMsgFailed(); return; } if ( 1 == [root[@"code"] integerValue]) { ShowMsg(@"请勿重复报名!"); return; } UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:@"提交成功!" preferredStyle:UIAlertControllerStyleAlert]; [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { [self.navigationController popViewControllerAnimated:YES]; }]]; [self presentViewController:alertFind animated:true completion:nil]; }]; } #pragma mark - tableview delegate -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return .1; } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 25; } -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { // if (section == 0 || section == 1) // { UIView *v = [[UIView alloc] initWithFrame:CGRectZero]; return v; // } // else // { // UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 25)]; // btn.backgroundColor = [UIColor clearColor]; // [btn.titleLabel setFont:[UIFont scaleSize:14]]; // [btn setTitle:@"点击获取验证码" forState:UIControlStateNormal]; // [btn setTitleColor:contentTextColor forState:UIControlStateNormal]; // [btn addTarget:self action:@selector(clickToSubmitNumber) forControlEvents:UIControlEventTouchUpInside]; // return btn; // } } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [titles[section] count]; } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 3; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { applyCell* cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; if (cell == nil) { cell = [[applyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; } NSArray* secArr = titles[indexPath.section]; [cell.titLabel setText:secArr[indexPath.row]]; cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.detailField.delegate = self; if (indexPath.section == 0) { cell.detailField.userInteractionEnabled = NO; cell.detailField.textColor = defGreen; if (indexPath.row == 0) { cell.detailField.text = @"C1-小型汽车 >"; carField = cell.detailField; } else { cell.detailField.text = @"身份证 >"; identField = cell.detailField; } } if (indexPath.section == 1) { cell.detailField.userInteractionEnabled = YES; cell.detailField.textColor = kTitleColor; if (indexPath.row == 0) { cell.detailField.placeholder = @"姓名"; nameField = cell.detailField; } else if (indexPath.row == 1) { cell.detailField.placeholder = @"证件号码"; cell.detailField.keyboardType = UIKeyboardTypeNumbersAndPunctuation; identHMField = cell.detailField; } else if (indexPath.row == 2) { cell.detailField.placeholder = @"固定号码"; cell.detailField.keyboardType = UIKeyboardTypePhonePad; dhField = cell.detailField; } else if (indexPath.row == 3) { cell.detailField.placeholder = @"手机号码"; cell.detailField.keyboardType = UIKeyboardTypePhonePad; iponeField = cell.detailField; } else { cell.detailField.placeholder = @"联系地址"; addressField = cell.detailField; } } // if (indexPath.section == 2) // { // cell.detailField.userInteractionEnabled = YES; // cell.detailField.textColor = kTitleColor; // cell.detailField.placeholder = @"请输入验证码"; // cell.detailField.keyboardType = UIKeyboardTypePhonePad; // submitField = cell.detailField; // } return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { UIActionSheet *myActionSheet; if (indexPath.row == 0) { sheetNow = 0; sheetsArray = @[@"A1-大型客车", @"A2-牵引车",@"A3-城市公交车",@"B1-中型客车",@"B2-大型货车",@"C1-小型汽车",@"C2-小型自动挡汽车",@"C3-低速载货汽车",@"C4-三轮汽车",@"C5-残疾人专用小型自动挡载客汽车",@"D-普通三轮摩托车",@"E-普通二轮摩托车",@"F-轻便摩托车",@"M-轮式自行机械车",@"N-无轨电车",@"P-有轨电车"]; myActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"A1-大型客车", @"A2-牵引车",@"A3-城市公交车",@"B1-中型客车",@"B2-大型货车",@"C1-小型汽车",@"C2-小型自动挡汽车",@"C3-低速载货汽车",@"C4-三轮汽车",@"C5-残疾人专用小型自动挡载客汽车",@"D-普通三轮摩托车",@"E-普通二轮摩托车",@"F-轻便摩托车",@"M-轮式自行机械车",@"N-无轨电车",@"P-有轨电车", nil]; } else { sheetNow = 1; sheetsArray = @[@"身份证",@"军官证",@"士兵证",@"军官离退休证",@"境外人员身份证明",@"外交人员身份证明"]; myActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"身份证",@"军官证",@"士兵证",@"军官离退休证",@"境外人员身份证明",@"外交人员身份证明", nil]; } [myActionSheet showInView:self.view]; } else { if (tfNow) { [tfNow resignFirstResponder]; } } } -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{ [self.view endEditing:YES]; } #pragma mark - -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { if (buttonIndex == actionSheet.cancelButtonIndex) { return; } if (sheetNow == 0) { carField.text = sheetsArray[buttonIndex]; } else { identField.text = sheetsArray[buttonIndex]; } } -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField { tfNow = textField; return YES; } -(BOOL)textFieldShouldReturn:(UITextField *)textField { [textField endEditing:YES]; return YES; } @end