// // KXMainWebViewController.m // QBCS // // Created by kuxuan on 2017/7/10. // Copyright © 2017年 kuxuan. All rights reserved. // #import "KXThirdWebViewController.h" #import "KXSelectTableViewCell.h" #import "KXLogginViewController.h" #import "KXUserIdentificationContronller.h" @interface KXThirdWebViewController () { UIView *_selectView; BOOL _selected; } @property (nonatomic,strong)UITableView *selectTableView; @property (nonatomic,strong)NSArray *careerArray; @property (nonatomic,strong)NSArray *incomellArray; @property (nonatomic,copy)NSString *Id; @end @implementation KXThirdWebViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self initNavBar]; [self initUpUIview]; [self createviewSelectView]; } -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; // [self checkLog]; } -(void)initNavBar { self.navigationController.navigationBar.hidden=NO; self.name=@"贷款申请"; [self addLeftBarButtonItemWithImageName:@"main_back" title:nil target:self selector:@selector(beforeAction)]; } -(void)beforeAction { UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"离开" message:@"现在离开将不会保存所填写信息,确认离开吗?" preferredStyle:UIAlertControllerStyleAlert]; [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [self.navigationController popViewControllerAnimated:YES]; }]]; [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { }]]; [self presentViewController:alertController animated:YES completion:nil]; } -(void)initUpUIview { // -64-49 UIScrollView *scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-64)]; scrollView.showsVerticalScrollIndicator=NO; scrollView.showsHorizontalScrollIndicator=NO; if(536*SCREEN_MUTI>SCREEN_HEIGHT-64){ scrollView.contentSize=CGSizeMake(SCREEN_WIDTH, 536*SCREEN_MUTI); }else{ scrollView.contentSize=CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT-63); } scrollView.backgroundColor=[UIColor background]; [self.view addSubview:scrollView]; UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 130*SCREEN_MUTI)]; imageView.image=[UIImage imageNamed:@"main_apply"]; [scrollView addSubview:imageView]; UILabel *lineLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, 130*SCREEN_MUTI, SCREEN_WIDTH, SCREEN_MUTI)]; lineLabel.backgroundColor=[UIColor lineColor1]; [scrollView addSubview:lineLabel]; UIView *whiteView=[[UIView alloc]initWithFrame:CGRectMake(14*SCREEN_MUTI, 140*SCREEN_MUTI, SCREEN_WIDTH-2*14*SCREEN_MUTI, 300*SCREEN_MUTI)]; whiteView.backgroundColor=[UIColor whiteColor]; whiteView.layer.cornerRadius=3; whiteView.layer.masksToBounds = YES; whiteView.layer.borderWidth = SCREEN_MUTI; whiteView.layer.borderColor =[[UIColor lineColor1]CGColor]; [scrollView addSubview:whiteView]; NSArray *infoArray=@[@"name",@"age",@"phone",@"work",@"income"]; NSArray *titleArray=@[@"真实姓名",@"年 龄",@"联系方式",@"职 业",@"月 收 入"]; NSArray *placeholderArray=@[@"请输入真实姓名",@"请输入年龄",@"请输入联系方式"]; CGFloat width=0; NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:16],}; for(NSString* title in titleArray){ CGFloat width1=[title boundingRectWithSize:CGSizeMake(0, 0) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size.width; if(width1>width){ width=width1; } } for (int i=0; i<5; i++) { UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(20*SCREEN_MUTI, (20+(60*i))*SCREEN_MUTI, 22*SCREEN_MUTI, 22*SCREEN_MUTI)]; imageView.image=[UIImage imageNamed:[NSString stringWithFormat:@"userinfo_%@",infoArray[i]]]; [whiteView addSubview:imageView]; UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(52*SCREEN_MUTI, (60*i+1)*SCREEN_MUTI, width,60*SCREEN_MUTI)]; label.text=titleArray[i]; label.textColor=[UIColor titleColor]; label.font=FONT_SYS(16); [whiteView addSubview:label]; if(i<4){ UILabel *lineLabel=[[UILabel alloc]initWithFrame:CGRectMake(14, (60*(i+1)+1)*SCREEN_MUTI, SCREEN_WIDTH-2*28*SCREEN_MUTI, SCREEN_MUTI)]; lineLabel.backgroundColor=[UIColor lineColor1]; [whiteView addSubview:lineLabel]; } } for (int i=0; i<3; i++) { UITextField *tf=[[UITextField alloc]initWithFrame:CGRectMake( (52+width+34)*SCREEN_MUTI, (60*i+1)*SCREEN_MUTI, SCREEN_WIDTH-(52+width+34)*SCREEN_MUTI, 60*SCREEN_MUTI)]; tf.tag=666+i; tf.textColor=[UIColor detailTitleColor]; tf.placeholder=placeholderArray[i]; tf.font=FONT_SYS(16); if(i!=0){ tf.keyboardType = UIKeyboardTypeNamePhonePad; tf.delegate=self; } [whiteView addSubview:tf]; } NSArray *buttonArray=@[@"请选择职业身份",@"请选择月收入"]; for (int i=0; i<2; i++) { UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom]; button.frame=CGRectMake((52+width+34)*SCREEN_MUTI, 60*(i+3)*SCREEN_MUTI, SCREEN_WIDTH-(86+width)*SCREEN_MUTI, 60*SCREEN_MUTI); [button setTitle:buttonArray[i] forState:UIControlStateNormal]; button.titleLabel.font=FONT_SYS(16); button.tag=8989+i; [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; button.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft; [button setTitleColor:[UIColor titleColor] forState:UIControlStateNormal]; [whiteView addSubview:button]; } UIButton *next=[UIButton buttonWithType:UIButtonTypeCustom]; next.frame=CGRectMake(14*SCREEN_MUTI,466*SCREEN_MUTI, SCREEN_WIDTH-28*SCREEN_MUTI, 44*SCREEN_MUTI); next.layer.cornerRadius=3; next.tag=999; next.layer.masksToBounds=YES; next.backgroundColor=[UIColor baseColor]; next.titleLabel.font=FONT_SYS(16); [next setTitle:@"下一步" forState:UIControlStateNormal]; [next setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [next addTarget:self action:@selector(nextllAction) forControlEvents:UIControlEventTouchUpInside]; [scrollView addSubview:next]; } -(void)buttonAction:(UIButton *)btn { switch (btn.tag) { case 8989: { _selected=YES; [self.selectTableView reloadData]; } break; case 8990: { _selected=NO; [self.selectTableView reloadData]; } break; default: break; } _selectView.hidden=NO; } //-(void)checkLog //{ // UITextField *nameTF=[self.view viewWithTag:666]; // UITextField *ageTF=[self.view viewWithTag:667]; //// UITextField *identityTF=[self.view viewWithTag:668]; // UITextField *cell_numTF=[self.view viewWithTag:668]; // UIButton *careerBtn=[self.view viewWithTag:8989]; // UIButton *incomeBtn=[self.view viewWithTag:8990]; // UIButton *nextBtn=[self.view viewWithTag:999]; // // NSString *urlString=[NSString stringWithFormat:@"%@/user/personalCenter",URL]; // [KXHTTP post:urlString params:nil success:^(id json) { // if ([[json[@"user"] valueForKey:@"user_level_id"] isEqual:@(YES)]) { // [nextBtn setTitle:@"审核中..." forState:UIControlStateNormal]; // nameTF.enabled=NO; // ageTF.enabled=NO; //// identityTF.enabled=NO; // cell_numTF.enabled=NO; // incomeBtn.enabled=NO; // careerBtn.enabled=NO; // NSString *urlSt=[NSString stringWithFormat:@"%@/user/getIosApplyById",URL]; // [KXHTTP post:urlSt params:@{@"id":[json[@"user"] valueForKey:@"id"]} success:^(id json) { // nameTF.text=json[@"name"]; // ageTF.text=json[@"age"]; //// identityTF.text=json[@"identity"]; // cell_numTF.text=json[@"cell_num"]; // [incomeBtn setTitle:json[@"monthly_income"] forState:UIControlStateNormal]; // [careerBtn setTitle:json[@"occupation"] forState:UIControlStateNormal]; // } failure:^(NSError *error) { // // }]; // }else{ // [nextBtn setTitle:@"下一步" forState:UIControlStateNormal]; // nameTF.enabled=YES; // ageTF.enabled=YES; //// identityTF.enabled=YES; // cell_numTF.enabled=YES; // incomeBtn.enabled=YES; // careerBtn.enabled=YES; // nameTF.text=@""; // ageTF.text=@""; //// identityTF.text=@""; // cell_numTF.text=@""; // [incomeBtn setTitle:@"请选择月收入" forState:UIControlStateNormal]; // [careerBtn setTitle:@"请选择职业身份" forState:UIControlStateNormal]; // } // } failure:^(NSError *error) { // // }]; //} -(void)nextllAction { UITextField *nameTF=[self.view viewWithTag:666]; UITextField *ageTF=[self.view viewWithTag:667]; // UITextField *identityTF=[self.view viewWithTag:668]; UITextField *cell_numTF=[self.view viewWithTag:668]; UIButton *careerBtn=[self.view viewWithTag:8989]; UIButton *incomeBtn=[self.view viewWithTag:8990]; UIButton *nextBtn=[self.view viewWithTag:999]; nextBtn.enabled=NO; if ([nextBtn.titleLabel.text isEqualToString:@"审核中..."]) { [self createPromptWhit:@"不要着急,请耐心等待审核......"]; return; } NSString *urlString=[NSString stringWithFormat:@"%@/user/personalCenter",URL]; [KXHTTP post:urlString params:nil success:^(id json) { NSString *username= [[NSUserDefaults standardUserDefaults]valueForKey:USER_NAME]; NSString *password=[[NSUserDefaults standardUserDefaults]valueForKey:USER_PASSWORD]; if (!username||!password) { UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"请登录" preferredStyle:UIAlertControllerStyleAlert]; [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { KXLogginViewController *loggin=[[KXLogginViewController alloc]init]; [self.navigationController pushViewController:loggin animated:YES]; [[NSUserDefaults standardUserDefaults]setObject:nil forKey:@"ISPOP"]; [[NSUserDefaults standardUserDefaults]synchronize]; }]]; [self presentViewController:alertController animated:YES completion:nil]; }else{ nextBtn.enabled=YES; if(nameTF.text.length==0){ [self createPromptWhit:@"填入真实姓名后在试"]; return; } if(ageTF.text.length==0){ [self createPromptWhit:@"请填入年龄后在试"]; return; } if(cell_numTF.text.length==0){ [self createPromptWhit:@"请填入联系方式后在试"]; return; } if([careerBtn.titleLabel.text isEqualToString:@"请选择职业身份"]){ [self createPromptWhit:@"请选择职业后在试"]; nextBtn.enabled=YES; return; } if([incomeBtn.titleLabel.text isEqualToString:@"请选择月收入"]){ [self createPromptWhit:@"请选择月收入后在试"]; return; } NSDictionary *userDict=json[@"user"]; // NSDictionary *para=@{@"information_id":self.ID,@"user_id":userDict[@"id"]}; KXUserIdentificationContronller *identification=[[KXUserIdentificationContronller alloc]init]; NSDictionary *paraDict=@{@"id":userDict[@"id"],@"amount":@(_amount),@"term":@(_term),@"name":nameTF.text,@"age":ageTF.text,@"cell_num":cell_numTF.text,@"occupation":careerBtn.titleLabel.text,@"monthly_income":incomeBtn.titleLabel.text}; identification.paraDict=paraDict; [self.navigationController pushViewController:identification animated:YES]; } } failure:^(NSError *error) { nextBtn.enabled=YES; }]; } -(void)createPromptWhit:(NSString*) message{ UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:message preferredStyle:UIAlertControllerStyleAlert]; [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { }]]; [self presentViewController:alertController animated:YES completion:nil]; } -(void)createviewSelectView { _selectView=[[UIView alloc]initWithFrame:self.view.bounds]; _selectView.hidden=YES; _selectView.backgroundColor=[UIColor colorWithWhite:0 alpha:0.5]; UITapGestureRecognizer *tapGesturRecognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hiddenAction:)]; tapGesturRecognizer.delegate = self; [_selectView addGestureRecognizer:tapGesturRecognizer]; [self.view addSubview:_selectView]; self.selectTableView = [[UITableView alloc]initWithFrame:CGRectMake(0,SCREEN_HEIGHT-220-64, SCREEN_WIDTH, 220) style:UITableViewStylePlain]; self.selectTableView.separatorStyle=UITableViewCellSeparatorStyleNone; [self.selectTableView registerClass:[KXSelectTableViewCell class] forCellReuseIdentifier:@"selected"]; self.selectTableView.tableFooterView=[[UIView alloc]init]; tapGesturRecognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hiddenAction:)]; tapGesturRecognizer.delegate = self; [_selectView addGestureRecognizer:tapGesturRecognizer]; [self.selectTableView addGestureRecognizer:tapGesturRecognizer]; self.selectTableView.delegate = self; self.selectTableView.dataSource = self; [_selectView addSubview:self.selectTableView]; } - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { if ([touch.view isKindOfClass:[UITableView class]]) { return YES; }else if([touch.view isMemberOfClass:[UIView class]]){ return YES; } return NO; } -(void)hiddenAction:(UIGestureRecognizer*) g{ _selectView.hidden=YES; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (_selected==YES) { return self.careerArray.count; }else{ return self.incomellArray.count; } } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { KXSelectTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"selected"]; if (!cell) { cell=[[KXSelectTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"selected"]; } if (_selected==YES) { cell.detailStr=self.careerArray[indexPath.row]; }else{ cell.detailStr=self.incomellArray[indexPath.row]; } return cell; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath { return 45; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (_selected==YES) { UIButton *button=[self.view viewWithTag:8989]; [button setTitle:self.careerArray[indexPath.row] forState:UIControlStateNormal]; }else{ UIButton *button=[self.view viewWithTag:8990]; [button setTitle:self.incomellArray[indexPath.row] forState:UIControlStateNormal]; } _selectView.hidden=YES; } -(NSArray *)careerArray { if (!_careerArray) { _careerArray=@[@"上班族",@"个体户",@"企业主",@"自由职业"]; } return _careerArray; } -(NSArray *)incomellArray { if (!_incomellArray) { _incomellArray=@[@"1000以下",@"1000-3000",@"3000-5000",@"5000-7000",@"7000-10000",@"1万-3万",@"3万-5万",@"5万以上"]; } return _incomellArray; } //- (BOOL)isPureInt:(NSString*)string{ // NSScanner* scan = [NSScanner scannerWithString:string]; // int val; // return[scan scanInt:&val] && [scan isAtEnd]; //} // //- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string //{ // if([self isPureInt:string]){ // return YES; // } // return NO; //} - (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