// // LDMyFansViewController.m // YouHuiProject // // Created by 小花 on 2018/5/19. // Copyright © 2018年 kuxuan. All rights reserved. // #import "LDMyFansViewController.h" #import "LDOrderTableView.h" #import "MLMSegmentHead.h" #import "MLMSegmentManager.h" #import "LDChildFansViewController.h" #import "LDFansHeaderView.h" #import "LDShowFansHelpView.h" #import "CCAlertShowView.h" #import "LDPotentialFansViewController.h" #import "UILabel+ChangeLineSpaceAndWordSpace.h" #import "TopTypeHeader.h" #import "TopTypeSegmentManager.h" #import "LDWebDetailController.h" #import "LDPrivilegeReferralViewController.h" #import "LDUserInfo.h" #import "LDPrivilegeReferralViewController.h" #import "LDAdWebViewController.h" @interface LDMyFansViewController () < UITableViewDelegate, UITableViewDataSource > { UIButton *allbtn; UIButton *friendbtn; UIButton *potentialbtn; UIButton *recommbtn; NSMutableDictionary *topnavDic;//存取顶部导航 NSDictionary *friendDic;//选择的顶部导航 NSMutableArray *btnArray; } @property (nonatomic, strong) LDOrderTableView *tableView; @property (nonatomic, strong) LDFansHeaderView *headerView; @property (nonatomic, strong) TopTypeHeader *titleView; @property (nonatomic, strong) MLMSegmentScroll *segScroll; @property (nonatomic, strong) NSMutableArray *vcList; @property (nonatomic, assign) BOOL canScroll; @property (nonatomic, strong) UIButton *rightHelpBtn; @end @implementation LDMyFansViewController - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; } - (void)viewDidLoad { [super viewDidLoad]; [self configNavigationBar]; [self.view addSubview:self.tableView]; [self creatHeaderViewAndFooterView]; [MBProgressHUD showLoadingAddedToView:self.view]; [self requestTopNav]; } - (void)setUpNoDataView { self.tableView.showNoDataView = YES; self.tableView.noDataImageOffsetY = -70; self.tableView.defaultNoDataText = @"您还没有好友,快去邀请吧~"; self.tableView.defaultNoDataImage = [UIImage imageNamed:@"no_order"]; } - (void)configNavigationBar { [self.navigationBar setNavTitle:@"我的好友"]; self.navigationBar.backgroundColor = [UIColor changeColor]; self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor]; UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)]; [leftBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal]; [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside]; [self.navigationBar setCustomLeftButtons:@[leftBtn]]; self.rightHelpBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)]; [self.rightHelpBtn setImage:[UIImage imageNamed:@"helpmonth"] forState:UIControlStateNormal]; [self.rightHelpBtn addTarget:self action:@selector(showHelpAlert) forControlEvents:UIControlEventTouchUpInside]; self.rightHelpBtn.hidden = YES; [self.navigationBar setCustomRightButtons:@[self.rightHelpBtn]]; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; } - (void)backAction { [self.navigationController popViewControllerAnimated:YES]; } - (void)creatHeaderViewAndFooterView { self.view.backgroundColor = [UIColor whiteColor]; UIButton *accountBtn =[[UIButton alloc]initWithFrame:CGRectMake(0, FITSIZE(5)+NavBarHeight, SCREEN_WIDTH, FITSIZE(30))]; [accountBtn setImage:[UIImage imageNamed:@"goto_detail"] forState:UIControlStateNormal]; [accountBtn setImageEdgeInsets:UIEdgeInsetsMake(FITSIZE(7.5), SCREEN_WIDTH-FITSIZE(30), FITSIZE(7.5), FITSIZE(15))]; accountBtn.backgroundColor =[UIColor whiteColor]; [self.view addSubview:accountBtn]; [accountBtn addTarget:self action:@selector(clickBtn) forControlEvents:UIControlEventTouchUpInside]; UIImageView *imgv =[[UIImageView alloc]initWithFrame:CGRectMake(FITSIZE(15), FITSIZE(7.5), FITSIZE(15), FITSIZE(15))]; imgv.image =[UIImage imageNamed:@"order_notice"]; [accountBtn addSubview:imgv]; UILabel *label =[[UILabel alloc]initWithFrame:CGRectMake(FITSIZE(40), 0, FITSIZE(300), FITSIZE(30))]; label.text=@"通知消息"; label.textColor=[UIColor YHColorWithHex:0xFB6526]; label.font=[UIFont systemFontOfSize:FITSIZE(12)]; [accountBtn addSubview:label]; label.tag = 1234; [self.view addSubview:accountBtn]; } #pragma mark--顶部通知 -(void)clickBtn { NSDictionary *userDic = [LDUserInfoManager shareManager].userInfoDic; LDUserInfo *userInfo = [LDUserInfo yy_modelWithJSON:userDic]; if ([userInfo.user_level isEqualToString:@"3"]) { LDAdWebViewController *web = [[LDAdWebViewController alloc] init]; web.url = topnavDic[@"url"]; [self.navigationController pushViewController:web animated:YES]; return; } LDPrivilegeReferralViewController *Privilege = [[LDPrivilegeReferralViewController alloc] init]; [self.navigationController pushViewController:Privilege animated:YES]; } /** 特权信息 */ - (void)showUserType { LDPrivilegeReferralViewController *Privilege = [[LDPrivilegeReferralViewController alloc] init]; [self.navigationController pushViewController:Privilege animated:YES]; } #pragma mark---获取顶部导航 -(void)requestTopNav { NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/getTopNaiv",BaseURL]; [LDHttp post:url params:nil success:^(id json) { [MBProgressHUD hideHUDForView:self.view]; topnavDic =[NSMutableDictionary dictionaryWithDictionary:json[@"data"]]; btnArray =[NSMutableArray array]; UILabel *messageLabel =[self.view viewWithTag:1234]; messageLabel.text=json[@"data"][@"top_message"]; NSMutableArray *array =[NSMutableArray array]; NSMutableArray *numA =[NSMutableArray array]; //取值(key值同名的时候会覆盖的) for (int i =0; i<[topnavDic[@"top_friend"] count]; i++) { NSDictionary *dics= topnavDic[@"top_friend"][i]; [array addObject:dics[@"top_name"]]; [numA addObject:[NSString stringWithFormat:@"%@",dics[@"count"]]]; LDChildFansViewController *childV =[[LDChildFansViewController alloc]init]; childV.type = [dics[@"top_type"] integerValue]; [self.vcList addObject:childV]; } self.segScroll =[[MLMSegmentScroll alloc] initWithFrame:CGRectMake(0, NavBarHeight+70+FITSIZE(40), SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight-70-FITSIZE(40)) vcOrViews:self.vcList]; self.segScroll.bounces = NO; self.segScroll.loadAll = YES; self.titleView = [[TopTypeHeader alloc] initWithFrame:CGRectMake(0, NavBarHeight+FITSIZE(40), SCREEN_WIDTH, 70) titles:array headStyle:TopTypeHeadStyleDefault layoutStyle:TopTypeLayoutDefault]; self.titleView.headColor = [UIColor whiteColor]; self.titleView.bottomLineHeight = 1; self.titleView.subTitles = numA; self.titleView.bottomLineColor = [UIColor yhGrayColor]; self.titleView.fontScale = 1; self.titleView.fontSize = 14; self.titleView.equalSize = YES; self.titleView.showIndex = _showIndex; self.titleView.selectColor = [UIColor homeRedColor]; self.titleView.deSelectColor = [UIColor YHColorWithHex:0x666666]; [TopTypeSegmentManager associateHead:self.titleView withScroll:self.segScroll completion:^{ [self.view addSubview:self.titleView]; [self.view addSubview:self.segScroll]; }]; } failure:^(NSError *error) { [MBProgressHUD hideHUDForView:self.view]; [self.tableView.mj_header endRefreshing]; }]; } #pragma mark === - (void)showHelpAlert { LDShowFansHelpView *popView = [[LDShowFansHelpView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-80, 213)]; CCAlertShowView *showView = [CCAlertShowView alertViewWithView:popView]; popView.dismissAction = ^{ [showView dismiss]; }; [showView show]; } #pragma mark --------------------- UITableView delegate ------- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 0.1; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 40; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return SCREEN_HEIGHT-NavBarHeight-40; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellID"]; return cell; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { return self.titleView; } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { return self.segScroll; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { } #pragma mark ----- scroll delegete ---- //- (void)scrollViewDidScroll:(UIScrollView *)scrollView { // CGFloat bottomCellOffset = [_tableView rectForSection:0].origin.y; // if (scrollView.contentOffset.y >= bottomCellOffset) { // scrollView.contentOffset = CGPointMake(0, bottomCellOffset); // if (self.canScroll) { // self.canScroll = NO; // [self setChildViewControllerCanScroll:YES]; // } // }else{ // if (!self.canScroll) {//子视图没到顶部 // scrollView.contentOffset = CGPointMake(0, bottomCellOffset); // } // } //} // //- (void)setChildViewControllerCanScroll:(BOOL)childCanScroll { // for (LDChildFansViewController *childVc in self.vcList) { // childVc.childCanScroll = childCanScroll; // if (!childCanScroll) { // childVc.tableView.contentOffset = CGPointZero; // } // } //} #pragma mark ---------------- - (LDOrderTableView *)tableView { if (!_tableView) { _tableView = [[LDOrderTableView alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight) style:UITableViewStylePlain]; _tableView.estimatedSectionHeaderHeight = 0; _tableView.estimatedSectionFooterHeight = 0; _tableView.sectionFooterHeight = 0; _tableView.sectionHeaderHeight = 0; _tableView.estimatedRowHeight = 0; _tableView.delegate = self; _tableView.dataSource = self; _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; _tableView.backgroundColor = [UIColor whiteColor]; _tableView.bounces = NO; _tableView.showsVerticalScrollIndicator = NO; [_tableView setSeparatorColor:[UIColor YHColorWithHex:0xdddddd]]; } return _tableView; } - (NSMutableArray *)vcList { if (!_vcList) { _vcList = [NSMutableArray array]; } return _vcList; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end