123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813 |
- //
- // KXMainHomeViewContronller.m
- // QBCS
- //
- // Created by qianbodong on 2017/7/28.
- // Copyright © 2017年 kuxuan. All rights reserved.
- //
- #import "KXMainHomeViewContronller.h"
- #import "KXThirdWebViewController.h"
- #import "KXSelectTableViewCell.h"
- #import "KXLogginViewController.h"
- #import "KXMainWaitBGView.h"
- #import <math.h>
- #import <WebKit/WebKit.h>
- @interface KXMainHomeViewContronller ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,UIGestureRecognizerDelegate,UIWebViewDelegate>
- {
- UIView *_selectView;
- // BOOL _selected;
- }
- @property (nonatomic,strong)UITableView *selectTableView;
- @property (nonatomic,strong)NSArray *monthArray;
- @property (nonatomic,assign)NSInteger month;
- @property (nonatomic,assign)BOOL agreeBool;
- @property (nonatomic,strong)UIView *topView;
- @property (nonatomic,strong)UIView *backView;
- @property (nonatomic,strong)NSArray *protocolArray;
- @end
- @implementation KXMainHomeViewContronller
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- // Do any additional setup after loading the view.
- [self createllView];
- [self createllSelectView];
- // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeView:) name:KXWAITING object:nil];
-
- self.agreeBool=YES;
- [self addViews];
-
- }
- -(void)addViews{
- [self.view addSubview:self.backView];
- [self.view addSubview:self.topView];
- self.topView.hidden=YES;
- self.backView.hidden=YES;
- }
- -(void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- self.navigationController.navigationBar.hidden=YES;
- [self checkLog];
- }
- -(void)createllView{
- self.navigationController.navigationBar.hidden=YES;
- // [self setTitle:@"财神借钱"];
- // [(UILabel*)[self.navigationItem titleView] setTextColor:[UIColor whiteColor]];
- self.view.backgroundColor=[UIColor background];
- UIView* viewHeader=[[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 170*SCREEN_MUTI)];
- viewHeader.backgroundColor=[UIColor baseColor];
- [self.view addSubview:viewHeader];
-
- UILabel* titleLable=[[UILabel alloc]initWithFrame:CGRectMake(0,20, SCREEN_WIDTH, 40)];
- titleLable.textColor=[UIColor whiteColor];
- titleLable.textAlignment=NSTextAlignmentCenter;
- titleLable.font=[UIFont boldSystemFontOfSize:17];
- titleLable.text=@"借贷申请";
- [viewHeader addSubview:titleLable];
-
- UILabel* la=[[UILabel alloc]init];
- [la setBackgroundColor:[UIColor baseColor]];
- la.text=@"5000.00";
- la.tag=8800;
- la.textColor=[UIColor whiteColor];
- la.textAlignment = NSTextAlignmentCenter;
- la.font=FONT_BOLD(28);
- [viewHeader addSubview:la];
-
- UILabel* titleYuan=[[UILabel alloc]init];
- titleYuan.textColor=[UIColor whiteColor];
- titleYuan.textAlignment=NSTextAlignmentCenter;
- titleYuan.font=[UIFont boldSystemFontOfSize:12];
- titleYuan.text=@"申请金额(元)";
- [viewHeader addSubview:titleYuan];
-
- [la mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(viewHeader);
- make.centerY.equalTo(viewHeader).offset(20);
- }];
-
- [titleYuan mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(la.mas_bottom).offset(8*SCREEN_MUTI);
- make.centerX.equalTo(viewHeader);
- }];
-
-
- UIView* view=[[UIView alloc]initWithFrame:CGRectMake(0, 170*SCREEN_MUTI, SCREEN_WIDTH/2, 70*SCREEN_MUTI)];
- [view setBackgroundColor:[UIColor baseColor]];
- [self.view addSubview:view];
- UILabel* labelTitle1=[[UILabel alloc] init];
- labelTitle1.textColor=[UIColor whiteColor];
- // labelTitle1.textAlignment=NSTextAlignmentCenter;
- labelTitle1.font=FONT_SYS(10);
- labelTitle1.text=@"每月还款金额";
- [view addSubview:labelTitle1];
-
- UILabel* labelTotal=[[UILabel alloc] init];
- labelTotal.textColor=[UIColor whiteColor];
- labelTotal.font=FONT_BOLD(19);
- // labelTotal.backgroundColor=[UIColor redColor];
- labelTotal.text=@"221.60";
- labelTotal.tag=8801;
- [view addSubview:labelTotal];
-
- UILabel* labelYuan=[[UILabel alloc] init];
- labelYuan.textColor=[UIColor whiteColor];
- labelYuan.font=FONT_SYS(12);
- labelYuan.text=@"(¥)";
- // labelYuan.backgroundColor=[UIColor redColor];
- [view addSubview:labelYuan];
- CGFloat height1=[labelTitle1.text boundingRectWithSize:CGSizeMake(0, 0) options:NSStringDrawingTruncatesLastVisibleLine attributes:@{NSFontAttributeName:labelTitle1.font} context:nil].size.height;
- CGFloat height2=[labelTotal.text boundingRectWithSize:CGSizeMake(0, 0) options:NSStringDrawingTruncatesLastVisibleLine attributes:@{NSFontAttributeName:labelTotal.font} context:nil].size.height;
- CGFloat width=[labelYuan.text boundingRectWithSize:CGSizeMake(0, 0) options:NSStringDrawingTruncatesLastVisibleLine attributes:@{NSFontAttributeName:labelYuan.font} context:nil].size.width;
- [labelTitle1 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(view.mas_top).offset((62*SCREEN_MUTI-height1-height2)/2);
- make.centerX.equalTo(view);
- }];
- [labelTotal mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(labelTitle1.mas_bottom).offset(8*SCREEN_MUTI);
- make.centerX.equalTo(view).offset(-width/2);
- }];
-
- [labelYuan mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(labelTotal.mas_right);
- make.bottom.equalTo(labelTotal.mas_bottom).offset(-2);
- }];
-
- view=[[UIView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2, 170*SCREEN_MUTI, SCREEN_WIDTH/2, 70*SCREEN_MUTI)];
- [view setBackgroundColor:[UIColor baseColor]];
- [self.view addSubview:view];
- labelTitle1=[[UILabel alloc] init];
- labelTitle1.textColor=[UIColor whiteColor];
- labelTitle1.font=FONT_SYS(10);
- labelTitle1.text=@"还款期数";
- [view addSubview:labelTitle1];
-
- labelTotal=[[UILabel alloc] init];
- labelTotal.textColor=[UIColor whiteColor];
- labelTotal.font=FONT_BOLD(19);
- labelTotal.text=@"24";
- labelTotal.tag=8802;
- [view addSubview:labelTotal];
-
- labelYuan=[[UILabel alloc] init];
- labelYuan.textColor=[UIColor whiteColor];
- labelYuan.font=FONT_SYS(12);
- labelYuan.text=@"(月)";
- [view addSubview:labelYuan];
-
- UIView* lin=[[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2,180*SCREEN_MUTI, 1, 50*SCREEN_MUTI)];
- [lin setBackgroundColor:[UIColor whiteColor]];
- [self.view addSubview:lin];
-
- CGFloat width1=[labelYuan.text boundingRectWithSize:CGSizeMake(0, 0) options:NSStringDrawingTruncatesLastVisibleLine attributes:@{NSFontAttributeName:labelYuan.font} context:nil].size.width;
- [labelTitle1 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(view.mas_top).offset((62*SCREEN_MUTI-height1-height2)/2);
- make.centerX.equalTo(view);
- }];
- [labelTotal mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(labelTitle1.mas_bottom).offset(8*SCREEN_MUTI);
- make.centerX.equalTo(view).offset(-width1/2);
- }];
-
- [labelYuan mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(labelTotal.mas_right);
- make.bottom.equalTo(labelTotal.mas_bottom).offset(-2);
- }];
-
- UILabel* labelAll=[[UILabel alloc] init];
- labelAll.textColor=[UIColor titleColor];
- labelAll.font=FONT_SYS(16);
- labelAll.text=@"借款金额";
- CGSize size=[labelAll.text boundingRectWithSize:CGSizeMake(0, 0) options:NSStringDrawingTruncatesLastVisibleLine attributes:@{NSFontAttributeName:labelAll.font} context:nil].size;
-
- view=[[UIView alloc]initWithFrame:CGRectMake(14*SCREEN_MUTI, 240*SCREEN_MUTI, SCREEN_WIDTH-28*SCREEN_MUTI, 142*SCREEN_MUTI+size.height*2-40)];
- view.layer.cornerRadius=2;
- view.layer.masksToBounds=YES;
- view.backgroundColor=[UIColor whiteColor];
- view.layer.borderWidth = SCREEN_MUTI;
- view.layer.borderColor =[[UIColor lineColor1]CGColor];
- view.tag=8888;
- [self.view addSubview:view];
- [view addSubview:labelAll];
-
- UITextField* textAll=[[UITextField alloc] init];
- textAll.textColor=[UIColor titleColor];
- textAll.font=FONT_SYS(16);
- textAll.placeholder=@"请输入金额";
- textAll.tag=8865;
- textAll.keyboardType = UIKeyboardTypeNumberPad;
- textAll.delegate=self;
- [view addSubview:textAll];
-
- UILabel* labelAll1=[[UILabel alloc] init];
- labelAll1.textColor=[UIColor titleColor];
- labelAll1.font=FONT_SYS(16);
- labelAll1.text=@"元";
- [view addSubview:labelAll1];
-
- CGFloat width2=[labelAll1.text boundingRectWithSize:CGSizeMake(0, 0) options:NSStringDrawingTruncatesLastVisibleLine attributes:@{NSFontAttributeName:labelAll1.font} context:nil].size.width;
-
- lin=[[UIView alloc] init];
- [lin setBackgroundColor:[UIColor lineColor1]];
- [view addSubview:lin];
-
- [labelAll mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(view.mas_top).offset(31*SCREEN_MUTI);
- make.left.equalTo(view.mas_left).offset(27*SCREEN_MUTI);
- make.width.mas_equalTo(size.width);
- }];
- [labelAll1 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(view.mas_right).offset(-26*SCREEN_MUTI);
- make.bottom.equalTo(labelAll.mas_bottom);
- make.width.mas_equalTo(width2);
- }];
- [textAll mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(labelAll.mas_right).offset(10*SCREEN_MUTI);
- make.right.equalTo(labelAll1.mas_left);
- make.bottom.equalTo(labelAll.mas_bottom);
- }];
- [lin mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(labelAll.mas_right);
- make.right.equalTo(labelAll1.mas_left);
- make.top.equalTo(labelAll.mas_bottom);
- make.height.mas_equalTo(1);
- }];
-
-
- labelAll=[[UILabel alloc] init];
- labelAll.textColor=[UIColor titleColor];
- labelAll.font=FONT_SYS(16);
- labelAll.text=@"借款期数";
- [view addSubview:labelAll];
-
- UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
- [button setTitle:@"请选择期数" forState:UIControlStateNormal];
- // button.backgroundColor=[UIColor redColor];
- button.titleLabel.font=FONT_SYS(16);
- button.tag=8866;
- button.titleEdgeInsets= UIEdgeInsetsMake(0, 0, -10, 0);
- [button addTarget:self action:@selector(buttonllAction:) forControlEvents:UIControlEventTouchUpInside];
- button.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
- [button setTitleColor:[UIColor baseColor] forState:UIControlStateNormal];
- [view addSubview:button];
-
-
-
- labelAll1=[[UILabel alloc] init];
- labelAll1.textColor=[UIColor titleColor];
- labelAll1.font=FONT_SYS(16);
- labelAll1.text=@"月";
- [view addSubview:labelAll1];
-
- lin=[[UIView alloc] init];
- [lin setBackgroundColor:[UIColor lineColor1]];
- // [lin setBackgroundColor:[UIColor redColor]];
- [view addSubview:lin];
- 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;
- [self.view addSubview:protocolText];
-
-
-
-
- [labelAll mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(view.mas_top).offset(71*SCREEN_MUTI+size.height);
- make.left.equalTo(view.mas_left).offset(27*SCREEN_MUTI);
- }];
- [labelAll1 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(view.mas_right).offset(-26*SCREEN_MUTI);
- make.bottom.equalTo(labelAll.mas_bottom);
- }];
- [button mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.equalTo(labelAll.mas_bottom);
- make.left.equalTo(labelAll.mas_right).offset(10*SCREEN_MUTI);
- make.right.equalTo(labelAll1.mas_left);
- }];
- [lin mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(labelAll.mas_right);
- make.right.equalTo(labelAll1.mas_left);
- make.top.equalTo(labelAll.mas_bottom);
- make.height.mas_equalTo(1);
- }];
- [protocolText mas_makeConstraints:^(MASConstraintMaker *make) {
- make.width.mas_equalTo(240+16+45);//
- make.height.mas_equalTo(20);
- make.top.equalTo(view.mas_bottom).offset(10);
- make.left.equalTo(view.mas_left);
- }];
- UIView * views=[[UIView alloc]initWithFrame:CGRectMake(18, 0, 45, 16)];
- views.backgroundColor=[UIColor clearColor];
- [protocolText addSubview:views];
- UIButton *next=[UIButton buttonWithType:UIButtonTypeCustom];
- // next.frame=CGRectMake(14*SCREEN_MUTI,(130+11+306+26)*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(nextAction) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:next];
- [next mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.top.equalTo(view.mas_bottom).offset(80*SCREEN_MUTI);
- make.bottom.equalTo(self.view.mas_bottom).offset(-80*SCREEN_MUTI);
- make.left.equalTo(view.mas_left);
- make.right.equalTo(view.mas_right);
- make.height.mas_equalTo(44*SCREEN_MUTI);
- }];
-
-
- UILabel *littleLabel=[[UILabel alloc]init];
- littleLabel.text=@"由南宁市海源小额贷款有限公司出品为您提供高品质金融服务";
- littleLabel.textColor=[UIColor detailTitleColor];
- littleLabel.textAlignment=NSTextAlignmentCenter;
- littleLabel.font=FONT_SYS(11);
- [self.view addSubview:littleLabel];
-
- [littleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(next.mas_centerX);
- make.top.equalTo(next.mas_bottom).offset(5);
- }];
- }
- -(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)createllSelectView
- {
- _month=0;
- _selectView=[[UIView alloc]initWithFrame:self.view.bounds];
- _selectView.hidden=YES;
- _selectView.backgroundColor=[UIColor colorWithWhite:0 alpha:0.5];
-
- [self.view addSubview:_selectView];
- UITapGestureRecognizer *tapGesturRecognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hiddenAction:)];
- tapGesturRecognizer.delegate = self;
- [_selectView addGestureRecognizer:tapGesturRecognizer];
-
- self.selectTableView = [[UITableView alloc]initWithFrame:CGRectMake(0,SCREEN_HEIGHT-220-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];
- }
- -(void)hiddenAction:(UITapGestureRecognizer*) g{
- _selectView.hidden=YES;
- }
- - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
- CGPoint point = [gestureRecognizer locationInView:_selectView];
- if(point.y<SCREEN_HEIGHT-220-49){
- return YES;
- }
- return NO;
- }
- -(void)checkLog
- {
- UITextField *allTF=[self.view viewWithTag:8865];
- UIButton *monthBtn=[self.view viewWithTag:8866];
- 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)]) {
- [self createWaitView];
- NSString *urlSt=[NSString stringWithFormat:@"%@/user/getIosApplyById",URL];
- [KXHTTP post:urlSt params:@{@"id":[json[@"user"] valueForKey:@"id"]} success:^(id json) {
- _month=[json[@"term"] integerValue];
- [self calculate:[json[@"amount"] integerValue]];
- } failure:^(NSError *error) {
- }];
- }else{
-
- UILabel* label=(UILabel*)[self.view viewWithTag:8800];
- UILabel* label1=(UILabel*)[self.view viewWithTag:8801];
- UILabel* label2=(UILabel*)[self.view viewWithTag:8802];
- // loan/limit+(loan-i*loan/limit)*0.005;
- // 应该等额本息计算:每月还款金额 = 〔贷款本金×月利率×(1+月利率)^还款月数〕÷〔(1+月利率)^还款月数-1〕
- label.text =@"5000.0";
- label2.text =@"24";
- label1.text=@"221.60";
- allTF.text=@"";
- [monthBtn setTitle:@"请选择期数" forState:UIControlStateNormal];
-
- KXMainWaitBGView* view=[self.view viewWithTag:8889];
- view.hidden=YES;
- UIView* viewOld=[self.view viewWithTag:8888];
- viewOld.hidden=NO;
- [nextBtn setTitle:@"申请借款" forState:UIControlStateNormal];
- allTF.enabled=YES;
- monthBtn.enabled=YES;
- nextBtn.enabled=YES;
- }
- } failure:^(NSError *error) {
- }];
- }
- //-(void)changeView:(NSNotification *)noti
- //{
- // [self createWaitView];
- //}
- -(void)createWaitView
- {
-
- UITextField *allTF=[self.view viewWithTag:8865];
- UIButton *monthBtn=[self.view viewWithTag:8866];
- UIButton *nextBtn=[self.view viewWithTag:999];
- UIView* viewOld=[self.view viewWithTag:8888];
- viewOld.hidden=YES;
- allTF.enabled=NO;
- monthBtn.enabled=NO;
- nextBtn.enabled=NO;
-
- [nextBtn setTitle:@"审核中..." forState:UIControlStateNormal];
- KXMainWaitBGView* view=[self.view viewWithTag:8889];
- if(view){
- view.hidden=NO;
- return;
- }
-
- UILabel* labelWait=[[UILabel alloc] init];
- labelWait.textColor=[UIColor titleColor];
- labelWait.font=FONT_SYS(13);
- labelWait.text=@"待审核";
-
- UILabel* labelSuccess=[[UILabel alloc] init];
- labelSuccess.textColor=[UIColor detailTitleColor];
- labelSuccess.font=FONT_SYS(10);
- labelSuccess.text=@"申请提交成功";
- CGFloat height1=[labelWait.text boundingRectWithSize:CGSizeMake(0, 0) options:NSStringDrawingTruncatesLastVisibleLine attributes:@{NSFontAttributeName:labelWait.font} context:nil].size.height;
- CGFloat height2=[labelSuccess.text boundingRectWithSize:CGSizeMake(0, 0) options:NSStringDrawingTruncatesLastVisibleLine attributes:@{NSFontAttributeName:labelSuccess.font} context:nil].size.height;
- view=[[KXMainWaitBGView alloc]initWithFrame:CGRectMake(14*SCREEN_MUTI, 240*SCREEN_MUTI, SCREEN_WIDTH-28*SCREEN_MUTI, 173*SCREEN_MUTI+height1/2+height2/2) height1:height1 height2:height2];
- view.layer.cornerRadius=2;
- view.layer.masksToBounds=YES;
- view.backgroundColor=[UIColor whiteColor];
- view.layer.borderWidth = SCREEN_MUTI;
- view.layer.borderColor =[[UIColor lineColor1]CGColor];
- view.tag=8889;
- [self.view addSubview:view];
- [view addSubview:labelWait];
- [view addSubview:labelSuccess];
-
- [labelWait mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(view.mas_top).offset(52*SCREEN_MUTI);
- make.left.equalTo(view.mas_left).offset(34*SCREEN_MUTI);
- }];
- [labelSuccess mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.equalTo(view.mas_bottom).offset(-52*SCREEN_MUTI);
- make.left.equalTo(labelWait.mas_left);
- }];
-
- UILabel* labelWaitIng=[[UILabel alloc] init];
- labelWaitIng.textColor=[UIColor detailTitleColor];
- labelWaitIng.font=FONT_SYS(10);
- labelWaitIng.text=@"您的借款申请正在进行审核,请稍等!";
- [view addSubview:labelWaitIng];
-
- UILabel* labelTime=[[UILabel alloc] init];
- labelTime.textColor=[UIColor detailTitleColor];
- labelTime.font=FONT_SYS(10);
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateFormat:@"yyyy-MM-dd"];
- NSString *currentDateStr = [dateFormatter stringFromDate:[NSDate date]];
- labelTime.text=currentDateStr;
- [view addSubview:labelTime];
- [labelWaitIng mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.equalTo(labelSuccess.mas_top).offset(-33*SCREEN_MUTI);
- make.left.equalTo(labelWait.mas_left);
- }];
- [labelTime mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.equalTo(labelSuccess.mas_bottom);
- make.right.equalTo(view.mas_right).offset(-14*SCREEN_MUTI);
- }];
-
- }
- #pragma mark UITextFieldDelegate
- -(void)textFieldDidEndEditing:(UITextField *)textField
- {
- if(textField.text.length==0||_month==0)
- {
- return;
- }
-
- [self calculate:[textField.text integerValue]];
-
- }
- -(void)calculate:(NSInteger) c {
- UILabel* label=(UILabel*)[self.view viewWithTag:8800];
- UILabel* label1=(UILabel*)[self.view viewWithTag:8801];
- UILabel* label2=(UILabel*)[self.view viewWithTag:8802];
- // loan/limit+(loan-i*loan/limit)*0.005;
- // 应该等额本息计算:每月还款金额 = 〔贷款本金×月利率×(1+月利率)^还款月数〕÷〔(1+月利率)^还款月数-1〕
- label.text =[NSString stringWithFormat:@"%.2f",(float)c];
- label2.text =[NSString stringWithFormat:@"%i",(int)_month];
- if (!c) {
- label1.text=@"0";
- }else{
- label1.text=[NSString stringWithFormat:@"%.2f",c*0.005*pow(1.005,(int)_month)/(pow(1.005,(int)_month)-1)];
- }
- }
- - (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 (textField.text.length+string.length>8) {
- return NO;
- }
- if([self isPureInt:string]){
- if(range.location==0&&[string hasPrefix:@"0"]){
- return NO;
- }
- }else{
- if(string.length!=0){
- return NO;
- }
- }
- return YES;
- }
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return 6;
- }
- -(NSArray *)monthArray
- {
- if (!_monthArray) {
- _monthArray=@[@"1",@"3",@"6",@"12",@"24",@"36"];
- }
- return _monthArray;
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- KXSelectTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"selected"];
- if (!cell) {
- cell=[[KXSelectTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"selected"];
- }
-
- cell.detailStr=self.monthArray[indexPath.row];
-
- return cell;
-
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath
- {
- return 45;
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
-
- _month=[self.monthArray[indexPath.row] integerValue];
-
- UIButton *button=[self.view viewWithTag:8866];
- [button setTitle:self.monthArray[indexPath.row] forState:UIControlStateNormal];
-
- UILabel* label=(UILabel*)[self.view viewWithTag:8802];
- label.text=self.monthArray[indexPath.row];
-
- UITextField* text=(UITextField*)[self.view viewWithTag:8865];
- if(text.text.length==0){
- [self calculate: 5000];
- }else{
- [self calculate: text.text.integerValue];
- }
- _selectView.hidden=YES;
-
- }
- -(void)buttonllAction:(UIButton *)btn{
- // [self.selectTableView reloadData];
- _selectView.hidden=NO;
- }
- -(void)nextAction
- {
- 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.navigationBar.hidden = NO;
- [self.navigationController pushViewController:loggin animated:YES];
- [[NSUserDefaults standardUserDefaults]setObject:nil forKey:@"ISPOP"];
- [[NSUserDefaults standardUserDefaults]synchronize];
- }]];
- [self presentViewController:alertController animated:YES completion:nil];
- nextBtn.enabled=YES;
- }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{
-
- UITextField* textfield=[self.view viewWithTag:8865];
-
- if(textfield.text.length==0){
- [self createPromptWhit:@"请输入金额后再试"];
- nextBtn.enabled=YES;
- return;
- }
-
- if(_month==0){
- [self createPromptWhit:@"请选择期限后再试"];
- nextBtn.enabled=YES;
- return;
- }
-
- KXThirdWebViewController *mainWeb=[[KXThirdWebViewController alloc]init];
- mainWeb.amount=textfield.text.integerValue ;
- mainWeb.term=_month;
- [self.navigationController pushViewController:mainWeb animated:YES];
- nextBtn.enabled=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)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;
- }
- @end
|