// // IfishDiscoverViewController.m // ifishTabTest // // Created by imac on 16/7/25. // Copyright © 2016年 xiang. All rights reserved. // #import "IfishDiscoverViewController.h" #import "UMComLoginDelegate.h" #define UpdateUserProfileSuccess @"update user profile success!" #import "UMComShowToast.h" #import "IfishTanSuoViewCell.h" #import "TanSuoViewModel.h" #import "ShopCertificationIntroduceController.h" #import "ShopCertifyFailViewController.h" #import "ShopCertifySucssesViewController.h" #import "ShopCertifyCheckViewController.h" #import "CertificationShopModel.h" #import "ShopCertifyStausModel.h" #import "IfishKanHuServiceViewController.h" #import "WorkbechViewController.h" #import "MineKanHuViewController.h" //#import "IfishKanKanListViewController.h" #import "LoveFishLiveListBaseViewController.h" #import "UMCommunityUI.h" #import "KanHuFuWuViewController.h" #import "WoShiShangJiaViewController.h" #import "FishDoctorViewController.h" #import "PushMasssageWebViewController.h" #import "IfishGoldCoastViewController.h" #import "AIyuYanXuanViewController.h" #import "IfishUsersActivityListController.h" @interface IfishDiscoverViewController () @property(nonatomic,strong)UITableView *tableView; @property(nonatomic,strong) NSMutableArray *dataArr; @property(nonatomic,strong) CertificationShopModel *CSModel; //@property(nonatomic,strong) UserModel *userModel; @property (nonatomic,strong) NSString *maxActivityIdNumber; @end BOOL isFromRootVC; //认证界面来源 BOOL cerViewFormRootVC; @implementation IfishDiscoverViewController -(id)init{ self = [super init]; if (self) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(homeAdViewAction) name:@"homeAdViewAction" object:nil]; } return self; } - (void)viewDidLoad { [super viewDidLoad]; if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) { self.navigationController.interactivePopGestureRecognizer.enabled = YES; self.navigationController.interactivePopGestureRecognizer.delegate = nil; } // Do any additional setup after loading the view. UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]; self.navigationItem.backBarButtonItem = item; //self.view.backgroundColor = TABLE_BACKGROUD_COLOR; self.view.backgroundColor = RGB(242, 242, 242); [self setInDataArr]; [self creatTab]; isFromRootVC = NO; cerViewFormRootVC = NO; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; //更新实时动态未读数据 每次进入界面都请求!擦擦擦 [self loadUserActivityMaxCount]; } -(void)dealloc{ [[NSNotificationCenter defaultCenter] removeObserver:self name:@"homeAdViewAction" object:nil]; } -(void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; } #pragma mark -homeAdViewAction -(void)homeAdViewAction { //弹窗 看看 //[self pushkankanView]; //弹窗 看护 [self lookService]; } -(void)pushkankanView{ self.hidesBottomBarWhenPushed = YES; //IfishKanKanListViewController *kankanVc=[[IfishKanKanListViewController alloc] init]; //IfishLiveListBaseViewController *kankanVc=[[IfishLiveListBaseViewController alloc] init]; LoveFishLiveListBaseViewController *kankanVc=[[LoveFishLiveListBaseViewController alloc] init]; [self.navigationController pushViewController:kankanVc animated:YES]; self.hidesBottomBarWhenPushed = NO; } -(void)lookService { UserModel *mode = [dataContorl getUserInfo]; if ([mode.userType isEqualToString:@"0"]) { //普通用户 KanHuFuWuViewController *kankanVc=[[KanHuFuWuViewController alloc] init]; [self.navigationController pushViewController:kankanVc animated:YES]; self.hidesBottomBarWhenPushed = NO; } } -(void)setInDataArr{ NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"tanSuoPlist" ofType:@"plist"]; if (!_dataArr) { _dataArr = [[NSMutableArray alloc] init]; NSArray *data = [[NSArray alloc] initWithContentsOfFile:plistPath]; for (int i=0; i<2; i++) { NSMutableArray *sectionArr = [[NSMutableArray alloc] init]; for (NSDictionary *listDic in data[i]) { TanSuoViewModel *model=[[TanSuoViewModel alloc] init]; model.headerImg = listDic[@"headerImg"]; model.detailL = listDic[@"descp"]; model.nameT = listDic [@"nameTitle"]; [sectionArr addObject:model]; } [_dataArr addObject:sectionArr]; } } } -(void)creatTab{ self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0, kScreenSize.width,kScreenSize.height - 49 ) style:UITableViewStylePlain]; self.tableView.delegate = self; self.tableView.dataSource = self; self.tableView.scrollEnabled = YES; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.showsVerticalScrollIndicator = NO; self.tableView.backgroundColor = TABLE_BACKGROUD_COLOR; [self.view addSubview:self.tableView]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 2; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (section ==0) { return 6; }else{ return 1; } } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { IfishTanSuoViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"IfishTanSuoViewCell"]; if (!cell) { cell = [[[NSBundle mainBundle]loadNibNamed:@"IfishTanSuoViewCell" owner:self options:nil]lastObject]; } TanSuoViewModel *mode =self.dataArr[indexPath.section][indexPath.row]; [cell cellSetNewsImgAt:mode atInex:indexPath]; [cell userActivityUnreadCount:_maxActivityIdNumber atInex:indexPath]; return cell; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 70.0f; } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ if (section ==0) { return 0.1f; }else{ return 10.0f; } } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [tableView deselectRowAtIndexPath:indexPath animated:YES]; if (indexPath.section ==0) { switch (indexPath.row) { case 0: { //优选商家 KanHuFuWuViewController *kanHuVC=[[KanHuFuWuViewController alloc] init]; isFromRootVC = NO; cerViewFormRootVC = NO; //老的已去 //IfishKanHuServiceViewController *kanHuVC=[[IfishKanHuServiceViewController alloc] init]; self.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:kanHuVC animated:YES]; self.hidesBottomBarWhenPushed = NO; } break; case 1: { //鱼医生 FishDoctorViewController *doctorVC= [[FishDoctorViewController alloc] init]; self.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:doctorVC animated:YES]; self.hidesBottomBarWhenPushed = NO; } break; case 2: { //爱鱼圈 // 精简版社区 sdk 会崩溃 已无人维护 CGFloat version = [[UIDevice currentDevice]systemVersion].floatValue; NSLog(@"version:%f",version); if (version>=10.3) { UIAlertController*ac=[UIAlertController alertControllerWithTitle:@"" message:@"当前手机系统暂不支持爱鱼圈点赞和回复" preferredStyle:UIAlertControllerStyleAlert]; [self presentViewController:ac animated:YES completion:nil]; [ac addAction:[UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleDefault handler:^(UIAlertAction*action){ PushMasssageWebViewController *web = [[PushMasssageWebViewController alloc] init]; web.pushlink = @"https://ifish.wsq.umeng.com"; web.pushtitle = @"爱鱼圈"; self.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:web animated:YES]; self.hidesBottomBarWhenPushed = NO ; }]]; return; } if (!IFISHIOS10) { // [self.view makeToast:@"手机系统版本太低,请更新到IOS10.0以上"]; UIAlertController*ac=[UIAlertController alertControllerWithTitle:@"" message:@"当前手机系统暂不支持爱鱼圈点赞和回复" preferredStyle:UIAlertControllerStyleAlert]; [self presentViewController:ac animated:YES completion:nil]; [ac addAction:[UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleDefault handler:^(UIAlertAction*action){ PushMasssageWebViewController *web = [[PushMasssageWebViewController alloc] init]; web.pushlink = @"https://ifish.wsq.umeng.com"; web.pushtitle = @"爱鱼圈"; self.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:web animated:YES]; self.hidesBottomBarWhenPushed = NO ; }]]; return; } // 精简版社区 sdk 会崩溃 已无人维护 // 使用开发者自有用户系统账号登录 UserModel*userModel=[[DataCenter defaultDtacenter]valueForKey:@"UserLogIn"]; NSString*userId=[NSString stringWithFormat:@"%@",userModel.userId]; UMComLoginUser *userAccount = [[UMComLoginUser alloc] init]; //字符串转NSnumber NSNumberFormatter*f=[[NSNumberFormatter alloc]init]; id gender; if ([userModel.userSex isKindOfClass:[NSNull class]]) { userModel.userSex=@"1";//默认男 } if ( [userModel.userSex isEqualToString:@""]) { userModel.userSex=@"1"; } if ([f numberFromString:userModel.userSex]) { gender=[NSNumber numberWithInt:[userModel.userSex intValue]]; } if ([userModel.userImg isKindOfClass:[NSNull class]]) { userModel.userImg=@""; } userAccount.name = userModel.nickName; userAccount.usid = userId; userAccount.icon_url = [NSString stringWithFormat:@"%@%@",kGetIconUrl,userModel.userImg]; userAccount.gender = gender;//性别,0-女 1-男 // userAccount.custom = @"自定义数据"; // 开发者自定义数据,用于扩展开发者特定需求 [self presentViewController:[UMCommunityUI navigationViewController] animated:YES completion:^{ // __weak typeof(self) weakSelf = self; [UMComLoginManager requestLoginWithLoginAccount:userAccount requestCompletion:^(NSDictionary *responseObject, NSError *error, dispatch_block_t callbackCompletion) { if (error) { // 登录失败 [UMComShowToast showFetchResultTipWithError:error]; } else { // 登录成功 /** * 以下调用二选一 */ #ifdef LoginWithUI // 当前有登录界面时调用,weakSelf是指presentViewController弹出的UIViewController [weakSelf dismissViewControllerAnimated:YES completion:callbackCompletion]; #else // 没有界面时调用,app后台静默登录,登录成功后调用callbackCompletion()用于SDK登录存储数据 callbackCompletion(); #endif } }]; }]; //每日打开社区 加金币 [[IfishUserObsever sharedInstance] addGoldWith:IFISHCOMMUNITY addType:IFISHADDGOLDTYPE0]; } break; case 3: { //爱鱼严选 AIyuYanXuanViewController *goodlistVC=[[AIyuYanXuanViewController alloc] init]; self.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:goodlistVC animated:YES]; self.hidesBottomBarWhenPushed = NO; } break; case 4: { //金币兑换 IfishGoldCoastViewController *coastVC =[[IfishGoldCoastViewController alloc] init]; self.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:coastVC animated:YES]; self.hidesBottomBarWhenPushed = NO ; } break; case 5: { //消息动态 self.hidesBottomBarWhenPushed = YES; IfishUsersActivityListController *activityVC= [[IfishUsersActivityListController alloc] init]; [self.navigationController pushViewController:activityVC animated:YES]; self.hidesBottomBarWhenPushed = NO ; } break; case 6: { //搜集拼图 } break; default: break; } }else{ //我是商户 WoShiShangJiaViewController *shangjiavc=[[WoShiShangJiaViewController alloc] init]; isFromRootVC = YES; cerViewFormRootVC = YES; self.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:shangjiavc animated:YES]; self.hidesBottomBarWhenPushed = NO; //shangjiavc.modalTransitionStyle=UIModalTransitionStyleCrossDissolve; //[self.navigationController presentViewController:shangjiavc animated:YES completion:^{ //}]; } } #pragma mark - 获取用户动态 最大ID -(void)loadUserActivityMaxCount { __weak typeof (self)weakSelf = self; [AFHttpTool getIFishUserActivityMaxCountSuccess:^(id response) { NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil]; if ([reDic[@"result"] isEqualToString:@"100"]){ _maxActivityIdNumber = [reDic objectForKey:@"data"]; [weakSelf.tableView reloadData]; } } failure:^(NSError *err) { }]; } @end