// // DRMineMainViewController.m // YouHuiProject // // Created by xiaoxi on 2018/1/16. // Copyright © 2018年 kuxuan. All rights reserved. // #import "DRMineMainViewController.h" #import "HFStretchableTableHeaderView.h" #import "DRLoginViewController.h" #import "DRCollectionViewController.h" #import "DRSettingViewController.h" #import "DRMyTicketViewController.h" #import "DRMyOrderViewController.h" #import #import "DRBrowserHistoryController.h" #import "DRAdWebViewController.h" #import "DRFeedbackController.h" #import #import "DRFindBookWebViewController.h" #import "UITableViewCell+Cc_CornRadio.h" #import "DRFourButtonView.h" #import "DRShopCarViewController.h" #import "CCActionSheet.h" #import "DRMineBlanceView.h" #import "DRMineOrderView.h" #import "DRMoreMenuView.h" #import "DROrderMainViewController.h" #import "DROrderMainViewController.h" #import "DRCommissionMainViewController.h" #import "DRMyFansViewController.h" #import "DRMyCollectionViewController.h" #import "DRInviteFansViewController.h" #import "DRMessageListController.h" #import "DRUserInfo.h" #import "DRUserInfoView.h" #import "DRCollectionMainViewController.h" #import "DRLinkFansController.h" #import "DRPrivilegeReferralViewController.h" #import "DRUserInfo.h" #import "DRMonthMainViewController.h" #import "DRMineAdView.h" #import "DRAccountDetailController.h" #import "AdPopModel.h" #import "AdJumpManager.h" #import "UIView+BABadgeView.h" #import "DRBuyLimitMainController.h" #import "DRHistoryViewController.h" #import "DRUserView.h" @interface DRMineMainViewController () < UITableViewDelegate, UITableViewDataSource, CCActionSheetDelegate, YHMineFourButtonViewDelegate, YHMoreMenuViewDelegate > @property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) UIView *header; @property (nonatomic, strong) UIImageView *headerImg; //@property (nonatomic, strong) DRUserInfoView *userInfoView; //@property (nonatomic, strong) DRMineBlanceView *blanceView; //@property (nonatomic, strong) DRMineOrderView *mineOrderView; @property (nonatomic, strong) DRMoreMenuView *topMenuView; //@property (nonatomic, strong) DRMoreMenuView *bottomMenuView; @property (nonatomic, strong) DRMineAdView *adView; @property (nonatomic, strong) UIButton *messageBtn; @property (nonatomic, strong) DRUserInfo *userInfo; @property (nonatomic, strong) DRUserView *userView; /*dataSource**/ @property (nonatomic, strong) NSArray *cellData; @property (nonatomic, strong) NSArray *sexArr; @end @implementation DRMineMainViewController - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; [self loadUserInfo]; if ([AccountTool isLogin]) { [self checkForNewMessage]; } } - (void)viewDidLoad { [super viewDidLoad]; [self configNavightion]; [self configTableView]; [self loadAdData]; } - (void)configNavightion { self.navigationBar.backgroundColor = [UIColor clearColor]; self.navigationBar.hidden = YES; } - (void)configTableView { [self.view addSubview:self.tableView]; __weak typeof(self) weakSelf = self; //头部背景图 self.headerImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 170)]; self.headerImg.userInteractionEnabled = YES; self.header.backgroundColor = [UIColor homeRedColor]; self.headerImg.contentMode = UIViewContentModeScaleAspectFill; //头视图 self.header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 170)]; self.headerImg.backgroundColor = [UIColor homeRedColor]; [self.header addSubview:self.headerImg]; //上边的多菜单 NSArray *buttons = @[@{@"title":@"我的收藏",@"image":@"shoucang"}, @{@"title":@"浏览记录",@"image":@"liulan"}]; self.topMenuView = [[DRMoreMenuView alloc] initWithFrame:CGRectMake(0, self.header.bottom, SCREEN_WIDTH, (SCREEN_WIDTH)/4) buttonInfoArray:buttons]; self.topMenuView.delelgate = self; [self.header addSubview:self.topMenuView]; //广告view self.adView = [[DRMineAdView alloc] initWithFrame:CGRectMake(0, self.topMenuView.bottom, SCREEN_WIDTH, 0)]; self.adView.tapAdBlock = ^(AdPopModel *model) { [AdJumpManager jumpToPageWithModel:model ParentViewControll:weakSelf]; }; self.adView.closeBlock = ^{ [weakSelf hiddenAdView]; }; [self.header addSubview:self.adView]; self.header.height = CGRectGetMaxY(self.adView.frame)+10; self.tableView.tableHeaderView = self.header; //用户信息 self.userView = [[DRUserView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 95)]; self.userView.centerY = KStatusBarHeight + (self.headerImg.height-KStatusBarHeight)/2; self.userView.tapActionBlock = ^{ if ([AccountTool isLogin]) { [weakSelf settingAction]; }else { [weakSelf goToLoginPage]; } }; [self.tableView addSubview:self.userView]; //消息按钮 // UIButton *setButton = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-20-40, KStatusBarHeight+10, 40, 40)]; // [setButton setImage:[UIImage imageNamed:@"message_icon"] forState:UIControlStateNormal]; // [setButton addTarget:self action:@selector(gotoMyMessagesPage) forControlEvents:UIControlEventTouchUpInside]; // self.messageBtn = setButton; // [setButton ba_addDotWithColor:[UIColor redColor]]; // [setButton ba_moveBadgeWithX:-12 Y:15]; // [self.tableView addSubview:setButton]; if (@available(iOS 11.0, *)) { self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;//UIScrollView也适用 }else { self.automaticallyAdjustsScrollViewInsets = NO; } } - (void)scrollViewDidScroll:(UIScrollView *)scrollView { CGFloat yOffset = scrollView.contentOffset.y; if(yOffset < 0) { self.headerImg.y = yOffset; self.headerImg.height = 170+ABS(yOffset); } } /** 加载用户信息 */ - (void)loadUserInfo { if (![AccountTool isLogin]) { [self noLoginView]; return; } [DRHttp post:UserInfo params:nil success:^(id json) { self.userInfo = [DRUserInfo yy_modelWithJSON:json]; [self.userView setLoginView:self.userInfo];//设置用户信息 } failure:^(NSError *error) { if (![AccountTool isLogin]) { [self noLoginView]; } }]; } - (void)noLoginView { [self.userView setUnLoginView]; } /** 检查是否有新消息 */ - (void)checkForNewMessage { if ([AccountTool isLogin]) { NSString *url = [NSString stringWithFormat:@"%@/api/v2/message_push/messageNew",BaseURL]; [DRHttp post:url params:nil success:^(id json) { NSNumber *new = json[@"data"][@"message_new"]; if ([new boolValue]) { [self.messageBtn ba_showBadge]; }else { [self.messageBtn ba_hiddenBadge]; } [self.tableView.mj_header endRefreshing]; } failure:^(NSError *error) { }]; } } /** 加载广告位数据 */ - (void)loadAdData { NSString *url = [NSString stringWithFormat:@"%@/api/v2/adv/advPersonCenter",BaseURL]; [DRHttp get:url params:nil success:^(id json) { NSArray *list = [NSArray yy_modelArrayWithClass:[AdPopModel class] json:json[@"data"]]; if (list.count > 0) { [self showAdViewWithAdModel:list.firstObject]; }else { [self hiddenAdView]; } } failure:^(NSError *error) { }]; } - (void)showAdViewWithAdModel:(AdPopModel *)model { [self showAdView]; self.adView.model = model; } - (void)showAdView { [UIView animateWithDuration:0.5 animations:^{ self.adView.height = 72; self.header.height = CGRectGetMaxY(self.adView.frame)+10; self.tableView.tableHeaderView = self.header; }]; } - (void)hiddenAdView { [UIView animateWithDuration:0.5 animations:^{ self.adView.height = 0; self.header.height = CGRectGetMaxY(self.adView.frame)+10; self.tableView.tableHeaderView = self.header; }]; } /** 特权信息 */ - (void)showUserType { [MobClick event:MineVipClick]; DRPrivilegeReferralViewController *Privilege = [[DRPrivilegeReferralViewController alloc] init]; [self.navigationController pushViewController:Privilege animated:YES]; } #pragma mark ------------ - (void)settingAction { DRSettingViewController *setting = [[DRSettingViewController alloc] init]; [self.navigationController pushViewController:setting animated:YES]; } #pragma mark ---- YHMoreMenuViewDelegate - (void)morenMenu:(DRMoreMenuView *)menuView Button:(UIButton *)button clickIndex:(NSInteger)index { switch (index) { case 0: //我的收藏 [self goToMyCollectionPage]; break; case 1: //浏览记录 [self goToMyBrowserHistory]; break; case 2: //新手指南 [self goTogetTicketGuide]; break; case 3:{ NSString *url = self.userInfo.becomeAgency; DRAdWebViewController *web = [[DRAdWebViewController alloc] init]; web.url = url; [self.navigationController pushViewController:web animated:YES]; } //成为代理 break; default: break; } } #pragma mark ---------------- private --------- /** 用户登录 */ - (void)goToLoginPage { DRLoginViewController *login = [[DRLoginViewController alloc] init]; [self presentViewController:login animated:YES completion:nil]; } /** 我的粉丝 */ - (void)goToMyFansPage { if (![AccountTool isLogin]) { [self goToLoginPage]; return; } DRMyFansViewController *myFans = [[DRMyFansViewController alloc] init]; [self.navigationController pushViewController:myFans animated:YES]; } /** 我的订单 */ - (void)goToMyOrderPage { [self openMyOrderWebView]; } - (void)openMyOrderWebView { if (![AccountTool isLogin]) { [self goToLoginPage]; return; } DRCommissionMainViewController *order = [[DRCommissionMainViewController alloc] init]; [self.navigationController pushViewController:order animated:YES]; } /** 购物车 */ - (void)goToMyshopCarPage { DRShopCarViewController *shopCar = [[DRShopCarViewController alloc] init]; [self.navigationController pushViewController:shopCar animated:YES]; } /** 我的收藏 */ - (void)goToMyCollectionPage { if (![AccountTool isLogin]) { [self goToLoginPage]; return; } DRMyCollectionViewController *collection = [[DRMyCollectionViewController alloc] init]; [self.navigationController pushViewController:collection animated:YES]; } /** 我的消息 */ - (void)gotoMyMessagesPage { if (![AccountTool isLogin]) { [self goToLoginPage]; return; } DRMessageListController *messages = [[DRMessageListController alloc] init]; [self.navigationController pushViewController:messages animated:YES]; } /** 绑定邀请码 */ - (void)blindInviteCode { if (![AccountTool isLogin]) { [self goToLoginPage]; return; } if ([self.userInfo.is_have_parent boolValue]) { NSString *msg = [NSString stringWithFormat:@"您已绑定过邀请码%@",self.userInfo.parent_code]; [MBProgressHUD showMessage:msg]; return; } DRLinkFansController *linkFans = [[DRLinkFansController alloc] init]; [self.navigationController pushViewController:linkFans animated:YES]; } /** 已领优惠券 */ - (void)goToMyTicketPage { if (![AccountTool isLogin]) { [self goToLoginPage]; return; } DRMyTicketViewController *ticket = [[DRMyTicketViewController alloc] init]; [self.navigationController pushViewController:ticket animated:YES]; } /** 浏览历史 */ - (void)goToMyBrowserHistory { if (![AccountTool isLogin]) { [self goToLoginPage]; return; } DRHistoryViewController *history = [[DRHistoryViewController alloc] init]; [self.navigationController pushViewController:history animated:YES]; } /** 邀请好友 */ - (void)goToInviteFansPage { if (![AccountTool isLogin]) { [self goToLoginPage]; return; } DRInviteFansViewController *invite = [[DRInviteFansViewController alloc] init]; [self.navigationController pushViewController:invite animated:YES]; } /** 新手指南 */ - (void)goTogetTicketGuide { DRFindBookWebViewController *findbook = [[DRFindBookWebViewController alloc] init]; [self.navigationController pushViewController:findbook animated:YES]; } /** 意见反馈 */ - (void)goToFeedbackPage { DRFeedbackController *feedback = [[DRFeedbackController alloc] init]; [self.navigationController pushViewController:feedback animated:YES]; } /** 赚钱秘籍 */ - (void)goToGetMoneyPage { DRFindBookWebViewController *findbook = [[DRFindBookWebViewController alloc] init]; findbook.isGetMontyPage = YES; [self.navigationController pushViewController:findbook animated:YES]; [MobClick event:MineGetMoneyUrl]; } /** 五星好评 */ - (void)commentAndStart { NSString * nsStringToOpen = [NSString stringWithFormat: @"itms-apps://itunes.apple.com/app/id%@?action=write-review",APP_ID];//替换为对应的APPID [[UIApplication sharedApplication] openURL:[NSURL URLWithString:nsStringToOpen]]; // if (@available(iOS 10.3, *)) { // if([SKStoreReviewController respondsToSelector:@selector(requestReview)]){ // [SKStoreReviewController requestReview]; // } // } else { // NSString * nsStringToOpen = [NSString stringWithFormat: @"itms-apps://itunes.apple.com/app/id%@?action=write-review",APP_ID];//替换为对应的APPID // [[UIApplication sharedApplication] openURL:[NSURL URLWithString:nsStringToOpen]]; // } // SKStoreProductViewController *storeProductViewContorller = [[SKStoreProductViewController alloc] init]; // storeProductViewContorller.delegate = self; // //加载App Store视图展示 // [storeProductViewContorller loadProductWithParameters: // // @{SKStoreProductParameterITunesItemIdentifier : @"APPID"} completionBlock:^(BOOL result, NSError *error) { // // if(error) { // // } else { // // //模态弹出appstore // // [self presentViewController:storeProductViewContorller animated:YES completion:^{ // // }]; // // } // // }]; } #pragma mark -------------------- YHMineFourButtonViewDelegate --------- - (void)YHMineFourButtonViewDidClickButtonIndex:(NSInteger)index { switch (index) { case 0: [self goToMyOrderPage]; break; case 1: [self goToMyTicketPage]; break; case 2: [self goToMyshopCarPage]; break; case 3: [self goToMyBrowserHistory]; break; default: break; } } #pragma mark ------------------------ - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { //圆角cell // [cell radioCellWithTableView:tableView atIndexPath:indexPath]; if ([cell respondsToSelector:@selector(separatorInset)]) { cell.separatorInset = UIEdgeInsetsMake(0, 20, 0, 20); } } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSArray *array = self.cellData[section]; return array.count; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return self.cellData.count; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if (section == 0) { return 0.1; }else { return 10; } } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellID"]; cell.textLabel.textColor = [UIColor YHColorWithHex:0x646464]; cell.textLabel.font = [UIFont systemFontOfSize:14]; cell.textLabel.text = self.cellData[indexPath.section][indexPath.row][@"title"]; NSString *imgStr = self.cellData[indexPath.section][indexPath.row][@"image"]; cell.imageView.image = [UIImage imageNamed:imgStr]; cell.selectionStyle = UITableViewCellSelectionStyleNone; if (indexPath.section == 1) { UIButton *sexBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-15-50, 12, 50, 30)]; [sexBtn setImage:[UIImage imageNamed:@"me_girl"] forState:UIControlStateNormal]; [sexBtn setImage:[UIImage imageNamed:@"me_man"] forState:UIControlStateSelected]; [cell addSubview:sexBtn]; NSString *sex = [[NSUserDefaults standardUserDefaults] objectForKey:UserSexKey]; sexBtn.selected = [sex boolValue]; [sexBtn addTarget:self action:@selector(changeSexButtonClick:) forControlEvents:UIControlEventTouchUpInside]; }else { cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; } // // [cell.contentView mas_updateConstraints:^(MASConstraintMaker *make) { // make.edges.mas_equalTo(UIEdgeInsetsMake(0, 10, 0, 0)); // }]; return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 55; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { switch (indexPath.row) { case 0: //用户反馈 [self goToFeedbackPage]; break; case 1: //五星好评 [self commentAndStart]; break; case 2: //设置 [self settingAction]; break; default: break; } } } /** 改变性别 */ - (void)changeSexButtonClick:(UIButton *)sender { NSString *newSex = sender.selected?@"0":@"1"; NSDictionary *para = @{@"sex":newSex}; if ([AccountTool isLogin]) { [SVProgressHUD show]; sender.enabled = NO; [DRHttp post:MySetting params:para success:^(id json) { [SVProgressHUD dismiss]; [self saveSexWithNewSex:newSex]; sender.enabled = YES; [[NSNotificationCenter defaultCenter] postNotificationName:ChangeSex object:nil]; } failure:^(NSError *error) { [SVProgressHUD dismiss]; sender.enabled = YES; }]; }else { [self saveSexWithNewSex:newSex]; [[NSNotificationCenter defaultCenter] postNotificationName:ChangeSex object:nil]; } } - (void)saveSexWithNewSex:(NSString *)newSex { [[NSUserDefaults standardUserDefaults] setObject:newSex forKey:UserSexKey]; [[NSUserDefaults standardUserDefaults] synchronize]; [self.tableView reloadData]; } #pragma mark ===================== layezer ============== - (UITableView *)tableView { if (!_tableView) { _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-TabbarHeight) style:UITableViewStyleGrouped]; _tableView.estimatedSectionHeaderHeight = 0; _tableView.estimatedSectionFooterHeight = 0; _tableView.sectionFooterHeight = 0; _tableView.sectionHeaderHeight = 0; _tableView.delegate = self; _tableView.dataSource = self; _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; _tableView.backgroundColor = [UIColor yhGrayColor]; _tableView.bounces = YES; _tableView.showsVerticalScrollIndicator = NO; _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; _tableView.separatorColor = [UIColor YHColorWithHex:0xEEEEEE]; // MJRefreshGifHeader *header = [MJRefreshGifHeader headerWithRefreshingBlock:^{ // [self loadUserInfo]; // if ([AccountTool isLogin]) { // [self checkForNewMessage]; // } // }]; // header.lastUpdatedTimeLabel.hidden = YES; // header.stateLabel.hidden = YES; // // //正在刷新的图片 // NSArray *imgArr = @[[UIImage imageNamed:@"ant1"],[UIImage imageNamed:@"ant2"]]; // [header setImages:imgArr duration:0.3 forState:MJRefreshStateRefreshing]; // [header setImages:@[[UIImage imageNamed:@"ant1"]] duration:1 forState:MJRefreshStateWillRefresh]; // [header setImages:@[[UIImage imageNamed:@"ant1"]] duration:1 forState:MJRefreshStatePulling]; // _tableView.mj_header = header; } return _tableView; } - (NSArray *)cellData { if (!_cellData) {//@"order",@"quan",@"history" _cellData = @[@[@{@"title":@"用户反馈",@"image":@"fankui"}, @{@"title":@"五星好评",@"image":@"haoping"}, @{@"title":@"设置",@"image":@"设置"}]]; } return _cellData; } - (NSArray *)sexArr { if (!_sexArr) { _sexArr = @[@"女",@"男"]; } return _sexArr; } - (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