// // IfishDeviceViewController.m // ifishTabTest // // Created by imac on 16/7/25. // Copyright © 2016年 xiang. All rights reserved. // #import "IfishDeviceViewController.h" #import "TabbarDeiceSecdCell.h" #import "TabBarDeviceShouYeCell.h" #import "DXPopover.h" #import "LXPopView.h" //#import "SelectDeviceViewController.h" //#import "IfishSelectCardViewController.h" #import "IfishBindDeviceSelectViewController.h" #import "IfishDataUnity.h" #import "IfishP2PMonitorController.h" #import "RightViewController.h" #import "UMComLoginDelegate.h" #import "UMComShowToast.h" #define UpdateUserProfileSuccess @"update user profile success!" #import "TabMineDeivceListViewCell.h" #import "UIImageView+WebCache.h" #import "FormatTankAddCamera.h" #import "IfishDataUnity.h" #import "IfishNewsModel.h" #import "PushMasssageWebViewController.h" #import "IfishP2PPlayBackListViewController.h" #import "ShuoMingShuCell.h" #import "UINavigationBar+Background.h" #import "IifshMineDJViewController.h" #import "QianDaoViewController.h" #import "IfishUserObsever.h" #import "IfishMineGoldViewController.h" #import "IfishUserDefaultHelper.h" #import "ShouYeAdViewCell.h" #import "IfishInformationViewController.h" #import "IfishAiLiShopGoodsViewCell.h" #import #import "IfishAlibcWebViewController.h" #import "MBProgressHUD.h" #import "NTESSessionListViewController.h" #import "RunSun84biteCenterViewController.h" #import "RunSunChangeNameViewController.h" @interface IfishDeviceViewController () @property(nonatomic,strong)UITableView *tableView; @property(nonatomic,strong) NSArray *deviceArr; @property(nonatomic,strong) DXPopover *popover; @property(nonatomic,strong) NSArray *cameraArr; @property(nonatomic,strong) UIButton*rightButton; @property(nonatomic,strong) UIView *tabHeaderImgView; @property(nonatomic,strong) UIImageView *userImgView; @property(nonatomic,strong) UILabel *userNameLabel; @property(nonatomic,strong) UIButton *newsButton; @property(nonatomic,strong) UIView *newsRedPoint; @property(nonatomic,strong) UILabel *newsLabel; @property(nonatomic,strong) UIView *orangeView; @property(nonatomic,strong) UIButton *qianDaoBtn; @property(nonatomic,strong) UIView *qianDaoRedPoint; @property(nonatomic,strong) UIButton *goldBtn; @property(nonatomic,strong) UIButton *levelBtn; @property(nonatomic,strong) NSMutableArray *totalArr; @property(nonatomic,strong) IfishNewsModel *newsModel; @property (nonatomic) CGPoint inputPoint0; @property (nonatomic) CGPoint inputPoint1; @property (nonatomic) UIColor *inputColor0; @property (nonatomic) UIColor *inputColor1; @property (nonatomic) CGFloat scrollHeight; @property (nonatomic,strong) NSMutableArray *adViewData; @property (nonatomic,strong) NSMutableArray *goodsArr; @property (nonatomic,strong) MBProgressHUD *progressHud; @property (nonatomic,strong) UILabel *mesglabel; //@property (nonatomic,strong) UIView *redView; @end @implementation IfishDeviceViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. //self.view.backgroundColor = []; _adViewData = [[NSMutableArray alloc] init]; self.deviceArr = [[NSArray alloc] init]; self.cameraArr = [[NSArray alloc] init]; self.totalArr = [[NSMutableArray alloc] init]; _goodsArr= [[NSMutableArray alloc] init]; [self creatNav]; [self initUI]; [self showProgress]; [self addDataRequestQueue]; [[NIMSDK sharedSDK].systemNotificationManager addDelegate:self]; [[NIMSDK sharedSDK].conversationManager addDelegate:self]; } -(void)addDataRequestQueue { //创建异步任务队列 避免UI更新受影响 //串行异步队列 //dispatch_queue_t queue = dispatch_queue_create("com.privateQueue",NULL); dispatch_async(dispatch_get_main_queue(), ^{ [self getMoreUserData]; [self initBannerData]; [self loadGoodsData]; }); } -(void)showProgress{ self.progressHud = [[MBProgressHUD alloc] initWithView:[UIApplication sharedApplication].keyWindow]; self.progressHud.mode=MBProgressHUDModeCustomView; self.progressHud.customView = [[UIView alloc] init]; //self.progressHud.delegate = self; self.progressHud.labelText = @"加载中..."; } #pragma mark - 首页广告位 -(void)initBannerData{ __weak typeof (self)weakSelf = self; [AFHttpTool getIfishBannerData:IfishAdTypeShouYE success:^(id response) { NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil]; NSString *result=reDic[@"result"]; if ([result isEqualToString:@"100"]) { NSArray *data= reDic[@"data"]; for (NSDictionary *dic in data) { IfishBannerData *bannerdata = [[IfishBannerData alloc] initWithDict:dic]; [_adViewData addObject:bannerdata]; } NSIndexSet *asset = [NSIndexSet indexSetWithIndex:1]; [weakSelf.tableView reloadSections:asset withRowAnimation:UITableViewRowAnimationNone]; }else{ //[weakSelf.view makeToast:@"广告位获取失败"]; } } failure:^(NSError *err) { }]; } #pragma mark - 获取更多用户数据(新加) -(void)getMoreUserData{ NSString *userId = [dataContorl dataControlGetUserIdInfo]; __weak typeof (self)weakSelf = self; [AFHttpTool getMoreUserDataWith:userId success:^(id response) { NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil]; NSString *result=reDic[@"result"]; if ([result isEqualToString:@"100"]) { NSDictionary *dataDic = reDic[@"data"]; //资讯 information NSDictionary *informationdic=dataDic[@"information"]; if (informationdic) { IfishNewsModel *newsModel=[[IfishNewsModel alloc] initWithDict:informationdic]; [[DataCenter defaultDtacenter]setValue:newsModel forKey:@"informationNews"]; } //任务 NSArray*doneTaskArray=dataDic[@"goldTasks"]; if (!doneTaskArray) { doneTaskArray = [[NSArray alloc] init]; } NSMutableArray *taskArr = [[NSMutableArray alloc] init]; if (doneTaskArray.count!=0) { for (NSDictionary *taskDic in doneTaskArray) { IfishTaskModel *task = [[IfishTaskModel alloc] initWithDict:taskDic]; [taskArr addObject:task]; } } [[DataCenter defaultDtacenter]setValue:taskArr forKey:IFISHTASK_ARR]; //自己是商家 NSDictionary *shopsInfoDic=dataDic[@"shopsInfo"]; if (shopsInfoDic.count !=0) { //空时用的时候对象判空 CertificationShopModel *shopInfo=[[CertificationShopModel alloc] initWithDict:shopsInfoDic]; [[DataCenter defaultDtacenter]setValue:shopInfo forKey:@"ShopsInfo"]; }else{ CertificationShopModel *shopInfo=[[CertificationShopModel alloc] init]; [[DataCenter defaultDtacenter]setValue:shopInfo forKey:@"ShopsInfo"]; } //选择的商家信息 NSDictionary *kanHushopsInfoDic=dataDic[@"shopsInfo2"]; NSLog(@"kanHushopsInfoDic%lu",(unsigned long)kanHushopsInfoDic.count); if (kanHushopsInfoDic.count != 0) { //空时用的时候对象判空 CertificationShopModel *shopInfo2=[[CertificationShopModel alloc] initWithDict:kanHushopsInfoDic]; [[DataCenter defaultDtacenter]setValue:shopInfo2 forKey:@"ShopsInfo2"]; }else{ CertificationShopModel *shopInfo2=[[CertificationShopModel alloc] init]; [[DataCenter defaultDtacenter]setValue:shopInfo2 forKey:@"ShopsInfo2"]; } //设备信息 NSArray*deviceArray=dataDic[@"device"]; NSArray*cameraA=dataDic[@"camera"]; NSMutableArray *deviceArr = [[NSMutableArray alloc] init]; if ([deviceArray count]!=0) { for (NSDictionary*deviceDic in deviceArray) { DeviceModel*devicemodel=[[DeviceModel alloc] initWithDict:deviceDic]; [deviceArr insertObject:devicemodel atIndex:0]; } } [[DataCenter defaultDtacenter]setValue:deviceArr forKey:@"deviceInfo"]; //存储摄像头设备信息 NSMutableArray *camras = [[NSMutableArray alloc] init]; if (cameraA .count !=0) { if ([cameraA count]!=0) { for (NSDictionary * cameraDic in cameraA) { IfishCameraModel *camera=[[IfishCameraModel alloc] initWithDict:cameraDic]; [camras insertObject:camera atIndex:0]; } } } //存储摄像头数组 [[DataCenter defaultDtacenter]setValue:camras forKey:@"cameraArr"]; /** * 设备摄像头关系数组 */ NSArray*deviceCamera=dataDic[@"deviceCamera"]; NSMutableArray *devicamerArr=[[NSMutableArray alloc] init]; if (deviceCamera) { for (NSDictionary * deviceCameraDic in deviceCamera) { DeviceCameraModel *dcmodel=[[DeviceCameraModel alloc] init]; dcmodel.deviceId = deviceCameraDic[@"deviceId"]; dcmodel.cameraId = deviceCameraDic[@"cameraId"]; [devicamerArr addObject:dcmodel]; } } //存储摄像头设备关系数组 [[DataCenter defaultDtacenter]setValue:devicamerArr forKey:@"devicamerArr"]; [weakSelf refreshUI]; }else{ [weakSelf.view makeToast:@"户数据获取失败"]; } } failure:^(NSError *err) { [weakSelf.view makeToast:@"请求异常"]; }]; } -(UIView *)tabHeaderImgView{ //1776 if (!_tabHeaderImgView) { CGFloat headerH = TabContentHeaght *0.245 +64; _tabHeaderImgView = [[UIView alloc] init]; _tabHeaderImgView.frame = CGRectMake(0, 0, kScreenSize.width, headerH); //设置渐变色 _inputColor0 = RGB(10, 18, 177); _inputColor1 = RGB(50, 176, 239); _inputPoint0 = CGPointMake(0, 0); _inputPoint1 = CGPointMake(0, 1); CAGradientLayer *layer = [CAGradientLayer new]; layer.colors = @[(__bridge id)_inputColor0.CGColor, (__bridge id)_inputColor1.CGColor]; layer.startPoint = _inputPoint0; layer.endPoint = _inputPoint1; layer.frame = _tabHeaderImgView.bounds; [_tabHeaderImgView.layer addSublayer:layer]; } return _tabHeaderImgView; } -(UIImageView *)userImgView { if (!_userImgView) { CGFloat userImgViewW = TabContentHeaght*0.068; _userImgView =[[UIImageView alloc] init]; _userImgView.frame = CGRectMake(kScreenSize.width * 0.04, TabContentHeaght*0.04 +64, userImgViewW, userImgViewW); _userImgView.layer.masksToBounds = YES; _userImgView.layer.cornerRadius = userImgViewW * 0.5; } return _userImgView; } -(UILabel *)userNameLabel{ if (!_userNameLabel) { CGFloat nameH = 16*KWidth_Scale; _userNameLabel = [[UILabel alloc] init]; _userNameLabel.frame = CGRectMake(CGRectGetMaxX(_userImgView.frame) + 5 , CGRectGetMidY(_userImgView.frame)-nameH, kScreenSize.width -CGRectGetMaxX(_userImgView.frame) - 5 ,nameH); _userNameLabel.textAlignment = NSTextAlignmentLeft; _userNameLabel.textColor = [UIColor whiteColor]; //_userNameLabel.backgroundColor = [UIColor lightGrayColor]; } return _userNameLabel; } -(UIButton *)levelBtn { if (!_levelBtn) { _levelBtn = [UIButton buttonWithType:UIButtonTypeCustom]; //_levelBtn.backgroundColor = [UIColor redColor]; [_levelBtn setContentVerticalAlignment:UIControlContentVerticalAlignmentBottom]; [_levelBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft]; [_levelBtn addTarget:self action:@selector(levelBtnAction) forControlEvents:UIControlEventTouchUpInside]; } return _levelBtn; } -(UIButton*)qianDaoBtn{ if (!_qianDaoBtn) { CGFloat btnW = 67*KWidth_Scale; CGFloat btnH = btnW*0.36; CGFloat oriX = kScreenSize.width - CGRectGetMinX(_userImgView.frame); _qianDaoBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _qianDaoBtn.frame = CGRectMake(oriX - btnW,CGRectGetMinY(_userNameLabel.frame) ,btnW, btnH); [_qianDaoBtn setBackgroundImage:[UIImage imageNamed:@"home_iocn_signin"] forState:UIControlStateNormal]; [_qianDaoBtn addTarget:self action:@selector(qianDaoBtnAction) forControlEvents:UIControlEventTouchUpInside]; CGFloat pointW = 8; _qianDaoRedPoint = [[UIView alloc] initWithFrame:CGRectMake(pointW*KWidth_Scale,0, pointW , pointW )]; _qianDaoRedPoint.backgroundColor = RGB(252, 89, 89); _qianDaoRedPoint.layer.masksToBounds = YES; _qianDaoRedPoint.layer.cornerRadius = pointW /2; [_qianDaoBtn addSubview:self.qianDaoRedPoint]; } return _qianDaoBtn; } -(UIButton*)goldBtn{ if (!_goldBtn) { _goldBtn =[UIButton buttonWithType:UIButtonTypeCustom]; //_goldBtn.backgroundColor = [UIColor blueColor]; CGFloat btnH =40*KWidth_Scale; CGFloat btnW =100*KWidth_Scale; _goldBtn.frame = CGRectMake(CGRectGetMinX(_userNameLabel.frame), CGRectGetMaxY(_userNameLabel.frame)+6, btnW, btnH); [_goldBtn setTitleColor:RGB(252, 217, 94) forState:UIControlStateNormal]; _goldBtn.titleLabel.font = [UIFont systemFontOfSize:14]; [_goldBtn setImage:[UIImage imageNamed:@"home_iocn_gold"] forState:UIControlStateNormal]; [_goldBtn setImageEdgeInsets:UIEdgeInsetsMake(2,0, 0, 0)]; //[_goldBtn setTitleEdgeInsets:UIEdgeInsetsMake(0,0, 0, 0)]; [_goldBtn setTitle:@"222" forState:UIControlStateNormal]; [_goldBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft]; [_goldBtn setContentVerticalAlignment:UIControlContentVerticalAlignmentTop]; [_goldBtn addTarget:self action:@selector(goldBtnAction:) forControlEvents:UIControlEventTouchUpInside]; } return _goldBtn; } -(void)getUsernameAddImg{ IfishUserAsset *userAsset = [dataContorl getAllIfishUserAsset]; UserModel*umodel=[dataContorl getUserInfo]; _userNameLabel.text = umodel.nickName; [_userNameLabel sizeToFit]; CGFloat btnH = 40*KWidth_Scale; CGFloat btnW =100*KWidth_Scale; _levelBtn.frame = CGRectMake(CGRectGetMaxX(_userNameLabel.frame) + 2, CGRectGetMaxY(_userNameLabel.frame) - btnH,btnW, btnH); NSString *title = [NSString stringWithFormat:@"LV%@",userAsset.gradeNum]; NSAttributedString * str= [[NSAttributedString alloc] initWithString:title attributes:@{NSFontAttributeName:[UIFont fontWithName:@"Arial-BoldItalicMT" size:14],NSForegroundColorAttributeName:RGB(252, 217, 94)}]; [_levelBtn setAttributedTitle:str forState:UIControlStateNormal]; [_levelBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0,10)]; NSString *goldValue = [NSString stringWithFormat:@" 金币 %ld",(long)userAsset.goldValue]; [_goldBtn setTitle:goldValue forState:UIControlStateNormal]; if ([umodel.userImg isKindOfClass:[NSNull class]]) { [_userImgView setImage:[UIImage imageNamed:@"account"]]; }else if ([umodel.userImg isEqualToString:@""]){ // int i = (arc4random()%11) + 1;// 设置随机头像 // [self.backImg setImage:[UIImage imageNamed:[NSString stringWithFormat:@"acount%d.png",i]]]; //int i = (arc4random()%7) + 1;// 设置随机头像 int i = 1; [_userImgView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"userIcon%d.png",i]]]; }else{ NSLog(@"%@",[NSString stringWithFormat:@"%@%@",kGetIconUrl,umodel.userImg]); [_userImgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",kGetIconUrl,umodel.userImg]]]; } //资讯首页 IfishNewsModel *newsModel=[[DataCenter defaultDtacenter] valueForKey:@"informationNews"]; self.newsModel = newsModel; NSString *newsTitle= self.newsModel.title; _newsLabel.text =newsTitle; //签到按钮红点 _qianDaoRedPoint.hidden = userAsset.toDaySignin ? YES : NO; //资讯按钮红点 NSString *infoId =[IfishUserDefaultHelper getDefualtInfoId]; if (infoId) { if (infoId.intValue 0) { CGFloat alpha = MIN(1, (offsetY)/_scrollHeight); [self.navigationController.navigationBar cnSetBackgroundColor:[color colorWithAlphaComponent:alpha]]; self.tableView.backgroundColor = [UIColor whiteColor]; } else { //下拉 [self.navigationController.navigationBar cnSetBackgroundColor:[color colorWithAlphaComponent:0]]; //CGRect rect = self.tabDowloadHoldView.frame; ////我们只需要改变图片的y值和高度即可 //rect.size.height = - offsetY; //self.tabDowloadHoldView.frame = rect; self.tableView.backgroundColor = RGB(10, 18, 177); } } #pragma mark - 我的等级 -(void)levelBtnAction{ IifshMineDJViewController *mineLevelVC = [[IifshMineDJViewController alloc] init]; self.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:mineLevelVC animated:YES]; self.hidesBottomBarWhenPushed = NO; } #pragma mark - 我的金币 -(void)goldBtnAction:(UIButton*)btn{ IfishMineGoldViewController *GoldViewVC = [[IfishMineGoldViewController alloc] init]; self.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:GoldViewVC animated:YES]; self.hidesBottomBarWhenPushed = NO; } #pragma mark - 广告点击事件 -(void)tapAdWithLink:(NSString *)pushLink { if (![pushLink isKindOfClass:[NSNull class]] &&pushLink &&![pushLink isEqualToString:@""]){ //字条串是否包含有某字符串 if ([pushLink rangeOfString:@"taobao"].location == NSNotFound) { self.hidesBottomBarWhenPushed = YES; PushMasssageWebViewController*webVC=[[PushMasssageWebViewController alloc]init]; webVC.pushlink =pushLink; webVC.pushtitle = @"详情"; [self.navigationController pushViewController:webVC animated:YES]; self.hidesBottomBarWhenPushed = NO; } else { [self openAliBCWithLink:pushLink]; } } } #pragma mark - 商品列表点击事件 // 宝贝详情页面 -(void)tapTtemListAt:(NSString *)goodslink { [self openAliBCWithLink:goodslink]; } -(void)openAliBCWithLink:(NSString *)linkUrl{ //查看商品 加金币 [[IfishUserObsever sharedInstance] addGoldWith:OPENGOODSLINK addType:IFISHADDGOLDTYPE0]; //535991514644 //根据商品ID //id page = [AlibcTradePageFactory itemDetailPage: @"535991514644"]; //根据链接打开页面 id page = [AlibcTradePageFactory page:linkUrl]; AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init]; //app 内闭环交易 强制H5 打开 showParam.openType = AlibcOpenTypeH5; //AlibcWebViewController* myView = [[AlibcWebViewController alloc] init]; //自定义web IfishAlibcWebViewController* myView = [[IfishAlibcWebViewController alloc] init]; NSInteger ret = [[AlibcTradeSDK sharedInstance].tradeService show:self.navigationController webView:myView.webView page:page showParams:showParam taoKeParams:nil trackParam:nil tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) { } tradeProcessFailedCallback:^(NSError * _Nullable error) { }]; //返回1,说明h5打开,否则不应该展示页面 if (ret == 1) { self.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:myView animated:YES]; self.hidesBottomBarWhenPushed = NO; } } #pragma mark - 导航栏消息 -(void)navMeaasageBtnAction{ NTESSessionListViewController *sessionList = [[NTESSessionListViewController alloc] init]; // UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:sessionList]; // [nav.navigationBar resetBackgroundImage]; // nav.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; // [self presentViewController:nav animated:YES completion:nil]; self.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:sessionList animated:YES]; self.hidesBottomBarWhenPushed = NO; } @end