Açıklama Yok

KXMainPageViewController.m 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. //
  2. // KXMainPageViewController.m
  3. // QBCS
  4. //
  5. // Created by kuxuan on 2017/6/6.
  6. // Copyright © 2017年 kuxuan. All rights reserved.
  7. //
  8. #import "KXMainPageViewController.h"
  9. #import "KXMainHorizontalCycleView.h"
  10. #import "KXCycleModel.h"
  11. #import "KXLoanButton.h"
  12. #import "KXMainListTableViewCell.h"
  13. #import "KXWebDetailViewController.h"
  14. #import "KXLoanAllDetailViewController.h"
  15. #import "KXLoanNewViewController.h"
  16. #import "KXMainDetailViewController.h"
  17. #import "KXLetterViewController.h"
  18. #import "KXMainDetailModel.h"
  19. #import "KXMainPageViewModel.h"
  20. #import "KXLoanAllModel.h"
  21. #import "KXDismissViewController.h"
  22. #import "KXMainVerticleCycleView.h"
  23. #import "KXVerticleModel.h"
  24. #import "KXMarkView.h"
  25. #import "KXThirdMarkView.h" //3.0的弹出框
  26. #import "KXBaseLinkViewController.h"
  27. #import "KXLaunchModel.h"
  28. #import <StoreKit/StoreKit.h>
  29. @interface KXMainPageViewController ()<KXMainHorizontalCycleDelegate,UITableViewDelegate,UITableViewDataSource,KXMainVerticleCycleViewDelegate,KXMarkViewDelegate,UINavigationControllerDelegate,KXThirdMarkViewDelegate>
  30. {
  31. KXMainHorizontalCycleView *_cycleView;
  32. KXMainVerticleCycleView *_verticleView;
  33. UIView *_headerView;
  34. UIView *_alertWindow;
  35. KXMarkView *_markView;
  36. KXLaunchModel *_launchModel;
  37. KXThirdMarkView *_thirdMarkView;
  38. }
  39. @property (nonatomic,strong)UITableView *tableView;
  40. @property (nonatomic,strong)NSMutableArray *dataSource;
  41. @property (nonatomic,assign)NSInteger page;
  42. @property (nonatomic,strong)UIButton *rightBtn;
  43. @property (nonatomic,strong)UILabel *redLabel;
  44. @property (nonatomic,strong)NSArray *otherSource; //新品区数据,暂时写死
  45. @property (nonatomic,strong)NSMutableArray *noticeArray; //公告数组
  46. @property (nonatomic,strong)NSMutableArray *allArray;
  47. @end
  48. @implementation KXMainPageViewController
  49. - (void)viewDidLoad {
  50. [super viewDidLoad];
  51. // Do any additional setup after loading the view.
  52. self.page=1;
  53. self.navigationController.delegate = self;
  54. [self setupUI];
  55. [self createTabletableView];
  56. [self setAdAlert];
  57. [self setNavgation];
  58. [self requestCycleViewData];
  59. [MobClick event:@"HomeTab"];
  60. }
  61. - (void)viewWillAppear:(BOOL)animated
  62. {
  63. [super viewWillAppear:animated];
  64. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
  65. // [self loadFirst];
  66. [self requestMoreLetterAction];
  67. }
  68. - (void)viewWillDisappear:(BOOL)animated
  69. {
  70. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
  71. }
  72. - (void)setAdAlert
  73. {
  74. NSDate *date = [[NSUserDefaults standardUserDefaults]valueForKey:KXADALERTKEY];
  75. if (!date||[KXTime isToday:date]==NO) {
  76. _alertWindow = [[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];
  77. _alertWindow.layer.cornerRadius = 8;
  78. _alertWindow.layer.masksToBounds = YES;
  79. _alertWindow.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
  80. UIImageView *adImageView = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2.0-150*SCREEN_MUTI, 106*SCREEN_MUTI, 300*SCREEN_MUTI, 430*SCREEN_MUTI)];
  81. [_alertWindow addSubview:adImageView];
  82. adImageView.userInteractionEnabled = YES;
  83. [KXMainPageViewModel getAdAlertUrl:^(KXLaunchModel *model) {
  84. _launchModel = model;
  85. [adImageView sd_setImageWithURL:[NSURL URLWithString:model.image_url]];
  86. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(adClick:)];
  87. [adImageView addGestureRecognizer:tap];
  88. [self.view addSubview:_alertWindow];
  89. }];
  90. UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
  91. closeButton.frame = CGRectMake(SCREEN_WIDTH/2.0-15, 560*SCREEN_MUTI, 30, 30);
  92. [closeButton setImage:[UIImage imageNamed:@"main_alert_close"] forState:UIControlStateNormal];
  93. [closeButton addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside];
  94. [_alertWindow addSubview:closeButton];
  95. }
  96. NSDate *USDate = [NSDate date];
  97. NSTimeZone *zone = [NSTimeZone systemTimeZone];
  98. NSInteger seconds = [zone secondsFromGMTForDate:USDate];
  99. NSDate *nowDate = [USDate dateByAddingTimeInterval:seconds];
  100. [[NSUserDefaults standardUserDefaults]setValue:nowDate forKey:KXADALERTKEY];
  101. [[NSUserDefaults standardUserDefaults]synchronize];
  102. }
  103. - (void)closeAction
  104. {
  105. [MobClick event:@"advertisementHomeClose"];
  106. [_alertWindow.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  107. [obj removeFromSuperview];
  108. }];
  109. [_alertWindow removeFromSuperview];
  110. _alertWindow = nil;
  111. }
  112. - (void)adClick:(UITapGestureRecognizer *)tap
  113. {
  114. [MobClick event:@"advertisementHomeClick"];
  115. [_alertWindow.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  116. [obj removeFromSuperview];
  117. }];
  118. [_alertWindow removeFromSuperview];
  119. _alertWindow = nil;
  120. if ([_launchModel.skip_type isEqualToString:@"0"]) {
  121. if ([_launchModel.product_id isEqualToString:@"0"]) {
  122. KXBaseLinkViewController *baselink = [[KXBaseLinkViewController alloc]init];
  123. baselink.linkString = _launchModel.link;
  124. KXDismissViewController *detailNav=[[KXDismissViewController alloc]initWithRootViewController:baselink];
  125. [self.navigationController presentViewController:detailNav animated:YES completion:nil];
  126. }else{
  127. KXMainDetailViewController *detail=[[KXMainDetailViewController alloc]init];
  128. KXDismissViewController *detailNav=[[KXDismissViewController alloc]initWithRootViewController:detail];
  129. detail.detailID=_launchModel.product_id;
  130. detail.enterSource = @"homeAd";
  131. [self.navigationController presentViewController:detailNav animated:YES completion:nil];
  132. }
  133. }else{
  134. KXWebDetailViewController *web=[[KXWebDetailViewController alloc]init];
  135. KXDismissViewController *detailNav=[[KXDismissViewController alloc]initWithRootViewController:web];
  136. web.product_apply_id = @"0";
  137. web.product_id = _launchModel.product_id;
  138. web.webStr=_launchModel.link;
  139. [self.navigationController presentViewController:detailNav animated:YES completion:nil];
  140. }
  141. }
  142. -(void)requestMoreLetterAction
  143. {
  144. NSString *urlString=[NSString stringWithFormat:@"%@/news/getMaxIdSecond",URL];
  145. [KXHTTP post:urlString params:nil success:^(id json) {
  146. NSString *max=[[NSUserDefaults standardUserDefaults]objectForKey:MAX_ID];
  147. if (self.rightBtn) {
  148. if (!max||max.intValue<[json[@"max_id"] intValue]) {
  149. dispatch_async(dispatch_get_main_queue(), ^{
  150. self.redLabel.hidden=NO;
  151. });
  152. }else{
  153. dispatch_async(dispatch_get_main_queue(), ^{
  154. self.redLabel.hidden=YES;
  155. });
  156. }
  157. }
  158. } failure:^(NSError *error) {
  159. }];
  160. }
  161. -(void)setNavgation
  162. {
  163. self.rightBtn=[[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - 30, 22, 20, 20)];
  164. [self.rightBtn setImage:[UIImage imageNamed:@"main_letter_white"] forState:UIControlStateNormal];
  165. [self.rightBtn addTarget:self action:@selector(letterAction) forControlEvents:UIControlEventTouchUpInside];
  166. [_headerView addSubview:self.rightBtn];
  167. [self.rightBtn setBadgeFrame:CGRectMake(14, 0, 6,6)];
  168. [self.rightBtn showBadge];
  169. }
  170. -(void)letterAction
  171. {
  172. [MobClick event:@"newsClick"];
  173. KXLetterViewController *letter=[[KXLetterViewController alloc]init];
  174. letter.hideblock = ^{
  175. [self.rightBtn clearBadge];
  176. };
  177. [self.navigationController pushViewController:letter animated:YES];
  178. }
  179. -(void)setupUI
  180. {
  181. _headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 370*SCREEN_MUTI)];
  182. _headerView.backgroundColor=[UIColor KXColorWithHex:0xF4F4F4];
  183. // _headerView.layer.borderColor=[UIColor lineColor].CGColor;
  184. // _headerView.layer.borderWidth=0.3;
  185. _cycleView=[[KXMainHorizontalCycleView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 120*SCREEN_MUTI)];
  186. _cycleView.delegate=self;
  187. [_headerView addSubview:_cycleView];
  188. // UILabel *peapleLabel=[[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2-50, 22, 100, 20)];
  189. // peapleLabel.text=[NSString stringWithFormat:@"在线人数:%d人",15000+arc4random()%1000];
  190. // peapleLabel.textColor=[UIColor whiteColor];
  191. // peapleLabel.layer.cornerRadius=10;
  192. // peapleLabel.layer.masksToBounds=YES;
  193. // peapleLabel.font=FONT_SYS(10);
  194. // peapleLabel.textAlignment=NSTextAlignmentCenter;
  195. // peapleLabel.layer.borderColor=[UIColor whiteColor].CGColor;
  196. // peapleLabel.layer.borderWidth=1;
  197. // peapleLabel.backgroundColor=[UIColor colorWithWhite:0 alpha:0.6];
  198. // [_headerView addSubview:peapleLabel];
  199. _verticleView = [[KXMainVerticleCycleView alloc]initWithFrame:CGRectMake(0, 120*SCREEN_MUTI, SCREEN_WIDTH, 46*SCREEN_MUTI)];
  200. _verticleView.backgroundColor = [UIColor whiteColor];
  201. _verticleView.delegate = self;
  202. [_headerView addSubview:_verticleView];
  203. NSMutableArray *contentArray = [NSMutableArray arrayWithCapacity:0];
  204. [KXMainPageViewModel requestVerticleViewData:^(NSArray *notice) {
  205. for (KXVerticleModel *model in notice) {
  206. [self.noticeArray addObject:model];
  207. [contentArray addObject:model.content];
  208. }
  209. _verticleView.noticeArray = contentArray;
  210. }];
  211. CGFloat weight = (SCREEN_WIDTH-1)/2;
  212. CGFloat height = Fitsize(73);
  213. NSInteger rank = 2;
  214. //每列间距
  215. CGFloat rankMargin = (self.view.frame.size.width - rank * weight) / (rank - 1);
  216. //每行间距
  217. CGFloat rowMargin = 1;
  218. NSUInteger index = 4;
  219. for (int i=0; i<index; i++) {
  220. //Item X轴
  221. CGFloat X = (i % rank) * (weight + rankMargin);
  222. //Item Y轴
  223. NSUInteger Y = (i / rank) * (height +rowMargin);
  224. KXLoanButton *loanButton = [[KXLoanButton alloc]initWithFrame:CGRectMake(X, Fitsize(172)+Y, weight, height)];
  225. loanButton.redButton.hidden = YES;
  226. NSDictionary *dict = self.otherSource[i];
  227. loanButton.name = dict[@"title"];
  228. loanButton.tag = 555+i;
  229. loanButton.descName = dict[@"desc"];
  230. loanButton.buttonImage = [UIImage imageNamed:dict[@"image"]];
  231. [loanButton addTarget:self action:@selector(loanAction:) forControlEvents:UIControlEventTouchUpInside];
  232. [_headerView addSubview:loanButton];
  233. if (i==3) {
  234. [loanButton.redButton setTitle:@"new" forState:UIControlStateNormal];
  235. loanButton.redButton.hidden = NO;
  236. }
  237. [self setloanAllLabelName];
  238. }
  239. // UIImageView *hotImageView = [[UIImageView alloc]initWithFrame:CGRectMake(14, 228*SCREEN_MUTI, 18, 18)];
  240. // hotImageView.image = [UIImage imageNamed:@"main_hot"];
  241. // [_headerView addSubview:hotImageView];
  242. UIView *tabTopView = [[UIView alloc] initWithFrame:CGRectMake(0, Fitsize(324), SCREEN_WIDTH, 46)];
  243. tabTopView.backgroundColor = [UIColor whiteColor];
  244. [_headerView addSubview:tabTopView];
  245. UILabel *hotLabel=[[UILabel alloc]init];
  246. hotLabel.text=@"热门贷款平台";
  247. hotLabel.textColor=[UIColor titleColor];
  248. hotLabel.font=FONT_SYS(14*SCREEN_MUTI);
  249. [tabTopView addSubview:hotLabel];
  250. UIView *lineView = [[UIView alloc] init];
  251. lineView.backgroundColor = [UIColor KXColorWithHex:0xe5e5e5];
  252. [tabTopView addSubview:lineView];
  253. [hotLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  254. make.left.equalTo(tabTopView.mas_left).offset(10);
  255. make.centerY.equalTo(tabTopView.mas_centerY);
  256. }];
  257. [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
  258. make.left.equalTo(tabTopView.mas_left).offset(10);
  259. make.bottom.equalTo(tabTopView.mas_bottom).offset(0);
  260. make.right.equalTo(tabTopView.mas_right).offset(-10);
  261. make.height.equalTo(@1);
  262. }];
  263. }
  264. - (void)loadFirst
  265. {
  266. BOOL mark = [[NSUserDefaults standardUserDefaults]boolForKey:@"mark"];
  267. if (mark == YES) {
  268. [self createMarkView];
  269. }
  270. [[NSUserDefaults standardUserDefaults]setBool:NO forKey:@"mark"];
  271. [[NSUserDefaults standardUserDefaults]synchronize];
  272. }
  273. - (void)markView:(NSNotification *)noti
  274. {
  275. [self createMarkView];
  276. }
  277. - (void)createMarkView
  278. {
  279. if (!_markView) {
  280. _markView = [[KXMarkView alloc]initWithFrame:[UIScreen mainScreen].bounds];
  281. _markView.delegate = self;
  282. [[UIApplication sharedApplication].keyWindow addSubview:_markView];
  283. }
  284. }
  285. - (void)createThirdMarkView{
  286. if (!_thirdMarkView) {
  287. _thirdMarkView = [[KXThirdMarkView alloc] initWithFrame:[UIScreen mainScreen].bounds];
  288. _thirdMarkView.delegate = self;
  289. [[UIApplication sharedApplication].keyWindow addSubview:_thirdMarkView];
  290. }
  291. }
  292. - (void)checkMarkView
  293. {
  294. NSDate *date = [[NSUserDefaults standardUserDefaults]objectForKey:KXMARK_TODAY];
  295. NSTimeInterval timeInterval = [[NSDate date] timeIntervalSinceDate:date];
  296. // 2.0的弹出框的处理逻辑
  297. // if (timeInterval > 3*24*60*60) {
  298. // [self createMarkView];
  299. // }
  300. // 3.0的处理逻辑
  301. NSInteger clickCount = [[NSUserDefaults standardUserDefaults] integerForKey:KXMARK_CLICKCOUNT];
  302. BOOL isMark = [[NSUserDefaults standardUserDefaults] boolForKey:KXMARK_TOAPPSTORE];
  303. if (isMark == YES) {
  304. if (timeInterval > 10*24*60*60) {
  305. if (clickCount >3 && clickCount%4 == 0) {
  306. [self createThirdMarkView];
  307. }
  308. }
  309. } else{
  310. if (!date) {
  311. if (clickCount >3 && clickCount%4==0) {
  312. [self createThirdMarkView];
  313. }
  314. }
  315. if (timeInterval > 3*24*60*60) {
  316. if (clickCount >3 && clickCount%4==0) {
  317. [self createThirdMarkView];
  318. }
  319. }
  320. }
  321. }
  322. #pragma mark ===================KXThirdMarkVIewDelegate==============
  323. - (void)markViewBtnClick:(UIButton *)button{
  324. switch (button.tag) {
  325. case 1000: //跳转按钮
  326. {
  327. [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:KXMARK_TODAY];
  328. [[NSUserDefaults standardUserDefaults] setBool:YES forKey:KXMARK_TOAPPSTORE];
  329. [[NSUserDefaults standardUserDefaults] synchronize];
  330. if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:KXAPPSTORE_ADDRESS]]) {
  331. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:KXAPPSTORE_ADDRESS]];
  332. [_thirdMarkView removeFromSuperview];
  333. }
  334. }
  335. break;
  336. case 2000: //关闭按钮
  337. {
  338. [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:KXMARK_TODAY];
  339. [[NSUserDefaults standardUserDefaults] setBool:NO forKey:KXMARK_TOAPPSTORE];
  340. [[NSUserDefaults standardUserDefaults] synchronize];
  341. [_thirdMarkView removeFromSuperview];
  342. }
  343. break;
  344. default:
  345. break;
  346. }
  347. }
  348. #pragma mark =============KXMarkViewDelegate======================
  349. - (void)markViewSelectMarkItem:(NSInteger)index
  350. {
  351. switch (index) {
  352. case 0:{
  353. [[NSUserDefaults standardUserDefaults]setObject:[NSDate distantFuture] forKey:KXMARK_TODAY];
  354. [[NSUserDefaults standardUserDefaults]synchronize];
  355. [[UIApplication sharedApplication]openURL:[NSURL URLWithString:KXAPPSTORE_ADDRESS]];
  356. }
  357. break;
  358. case 1:{
  359. [[NSUserDefaults standardUserDefaults]setObject:[NSDate date] forKey:KXMARK_TODAY];
  360. [[NSUserDefaults standardUserDefaults]synchronize];
  361. }
  362. break;
  363. case 2:{
  364. [[NSUserDefaults standardUserDefaults]setObject:[NSDate distantFuture] forKey:KXMARK_TODAY];
  365. [[NSUserDefaults standardUserDefaults]synchronize];
  366. }
  367. break;
  368. default:
  369. break;
  370. }
  371. _markView = nil;
  372. }
  373. - (void)loanAction:(KXLoanButton *)btn
  374. {
  375. // if (btn.tag == 555) {
  376. // KXLoanNewViewController *new = [[KXLoanNewViewController alloc]init];
  377. // [self.navigationController pushViewController:new animated:YES];
  378. // }else{
  379. KXLoanAllModel *model = self.allArray[btn.tag - 555];
  380. NSArray *eventArr = @[@"speedKind",@"hotKind",@"largeKind",@"newKind"];
  381. [MobClick event:eventArr[btn.tag-555]];
  382. NSDictionary *dict = self.otherSource[btn.tag - 555];
  383. KXLoanAllDetailViewController *detail = [[KXLoanAllDetailViewController alloc]init];
  384. detail.changeLabel = ^{
  385. btn.redButton.hidden = YES;
  386. };
  387. detail.ID = [NSNumber numberWithInteger:model.Id.integerValue];
  388. detail.titleString = dict[@"title"];
  389. [self.navigationController pushViewController:detail animated:YES];
  390. }
  391. - (void)setloanAllLabelName
  392. {
  393. [KXMainPageViewModel loanAllLabelName:^(id json) {
  394. for (int i = 0; i < [json count]; i ++) {
  395. KXLoanAllModel *model = json[i];
  396. [self.allArray addObject:model];
  397. KXLoanButton *btn = [_headerView viewWithTag:556+i];
  398. if (model.label_name.length != 0) {
  399. btn.redButton.hidden = NO;
  400. [btn.redButton setTitle:model.label_name forState:UIControlStateNormal];
  401. }
  402. }
  403. }];
  404. }
  405. //请求轮播
  406. -(void)requestCycleViewData
  407. {
  408. NSString *urlString=[NSString stringWithFormat:@"%@/product/homeact",URL];
  409. [KXHTTP post:urlString params:@{@"version":@"2"} success:^(id json) {
  410. NSArray *array=[NSArray yy_modelArrayWithClass:[KXCycleModel class] json:json[@"homeact"]];
  411. _cycleView.scrollArray=array;
  412. } failure:^(NSError *error) {
  413. }];
  414. }
  415. -(void)clickScrollViewItemWithIndex:(NSInteger)index
  416. {
  417. [MobClick event:@"bannerClick"];
  418. KXCycleModel *model=_cycleView.scrollArray[index];
  419. if (model.link.length == 0) {
  420. KXMainDetailViewController *detail=[[KXMainDetailViewController alloc]init];
  421. detail.detailID=model.product_id.stringValue;
  422. detail.enterSource = @"banner";
  423. [self.navigationController pushViewController:detail animated:YES];
  424. }else{
  425. KXBaseLinkViewController *baseLink = [[KXBaseLinkViewController alloc]init];
  426. baseLink.linkString = model.link;
  427. [self.navigationController pushViewController:baseLink animated:YES];
  428. }
  429. }
  430. -(void)createTabletableView
  431. {
  432. self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-TabbarHeight) style:UITableViewStylePlain];
  433. if (@available(iOS 11.0, *)) {
  434. self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  435. } else {
  436. }
  437. self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
  438. [self.tableView registerClass:[KXMainListTableViewCell class] forCellReuseIdentifier:@"main"];
  439. self.tableView.tableHeaderView = _headerView;
  440. //下拉刷新
  441. MJRefreshNormalHeader *header =
  442. [[MJRefreshNormalHeader alloc]init];
  443. header.arrowView.image = nil;
  444. [header setRefreshingTarget:self refreshingAction:@selector(refreshHeader:)];
  445. self.tableView.mj_header = header;
  446. [header beginRefreshing];
  447. //上拉加载
  448. MJRefreshAutoNormalFooter *footer=[[MJRefreshAutoNormalFooter alloc]init];
  449. [footer setRefreshingTarget:self refreshingAction:@selector(refreshFooter:)];
  450. self.tableView.mj_footer=footer;
  451. self.tableView.delegate = self;
  452. self.tableView.dataSource = self;
  453. [self.view addSubview:self.tableView];
  454. header.stateLabel.font = FONT_SYS(14);
  455. header.stateLabel.textColor=[UIColor detailTitleColor];
  456. header.lastUpdatedTimeLabel.font=FONT_SYS(14);
  457. header.lastUpdatedTimeLabel.textColor=[UIColor detailTitleColor];
  458. footer.stateLabel.textColor=[UIColor detailTitleColor];
  459. }
  460. #pragma mark 下拉刷新和上拉加载
  461. -(void)refreshHeader:(MJRefreshHeader *)header
  462. {
  463. self.page=1;
  464. [self requestSourceWithPage:self.page];
  465. }
  466. -(void)refreshFooter:(MJRefreshAutoFooter *)footer
  467. {
  468. self.page++;
  469. [self requestSourceWithPage:self.page];
  470. }
  471. -(void)requestSourceWithPage:(NSInteger)page
  472. {
  473. NSString *urlString=[NSString stringWithFormat:@"%@/product/searchSecond",URL];
  474. [KXHTTP post:urlString params:@{@"is_hot":@(YES),@"page":@(page)} success:^(id json) {
  475. NSArray *array=[NSArray yy_modelArrayWithClass:[KXHotList class] json:json[@"data"]];
  476. if (self.page==1) {
  477. [self.dataSource removeAllObjects];
  478. }
  479. for (KXHotList *model in array) {
  480. [self.dataSource addObject:model];
  481. }
  482. if (array.count < 10) {
  483. [_tableView.mj_header endRefreshing];
  484. [_tableView.mj_footer endRefreshing];
  485. [_tableView.mj_footer endRefreshingWithNoMoreData];
  486. }else{
  487. [_tableView.mj_header endRefreshing];
  488. [_tableView.mj_footer endRefreshing];
  489. }
  490. [_tableView reloadData];
  491. } failure:^(NSError *error) {
  492. }];
  493. }
  494. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  495. {
  496. return self.dataSource.count;
  497. }
  498. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  499. {
  500. KXHotList *model=self.dataSource[indexPath.row];
  501. KXMainListTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"main"];
  502. if (!cell) {
  503. cell=[[KXMainListTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"main"];
  504. }
  505. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  506. // cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
  507. cell.hotmodel=model;
  508. return cell;
  509. }
  510. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  511. {
  512. return 87*SCREEN_MUTI;
  513. }
  514. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  515. {
  516. [MobClick event:@"homeListClick"];
  517. KXHotList *model=self.dataSource[indexPath.row];
  518. //0跳详情,1跳链接
  519. if ([model.skip_type isEqualToString:@"1"]) {
  520. KXWebDetailViewController *web=[[KXWebDetailViewController alloc]init];
  521. web.webStr=model.link;
  522. web.titleStr = model.name;
  523. web.product_id = model.Id;
  524. web.product_apply_id = @"0";
  525. [self.navigationController pushViewController:web animated:YES];
  526. }else{
  527. KXMainDetailViewController *detail=[[KXMainDetailViewController alloc]init];
  528. detail.detailID=model.Id;
  529. detail.titleString=model.name;
  530. detail.enterSource = @"hotList";
  531. [self.navigationController pushViewController:detail animated:YES];
  532. }
  533. }
  534. #pragma mark ------------------KXMainVerticleCycleViewDelegate------------------------
  535. - (void)clickmiddleViewWithIndex:(NSInteger)index
  536. {
  537. [MobClick event:@"noticeClick"];
  538. KXVerticleModel *model = self.noticeArray[index];
  539. if (!model.link) {
  540. }else{
  541. if ([model.skip_type isEqualToString:@"0"]) {
  542. if ([model.product_id isEqualToString:@"0"]) {
  543. KXBaseLinkViewController *baselink = [[KXBaseLinkViewController alloc]init];
  544. baselink.linkString = model.link;
  545. [self.navigationController pushViewController:baselink animated:YES];
  546. }else{
  547. KXMainDetailViewController *detail=[[KXMainDetailViewController alloc]init];
  548. detail.detailID=model.product_id;
  549. detail.enterSource = @"notice";
  550. [self.navigationController pushViewController:detail animated:YES];
  551. }
  552. }else{
  553. KXWebDetailViewController *web=[[KXWebDetailViewController alloc]init];
  554. web.product_apply_id = @"0";
  555. web.product_id = model.product_id;
  556. web.webStr=model.link;
  557. [self.navigationController pushViewController:web animated:YES];
  558. }
  559. }
  560. }
  561. #pragma mark - NAV的代理方法
  562. - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
  563. BOOL isShow = [viewController isKindOfClass:[self class]];
  564. [self.navigationController setNavigationBarHidden:isShow animated:YES];
  565. }
  566. -(NSMutableArray *)dataSource
  567. {
  568. if (!_dataSource) {
  569. _dataSource=[[NSMutableArray alloc]init];
  570. }
  571. return _dataSource;
  572. }
  573. -(NSArray *)otherSource
  574. {
  575. if (!_otherSource) {
  576. _otherSource=@[@{@"image":@"main_all_quick",@"title":@"极速贷",@"desc":@"最快2小时到账"},@{@"image":@"main_all_hot",@"title":@"热门贷",@"desc":@"大热贷款平台推荐"},@{@"image":@"main_all_stu",@"title":@"大额贷",@"desc":@"高额度 低门槛"},@{@"image":@"main_all_house",@"title":@"新品区",@"desc":@"最新上架平台"}];
  577. }
  578. return _otherSource;
  579. }
  580. - (NSMutableArray *)noticeArray
  581. {
  582. if (!_noticeArray) {
  583. _noticeArray = [NSMutableArray arrayWithCapacity:0];
  584. }
  585. return _noticeArray;
  586. }
  587. - (NSMutableArray *)allArray
  588. {
  589. if (!_allArray) {
  590. _allArray = [[NSMutableArray alloc]init];
  591. }
  592. return _allArray;
  593. }
  594. - (void)didReceiveMemoryWarning {
  595. [super didReceiveMemoryWarning];
  596. // Dispose of any resources that can be recreated.
  597. }
  598. /*
  599. #pragma mark - Navigation
  600. // In a storyboard-based application, you will often want to do a little preparation before navigation
  601. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  602. // Get the new view controller using [segue destinationViewController].
  603. // Pass the selected object to the new view controller.
  604. }
  605. */
  606. @end