123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447 |
- //
- // KXEventViewController.m
- // CAISHEN
- //
- // Created by jikaipeng on 2017/8/24.
- // Copyright © 2017年 kuxuan. All rights reserved.
- //
- #import "KXEventViewController.h"
- #import "KXEventTopView.h"
- #import "KXEventCollectionViewCell.h"
- #import "KXbodyPriceColumnViewController.h"
- #import "KXCalculatePageViewController.h"
- #import "KXLittleLogginView.h"
- #import "KXFindToolListModel.h"
- #import "KXInstallmentViewController.h" //分期计算器
- #import "KXCarLoancalViewController.h" // 车贷计算器
- #import "KXHouseCalculateViewController.h" //房贷计算器
- #import "KXIndividualIncomeViewController.h" //个税计算器
- #import "KXBaseLinkViewController.h"
- static NSString *collectionHeaderIdenti = @"collectionHeaderIdenti";
- static NSString *collectionCellID = @"cellID";
- @interface KXEventViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,KXLittleLogginViewDelegate,UICollectionViewDelegateFlowLayout>
- @property (nonatomic, strong) UICollectionView *collectionView;
- @property (nonatomic, assign) NSInteger page;
- @property (nonatomic ,strong) NSMutableArray *dataSource;
- @property (nonatomic,assign) NSInteger index;
- @property (nonatomic,strong) NSMutableArray *systemArr;
- @property (nonatomic,strong) UIView *headerView;
- @property (nonatomic,strong) NSMutableArray *custonArr;
- @end
- @implementation KXEventViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self setupNavBackground];
- self.name = @"发现";
- self.view.backgroundColor = [UIColor KXColorWithHex:0xf5f4f9];
- // 2.0的头
- // [self CreateTopView];
- [self requestFindCustomData];
- [self setUpCollectionView];
- [MobClick event:@"FindTab"];
- }
- #pragma mark - 请求发现页工具列表
- - (void)requestFindCustomData{
- NSString *url = [NSString stringWithFormat:@"%@/activity/getToolsList",URL];
- [KXHTTP get:url params:nil success:^(id json) {
- [self.custonArr removeAllObjects];
- NSArray *array = [NSArray yy_modelArrayWithClass:[KXFindToolListModel class] json:json];
- for (KXFindToolListModel *model in array) {
- if ([model.show integerValue] == 1) {
- [self.custonArr addObject:model];
- }
- }
- [self setUpHeaderView];
- } failure:^(NSError *error) {
- [self setUpHeaderView];
- }];
- }
- #pragma mark - getter and setter
- - (UICollectionView *)collectionView{
- if (!_collectionView) {
- UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
- layout.itemSize = CGSizeMake(SCREEN_WIDTH-20, 230);
- layout.minimumInteritemSpacing = 6;
- _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(10, 0, SCREEN_WIDTH-20, SCREEN_HEIGHT-NavHeight-TabbarHeight) collectionViewLayout:layout];
- _collectionView.showsVerticalScrollIndicator = NO;
- }
- return _collectionView;
- }
- -(NSMutableArray *)dataSource
- {
- if (!_dataSource) {
- _dataSource=[[NSMutableArray alloc]init];
- }
- return _dataSource;
- }
- #pragma mark - event handle
- - (void)tapAction1:(UITapGestureRecognizer *)tapG
- {
- KXbodyPriceColumnViewController *bodyPriceVC = [[KXbodyPriceColumnViewController alloc]init];
- bodyPriceVC.webString = [NSString stringWithFormat:@"%@/Atesting/?channel_id=%@",CALURL,KXCHANNEL_ID];
- bodyPriceVC.titleString = @"身价计算器";
- bodyPriceVC.enterSource = @"valueCalculationa";
- self.tabBarController.tabBar.hidden = NO;
- [self.navigationController pushViewController:bodyPriceVC animated:YES];
- }
- - (void)tapAction2:(UITapGestureRecognizer *)tapG
- {
- KXCalculatePageViewController *calculate = [[KXCalculatePageViewController alloc]init];
- self.tabBarController.tabBar.hidden = NO;
- [self.navigationController pushViewController:calculate animated:YES];
- }
- - (void)CreateTopView{
- NSArray *imageNameArray = @[@"main_event_price",@"main_event_calculator"];
- NSArray *titleArray = @[@"身价计算器",@"贷款计算器"];
- NSArray *detailArray = @[@"等你来测",@"比价神器"];
- UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_MUTI*80)];
- backView.backgroundColor = [UIColor KXColorWithHex:0xffe100];
- for (NSInteger i = 0; i < 2; i++) {
- KXEventTopView *topView = [[KXEventTopView alloc] initWithFrame:CGRectMake(i*(SCREEN_WIDTH-1)/2, 0, (SCREEN_WIDTH-1)/2, SCREEN_MUTI*80)];
- topView.imageview.image = [UIImage imageNamed:imageNameArray[i]];
- topView.titleLabel.text = titleArray[i];
- topView.detaileLabel.text = detailArray[i];
- [backView addSubview:topView];
- if (i == 0) {
- UIView *view = [[UIView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-1)/2, 10*SCREEN_MUTI, 1, 60*SCREEN_MUTI)];
- view.backgroundColor = [UIColor whiteColor];
- UITapGestureRecognizer *tapG = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction1:)];
- tapG.numberOfTapsRequired = 1;
- [topView addGestureRecognizer:tapG];
- [backView addSubview:view];
- }
- else{
- UITapGestureRecognizer *tapG = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction2:)];
- tapG.numberOfTapsRequired = 1;
- [topView addGestureRecognizer:tapG];
- }
- }
- [self.view addSubview:backView];
- }
- /**
- 贷款超市3.0的头
- */
- - (void)setUpHeaderView{
- UIView *topBackView = [[UIView alloc] init];
- topBackView.backgroundColor = [UIColor whiteColor];
- CGFloat width = (SCREEN_WIDTH-20)/4;
- CGFloat height = 95;
- NSInteger rank = 4;
- for (NSInteger i=0; i<self.systemArr.count; i++) {
- UIButton *systemBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- //Item X轴
- CGFloat X = (i % rank) * width;
- //Item Y轴
- NSUInteger Y = (i / rank) * height;
- NSDictionary *dict = self.systemArr[i];
- systemBtn.frame = CGRectMake(X, Y, width, height);
- [systemBtn setImage:[UIImage imageNamed:dict[@"image"]] forState:UIControlStateNormal];
- systemBtn.tag = 1000 + i;
- NSDictionary *mutabDict = @{NSFontAttributeName:FONT_SYS(12),NSForegroundColorAttributeName:[UIColor titleColor]};
- NSAttributedString *attibute = [[NSAttributedString alloc] initWithString:dict[@"title"] attributes:mutabDict];
- [systemBtn setAttributedTitle:attibute forState:UIControlStateNormal];
- systemBtn.adjustsImageWhenHighlighted = NO;
- [systemBtn addTarget:self action:@selector(topButtonClick:) forControlEvents:UIControlEventTouchUpInside];
- [systemBtn setButtonStyle:WSLButtonStyleImageTop spacing:4];
- [topBackView addSubview:systemBtn];
- }
-
- [self.systemArr addObjectsFromArray:self.custonArr];
- for (NSInteger i=5; i<self.systemArr.count; i++) {
- UIButton *customBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- //Item X轴
- CGFloat X = (i % rank) * width;
- //Item Y轴
- NSUInteger Y = (i / rank) * height;
- KXFindToolListModel *model = self.systemArr[i];
- customBtn.frame = CGRectMake(X, Y, width, height);
- NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:model.icon]];
- UIImage *image = [[UIImage alloc] initWithData:imageData];
- [customBtn setImage:image forState:UIControlStateNormal];
- customBtn.tag = 1000 + i;
- NSDictionary *mutabDict = @{NSFontAttributeName:FONT_SYS(12),NSForegroundColorAttributeName:[UIColor titleColor]};
- NSAttributedString *attibute = [[NSAttributedString alloc] initWithString:model.name attributes:mutabDict];
- [customBtn setAttributedTitle:attibute forState:UIControlStateNormal];
- customBtn.adjustsImageWhenHighlighted = NO;
- [customBtn addTarget:self action:@selector(topButtonClick:) forControlEvents:UIControlEventTouchUpInside];
- [customBtn setButtonStyle:WSLButtonStyleImageTop spacing:4];
- [topBackView addSubview:customBtn];
- }
-
- UIButton *placeHolderBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- placeHolderBtn.adjustsImageWhenHighlighted = NO;
- //Item X轴
- CGFloat X = (self.systemArr.count % rank) * width;
- //Item Y轴
- NSUInteger Y = (self.systemArr.count / rank) * height;
- placeHolderBtn.frame = CGRectMake(X, Y, width, height);
- [placeHolderBtn setImage:[UIImage imageNamed:@"find_placeholder"] forState:UIControlStateNormal];
- [topBackView addSubview:placeHolderBtn];
- topBackView.frame = CGRectMake(0, 0, SCREEN_WIDTH-20, Y+height-10);
- topBackView.layer.cornerRadius = 4.f;
- self.headerView = topBackView;
- [self.collectionView reloadData];
- }
- #pragma mark - 头部按钮点击方法
- - (void)topButtonClick:(UIButton *)button{
- switch (button.tag - 1000) {
- case 0: //身价计算器
- {
- [MobClick event:@"priceCalculator"];
- KXbodyPriceColumnViewController *bodyPriceVC = [[KXbodyPriceColumnViewController alloc]init];
- bodyPriceVC.webString = [NSString stringWithFormat:@"%@/Atesting/?channel_id=%@",CALURL,KXCHANNEL_ID];
- bodyPriceVC.titleString = @"身价计算器";
- bodyPriceVC.enterSource = @"valueCalculationa";
- self.tabBarController.tabBar.hidden = NO;
- [self.navigationController pushViewController:bodyPriceVC animated:YES];
- }
- break;
- case 1: // 分期计算器
- {
- [MobClick event:@"sectionCalculator"];
- KXInstallmentViewController *instalVC = [[KXInstallmentViewController alloc] init];
- [self.navigationController pushViewController:instalVC animated:YES];
- }
- break;
- case 2: // 车贷计算器
- {
- [MobClick event:@"carCalculator"];
- KXCarLoancalViewController *carLoanVC = [[KXCarLoancalViewController alloc] init];
- [self.navigationController pushViewController:carLoanVC animated:YES];
- }
- break;
- case 3: //房贷计算器
- {
- [MobClick event:@"houseCalculator"];
- KXHouseCalculateViewController *houseCalVC = [[KXHouseCalculateViewController alloc] init];
- [self.navigationController pushViewController:houseCalVC animated:YES];
- }
- break;
- case 4: //个税计算器
- {
- [MobClick event:@"personalTaxCalculator"];
- KXIndividualIncomeViewController *incomeVC = [[KXIndividualIncomeViewController alloc] init];
- [self.navigationController pushViewController:incomeVC animated:YES];
- }
- break;
- // case 5: //公积金查询
- // {
- //
- // }
- // break;
- default:
- // 跳转到h5
- {
- KXBaseLinkViewController *lineVC = [[KXBaseLinkViewController alloc] init];
- KXFindToolListModel *model = self.systemArr[button.tag-1000];
- lineVC.linkString = model.url;
- lineVC.nameStr = model.name;
- [self.navigationController pushViewController:lineVC animated:YES];
- }
- break;
- }
- }
- - (void) setUpCollectionView{
-
- //下拉刷新
- MJRefreshNormalHeader *header =
- [[MJRefreshNormalHeader alloc]init];
- [header setRefreshingTarget:self refreshingAction:@selector(refreshWithHeader:)];
- self.collectionView.mj_header = header;
- [header beginRefreshing];
- //上拉加载
- MJRefreshAutoNormalFooter *footer=[[MJRefreshAutoNormalFooter alloc]init];
- [footer setRefreshingTarget:self refreshingAction:@selector(refreshFooter:)];
- self.collectionView.mj_footer=footer;
-
- _collectionView.backgroundColor = [UIColor KXColorWithHex:0xf5f4f9];
- [_collectionView registerClass:[KXEventCollectionViewCell class] forCellWithReuseIdentifier:collectionCellID];
- [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionHeaderIdenti];
- _collectionView.dataSource = self;
- _collectionView.delegate = self;
- _collectionView.layer.cornerRadius = 4.f;
- _collectionView.layer.masksToBounds = YES;
- [self.view addSubview:self.collectionView];
-
- header.stateLabel.font = FONT_SYS(14);
- header.stateLabel.textColor=[UIColor detailTitleColor];
- header.lastUpdatedTimeLabel.font=FONT_SYS(14);
- header.lastUpdatedTimeLabel.textColor=[UIColor detailTitleColor];
- footer.stateLabel.textColor=[UIColor detailTitleColor];
- }
- #pragma mark 下拉刷新和上拉加载
- -(void)refreshWithHeader:(MJRefreshHeader *)header
- {
- self.page=1;
- [self requestDataWithPage:self.page];
- }
- -(void)refreshFooter:(MJRefreshAutoFooter *)footer
- {
- self.page++;
- [self requestDataWithPage:self.page];
-
- }
- -(void)requestDataWithPage:(NSInteger)page
- {
- NSString *urlString=[NSString stringWithFormat:@"%@/activity/getActivityList",URL];
- [KXHTTP post:urlString params:@{@"page":@(page)} success:^(id json) {
-
- if (self.page==1) {
- [self.dataSource removeAllObjects];
- }
- NSArray *array=[NSArray yy_modelArrayWithClass:[KXEventModel class] json:json[@"data"]];
-
- for (KXEventModel *model in array) {
- [self.dataSource addObject:model];
- }
- if (array.count < 10) {
- [_collectionView.mj_header endRefreshing];
- [_collectionView.mj_footer endRefreshing];
- [_collectionView.mj_footer endRefreshingWithNoMoreData];
- }else{
- [_collectionView.mj_header endRefreshing];
- [_collectionView.mj_footer endRefreshing];
-
- }
- [_collectionView reloadData];
- } failure:^(NSError *error) {
-
- }];
- }
- #pragma mark collectionview datasource
- - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
- if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
- UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:collectionHeaderIdenti forIndexPath:indexPath];
- [headerView addSubview:self.headerView];
- return headerView;
- }
- return nil;
- }
- - (CGSize )collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
- NSUInteger Y = (self.systemArr.count / 4) * 95 + 95;
- return CGSizeMake(SCREEN_WIDTH-20, Y);
- }
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
- return 1;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
- return self.dataSource.count;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
- KXEventCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:collectionCellID forIndexPath:indexPath];
- cell.backgroundColor = [UIColor whiteColor];
- cell.layer.cornerRadius = 4.f;
- cell.model = self.dataSource[indexPath.row];
- return cell;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
- {
- self.index = indexPath.item;
- NSString *urlString=[NSString stringWithFormat:@"%@/user/personalCenter",URL];
- [KXHTTP post:urlString params:nil success:^(id json) {
- NSString *username= [[NSUserDefaults standardUserDefaults]valueForKey:USER_NAME];
-
- if (!username) {
- KXLittleLogginView *littleView = [[KXLittleLogginView alloc]initWithFrame:self.view.bounds];
- littleView.delegate = self;
- [self.view addSubview:littleView];
- }else{
- [MobClick event:@"findListClick"];
- KXEventModel *model = self.dataSource[indexPath.row];
- KXbodyPriceColumnViewController *bodyPriceVC = [[KXbodyPriceColumnViewController alloc]init];
- bodyPriceVC.webString = [NSString stringWithFormat:@"%@&channel_id=%@",model.activity_url,KXCHANNEL_ID];
- self.tabBarController.tabBar.hidden = NO;
- bodyPriceVC.titleString = model.title;
- bodyPriceVC.enterSource = @"activityList";
- [self.navigationController pushViewController:bodyPriceVC animated:YES];
- }
- } failure:^(NSError *error) {
-
- }];
-
- }
- - (NSMutableArray *)systemArr{
- if (!_systemArr) {
- _systemArr = [[NSMutableArray alloc] initWithArray: @[@{@"image":@"find_bodyPrice",@"title":@"身价计算器"},@{@"image":@"find_stages",@"title":@"分期计算器"},@{@"image":@"find_car",@"title":@"车贷计算器"},@{@"image":@"find_house",@"title":@"房贷计算器"},@{@"image":@"find_personTax",@"title":@"个税计算器"}]];
- }
- return _systemArr;
- }
- - (NSMutableArray *)custonArr{
- if (!_custonArr) {
- _custonArr = [NSMutableArray array];
- }
- return _custonArr;
- }
- #pragma mark =======================KXLittleLogginViewDelegate================
- - (void)littleLogginViewSuccess
- {
- KXEventModel *model = self.dataSource[self.index];
- KXbodyPriceColumnViewController *bodyPriceVC = [[KXbodyPriceColumnViewController alloc]init];
- bodyPriceVC.webString = [NSString stringWithFormat:@"%@&channel_id=%@",model.activity_url,KXCHANNEL_ID];
- self.tabBarController.tabBar.hidden = NO;
- bodyPriceVC.titleString = model.title;
- [self.navigationController pushViewController:bodyPriceVC animated:YES];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
|