// // KXMainWebViewController.m // QBCS // // Created by kuxuan on 2017/7/10. // Copyright © 2017年 kuxuan. All rights reserved. // #import "KXMainWebViewController.h" #import "KXSelectTableViewCell.h" #import "KXLogginViewController.h" #import "KXNextStepViewController.h" @interface KXMainWebViewController () { UIView *_selectView; BOOL _selected; } @property (nonatomic,strong)UITableView *selectTableView; @property (nonatomic,strong)NSArray *careerArray; @property (nonatomic,strong)NSArray *incomeArray; @property (nonatomic,copy)NSString *Id; @property (nonatomic,assign)BOOL agreeBool; @property (nonatomic,strong)UIView *backView; @property (nonatomic,strong)UIView *topView; @property (nonatomic,strong)NSArray *protocolArray; @end @implementation KXMainWebViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.name=@"申请"; self.agreeBool=YES; [self setupUIview]; [self createSelectView]; [self addViews]; } -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self checkLog]; } -(void)addViews{ [self.view addSubview:self.backView]; [self.view addSubview:self.topView]; self.topView.hidden=YES; self.backView.hidden=YES; } -(void)setupUIview { UIScrollView *scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-64)]; scrollView.showsVerticalScrollIndicator=NO; scrollView.showsHorizontalScrollIndicator=NO; scrollView.contentSize=CGSizeMake(SCREEN_WIDTH, 690); [self.view addSubview:scrollView]; UIImageView *bannerIV=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"main_banner"]]; bannerIV.frame=CGRectMake(0, 0, SCREEN_WIDTH, 90); [scrollView addSubview:bannerIV]; UIView *whiteView=[[UIView alloc]initWithFrame:CGRectMake(0, 90, SCREEN_WIDTH, 350)]; whiteView.backgroundColor=[UIColor whiteColor]; [scrollView addSubview:whiteView]; NSArray *titleArray=@[@"真实姓名",@"年 龄",@"联系方式",@"贷款金额",@"贷款期限",@"职 业",@"月 收 入"]; NSArray *placeholderArray=@[@"请输入真实姓名",@"请输入年龄",@"请输入联系方式",@"请输入贷款金额",@"请输入贷款期限(月)"]; for (int i=0; i<7; i++) { UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(14, 50*i, 100, 50)]; label.text=titleArray[i]; label.textColor=[UIColor titleColor]; label.font=FONT_SYS(16); [whiteView addSubview:label]; UILabel *lineLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, 50*(i+1), SCREEN_WIDTH, 1)]; lineLabel.backgroundColor=[UIColor lineColor]; [whiteView addSubview:lineLabel]; } for (int i=0; i<5; i++) { UITextField *tf=[[UITextField alloc]initWithFrame:CGRectMake(120, 50*i, SCREEN_WIDTH-140, 50)]; tf.tag=666+i; tf.textColor=[UIColor detailTitleColor]; tf.placeholder=placeholderArray[i]; tf.font=FONT_SYS(16); [whiteView addSubview:tf]; } NSArray *buttonArray=@[@"请选择职业身份",@"请选择月收入"]; for (int i=0; i<2; i++) { UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom]; button.frame=CGRectMake(120, 50*i+250, SCREEN_WIDTH-140, 50); [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 *agreeButton=[UIButton buttonWithType:UIButtonTypeCustom]; agreeButton.frame=CGRectMake(0, 0, 16, 16); agreeButton.tag=2000; [agreeButton addTarget:self action:@selector(agreeAction:) forControlEvents:UIControlEventTouchUpInside]; agreeButton.selected=YES; [agreeButton setImage:[UIImage imageNamed:@"disagree_protocol"] forState:UIControlStateNormal]; [agreeButton setImage:[UIImage imageNamed:@"agree_protocol"] forState:UIControlStateSelected]; UIView *protocolView=[[UIView alloc]init]; protocolView.frame=CGRectMake(0, 0, 240, 20); for (int i=0; i<3; i++) { UIButton *button=[[UIButton alloc]init]; button.titleLabel.font=[UIFont systemFontOfSize:12.0f]; [button addTarget:self action:@selector(protocolAction:) forControlEvents:UIControlEventTouchUpInside]; [button setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal]; button.tag=1000+i; switch (i) { case 0: { [button setTitle:@"《委托授权协议》" forState:UIControlStateNormal]; button.frame=CGRectMake(0, -3, 100, 20); } break; case 1: { [button setTitle:@"《借款协议》" forState:UIControlStateNormal]; button.frame=CGRectMake(90, -3, 65, 20); } break; case 2: { [button setTitle:@"《平台服务协议》" forState:UIControlStateNormal]; button.frame=CGRectMake(90+65, -3, 70, 20); } break; default: break; } [button sizeToFit]; [protocolView addSubview:button]; } // protocolView.backgroundColor=[UIColor redColor]; UITextField *protocolText=[[UITextField alloc]init]; protocolText.text=@"同意"; protocolText.font = [UIFont systemFontOfSize:12.0]; protocolText.textAlignment=NSTextAlignmentCenter; protocolText.leftView=agreeButton; protocolText.leftViewMode=UITextFieldViewModeAlways; protocolText.rightView=protocolView; protocolText.rightViewMode=UITextFieldViewModeAlways; [scrollView addSubview:protocolText]; UIButton *next=[UIButton buttonWithType:UIButtonTypeCustom]; next.frame=CGRectMake(14,480, SCREEN_WIDTH-28, 45); next.layer.cornerRadius=6; 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(nextAction) forControlEvents:UIControlEventTouchUpInside]; [scrollView addSubview:next]; UILabel *littleLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, 525, SCREEN_WIDTH, 30)]; littleLabel.text=[NSString stringWithFormat:@"由%@出品为您提供高品质金融服务",KXCOMPANY]; littleLabel.textColor=[UIColor detailTitleColor]; littleLabel.textAlignment=NSTextAlignmentCenter; littleLabel.font=FONT_SYS(12); littleLabel.numberOfLines=0; [scrollView addSubview:littleLabel]; [protocolText mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(240+16+45);// make.height.mas_equalTo(20); make.top.equalTo(whiteView.mas_bottom).offset(10); make.left.equalTo(scrollView.mas_left).offset(16); }]; } -(void)agreeAction:(UIButton *)sender{ self.agreeBool=!self.agreeBool; sender.selected=self.agreeBool; } -(void)protocolAction:(UIButton *)sender{ self.backView.hidden=NO; self.topView.hidden=NO; long indexSender=sender.tag-1000; UILabel *titleLabel=[self.topView viewWithTag:764]; titleLabel.text=sender.titleLabel.text; UIWebView *content=[self.topView viewWithTag:766]; content.delegate=self; NSString *path = [[NSBundle mainBundle] bundlePath]; NSURL *baseURL = [NSURL fileURLWithPath:path]; NSString * htmlPath = [[NSBundle mainBundle] pathForResource:self.protocolArray[indexSender][@"html"] ofType:@"html"]; // NSLog(@"--%@--%@--",self.protocolArray[indexSender][@"html"],htmlPath); NSString * htmlCont = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil]; [content loadHTMLString:htmlCont baseURL:baseURL]; } -(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 *cell_numTF=[self.view viewWithTag:668]; UITextField *amountTF=[self.view viewWithTag:669]; UITextField *termTF=[self.view viewWithTag:670]; 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; cell_numTF.enabled=NO; amountTF.enabled=NO; termTF.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"]; cell_numTF.text=json[@"cell_num"]; amountTF.text=json[@"amount"]; termTF.text=json[@"term"]; [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; cell_numTF.enabled=YES; incomeBtn.enabled=YES; careerBtn.enabled=YES; amountTF.enabled=YES; termTF.enabled=YES; nameTF.text=@""; ageTF.text=@""; amountTF.text=@""; termTF.text=@""; cell_numTF.text=@""; [incomeBtn setTitle:@"请选择月收入" forState:UIControlStateNormal]; [careerBtn setTitle:@"请选择职业身份" forState:UIControlStateNormal]; } } failure:^(NSError *error) { }]; } -(void)nextAction { UITextField *nameTF=[self.view viewWithTag:666]; UITextField *ageTF=[self.view viewWithTag:667]; UITextField *cell_numTF=[self.view viewWithTag:668]; UITextField *amountTF=[self.view viewWithTag:669]; UITextField *termTF=[self.view viewWithTag:670]; UIButton *careerBtn=[self.view viewWithTag:8989]; UIButton *incomeBtn=[self.view viewWithTag:8990]; UIButton *nextBtn=[self.view viewWithTag:999]; if (!nameTF.text||!ageTF.text||!cell_numTF.text||!amountTF.text||!termTF.text||[careerBtn.titleLabel.text isEqualToString:@"请选择职业身份"]||[incomeBtn.titleLabel.text isEqualToString:@"请选择月收入"]) { UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"请正确输入内容" preferredStyle:UIAlertControllerStyleAlert]; [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { }]]; [self presentViewController:alertController animated:YES completion:nil]; return; } if ([nextBtn.titleLabel.text isEqualToString:@"审核中..."]) { UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:[NSString stringWithFormat:@"%@正在为您审核,请耐心等待",KXCOMPANY_SERVICE] preferredStyle:UIAlertControllerStyleAlert]; [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { }]]; [self presentViewController:alertController animated:YES completion:nil]; return; } NSString *urlString=[NSString stringWithFormat:@"%@/user/personalCenter",URL]; [KXHTTP post:urlString params:nil success:^(id json) { NSString *username= [[NSUserDefaults standardUserDefaults]valueForKey:USER_NAME]; if (!username) { 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 if (!self.agreeBool){//请勾选同意协议 UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"请勾选同意协议" preferredStyle:UIAlertControllerStyleAlert]; [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [[NSUserDefaults standardUserDefaults]setObject:nil forKey:@"ISPOP"]; [[NSUserDefaults standardUserDefaults]synchronize]; }]]; [self presentViewController:alertController animated:YES completion:nil]; nextBtn.enabled=YES; }else{ KXNextStepViewController *next=[[KXNextStepViewController alloc]init]; next.personName=nameTF.text; next.age=ageTF.text; next.cell=cell_numTF.text; next.amount=amountTF.text; next.term=termTF.text; next.occupation=careerBtn.titleLabel.text; next.income=incomeBtn.titleLabel.text; [self.navigationController pushViewController:next animated:YES]; } } failure:^(NSError *error) { }]; } -(void)createSelectView { _selectView=[[UIView alloc]initWithFrame:self.view.bounds]; _selectView.hidden=YES; _selectView.backgroundColor=[UIColor colorWithWhite:0 alpha:0.5]; [self.view addSubview:_selectView]; self.selectTableView = [[UITableView alloc]initWithFrame:CGRectMake(0,SCREEN_HEIGHT-220-64-49, SCREEN_WIDTH, 220) style:UITableViewStylePlain]; self.selectTableView.separatorStyle=UITableViewCellSeparatorStyleNone; [self.selectTableView registerClass:[KXSelectTableViewCell class] forCellReuseIdentifier:@"selected"]; self.selectTableView.tableFooterView=[[UIView alloc]init]; self.selectTableView.delegate = self; self.selectTableView.dataSource = self; [_selectView addSubview:self.selectTableView]; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (_selected==YES) { return self.careerArray.count; }else{ return self.incomeArray.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.incomeArray[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.incomeArray[indexPath.row] forState:UIControlStateNormal]; } _selectView.hidden=YES; } -(NSArray *)careerArray { if (!_careerArray) { _careerArray=@[@"上班族",@"个体户",@"企业主",@"自由职业"]; } return _careerArray; } -(NSArray *)incomeArray { if (!_incomeArray) { _incomeArray=@[@"1000以下",@"1000-3000",@"3000-5000",@"5000-7000",@"7000-10000",@"1万-3万",@"3万-5万",@"5万以上"]; } return _incomeArray; } -(void)closeTop{ self.topView.hidden=YES; self.backView.hidden=YES; UIWebView *content=[self.topView viewWithTag:766]; [content loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@""]]]; } -(UIView *)topView{ if (!_topView) { _topView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 300, 380)]; _topView.center=self.view.center; _topView.backgroundColor=[UIColor whiteColor]; UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 300, 49.5)]; titleLabel.textColor=[UIColor baseColor]; titleLabel.textAlignment=NSTextAlignmentCenter; UIView *line1=[[UIView alloc]initWithFrame:CGRectMake(0, 49.5, 300, 0.5)]; line1.backgroundColor=[UIColor baseColor]; UIView *line2=[[UIView alloc]initWithFrame:CGRectMake(0, 330, 300, 0.5)]; line2.backgroundColor=[UIColor baseColor]; titleLabel.tag=764; // UIScrollView *contentScrollView=[[UIScrollView alloc]initWithFrame:]; // contentScrollView.tag=765; UIWebView*content=[[UIWebView alloc]initWithFrame:CGRectMake(0, 50, 300, 280)]; content.tag=766; UIButton *closeButton=[[UIButton alloc]initWithFrame:CGRectMake(0, 330.5, 300, 50)]; content.backgroundColor=[UIColor whiteColor]; [closeButton setTitle:@"关闭" forState:UIControlStateNormal]; [closeButton setTitleColor:[UIColor baseColor] forState:UIControlStateNormal]; [closeButton addTarget:self action:@selector(closeTop) forControlEvents:UIControlEventTouchUpInside]; closeButton.tag=767; [_topView addSubview:titleLabel]; // [contentScrollView addSubview:content]; // [_topView addSubview:contentScrollView]; [_topView addSubview:content]; [_topView addSubview:closeButton]; [_topView addSubview:line1]; [_topView addSubview:line2]; } return _topView; } -(UIView *)backView{ if (!_backView) { _backView=[[UIView alloc]initWithFrame:self.view.bounds]; _backView.backgroundColor=[UIColor KXColorWithHex:0x000000 alpha:0.3]; } return _backView; } -(NSArray *)protocolArray{ if (!_protocolArray) { NSMutableArray *arr=[NSMutableArray array]; NSString*path=[[NSBundle mainBundle] pathForResource:@"protocolList" ofType:@"plist"]; NSMutableArray *dataList=[NSMutableArray arrayWithContentsOfFile:path]; for (NSDictionary *dic in dataList) { [arr addObject:dic]; } _protocolArray=[NSArray arrayWithArray:arr]; } return _protocolArray; } - (void)webViewDidFinishLoad:(UIWebView *)webView{ NSString *company=[NSString stringWithFormat:@"document.getElementById('company').innerHTML='%@'",KXCOMPANY]; [webView stringByEvaluatingJavaScriptFromString:company]; NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"]; NSString *appName=[NSString stringWithFormat:@"document.getElementById('appName').innerHTML='%@'",app_Name]; [webView stringByEvaluatingJavaScriptFromString:appName]; } - (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