説明なし

KXMainHomeViewContronller.m 32KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. //
  2. // KXMainHomeViewContronller.m
  3. // QBCS
  4. //
  5. // Created by qianbodong on 2017/7/28.
  6. // Copyright © 2017年 kuxuan. All rights reserved.
  7. //
  8. #import "KXMainHomeViewContronller.h"
  9. #import "KXThirdWebViewController.h"
  10. #import "KXSelectTableViewCell.h"
  11. #import "KXLogginViewController.h"
  12. #import "KXMainWaitBGView.h"
  13. #import <math.h>
  14. #import <WebKit/WebKit.h>
  15. @interface KXMainHomeViewContronller ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,UIGestureRecognizerDelegate,UIWebViewDelegate>
  16. {
  17. UIView *_selectView;
  18. // BOOL _selected;
  19. }
  20. @property (nonatomic,strong)UITableView *selectTableView;
  21. @property (nonatomic,strong)NSArray *monthArray;
  22. @property (nonatomic,assign)NSInteger month;
  23. @property (nonatomic,assign)BOOL agreeBool;
  24. @property (nonatomic,strong)UIView *topView;
  25. @property (nonatomic,strong)UIView *backView;
  26. @property (nonatomic,strong)NSArray *protocolArray;
  27. @end
  28. @implementation KXMainHomeViewContronller
  29. - (void)viewDidLoad {
  30. [super viewDidLoad];
  31. // Do any additional setup after loading the view.
  32. [self createllView];
  33. [self createllSelectView];
  34. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeView:) name:KXWAITING object:nil];
  35. self.agreeBool=YES;
  36. [self addViews];
  37. }
  38. -(void)addViews{
  39. [self.view addSubview:self.backView];
  40. [self.view addSubview:self.topView];
  41. self.topView.hidden=YES;
  42. self.backView.hidden=YES;
  43. }
  44. -(void)viewWillAppear:(BOOL)animated
  45. {
  46. [super viewWillAppear:animated];
  47. self.navigationController.navigationBar.hidden=YES;
  48. [self checkLog];
  49. }
  50. -(void)createllView{
  51. self.navigationController.navigationBar.hidden=YES;
  52. // [self setTitle:@"财神借钱"];
  53. // [(UILabel*)[self.navigationItem titleView] setTextColor:[UIColor whiteColor]];
  54. self.view.backgroundColor=[UIColor background];
  55. UIView* viewHeader=[[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 170*SCREEN_MUTI)];
  56. viewHeader.backgroundColor=[UIColor baseColor];
  57. [self.view addSubview:viewHeader];
  58. UILabel* titleLable=[[UILabel alloc]initWithFrame:CGRectMake(0,20, SCREEN_WIDTH, 40)];
  59. titleLable.textColor=[UIColor whiteColor];
  60. titleLable.textAlignment=NSTextAlignmentCenter;
  61. titleLable.font=[UIFont boldSystemFontOfSize:17];
  62. titleLable.text=@"借贷申请";
  63. [viewHeader addSubview:titleLable];
  64. UILabel* la=[[UILabel alloc]init];
  65. [la setBackgroundColor:[UIColor baseColor]];
  66. la.text=@"5000.00";
  67. la.tag=8800;
  68. la.textColor=[UIColor whiteColor];
  69. la.textAlignment = NSTextAlignmentCenter;
  70. la.font=FONT_BOLD(28);
  71. [viewHeader addSubview:la];
  72. UILabel* titleYuan=[[UILabel alloc]init];
  73. titleYuan.textColor=[UIColor whiteColor];
  74. titleYuan.textAlignment=NSTextAlignmentCenter;
  75. titleYuan.font=[UIFont boldSystemFontOfSize:12];
  76. titleYuan.text=@"申请金额(元)";
  77. [viewHeader addSubview:titleYuan];
  78. [la mas_makeConstraints:^(MASConstraintMaker *make) {
  79. make.centerX.equalTo(viewHeader);
  80. make.centerY.equalTo(viewHeader).offset(20);
  81. }];
  82. [titleYuan mas_makeConstraints:^(MASConstraintMaker *make) {
  83. make.top.equalTo(la.mas_bottom).offset(8*SCREEN_MUTI);
  84. make.centerX.equalTo(viewHeader);
  85. }];
  86. UIView* view=[[UIView alloc]initWithFrame:CGRectMake(0, 170*SCREEN_MUTI, SCREEN_WIDTH/2, 70*SCREEN_MUTI)];
  87. [view setBackgroundColor:[UIColor baseColor]];
  88. [self.view addSubview:view];
  89. UILabel* labelTitle1=[[UILabel alloc] init];
  90. labelTitle1.textColor=[UIColor whiteColor];
  91. // labelTitle1.textAlignment=NSTextAlignmentCenter;
  92. labelTitle1.font=FONT_SYS(10);
  93. labelTitle1.text=@"每月还款金额";
  94. [view addSubview:labelTitle1];
  95. UILabel* labelTotal=[[UILabel alloc] init];
  96. labelTotal.textColor=[UIColor whiteColor];
  97. labelTotal.font=FONT_BOLD(19);
  98. // labelTotal.backgroundColor=[UIColor redColor];
  99. labelTotal.text=@"221.60";
  100. labelTotal.tag=8801;
  101. [view addSubview:labelTotal];
  102. UILabel* labelYuan=[[UILabel alloc] init];
  103. labelYuan.textColor=[UIColor whiteColor];
  104. labelYuan.font=FONT_SYS(12);
  105. labelYuan.text=@"(¥)";
  106. // labelYuan.backgroundColor=[UIColor redColor];
  107. [view addSubview:labelYuan];
  108. CGFloat height1=[labelTitle1.text boundingRectWithSize:CGSizeMake(0, 0) options:NSStringDrawingTruncatesLastVisibleLine attributes:@{NSFontAttributeName:labelTitle1.font} context:nil].size.height;
  109. CGFloat height2=[labelTotal.text boundingRectWithSize:CGSizeMake(0, 0) options:NSStringDrawingTruncatesLastVisibleLine attributes:@{NSFontAttributeName:labelTotal.font} context:nil].size.height;
  110. CGFloat width=[labelYuan.text boundingRectWithSize:CGSizeMake(0, 0) options:NSStringDrawingTruncatesLastVisibleLine attributes:@{NSFontAttributeName:labelYuan.font} context:nil].size.width;
  111. [labelTitle1 mas_makeConstraints:^(MASConstraintMaker *make) {
  112. make.top.equalTo(view.mas_top).offset((62*SCREEN_MUTI-height1-height2)/2);
  113. make.centerX.equalTo(view);
  114. }];
  115. [labelTotal mas_makeConstraints:^(MASConstraintMaker *make) {
  116. make.top.equalTo(labelTitle1.mas_bottom).offset(8*SCREEN_MUTI);
  117. make.centerX.equalTo(view).offset(-width/2);
  118. }];
  119. [labelYuan mas_makeConstraints:^(MASConstraintMaker *make) {
  120. make.left.equalTo(labelTotal.mas_right);
  121. make.bottom.equalTo(labelTotal.mas_bottom).offset(-2);
  122. }];
  123. view=[[UIView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2, 170*SCREEN_MUTI, SCREEN_WIDTH/2, 70*SCREEN_MUTI)];
  124. [view setBackgroundColor:[UIColor baseColor]];
  125. [self.view addSubview:view];
  126. labelTitle1=[[UILabel alloc] init];
  127. labelTitle1.textColor=[UIColor whiteColor];
  128. labelTitle1.font=FONT_SYS(10);
  129. labelTitle1.text=@"还款期数";
  130. [view addSubview:labelTitle1];
  131. labelTotal=[[UILabel alloc] init];
  132. labelTotal.textColor=[UIColor whiteColor];
  133. labelTotal.font=FONT_BOLD(19);
  134. labelTotal.text=@"24";
  135. labelTotal.tag=8802;
  136. [view addSubview:labelTotal];
  137. labelYuan=[[UILabel alloc] init];
  138. labelYuan.textColor=[UIColor whiteColor];
  139. labelYuan.font=FONT_SYS(12);
  140. labelYuan.text=@"(月)";
  141. [view addSubview:labelYuan];
  142. UIView* lin=[[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2,180*SCREEN_MUTI, 1, 50*SCREEN_MUTI)];
  143. [lin setBackgroundColor:[UIColor whiteColor]];
  144. [self.view addSubview:lin];
  145. CGFloat width1=[labelYuan.text boundingRectWithSize:CGSizeMake(0, 0) options:NSStringDrawingTruncatesLastVisibleLine attributes:@{NSFontAttributeName:labelYuan.font} context:nil].size.width;
  146. [labelTitle1 mas_makeConstraints:^(MASConstraintMaker *make) {
  147. make.top.equalTo(view.mas_top).offset((62*SCREEN_MUTI-height1-height2)/2);
  148. make.centerX.equalTo(view);
  149. }];
  150. [labelTotal mas_makeConstraints:^(MASConstraintMaker *make) {
  151. make.top.equalTo(labelTitle1.mas_bottom).offset(8*SCREEN_MUTI);
  152. make.centerX.equalTo(view).offset(-width1/2);
  153. }];
  154. [labelYuan mas_makeConstraints:^(MASConstraintMaker *make) {
  155. make.left.equalTo(labelTotal.mas_right);
  156. make.bottom.equalTo(labelTotal.mas_bottom).offset(-2);
  157. }];
  158. UILabel* labelAll=[[UILabel alloc] init];
  159. labelAll.textColor=[UIColor titleColor];
  160. labelAll.font=FONT_SYS(16);
  161. labelAll.text=@"借款金额";
  162. CGSize size=[labelAll.text boundingRectWithSize:CGSizeMake(0, 0) options:NSStringDrawingTruncatesLastVisibleLine attributes:@{NSFontAttributeName:labelAll.font} context:nil].size;
  163. view=[[UIView alloc]initWithFrame:CGRectMake(14*SCREEN_MUTI, 240*SCREEN_MUTI, SCREEN_WIDTH-28*SCREEN_MUTI, 142*SCREEN_MUTI+size.height*2-40)];
  164. view.layer.cornerRadius=2;
  165. view.layer.masksToBounds=YES;
  166. view.backgroundColor=[UIColor whiteColor];
  167. view.layer.borderWidth = SCREEN_MUTI;
  168. view.layer.borderColor =[[UIColor lineColor1]CGColor];
  169. view.tag=8888;
  170. [self.view addSubview:view];
  171. [view addSubview:labelAll];
  172. UITextField* textAll=[[UITextField alloc] init];
  173. textAll.textColor=[UIColor titleColor];
  174. textAll.font=FONT_SYS(16);
  175. textAll.placeholder=@"请输入金额";
  176. textAll.tag=8865;
  177. textAll.keyboardType = UIKeyboardTypeNumberPad;
  178. textAll.delegate=self;
  179. [view addSubview:textAll];
  180. UILabel* labelAll1=[[UILabel alloc] init];
  181. labelAll1.textColor=[UIColor titleColor];
  182. labelAll1.font=FONT_SYS(16);
  183. labelAll1.text=@"元";
  184. [view addSubview:labelAll1];
  185. CGFloat width2=[labelAll1.text boundingRectWithSize:CGSizeMake(0, 0) options:NSStringDrawingTruncatesLastVisibleLine attributes:@{NSFontAttributeName:labelAll1.font} context:nil].size.width;
  186. lin=[[UIView alloc] init];
  187. [lin setBackgroundColor:[UIColor lineColor1]];
  188. [view addSubview:lin];
  189. [labelAll mas_makeConstraints:^(MASConstraintMaker *make) {
  190. make.top.equalTo(view.mas_top).offset(31*SCREEN_MUTI);
  191. make.left.equalTo(view.mas_left).offset(27*SCREEN_MUTI);
  192. make.width.mas_equalTo(size.width);
  193. }];
  194. [labelAll1 mas_makeConstraints:^(MASConstraintMaker *make) {
  195. make.right.equalTo(view.mas_right).offset(-26*SCREEN_MUTI);
  196. make.bottom.equalTo(labelAll.mas_bottom);
  197. make.width.mas_equalTo(width2);
  198. }];
  199. [textAll mas_makeConstraints:^(MASConstraintMaker *make) {
  200. make.left.equalTo(labelAll.mas_right).offset(10*SCREEN_MUTI);
  201. make.right.equalTo(labelAll1.mas_left);
  202. make.bottom.equalTo(labelAll.mas_bottom);
  203. }];
  204. [lin mas_makeConstraints:^(MASConstraintMaker *make) {
  205. make.left.equalTo(labelAll.mas_right);
  206. make.right.equalTo(labelAll1.mas_left);
  207. make.top.equalTo(labelAll.mas_bottom);
  208. make.height.mas_equalTo(1);
  209. }];
  210. labelAll=[[UILabel alloc] init];
  211. labelAll.textColor=[UIColor titleColor];
  212. labelAll.font=FONT_SYS(16);
  213. labelAll.text=@"借款期数";
  214. [view addSubview:labelAll];
  215. UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
  216. [button setTitle:@"请选择期数" forState:UIControlStateNormal];
  217. // button.backgroundColor=[UIColor redColor];
  218. button.titleLabel.font=FONT_SYS(16);
  219. button.tag=8866;
  220. button.titleEdgeInsets= UIEdgeInsetsMake(0, 0, -10, 0);
  221. [button addTarget:self action:@selector(buttonllAction:) forControlEvents:UIControlEventTouchUpInside];
  222. button.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
  223. [button setTitleColor:[UIColor baseColor] forState:UIControlStateNormal];
  224. [view addSubview:button];
  225. labelAll1=[[UILabel alloc] init];
  226. labelAll1.textColor=[UIColor titleColor];
  227. labelAll1.font=FONT_SYS(16);
  228. labelAll1.text=@"月";
  229. [view addSubview:labelAll1];
  230. lin=[[UIView alloc] init];
  231. [lin setBackgroundColor:[UIColor lineColor1]];
  232. // [lin setBackgroundColor:[UIColor redColor]];
  233. [view addSubview:lin];
  234. UIButton *agreeButton=[UIButton buttonWithType:UIButtonTypeCustom];
  235. agreeButton.frame=CGRectMake(0, 0, 16, 16);
  236. agreeButton.tag=2000;
  237. [agreeButton addTarget:self action:@selector(agreeAction:) forControlEvents:UIControlEventTouchUpInside];
  238. agreeButton.selected=YES;
  239. [agreeButton setImage:[UIImage imageNamed:@"disagree_protocol"] forState:UIControlStateNormal];
  240. [agreeButton setImage:[UIImage imageNamed:@"agree_protocol"] forState:UIControlStateSelected];
  241. UIView *protocolView=[[UIView alloc]init];
  242. protocolView.frame=CGRectMake(0, 0, 240, 20);
  243. for (int i=0; i<3; i++) {
  244. UIButton *button=[[UIButton alloc]init];
  245. button.titleLabel.font=[UIFont systemFontOfSize:12.0f];
  246. [button addTarget:self action:@selector(protocolAction:) forControlEvents:UIControlEventTouchUpInside];
  247. [button setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
  248. button.tag=1000+i;
  249. switch (i) {
  250. case 0:
  251. {
  252. [button setTitle:@"《委托授权协议》" forState:UIControlStateNormal];
  253. button.frame=CGRectMake(0, -3, 100, 20);
  254. }
  255. break;
  256. case 1:
  257. {
  258. [button setTitle:@"《借款协议》" forState:UIControlStateNormal];
  259. button.frame=CGRectMake(90, -3, 65, 20);
  260. }
  261. break;
  262. case 2:
  263. {
  264. [button setTitle:@"《平台服务协议》" forState:UIControlStateNormal];
  265. button.frame=CGRectMake(90+65, -3, 70, 20);
  266. }
  267. break;
  268. default:
  269. break;
  270. }
  271. [button sizeToFit];
  272. [protocolView addSubview:button];
  273. }
  274. // protocolView.backgroundColor=[UIColor redColor];
  275. UITextField *protocolText=[[UITextField alloc]init];
  276. protocolText.text=@"同意";
  277. protocolText.font = [UIFont systemFontOfSize:12.0];
  278. protocolText.textAlignment=NSTextAlignmentCenter;
  279. protocolText.leftView=agreeButton;
  280. protocolText.leftViewMode=UITextFieldViewModeAlways;
  281. protocolText.rightView=protocolView;
  282. protocolText.rightViewMode=UITextFieldViewModeAlways;
  283. [self.view addSubview:protocolText];
  284. [labelAll mas_makeConstraints:^(MASConstraintMaker *make) {
  285. make.top.equalTo(view.mas_top).offset(71*SCREEN_MUTI+size.height);
  286. make.left.equalTo(view.mas_left).offset(27*SCREEN_MUTI);
  287. }];
  288. [labelAll1 mas_makeConstraints:^(MASConstraintMaker *make) {
  289. make.right.equalTo(view.mas_right).offset(-26*SCREEN_MUTI);
  290. make.bottom.equalTo(labelAll.mas_bottom);
  291. }];
  292. [button mas_makeConstraints:^(MASConstraintMaker *make) {
  293. make.bottom.equalTo(labelAll.mas_bottom);
  294. make.left.equalTo(labelAll.mas_right).offset(10*SCREEN_MUTI);
  295. make.right.equalTo(labelAll1.mas_left);
  296. }];
  297. [lin mas_makeConstraints:^(MASConstraintMaker *make) {
  298. make.left.equalTo(labelAll.mas_right);
  299. make.right.equalTo(labelAll1.mas_left);
  300. make.top.equalTo(labelAll.mas_bottom);
  301. make.height.mas_equalTo(1);
  302. }];
  303. [protocolText mas_makeConstraints:^(MASConstraintMaker *make) {
  304. make.width.mas_equalTo(240+16+45);//
  305. make.height.mas_equalTo(20);
  306. make.top.equalTo(view.mas_bottom).offset(10);
  307. make.left.equalTo(view.mas_left);
  308. }];
  309. UIView * views=[[UIView alloc]initWithFrame:CGRectMake(18, 0, 45, 16)];
  310. views.backgroundColor=[UIColor clearColor];
  311. [protocolText addSubview:views];
  312. UIButton *next=[UIButton buttonWithType:UIButtonTypeCustom];
  313. // next.frame=CGRectMake(14*SCREEN_MUTI,(130+11+306+26)*SCREEN_MUTI, SCREEN_WIDTH-28*SCREEN_MUTI, 44*SCREEN_MUTI);
  314. next.layer.cornerRadius=3;
  315. next.tag=999;
  316. next.layer.masksToBounds=YES;
  317. next.backgroundColor=[UIColor baseColor];
  318. next.titleLabel.font=FONT_SYS(16);
  319. [next setTitle:@"申请贷款" forState:UIControlStateNormal];
  320. [next setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  321. [next addTarget:self action:@selector(nextAction) forControlEvents:UIControlEventTouchUpInside];
  322. [self.view addSubview:next];
  323. [next mas_makeConstraints:^(MASConstraintMaker *make) {
  324. // make.top.equalTo(view.mas_bottom).offset(80*SCREEN_MUTI);
  325. make.bottom.equalTo(self.view.mas_bottom).offset(-80*SCREEN_MUTI);
  326. make.left.equalTo(view.mas_left);
  327. make.right.equalTo(view.mas_right);
  328. make.height.mas_equalTo(44*SCREEN_MUTI);
  329. }];
  330. UILabel *littleLabel=[[UILabel alloc]init];
  331. littleLabel.text=@"由南宁市海源小额贷款有限公司出品为您提供高品质金融服务";
  332. littleLabel.textColor=[UIColor detailTitleColor];
  333. littleLabel.textAlignment=NSTextAlignmentCenter;
  334. littleLabel.font=FONT_SYS(11);
  335. [self.view addSubview:littleLabel];
  336. [littleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  337. make.centerX.equalTo(next.mas_centerX);
  338. make.top.equalTo(next.mas_bottom).offset(5);
  339. }];
  340. }
  341. -(void)agreeAction:(UIButton *)sender{
  342. self.agreeBool=!self.agreeBool;
  343. sender.selected=self.agreeBool;
  344. }
  345. -(void)protocolAction:(UIButton *)sender{
  346. self.backView.hidden=NO;
  347. self.topView.hidden=NO;
  348. long indexSender=sender.tag-1000;
  349. UILabel *titleLabel=[self.topView viewWithTag:764];
  350. titleLabel.text=sender.titleLabel.text;
  351. UIWebView *content=[self.topView viewWithTag:766];
  352. content.delegate = self;
  353. NSString *path = [[NSBundle mainBundle] bundlePath];
  354. NSURL *baseURL = [NSURL fileURLWithPath:path];
  355. NSString * htmlPath = [[NSBundle mainBundle] pathForResource:self.protocolArray[indexSender][@"html"]
  356. ofType:@"html"];
  357. // NSLog(@"--%@--%@--",self.protocolArray[indexSender][@"html"],htmlPath);
  358. NSString * htmlCont = [NSString stringWithContentsOfFile:htmlPath
  359. encoding:NSUTF8StringEncoding
  360. error:nil];
  361. [content loadHTMLString:htmlCont baseURL:baseURL];
  362. }
  363. -(void)createllSelectView
  364. {
  365. _month=0;
  366. _selectView=[[UIView alloc]initWithFrame:self.view.bounds];
  367. _selectView.hidden=YES;
  368. _selectView.backgroundColor=[UIColor colorWithWhite:0 alpha:0.5];
  369. [self.view addSubview:_selectView];
  370. UITapGestureRecognizer *tapGesturRecognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hiddenAction:)];
  371. tapGesturRecognizer.delegate = self;
  372. [_selectView addGestureRecognizer:tapGesturRecognizer];
  373. self.selectTableView = [[UITableView alloc]initWithFrame:CGRectMake(0,SCREEN_HEIGHT-220-49, SCREEN_WIDTH, 220) style:UITableViewStylePlain];
  374. self.selectTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
  375. [self.selectTableView registerClass:[KXSelectTableViewCell class] forCellReuseIdentifier:@"selected"];
  376. self.selectTableView.tableFooterView=[[UIView alloc]init];
  377. self.selectTableView.delegate = self;
  378. self.selectTableView.dataSource = self;
  379. [_selectView addSubview:self.selectTableView];
  380. }
  381. -(void)hiddenAction:(UITapGestureRecognizer*) g{
  382. _selectView.hidden=YES;
  383. }
  384. - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
  385. CGPoint point = [gestureRecognizer locationInView:_selectView];
  386. if(point.y<SCREEN_HEIGHT-220-49){
  387. return YES;
  388. }
  389. return NO;
  390. }
  391. -(void)checkLog
  392. {
  393. UITextField *allTF=[self.view viewWithTag:8865];
  394. UIButton *monthBtn=[self.view viewWithTag:8866];
  395. UIButton *nextBtn=[self.view viewWithTag:999];
  396. NSString *urlString=[NSString stringWithFormat:@"%@/user/personalCenter",URL];
  397. [KXHTTP post:urlString params:nil success:^(id json) {
  398. if ([[json[@"user"] valueForKey:@"user_level_id"] isEqual:@(YES)]) {
  399. [self createWaitView];
  400. NSString *urlSt=[NSString stringWithFormat:@"%@/user/getIosApplyById",URL];
  401. [KXHTTP post:urlSt params:@{@"id":[json[@"user"] valueForKey:@"id"]} success:^(id json) {
  402. _month=[json[@"term"] integerValue];
  403. [self calculate:[json[@"amount"] integerValue]];
  404. } failure:^(NSError *error) {
  405. }];
  406. }else{
  407. UILabel* label=(UILabel*)[self.view viewWithTag:8800];
  408. UILabel* label1=(UILabel*)[self.view viewWithTag:8801];
  409. UILabel* label2=(UILabel*)[self.view viewWithTag:8802];
  410. // loan/limit+(loan-i*loan/limit)*0.005;
  411. // 应该等额本息计算:每月还款金额 = 〔贷款本金×月利率×(1+月利率)^还款月数〕÷〔(1+月利率)^还款月数-1〕
  412. label.text =@"5000.0";
  413. label2.text =@"24";
  414. label1.text=@"221.60";
  415. allTF.text=@"";
  416. [monthBtn setTitle:@"请选择期数" forState:UIControlStateNormal];
  417. KXMainWaitBGView* view=[self.view viewWithTag:8889];
  418. view.hidden=YES;
  419. UIView* viewOld=[self.view viewWithTag:8888];
  420. viewOld.hidden=NO;
  421. [nextBtn setTitle:@"申请借款" forState:UIControlStateNormal];
  422. allTF.enabled=YES;
  423. monthBtn.enabled=YES;
  424. nextBtn.enabled=YES;
  425. }
  426. } failure:^(NSError *error) {
  427. }];
  428. }
  429. //-(void)changeView:(NSNotification *)noti
  430. //{
  431. // [self createWaitView];
  432. //}
  433. -(void)createWaitView
  434. {
  435. UITextField *allTF=[self.view viewWithTag:8865];
  436. UIButton *monthBtn=[self.view viewWithTag:8866];
  437. UIButton *nextBtn=[self.view viewWithTag:999];
  438. UIView* viewOld=[self.view viewWithTag:8888];
  439. viewOld.hidden=YES;
  440. allTF.enabled=NO;
  441. monthBtn.enabled=NO;
  442. nextBtn.enabled=NO;
  443. [nextBtn setTitle:@"审核中..." forState:UIControlStateNormal];
  444. KXMainWaitBGView* view=[self.view viewWithTag:8889];
  445. if(view){
  446. view.hidden=NO;
  447. return;
  448. }
  449. UILabel* labelWait=[[UILabel alloc] init];
  450. labelWait.textColor=[UIColor titleColor];
  451. labelWait.font=FONT_SYS(13);
  452. labelWait.text=@"待审核";
  453. UILabel* labelSuccess=[[UILabel alloc] init];
  454. labelSuccess.textColor=[UIColor detailTitleColor];
  455. labelSuccess.font=FONT_SYS(10);
  456. labelSuccess.text=@"申请提交成功";
  457. CGFloat height1=[labelWait.text boundingRectWithSize:CGSizeMake(0, 0) options:NSStringDrawingTruncatesLastVisibleLine attributes:@{NSFontAttributeName:labelWait.font} context:nil].size.height;
  458. CGFloat height2=[labelSuccess.text boundingRectWithSize:CGSizeMake(0, 0) options:NSStringDrawingTruncatesLastVisibleLine attributes:@{NSFontAttributeName:labelSuccess.font} context:nil].size.height;
  459. 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];
  460. view.layer.cornerRadius=2;
  461. view.layer.masksToBounds=YES;
  462. view.backgroundColor=[UIColor whiteColor];
  463. view.layer.borderWidth = SCREEN_MUTI;
  464. view.layer.borderColor =[[UIColor lineColor1]CGColor];
  465. view.tag=8889;
  466. [self.view addSubview:view];
  467. [view addSubview:labelWait];
  468. [view addSubview:labelSuccess];
  469. [labelWait mas_makeConstraints:^(MASConstraintMaker *make) {
  470. make.top.equalTo(view.mas_top).offset(52*SCREEN_MUTI);
  471. make.left.equalTo(view.mas_left).offset(34*SCREEN_MUTI);
  472. }];
  473. [labelSuccess mas_makeConstraints:^(MASConstraintMaker *make) {
  474. make.bottom.equalTo(view.mas_bottom).offset(-52*SCREEN_MUTI);
  475. make.left.equalTo(labelWait.mas_left);
  476. }];
  477. UILabel* labelWaitIng=[[UILabel alloc] init];
  478. labelWaitIng.textColor=[UIColor detailTitleColor];
  479. labelWaitIng.font=FONT_SYS(10);
  480. labelWaitIng.text=@"您的借款申请正在进行审核,请稍等!";
  481. [view addSubview:labelWaitIng];
  482. UILabel* labelTime=[[UILabel alloc] init];
  483. labelTime.textColor=[UIColor detailTitleColor];
  484. labelTime.font=FONT_SYS(10);
  485. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  486. [dateFormatter setDateFormat:@"yyyy-MM-dd"];
  487. NSString *currentDateStr = [dateFormatter stringFromDate:[NSDate date]];
  488. labelTime.text=currentDateStr;
  489. [view addSubview:labelTime];
  490. [labelWaitIng mas_makeConstraints:^(MASConstraintMaker *make) {
  491. make.bottom.equalTo(labelSuccess.mas_top).offset(-33*SCREEN_MUTI);
  492. make.left.equalTo(labelWait.mas_left);
  493. }];
  494. [labelTime mas_makeConstraints:^(MASConstraintMaker *make) {
  495. make.bottom.equalTo(labelSuccess.mas_bottom);
  496. make.right.equalTo(view.mas_right).offset(-14*SCREEN_MUTI);
  497. }];
  498. }
  499. #pragma mark UITextFieldDelegate
  500. -(void)textFieldDidEndEditing:(UITextField *)textField
  501. {
  502. if(textField.text.length==0||_month==0)
  503. {
  504. return;
  505. }
  506. [self calculate:[textField.text integerValue]];
  507. }
  508. -(void)calculate:(NSInteger) c {
  509. UILabel* label=(UILabel*)[self.view viewWithTag:8800];
  510. UILabel* label1=(UILabel*)[self.view viewWithTag:8801];
  511. UILabel* label2=(UILabel*)[self.view viewWithTag:8802];
  512. // loan/limit+(loan-i*loan/limit)*0.005;
  513. // 应该等额本息计算:每月还款金额 = 〔贷款本金×月利率×(1+月利率)^还款月数〕÷〔(1+月利率)^还款月数-1〕
  514. label.text =[NSString stringWithFormat:@"%.2f",(float)c];
  515. label2.text =[NSString stringWithFormat:@"%i",(int)_month];
  516. if (!c) {
  517. label1.text=@"0";
  518. }else{
  519. label1.text=[NSString stringWithFormat:@"%.2f",c*0.005*pow(1.005,(int)_month)/(pow(1.005,(int)_month)-1)];
  520. }
  521. }
  522. - (BOOL)isPureInt:(NSString*)string{
  523. NSScanner* scan = [NSScanner scannerWithString:string];
  524. int val;
  525. return[scan scanInt:&val] && [scan isAtEnd];
  526. }
  527. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
  528. {
  529. if (textField.text.length+string.length>8) {
  530. return NO;
  531. }
  532. if([self isPureInt:string]){
  533. if(range.location==0&&[string hasPrefix:@"0"]){
  534. return NO;
  535. }
  536. }else{
  537. if(string.length!=0){
  538. return NO;
  539. }
  540. }
  541. return YES;
  542. }
  543. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  544. {
  545. return 6;
  546. }
  547. -(NSArray *)monthArray
  548. {
  549. if (!_monthArray) {
  550. _monthArray=@[@"1",@"3",@"6",@"12",@"24",@"36"];
  551. }
  552. return _monthArray;
  553. }
  554. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  555. {
  556. KXSelectTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"selected"];
  557. if (!cell) {
  558. cell=[[KXSelectTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"selected"];
  559. }
  560. cell.detailStr=self.monthArray[indexPath.row];
  561. return cell;
  562. }
  563. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath
  564. {
  565. return 45;
  566. }
  567. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  568. {
  569. _month=[self.monthArray[indexPath.row] integerValue];
  570. UIButton *button=[self.view viewWithTag:8866];
  571. [button setTitle:self.monthArray[indexPath.row] forState:UIControlStateNormal];
  572. UILabel* label=(UILabel*)[self.view viewWithTag:8802];
  573. label.text=self.monthArray[indexPath.row];
  574. UITextField* text=(UITextField*)[self.view viewWithTag:8865];
  575. if(text.text.length==0){
  576. [self calculate: 5000];
  577. }else{
  578. [self calculate: text.text.integerValue];
  579. }
  580. _selectView.hidden=YES;
  581. }
  582. -(void)buttonllAction:(UIButton *)btn{
  583. // [self.selectTableView reloadData];
  584. _selectView.hidden=NO;
  585. }
  586. -(void)nextAction
  587. {
  588. UIButton *nextBtn=[self.view viewWithTag:999];
  589. nextBtn.enabled=NO;
  590. // if ([nextBtn.titleLabel.text isEqualToString:@"审核中..."]) {
  591. // [self createPromptWhit:@"不要着急,请耐心等待审核......"];
  592. // return;
  593. // }
  594. NSString *urlString=[NSString stringWithFormat:@"%@/user/personalCenter",URL];
  595. [KXHTTP post:urlString params:nil success:^(id json) {
  596. NSString *username= [[NSUserDefaults standardUserDefaults]valueForKey:USER_NAME];
  597. NSString *password=[[NSUserDefaults standardUserDefaults]valueForKey:USER_PASSWORD];
  598. if (!username||!password) {
  599. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"请登录" preferredStyle:UIAlertControllerStyleAlert];
  600. [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  601. KXLogginViewController *loggin=[[KXLogginViewController alloc]init];
  602. self.navigationController.navigationBar.hidden = NO;
  603. [self.navigationController pushViewController:loggin animated:YES];
  604. [[NSUserDefaults standardUserDefaults]setObject:nil forKey:@"ISPOP"];
  605. [[NSUserDefaults standardUserDefaults]synchronize];
  606. }]];
  607. [self presentViewController:alertController animated:YES completion:nil];
  608. nextBtn.enabled=YES;
  609. }else if (!self.agreeBool){//请勾选同意协议
  610. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"请勾选同意协议" preferredStyle:UIAlertControllerStyleAlert];
  611. [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  612. [[NSUserDefaults standardUserDefaults]setObject:nil forKey:@"ISPOP"];
  613. [[NSUserDefaults standardUserDefaults]synchronize];
  614. }]];
  615. [self presentViewController:alertController animated:YES completion:nil];
  616. nextBtn.enabled=YES;
  617. }else{
  618. UITextField* textfield=[self.view viewWithTag:8865];
  619. if(textfield.text.length==0){
  620. [self createPromptWhit:@"请输入金额后再试"];
  621. nextBtn.enabled=YES;
  622. return;
  623. }
  624. if(_month==0){
  625. [self createPromptWhit:@"请选择期限后再试"];
  626. nextBtn.enabled=YES;
  627. return;
  628. }
  629. KXThirdWebViewController *mainWeb=[[KXThirdWebViewController alloc]init];
  630. mainWeb.amount=textfield.text.integerValue ;
  631. mainWeb.term=_month;
  632. [self.navigationController pushViewController:mainWeb animated:YES];
  633. nextBtn.enabled=YES;
  634. }
  635. } failure:^(NSError *error) {
  636. nextBtn.enabled=YES;
  637. }];
  638. }
  639. -(void)createPromptWhit:(NSString*) message{
  640. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:message preferredStyle:UIAlertControllerStyleAlert];
  641. [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  642. }]];
  643. [self presentViewController:alertController animated:YES completion:nil];
  644. }
  645. -(void)closeTop{
  646. self.topView.hidden=YES;
  647. self.backView.hidden=YES;
  648. UIWebView *content=[self.topView viewWithTag:766];
  649. [content loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@""]]];
  650. }
  651. -(UIView *)topView{
  652. if (!_topView) {
  653. _topView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 300, 380)];
  654. _topView.center=self.view.center;
  655. _topView.backgroundColor=[UIColor whiteColor];
  656. UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 300, 49.5)];
  657. titleLabel.textColor=[UIColor baseColor];
  658. titleLabel.textAlignment=NSTextAlignmentCenter;
  659. UIView *line1=[[UIView alloc]initWithFrame:CGRectMake(0, 49.5, 300, 0.5)];
  660. line1.backgroundColor=[UIColor baseColor];
  661. UIView *line2=[[UIView alloc]initWithFrame:CGRectMake(0, 330, 300, 0.5)];
  662. line2.backgroundColor=[UIColor baseColor];
  663. titleLabel.tag=764;
  664. // UIScrollView *contentScrollView=[[UIScrollView alloc]initWithFrame:];
  665. // contentScrollView.tag=765;
  666. UIWebView*content=[[UIWebView alloc]initWithFrame:CGRectMake(0, 50, 300, 280)];
  667. content.tag=766;
  668. UIButton *closeButton=[[UIButton alloc]initWithFrame:CGRectMake(0, 330.5, 300, 50)];
  669. content.backgroundColor=[UIColor whiteColor];
  670. [closeButton setTitle:@"关闭" forState:UIControlStateNormal];
  671. [closeButton setTitleColor:[UIColor baseColor] forState:UIControlStateNormal];
  672. [closeButton addTarget:self action:@selector(closeTop) forControlEvents:UIControlEventTouchUpInside];
  673. closeButton.tag=767;
  674. [_topView addSubview:titleLabel];
  675. // [contentScrollView addSubview:content];
  676. // [_topView addSubview:contentScrollView];
  677. [_topView addSubview:content];
  678. [_topView addSubview:closeButton];
  679. [_topView addSubview:line1];
  680. [_topView addSubview:line2];
  681. }
  682. return _topView;
  683. }
  684. -(UIView *)backView{
  685. if (!_backView) {
  686. _backView=[[UIView alloc]initWithFrame:self.view.bounds];
  687. _backView.backgroundColor=[UIColor KXColorWithHex:0x000000 alpha:0.3];
  688. }
  689. return _backView;
  690. }
  691. -(NSArray *)protocolArray{
  692. if (!_protocolArray) {
  693. NSMutableArray *arr=[NSMutableArray array];
  694. NSString*path=[[NSBundle mainBundle] pathForResource:@"protocolList" ofType:@"plist"];
  695. NSMutableArray *dataList=[NSMutableArray arrayWithContentsOfFile:path];
  696. for (NSDictionary *dic in dataList) {
  697. [arr addObject:dic];
  698. }
  699. _protocolArray=[NSArray arrayWithArray:arr];
  700. }
  701. return _protocolArray;
  702. }
  703. @end