Keine Beschreibung

KXMainDetailViewController.m 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. //
  2. // KXMainDetailViewController.m
  3. // QBCS
  4. //
  5. // Created by kuxuan on 2017/6/6.
  6. // Copyright © 2017年 kuxuan. All rights reserved.
  7. //
  8. #import "KXMainDetailViewController.h"
  9. #import "KXMainDetailModel.h"
  10. #import "KXMainDetailThreeView.h"
  11. #import "KXMainDetailTableViewCell.h"
  12. #import "KXQuesViewController.h"
  13. #import "KXSelectTableViewCell.h"
  14. #import "KXWebDetailViewController.h"
  15. #import "KXLogginViewController.h"
  16. #import "KXUpDownButton.h"
  17. #import "KXRecommendView.h"
  18. #import "KXMainPageViewModel.h"
  19. #import "KXLittleLogginView.h"
  20. @interface KXMainDetailViewController ()<UITextFieldDelegate,UITableViewDelegate,UITableViewDataSource,KXRecommendViewDelegate,KXLittleLogginViewDelegate>
  21. {
  22. UIView *_headerView;
  23. UIView *_footerView;
  24. KXMainDetailModel *_detailModel;
  25. UITextField *_amountTF;
  26. UIButton *_dateButton;
  27. NSArray *_titleArray;
  28. NSArray *_detailImageArr;
  29. UIView *_selectView;
  30. KXUpDownButton *_updownButton;
  31. BOOL _isSpread;
  32. KXRecommendView *_recommendView;
  33. UIButton *_applyButton;
  34. }
  35. @property (nonatomic,strong)UITableView *tableView;
  36. @property (nonatomic,strong)UITableView *selectTableView;
  37. @property (nonatomic,strong)MBProgressHUD *hud;
  38. @end
  39. @implementation KXMainDetailViewController
  40. - (void)viewDidLoad {
  41. [super viewDidLoad];
  42. // Do any additional setup after loading the view.
  43. _titleArray=@[@"申请条件",@"所需资料",@"详细说明"];
  44. _detailImageArr = @[@"main_detail_term",@"main_detail_data",@"main_detail_explain"];
  45. _isSpread = NO;
  46. if (self.enterSource == nil) {
  47. self.enterSource = @"";
  48. }
  49. [self createNavigation];
  50. [self requestData];
  51. }
  52. -(void)createNavigation
  53. {
  54. self.name = self.titleString;
  55. [self addLeftBarButtonItemWithImageName:@"main_back" title:nil target:self selector:@selector(pop)];
  56. if (_detailModel.customer_service_number.length) {
  57. [self addRightBarButtonItemWithImageName:@"main_detail_phone" target:self selector:@selector(phone) redDot:NO];
  58. }
  59. }
  60. -(void)pop
  61. {
  62. if (self.isPresent == YES) {
  63. [self.navigationController dismissViewControllerAnimated:YES completion:nil];
  64. } else{
  65. [self.navigationController popViewControllerAnimated:YES];
  66. }
  67. }
  68. -(void)phone
  69. {
  70. NSString *phoneNumber = [NSString stringWithFormat:@"tel:%@",_detailModel.customer_service_number];
  71. UIAlertController *alert = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"%@客服电话",_detailModel.name] message:_detailModel.customer_service_number preferredStyle:UIAlertControllerStyleAlert];
  72. [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  73. }]];
  74. [alert addAction:[UIAlertAction actionWithTitle:@"呼叫" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  75. if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:phoneNumber]]) {
  76. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
  77. }
  78. }]];
  79. [self presentViewController:alert animated:YES completion:nil];
  80. }
  81. -(void)setBottomView
  82. {
  83. UIView *bottomView=[[UIView alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT-62-NavHeight-safeBottomHeight, SCREEN_WIDTH, 62)];
  84. [self.view addSubview:bottomView];
  85. _applyButton=[UIButton buttonWithType:UIButtonTypeCustom];
  86. _applyButton.layer.cornerRadius=3;
  87. _applyButton.layer.masksToBounds=YES;
  88. _applyButton.frame=CGRectMake(LEADING_SPACE, 8, SCREEN_WIDTH-2*LEADING_SPACE, 46);
  89. [_applyButton setBackgroundColor:[UIColor baseColor]];
  90. [_applyButton setTitle:@"立即申请" forState:UIControlStateNormal];
  91. [_applyButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  92. [_applyButton addTarget:self action:@selector(applyAction) forControlEvents:UIControlEventTouchUpInside];
  93. [bottomView addSubview:_applyButton];
  94. BOOL isEnable = [_detailModel.status integerValue] == 1? YES:NO;
  95. if(isEnable == NO)
  96. {
  97. [_applyButton setBackgroundColor:[UIColor grayColor]];
  98. [_applyButton setTitle:@"已下架" forState:UIControlStateNormal];
  99. [_applyButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  100. _applyButton.enabled = NO;
  101. }
  102. }
  103. -(void)applyAction
  104. {
  105. // _applyButton.enabled = NO;
  106. NSString *urlString=[NSString stringWithFormat:@"%@/user/personalCenter",URL];
  107. [KXHTTP post:urlString params:nil success:^(id json) {
  108. NSString *username= [[NSUserDefaults standardUserDefaults]valueForKey:USER_NAME];
  109. if (!username) {
  110. KXLittleLogginView *littleView = [[KXLittleLogginView alloc]initWithFrame:self.view.bounds];
  111. littleView.delegate = self;
  112. [self.view addSubview:littleView];
  113. _applyButton.enabled = YES;
  114. }else{
  115. NSInteger markCount = [[NSUserDefaults standardUserDefaults] integerForKey:KXMARK_CLICKCOUNT];
  116. if (!markCount) {
  117. markCount = 0;
  118. }
  119. markCount ++;
  120. [[NSUserDefaults standardUserDefaults] setInteger:markCount forKey:KXMARK_CLICKCOUNT];
  121. [[NSUserDefaults standardUserDefaults] synchronize];
  122. [MobClick event:@"applyClick"];
  123. NSString *urlString=[NSString stringWithFormat:@"%@/user/addapply",URL];
  124. [KXHTTP post:urlString params:@{@"product_id":self.detailID,@"periods":_dateButton.titleLabel.text,@"money":_amountTF.text} success:^(id json) {
  125. NSDictionary *dict = @{@"entersource":self.enterSource};
  126. [MobClick event:@"applyAction" attributes:dict];
  127. KXWebDetailViewController *web=[[KXWebDetailViewController alloc]init];
  128. web.webStr = json[@"url"];
  129. web.titleStr = self.name;
  130. web.product_id = self.detailID;
  131. web.product_apply_id = json[@"product_apply_id"];
  132. [self.navigationController pushViewController:web animated:YES];
  133. _applyButton.enabled = YES;
  134. } failure:^(NSError *error) {
  135. _applyButton.enabled = YES;
  136. }];
  137. }
  138. } failure:^(NSError *error) {
  139. _applyButton.enabled = YES;
  140. }];
  141. }
  142. -(void)requestData
  143. {
  144. //[self.hud showAnimated:YES];
  145. NSString *urlString=[NSString stringWithFormat:@"%@/product/detail",URL];
  146. [KXHTTP post:urlString params:@{@"id":self.detailID,@"enter_source":self.enterSource} success:^(id json) {
  147. [self.hud hide:YES];
  148. _detailModel=[KXMainDetailModel yy_modelWithJSON:json];
  149. [self createHeaderView];
  150. [self setBottomView];
  151. [self setupSelectView];
  152. [self createNavigation];
  153. } failure:^(NSError *error) {
  154. [self.hud hide:YES];
  155. }];
  156. }
  157. -(void)createHeaderView
  158. {
  159. _headerView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 373)];
  160. _headerView.backgroundColor=[UIColor KXColorWithRed:239 green:239 blue:244];
  161. UIView *topView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 168)];
  162. topView.backgroundColor=[UIColor whiteColor];
  163. [_headerView addSubview:topView];
  164. UIImageView *headImageView=[[UIImageView alloc]initWithFrame:CGRectMake(14, 19, 50, 50)];
  165. [headImageView sd_setImageWithURL:[NSURL URLWithString:_detailModel.icon] placeholderImage:[UIImage imageNamed:@"placeholder_square"] options:SDWebImageRefreshCached];
  166. headImageView.layer.cornerRadius=8;
  167. headImageView.layer.masksToBounds=YES;
  168. [topView addSubview:headImageView];
  169. UILabel *nameLabel=[[UILabel alloc]initWithFrame:CGRectMake(78, 19, 200, 20)];
  170. nameLabel.textColor=[UIColor titleColor];
  171. nameLabel.font=FONT_SYS(18);
  172. nameLabel.text=_detailModel.name;
  173. [topView addSubview:nameLabel];
  174. UILabel *applyLabel=[[UILabel alloc]initWithFrame:CGRectMake(78, 55, 130, 15)];
  175. applyLabel.textColor=[UIColor detailTitleColor];
  176. applyLabel.font=FONT_SYS(12);
  177. applyLabel.text=[NSString stringWithFormat:@"%@人申请成功",_detailModel.applicants];
  178. [topView addSubview:applyLabel];
  179. UILabel *ratelabel=[[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-130, 55, 40, 15)];
  180. ratelabel.textColor=[UIColor detailTitleColor];
  181. ratelabel.font=FONT_SYS(12);
  182. ratelabel.text=@"成功率";
  183. [topView addSubview:ratelabel];
  184. for (int i=0; i<5; i++) {
  185. UIImageView *starImageView=[[UIImageView alloc]initWithFrame:CGRectMake((SCREEN_WIDTH-90)+16*i, 55, 14, 14)];
  186. if (i<_detailModel.star.intValue) {
  187. starImageView.image=[UIImage imageNamed:@"main_star_highlight"];
  188. }else{
  189. starImageView.image=[UIImage imageNamed:@"main_star_normal"];
  190. }
  191. [topView addSubview:starImageView];
  192. }
  193. UIView *toplineView = [[UIView alloc] initWithFrame:CGRectMake(15, 87, SCREEN_WIDTH-30, 1)];
  194. toplineView.backgroundColor = [UIColor KXColorWithHex:0xeeeeee];
  195. [topView addSubview:toplineView];
  196. NSArray *topTitleArr = @[@"额度",@"期限",@"参考月利率"];
  197. NSString *quotaStr = [NSString stringWithFormat:@"%@-%@",_detailModel.upper_amount,_detailModel.lower_amount];
  198. NSString *segStr = _detailModel.term;
  199. NSString *topMonthRateStr = [NSString stringWithFormat:@"%.2f%@",_detailModel.monthly_rate.floatValue,@"%"];
  200. NSArray *topDetailArr = @[quotaStr,segStr,topMonthRateStr];
  201. for (NSInteger i =0; i<3; i++) {
  202. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(i*(SCREEN_WIDTH/3), 107, SCREEN_WIDTH/3, 17)];
  203. label.font = FONT_SYS(12);
  204. label.textColor = [UIColor KXColorWithHex:0x666666];
  205. label.textAlignment = NSTextAlignmentCenter;
  206. label.text = topTitleArr[i];
  207. [topView addSubview:label];
  208. UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(i*(SCREEN_WIDTH/3), 130, SCREEN_WIDTH/3, 20)];
  209. label2.font = FONT_SYS(14);
  210. label2.textColor = [UIColor titleColor];
  211. label2.textAlignment = NSTextAlignmentCenter;
  212. label2.text = topDetailArr[i];
  213. [topView addSubview:label2];
  214. }
  215. UIView *middleView=[[UIView alloc]initWithFrame:CGRectMake(0, 174, SCREEN_WIDTH, 215)];
  216. middleView.backgroundColor=[UIColor whiteColor];
  217. [_headerView addSubview:middleView];
  218. UILabel *quotaLabel=[[UILabel alloc]initWithFrame:CGRectMake(15, 31, 30*SCREEN_MUTI, 15)];
  219. quotaLabel.textColor=[UIColor KXColorWithHex:0x666666];
  220. quotaLabel.font=FONT_SYS(14);
  221. quotaLabel.text=@"金额";
  222. [middleView addSubview:quotaLabel];
  223. UILabel *amountLabel=[[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-44, 31, 15, 15)];
  224. amountLabel.text=@"元";
  225. amountLabel.font=FONT_SYS(14);
  226. amountLabel.textColor=[UIColor KXColorWithHex:0x666666];
  227. [middleView addSubview:amountLabel];
  228. _amountTF=[[UITextField alloc]initWithFrame:CGRectMake(45, 24, SCREEN_WIDTH-90,28)];
  229. _amountTF.font=FONT_SYS(20);
  230. _amountTF.textColor = [UIColor baseColor];
  231. _amountTF.text=_detailModel.upper_amount.stringValue;
  232. _amountTF.textAlignment=NSTextAlignmentCenter;
  233. _amountTF.returnKeyType=UIReturnKeyDone;
  234. _amountTF.keyboardType=UIKeyboardTypeNumberPad;
  235. _amountTF.delegate=self;
  236. [middleView addSubview:_amountTF];
  237. UIView *amountLine = [[UIView alloc] initWithFrame:CGRectMake(15, 62, SCREEN_WIDTH-30, 1)];
  238. amountLine.backgroundColor = [UIColor KXColorWithHex:0xeeeeee];
  239. [middleView addSubview:amountLine];
  240. UILabel *segLabel=[[UILabel alloc]initWithFrame:CGRectMake(15, 80, Fitsize(30), 20)];
  241. segLabel.textColor=[UIColor KXColorWithHex:0x666666];
  242. segLabel.font=FONT_SYS(14);
  243. segLabel.text=@"期限";
  244. [middleView addSubview:segLabel];
  245. _dateButton=[UIButton buttonWithType:UIButtonTypeCustom];
  246. _dateButton.frame=CGRectMake(45, 73, SCREEN_WIDTH-90, 28);
  247. NSDictionary *dict=_detailModel.loan_period[0];
  248. NSString *month = dict[@"k"];
  249. [_dateButton setTitle:month forState:UIControlStateNormal];
  250. [_dateButton setTitleColor:[UIColor baseColor] forState:UIControlStateNormal];
  251. _dateButton.titleLabel.font=FONT_SYS(20);
  252. [_dateButton addTarget:self action:@selector(chooseDate) forControlEvents:UIControlEventTouchUpInside];
  253. [middleView addSubview:_dateButton];
  254. UIButton *daterightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  255. daterightBtn.frame =CGRectMake(SCREEN_WIDTH-60, 80, 60, 15);
  256. [daterightBtn setImage:[UIImage imageNamed:@"main_detail_down"] forState:UIControlStateNormal];
  257. [daterightBtn setTitle:[dict[@"v"] substringWithRange:NSMakeRange([dict[@"v"] length]-1, 1)] forState:UIControlStateNormal];
  258. [daterightBtn setTitleColor:[UIColor KXColorWithHex:0x666666] forState:UIControlStateNormal];
  259. daterightBtn.titleLabel.font=FONT_SYS(14);
  260. [daterightBtn addTarget:self action:@selector(chooseDate) forControlEvents:UIControlEventTouchUpInside];
  261. [middleView addSubview:daterightBtn];
  262. [self setImageToRight:daterightBtn];
  263. UIView *dateLine = [[UIView alloc] initWithFrame:CGRectMake(15, 111, SCREEN_WIDTH-30, 1)];
  264. dateLine.backgroundColor = [UIColor KXColorWithHex:0xeeeeee];
  265. [middleView addSubview:dateLine];
  266. UILabel *bottomLeftLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 128, 120, 20)];
  267. bottomLeftLabel.font = FONT_SYS(14);
  268. bottomLeftLabel.textColor = [UIColor KXColorWithHex:0x666666];
  269. bottomLeftLabel.text = @"最快放款时间";
  270. [middleView addSubview:bottomLeftLabel];
  271. UILabel *bottomRightLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-75, 128, 60, 20)];
  272. bottomRightLabel.font = FONT_SYS(14);
  273. bottomRightLabel.textAlignment = NSTextAlignmentRight;
  274. bottomRightLabel.textColor = [UIColor KXColorWithHex:0x666666];
  275. bottomRightLabel.text = [NSString stringWithFormat:@"%@",[[self calculateSumMoney] objectAtIndex:2]];
  276. [middleView addSubview:bottomRightLabel];
  277. UILabel *bottomMidLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 164, SCREEN_WIDTH, 22)];
  278. bottomMidLabel.font = FONT_SYS(16);
  279. bottomMidLabel.textColor = [UIColor detailTitleColor];
  280. bottomMidLabel.textAlignment = NSTextAlignmentCenter;
  281. bottomMidLabel.text = [NSString stringWithFormat:@"预计还款总额%@",[[self calculateSumMoney] objectAtIndex:0]];
  282. bottomMidLabel.tag = 12345;
  283. [middleView addSubview:bottomMidLabel];
  284. [self createFooterView];
  285. [self createTableView];
  286. }
  287. -(void)setupSelectView
  288. {
  289. _selectView=[[UIView alloc]initWithFrame:self.view.bounds];
  290. _selectView.hidden=YES;
  291. _selectView.backgroundColor=[UIColor colorWithWhite:0 alpha:0.5];
  292. [self.view addSubview:_selectView];
  293. self.selectTableView = [[UITableView alloc]initWithFrame:CGRectMake(0,SCREEN_HEIGHT-220-64, SCREEN_WIDTH, 220) style:UITableViewStylePlain];
  294. self.selectTableView.backgroundColor=[UIColor KXColorWithRed:239 green:239 blue:244];
  295. self.selectTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
  296. [self.selectTableView registerClass:[KXSelectTableViewCell class] forCellReuseIdentifier:@"select"];
  297. self.selectTableView.tableFooterView=[[UIView alloc]init];
  298. self.selectTableView.delegate = self;
  299. self.selectTableView.dataSource = self;
  300. [_selectView addSubview:self.selectTableView];
  301. }
  302. -(void)tapAction:(UITapGestureRecognizer *)tap
  303. {
  304. _selectView.hidden=YES;
  305. }
  306. -(NSArray *)calculateSumMoney
  307. {
  308. NSInteger amount=_amountTF.text.integerValue;
  309. NSInteger date=[_dateButton.titleLabel.text integerValue];
  310. float rate;
  311. NSString *rateString;
  312. if ([_detailModel.show_day isEqualToString:@"参考月利率"]) {
  313. rate=_detailModel.monthly_rate.floatValue/100;
  314. rateString=[NSString stringWithFormat:@"%.2f%@",_detailModel.monthly_rate.floatValue,@"%"];
  315. }else{
  316. rate=_detailModel.day_rate.floatValue/100;
  317. rateString=[NSString stringWithFormat:@"%.2f%@",_detailModel.day_rate.floatValue,@"%"];
  318. }
  319. NSArray *detailArray=@[[NSString stringWithFormat:@"%.2f元",amount*date*rate+amount],rateString,_detailModel.lend_time];
  320. return detailArray;
  321. }
  322. -(void)chooseDate
  323. {
  324. _selectView.hidden=NO;
  325. }
  326. //设置图片居右
  327. -(void)setImageToRight:(UIButton *)btn
  328. {
  329. NSDictionary *attribute = @{NSFontAttributeName:btn.titleLabel.font};
  330. //获取文本的宽度
  331. CGFloat btnWidth = [btn.titleLabel.text boundingRectWithSize:CGSizeMake(0, 15)
  332. options:\
  333. NSStringDrawingTruncatesLastVisibleLine |
  334. NSStringDrawingUsesLineFragmentOrigin |
  335. NSStringDrawingUsesFontLeading
  336. attributes:attribute
  337. context:nil].size.width;
  338. //通过调节文本和图片的内边距到达目的
  339. btn.imageEdgeInsets = UIEdgeInsetsMake(0, btnWidth+4, 0, -btnWidth);
  340. [btn setTitleEdgeInsets:UIEdgeInsetsMake(0, -btn.imageView.image.size.width-3, 0, btn.imageView.image.size.width)];
  341. }
  342. -(void)createTableView
  343. {
  344. self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-NavHeight-62-safeBottomHeight) style:UITableViewStylePlain];
  345. self.tableView.backgroundColor=[UIColor KXColorWithRed:239 green:239 blue:244];
  346. self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
  347. [self.tableView registerClass:[KXMainDetailTableViewCell class] forCellReuseIdentifier:@"detail"];
  348. self.tableView.tableHeaderView=_headerView;
  349. self.tableView.tableFooterView=_footerView;
  350. self.tableView.delegate = self;
  351. self.tableView.dataSource = self;
  352. [self.view addSubview:self.tableView];
  353. }
  354. - (void)createFooterView
  355. {
  356. _footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 75 + 90*SCREEN_MUTI)];
  357. _footerView.backgroundColor=[UIColor KXColorWithRed:239 green:239 blue:244];
  358. _updownButton = [[KXUpDownButton alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 45)];
  359. [_updownButton addTarget:self action:@selector(upAndDownAction:) forControlEvents:UIControlEventTouchUpInside];
  360. [_footerView addSubview:_updownButton];
  361. UILabel *sameMoreLabel = [[UILabel alloc]initWithFrame:CGRectMake(14, 45, 300, 30)];
  362. sameMoreLabel.text = @"同时申请这些产品的贷款通过率更高哦~";
  363. sameMoreLabel.font = FONT_SYS(14);
  364. sameMoreLabel.textColor = [UIColor KXColorWithHex:0x666666];
  365. [_footerView addSubview:sameMoreLabel];
  366. _recommendView = [[KXRecommendView alloc]initWithFrame:CGRectMake(0, 75, SCREEN_WIDTH, 90*SCREEN_MUTI)];
  367. _recommendView.delegate = self;
  368. [_footerView addSubview:_recommendView];
  369. [KXMainPageViewModel recommendData:@{@"id":self.detailID} data:^(NSArray *dataSource) {
  370. _recommendView.dataSource = dataSource;
  371. }];
  372. }
  373. - (void)upAndDownAction:(KXUpDownButton *)btn
  374. {
  375. if (_isSpread == NO) {
  376. _isSpread = YES;
  377. btn.imageView.image = [UIImage imageWithCGImage:btn.imageView.image.CGImage scale:1 orientation:UIImageOrientationDown];
  378. [self.tableView reloadData];
  379. btn.titleLabel.text = @"收起";
  380. }else{
  381. _isSpread = NO;
  382. btn.imageView.image = [UIImage imageWithCGImage:btn.imageView.image.CGImage scale:1 orientation:UIImageOrientationUp];
  383. [self.tableView reloadData];
  384. btn.titleLabel.text = @"查看更多";
  385. }
  386. }
  387. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  388. {
  389. if ([tableView isEqual:self.selectTableView]) {
  390. return 1;
  391. }else{
  392. if (_isSpread == YES) {
  393. return 3;
  394. }else{
  395. return 0;
  396. }
  397. }
  398. }
  399. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  400. {
  401. if ([tableView isEqual:self.selectTableView]) {
  402. return _detailModel.loan_period.count;
  403. }else{
  404. return 1;
  405. }
  406. }
  407. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  408. {
  409. if ([tableView isEqual:self.selectTableView]) {
  410. KXSelectTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"select"];
  411. if (!cell) {
  412. cell=[[KXSelectTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"select"];
  413. }
  414. NSDictionary *dict=_detailModel.loan_period[indexPath.row];
  415. cell.backgroundColor=[UIColor whiteColor];
  416. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  417. cell.detailStr=dict[@"v"];
  418. return cell;
  419. }else{
  420. KXMainDetailTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"detail"];
  421. if (!cell) {
  422. cell=[[KXMainDetailTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"detail"];
  423. }
  424. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  425. cell.nameLabel.text=_titleArray[indexPath.section];
  426. cell.ImageView.image = [UIImage imageNamed:_detailImageArr[indexPath.section]];
  427. NSMutableAttributedString * attrStr = [[NSMutableAttributedString alloc] initWithData:[_detailModel.req_list[indexPath.section] dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType} documentAttributes:nil error:nil];
  428. if (indexPath.section!=2) {
  429. cell.contentLabel.text=_detailModel.req_list[indexPath.section];
  430. }else{
  431. cell.contentLabel.attributedText=attrStr;
  432. }
  433. if (indexPath.section == 0) {
  434. cell.lineLabel.hidden = YES;
  435. }
  436. cell.contentLabel.font=FONT_SYS(14);
  437. cell.contentLabel.textColor=[UIColor titleColor];
  438. return cell;
  439. }
  440. }
  441. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath
  442. {
  443. if ([tableView isEqual:self.selectTableView]) {
  444. return 45;
  445. }else{
  446. if (indexPath.section!=2) {
  447. NSMutableAttributedString *att=[[NSMutableAttributedString alloc]initWithString:_detailModel.req_list[indexPath.section]];
  448. [att addAttribute:NSFontAttributeName value:FONT_SYS(14) range:NSMakeRange(0, [_detailModel.req_list[indexPath.section] length]-1)];
  449. CGRect rect=[att boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-28, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading context:nil];
  450. return rect.size.height+65;
  451. }else{
  452. NSMutableAttributedString * attrStr = [[NSMutableAttributedString alloc] initWithData:[_detailModel.req_list[indexPath.section] dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType} documentAttributes:nil error:nil];
  453. [attrStr addAttribute:NSFontAttributeName value:FONT_SYS(14) range:NSMakeRange(0, [attrStr length]-1)];
  454. CGRect rect = [attrStr boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-28, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin context:nil];
  455. return rect.size.height+65;
  456. }
  457. }
  458. }
  459. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  460. {
  461. if ([tableView isEqual:self.selectTableView]) {
  462. NSDictionary *dict=_detailModel.loan_period[indexPath.row];
  463. NSString *dateStr = dict[@"k"];
  464. [_dateButton setTitle:dateStr forState:UIControlStateNormal];
  465. [self setImageToRight:_dateButton];
  466. _selectView.hidden=YES;
  467. KXMainDetailThreeView *threeView=[_headerView viewWithTag:888];
  468. threeView.detailLabel.text=[[self calculateSumMoney] objectAtIndex:0];
  469. UILabel *label = [_headerView viewWithTag:12345];
  470. label.text = [NSString stringWithFormat:@"预计还款总额%@",[[self calculateSumMoney] objectAtIndex:0]];
  471. }
  472. }
  473. #pragma mark -----------UITextFieldDelagate---------------
  474. -(void)textFieldDidBeginEditing:(UITextField *)textField
  475. {
  476. textField.text=@"";
  477. }
  478. -(void)textFieldDidEndEditing:(UITextField *)textField reason:(UITextFieldDidEndEditingReason)reason
  479. {
  480. // if (textField.text.integerValue>_detailModel.lower_amount.integerValue) {
  481. // textField.text=_detailModel.lower_term.stringValue;
  482. // }
  483. // if (textField.text.integerValue<_detailModel.upper_amount.integerValue) {
  484. // textField.text=_detailModel.upper_amount.stringValue;
  485. // }
  486. KXMainDetailThreeView *threeView=[_headerView viewWithTag:888];
  487. threeView.detailLabel.text=[[self calculateSumMoney] objectAtIndex:0];
  488. UILabel *label = [_headerView viewWithTag:12345];
  489. label.text = [NSString stringWithFormat:@"预计还款总额%@",[[self calculateSumMoney] objectAtIndex:0]];
  490. }
  491. -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
  492. {
  493. return YES;
  494. }
  495. #pragma mark ----------------KXRecommendViewDelegate-------------------
  496. -(void)recmmendViewClickWithId:(NSString *)ID name:(NSString *)name
  497. {
  498. [MobClick event:@"detailListClick"];
  499. KXMainDetailViewController *detail=[[KXMainDetailViewController alloc]init];
  500. detail.detailID=ID;
  501. detail.titleString=name;
  502. detail.enterSource = @"detailList";
  503. [self.navigationController pushViewController:detail animated:YES];
  504. }
  505. #pragma mark =======================KXLittleLogginViewDelegate================
  506. - (void)littleLogginViewSuccess
  507. {
  508. NSString *urlString=[NSString stringWithFormat:@"%@/user/addapply",URL];
  509. [KXHTTP post:urlString params:@{@"product_id":self.detailID,@"periods":_dateButton.titleLabel.text,@"money":_amountTF.text} success:^(id json) {
  510. KXWebDetailViewController *web=[[KXWebDetailViewController alloc]init];
  511. web.webStr=_detailModel.link;
  512. web.titleStr = self.name;
  513. web.product_id = self.detailID;
  514. web.product_apply_id = json[@"product_apply_id"];
  515. [self.navigationController pushViewController:web animated:YES];
  516. } failure:^(NSError *error) {
  517. }];
  518. }
  519. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
  520. {
  521. _selectView.hidden=YES;
  522. }
  523. -(MBProgressHUD *)hud
  524. {
  525. if (!_hud) {
  526. _hud=[[MBProgressHUD alloc]initWithView:self.view];
  527. _hud.labelText=@"加载中...";
  528. [self.view addSubview:_hud];
  529. }
  530. return _hud;
  531. }
  532. - (void)didReceiveMemoryWarning {
  533. [super didReceiveMemoryWarning];
  534. // Dispose of any resources that can be recreated.
  535. }
  536. -(void)gotoMainDetail
  537. {
  538. NSLog(@"gotoMainDetail");
  539. }
  540. /*
  541. #pragma mark - Navigation
  542. // In a storyboard-based application, you will often want to do a little preparation before navigation
  543. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  544. // Get the new view controller using [segue destinationViewController].
  545. // Pass the selected object to the new view controller.
  546. }
  547. */
  548. @end