// // KBGoodDetailViewController.m // YouHuiProject // // Created by xiaoxi on 2018/1/22. // Copyright © 2018年 kuxuan. All rights reserved. // #import "KBGoodDetailViewController.h" #import #import "KBGoodDetailRequestViewModel.h" #import "SDCycleScrollView.h" #import "KBTableView.h" #import "KBGoodDetailBottomView.h" #import "KBGoodDetailView.h" #import "KBCollectionView.h" #import "KBGoodCollectionCell.h" #import "KBShopDetailViewController.h" #import #import "KBHistoryTool.h" #import "KBHistoryModel.h" #import "KBGoodListViewController.h" #import "KBLoginViewController.h" #import "KBEventTool.h" #import "KBGotoDetailView.h" #import "KBShareGoodsViewController.h" #import "KBWebDetailController.h" #import "KBLinkFansController.h" #import "KBPrivilegeReferralViewController.h" #import "KBModuleView.h" #import "KBDetailHeaderTitle.h" #import "CCAlertShowView.h" #import "KBShareImgPopView.h" #import "KBShopInfoView.h" #import "KBDetailGuideView.h" #import "PhoneLoginManager.h" #import "PhoneLoginManager.h" #import "KBGoodDetailImageCell.h" #import "KBAuthorityManager.h" #import "KBFiveStartAlertView.h" #import "KBPushAlertView.h" #import "KBDetailPopQueneManager.h" #import #define GoodSimilarViewHeight ((self.goodSimilarArr.count-1)/2+1)*FITSIZE(292)+FITSIZE(45) static NSInteger const detailDescWebTag = 111; static NSString *const cellID = @"KBGoodCollectionCell"; static NSString *const collectionViewHeader = @"collectionViewHeader"; static NSString *showAlert = @"AlertNotifation"; @interface KBGoodDetailViewController () < SDCycleScrollViewDelegate, UITableViewDelegate, UITableViewDataSource, YHGoodDetailBottomViewDelegate, YHGoodDetailViewDelegate, UIWebViewDelegate, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, SGPageTitleViewDelegate, UIWebViewDelegate, WKNavigationDelegate > { NSInteger _page; NSString *goBuyUrl; ActivityIndicatorView *_indicatorView; } @property (nonatomic, strong) KBGoodDetailModel *goodModel; @property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) WKWebView *detailDescWebView; @property (nonatomic, strong) UIView *tableHeaderView; @property (nonatomic, strong) KBGoodDetailView *goodDetailView; @property (nonatomic, strong) SDCycleScrollView *cycleView; @property (nonatomic, strong) NSArray *goodSimilarArr; @property (nonatomic, strong) UICollectionView *collectionView; @property (nonatomic, strong) UIButton *backButton; @property (nonatomic, strong) SGPageTitleView *topTitleView; @property (nonatomic, strong) YYFPSLabel *fpsLabel; @property (nonatomic, strong) KBGoodDetailBottomView *goodBottomView; @property (nonatomic, strong) NSNumber *flag;//用户等级 1 会员 2 超级会员 3 运营商 @property (nonatomic, strong) KBModuleView *moduleView; @property (nonatomic, strong) KBShopInfoView *shopInfoView; @property (nonatomic, strong) KBGoodDetailBottomView *bottomView; @property (nonatomic, strong) UIView *moduleBg; @property (nonatomic, strong) KBDetailHeaderTitle *detailHeader; @end @implementation KBGoodDetailViewController - (void)dealloc { [self.detailDescWebView removeObserver:self forKeyPath:@"scrollView.contentSize"]; NSLog(@"释放了------------"); } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [SVProgressHUD dismiss]; } - (void)viewDidLoad { [super viewDidLoad]; [self initNavBar]; [self initSubviews]; [self initHUD]; [self addPopAlertNotifation]; [self request]; [self requestCount]; [self checkUserNotifation]; [self loadFiveStartAlert]; } -(void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; } - (void)configParam { _page = 1; } - (void)requestCount { [KBEventTool eventWithEventType:0 origin:self.eventModel.origin category_id:self.eventModel.category_id goods_id:self.requestModel.goods_id source:self.eventModel.source]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault]; self.navigationController.navigationBar.hidden = YES; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } - (void)addPopAlertNotifation { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showAlertAction) name:showAlert object:nil]; } - (void)showAlertAction { NSMutableArray *alertArray = [KBDetailPopQueneManager shareManager].alertArray; if (alertArray.count > 0) { if (![KBDetailPopQueneManager shareManager].isShowing) { CCAlertShowView *showView = alertArray.firstObject; [KBDetailPopQueneManager shareManager].isShowing = YES; [showView showInView:self.view]; [[KBDetailPopQueneManager shareManager].alertArray removeObject:showView]; } } } - (void)initNavBar { [self.navigationBar setNavightionBarBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:0.0]]; UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom]; leftButton.frame = CGRectMake(0, 0, FITSIZE(22), FITSIZE(22)); leftButton.backgroundColor = [UIColor clearColor]; [leftButton setImage:[UIImage imageNamed:@"detail_back_g"] forState:UIControlStateNormal]; [leftButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside]; self.backButton = leftButton; [self.navigationBar setCustomLeftButtons:@[leftButton]]; [self.navigationBar addSubview:self.topTitleView]; } - (void)initSubviews { __weak typeof(self) weakSelf = self; //底部栏 KBGoodDetailBottomView *bottomView = [[KBGoodDetailBottomView alloc] initWithFrame:CGRectMake(0, kScreenHeight-FITSIZE(55)-BottomMargin, kScreenWidth, FITSIZE(55))]; bottomView.delegate = self; self.bottomView = bottomView; [self.view addSubview:bottomView]; self.goodBottomView = bottomView; //轮播 SDCycleScrollView *cycleView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, FITSIZE(375), FITSIZE(375)) delegate:self placeholderImage:[UIImage imageNamed:@""]]; cycleView.currentPageDotImage = [UIImage imageNamed:@"page_sel"]; cycleView.pageDotImage = [UIImage imageNamed:@"page_nor"]; self.cycleView = cycleView; //商品信息 self.goodDetailView = [[KBGoodDetailView alloc] initWithFrame:CGRectMake(0, cycleView.height, kScreenWidth, FITSIZE(140))]; self.goodDetailView.delegate = self; KBDetailGuideView *guide = [[KBDetailGuideView alloc] initWithFrame:CGRectMake(0, self.goodDetailView.bottom, SCREEN_WIDTH, 35)]; guide.tapAction = ^{ KBPrivilegeReferralViewController *Privilege = [[KBPrivilegeReferralViewController alloc] init]; [weakSelf.navigationController pushViewController:Privilege animated:YES]; }; guide.height = 0;//省钱快报不需要展示 //店铺信息 self.shopInfoView = [[KBShopInfoView alloc] initWithFrame:CGRectMake(0, guide.bottom+5, SCREEN_WIDTH, 0)]; //推荐模块 UIView *moduleBg = [[UIView alloc] initWithFrame:CGRectMake(0, self.shopInfoView.bottom+5, SCREEN_WIDTH, Fitsize(202))]; self.moduleBg = moduleBg; KBDetailHeaderTitle *headerTitle = [[KBDetailHeaderTitle alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, Fitsize(34)) title:@"相关推荐" color:[UIColor gradientWidthFromColor:[UIColor YHColorWithHex:0xF62259] toColor:[UIColor YHColorWithHex:0xFC0E2F] withWidth:SCREEN_WIDTH]]; [moduleBg addSubview:headerTitle]; self.moduleView = [[KBModuleView alloc] initWithFrame:CGRectMake(0, headerTitle.height, SCREEN_WIDTH, moduleBg.height-Fitsize(34))]; self.moduleView.didSelectedGood = ^(KBChildGoodModel *model) { DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithChildModel:model]; KBGoodDetailViewController *detail = [[KBGoodDetailViewController alloc] init]; detail.requestModel = requestModel; KBEventModel *evevtModel = [[KBEventModel alloc] initWithOrigin:model.origin category_id:@"0" source:goodsDetailTopRecommendAction]; detail.eventModel = evevtModel; [weakSelf.navigationController pushViewController:detail animated:YES]; [MobClick event:GoodsDetailRecommend]; }; [moduleBg addSubview:self.moduleView]; self.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, moduleBg.bottom+5)]; //详情webview KBDetailHeaderTitle *detailHeader = [[KBDetailHeaderTitle alloc] initWithFrame:CGRectMake(0, moduleBg.bottom+5, SCREEN_WIDTH, Fitsize(34)) title:@"宝贝详情" color:[UIColor gradientWidthFromColor:[UIColor YHColorWithHex:0x8976FB] toColor:[UIColor YHColorWithHex:0x3CC1F8] withWidth:SCREEN_WIDTH]]; self.detailHeader = detailHeader; _detailDescWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0, detailHeader.bottom, kScreenWidth, 0)]; _detailDescWebView.tag = detailDescWebTag; _detailDescWebView.navigationDelegate = self; _detailDescWebView.scrollView.scrollEnabled = NO; // _detailDescWebView.scalesPageToFit = YES; [self.tableHeaderView addSubview:cycleView]; [self.tableHeaderView addSubview:self.goodDetailView]; [self.tableHeaderView addSubview:guide]; [self.tableHeaderView addSubview:self.shopInfoView]; [self.tableHeaderView addSubview:moduleBg]; [self.tableHeaderView addSubview:detailHeader]; [self.tableHeaderView addSubview:_detailDescWebView]; self.tableView.tableHeaderView = self.tableHeaderView; [self.view addSubview:self.tableView]; [self.view bringSubviewToFront:self.navigationBar]; //添加监听 @try{ // [self.detailDescWebView removeObserver:self forKeyPath:@"scrollView.contentSize"]; }@catch (NSException *exception) { } [_detailDescWebView addObserver:self forKeyPath:@"scrollView.contentSize" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil]; [self.view bringSubviewToFront:self.navigationBar]; [KBGoodDetailRequestViewModel requestGoodSimilarParamGoods_id:self.requestModel.goods_id page:@(_page) success:^(NSArray *array) { if (array.count > 0) { self.goodSimilarArr = array; self.tableView.tableFooterView = self.collectionView; } } failure:^(NSError *error) { }]; } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if ([keyPath isEqualToString:@"scrollView.contentSize"]) { if (self.goodModel.detail_pic.count > 0) { self.detailDescWebView.height = 0; return; } id height = [change valueForKey:NSKeyValueChangeNewKey]; CGSize size; [(NSValue *)height getValue:&size]; if (_detailDescWebView.height != size.height) { self.detailDescWebView.height = size.height; self.tableHeaderView.height = self.detailDescWebView.top+size.height; self.tableView.tableHeaderView = self.tableHeaderView; } } } - (void)backAction { [self.navigationController popViewControllerAnimated:YES]; } #pragma mark - HUD - (void)initHUD { ActivityIndicatorView *indicatorView = [ActivityIndicatorView showInView:self.view frame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)]; _indicatorView = indicatorView; } #pragma mark - request /** 请求是否展示五星好评 */ - (void)loadFiveStartAlert { NSString *url = [NSString stringWithFormat:@"%@/api/v2/users/isAlertFiveStar",BaseURL]; NSString *deviceUUID = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString]; NSDictionary *para = @{@"idfa":deviceUUID}; [KBHttp get:url params:para success:^(id json) { if ([json[@"data"][@"is_show"] boolValue]) { NSString *msg = json[@"data"][@"message"]; [self showStartView:msg]; } } failure:^(NSError *error) { }]; } - (void)showStartView:(NSString *)msg { KBFiveStartAlertView *startAlert = [[KBFiveStartAlertView alloc] initWithFrame:CGRectMake(0, 0, Fitsize(257), Fitsize(333)) text:msg]; CCAlertShowView *showView = [CCAlertShowView alertViewWithView:startAlert]; startAlert.cancelBlock = ^{ [showView dismiss]; [self fiveStartCommitRequest:@"0"]; [KBDetailPopQueneManager shareManager].isShowing = NO; [[NSNotificationCenter defaultCenter] postNotificationName:showAlert object:nil]; }; startAlert.sureBlock = ^{ [self commentAndStart]; [showView dismiss]; [self fiveStartCommitRequest:@"1"]; [KBDetailPopQueneManager shareManager].isShowing = NO; [[NSNotificationCenter defaultCenter] postNotificationName:showAlert object:nil]; }; [[KBDetailPopQueneManager shareManager].alertArray addObject:showView]; [[NSNotificationCenter defaultCenter] postNotificationName:showAlert object:nil]; } /** 提交用户评论状态 */ - (void)fiveStartCommitRequest:(NSString *)commit { NSString *url = [NSString stringWithFormat:@"%@/api/v2/users/fiveStarNote",BaseURL]; NSString *deviceUUID = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString]; NSDictionary *para = @{@"idfa":deviceUUID, @"commit":commit}; [KBHttp get:url params:para success:^(id json) { } failure:^(NSError *error) { }]; } /** 五星好评 */ - (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]]; } - (void)request { // [SVProgressHUD show]; [KBGoodDetailRequestViewModel requestGoodDetailParamGoods_id:self.requestModel success:^(KBGoodDetailModel *model,NSDictionary *dic) { if (model) { self.goodModel = model; // [self initSubviews]; [self setGoodInfoForHeader]; [self requestUserIdentity]; [self requestThressRecommon]; [self saveGoodsInfoAsBrowserHistoryWith:dic]; [self.tableView reloadData]; } [SVProgressHUD dismiss]; [_indicatorView stopAnimating]; } failure:^(NSError *error) { [SVProgressHUD dismiss]; [MBProgressHUD showMessage:@"加载失败"]; [_indicatorView stopAnimating]; }]; [self loadGoBuyUrl]; } - (void)setGoodInfoForHeader { self.bottomView.goodModel = self.goodModel; self.cycleView.imageURLStringsGroup = self.goodModel.small_img; self.goodDetailView.goodModel = self.goodModel; KBShopModel *model = self.goodModel.shop; CGFloat shopViewHeight = model==nil?0:Fitsize(68); [self.shopInfoView setShopInfo:model]; self.shopInfoView.height = shopViewHeight; self.moduleBg.y = self.shopInfoView.bottom+5; self.detailHeader.y = self.moduleBg.bottom+5; _detailDescWebView.y = self.detailHeader.bottom; // NSURL *url = [NSURL URLWithString:self.goodModel.detail_url]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:self.goodModel.detail_url] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:15.0]; NSArray *picList = self.goodModel.detail_pic; if (picList.count == 0) { // [_detailDescWebView addObserver:self forKeyPath:@"scrollView.contentSize" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil]; if (@available(iOS 9.0, *)) { NSArray * types=@[WKWebsiteDataTypeCookies,WKWebsiteDataTypeLocalStorage]; NSSet *websiteDataTypes= [NSSet setWithArray:types]; NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0]; [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:^{ }]; } // NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.url]]; [_detailDescWebView loadRequest:request]; } self.tableHeaderView.height = self.detailDescWebView.bottom; self.tableView.tableHeaderView = self.tableHeaderView; } /** 加载购买的url */ - (void)loadGoBuyUrl { NSString *category_id = self.eventModel.category_id==nil?@"":self.eventModel.category_id; NSString *source = self.eventModel.source==nil?@"":self.eventModel.source; NSString *commission_rate = self.requestModel.commission_rate==nil?@"":self.requestModel.commission_rate; NSString *discount_price = self.requestModel.discount_price==nil?@"":self.requestModel.discount_price; NSString *coupon_price = self.requestModel.coupon_price==nil?@"":self.requestModel.coupon_price; NSString *price = self.requestModel.price==nil?@"":self.requestModel.price; NSString *coupon_start_time = self.requestModel.coupon_start_time==nil?@"":self.requestModel.coupon_start_time; NSString *coupon_end_time = self.requestModel.coupon_end_time==nil?@"":self.requestModel.coupon_end_time; NSDictionary *param = @{@"goods_id":self.requestModel.goods_id, @"is_coupon":self.requestModel.is_coupon, @"category_id":category_id, @"path":source, @"commission_rate":commission_rate, @"discount_price":discount_price, @"coupon_price":coupon_price, @"price":price, @"coupon_start_time":coupon_start_time, @"coupon_end_time":coupon_end_time }; NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/orderDown",BaseURL]; [KBHttp post:url params:param success:^(id json) { goBuyUrl = json[@"url"]; } failure:^(NSError *error) { }]; } /** 加载上部相关推荐 */ - (void)requestThressRecommon { NSString *url = [NSString stringWithFormat:@"%@/api/v2/goods/recommendtop",BaseURL]; NSDictionary *para = @{@"goods_id":self.requestModel.goods_id}; [KBHttp post:url params:para success:^(id json) { NSArray *list = [NSArray yy_modelArrayWithClass:[KBChildGoodModel class] json:json[@"data"]]; [self.moduleView setRecommonData:list]; } failure:^(NSError *error) { }]; } - (void)requestUserIdentity { NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/userIdentity",BaseURL]; [KBHttp post:url params:nil success:^(id json) { if (json[@"data"]) { NSNumber *flag=json[@"data"][@"flag"]; self.flag=flag; } } failure:^(NSError *error) { self.flag=0; }]; } /** 保存浏览记录 */ - (void)saveGoodsInfoAsBrowserHistoryWith:(NSDictionary *)dic { if (![AccountTool isLogin]) { return; } NSString *urlString = [NSString stringWithFormat:@"%@/api/v2/brower/record", BaseURL]; NSDictionary *para = [self.requestModel modelToDictionary]; [KBHttp post:urlString params:para success:^(id json) { } failure:^(NSError *error) { }]; } #pragma mark - scrollView - (void)scrollViewDidScroll:(UIScrollView *)scrollView { CGFloat offsetY = scrollView.contentOffset.y; // CGFloat standard = FITSIZE(734)-NavBarHeight; CGFloat standard = self.cycleView.height-NavBarHeight; if (offsetY > -standard && offsetY < standard) { [self.navigationBar setNavightionBarBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:offsetY/standard]]; self.topTitleView.alpha = offsetY/standard; if (offsetY/standard < 0.5) { [self.backButton setImage:[UIImage imageNamed:@"detail_back_g"] forState:UIControlStateNormal]; self.backButton.alpha = 1-offsetY/standard; } else { [self.backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal]; self.backButton.alpha = offsetY/standard; } } else { } if (offsetY >= standard) { [self.navigationBar setShowNavigationBarBottomLine:YES]; } else { [self.navigationBar setShowNavigationBarBottomLine:NO]; } //设置导航栏头部seg下标 CGFloat indexOneHeight = self.moduleView.superview.bottom+5-NavBarHeight; CGFloat indexTwoHeight; if (self.goodModel.detail_pic.count > 0) { //详情为图片数组时 CGRect senctionHeight = [self.tableView rectForSection:0]; indexTwoHeight = senctionHeight.size.height+self.tableHeaderView.height-NavBarHeight; }else { //详情为web indexTwoHeight = self.tableHeaderView.height-NavBarHeight; } if (offsetY < indexOneHeight) { self.topTitleView.newSelectedIndex = 0; }else if (offsetY>=indexOneHeight && offsetY 0) { CGRect senctionHeight = [self.tableView rectForSection:0]; indexTwoHeight = senctionHeight.size.height+self.tableHeaderView.height-NavBarHeight; }else { indexTwoHeight = self.tableHeaderView.height-NavBarHeight; } switch (selectedIndex) { case 0: [self.tableView setContentOffset:CGPointMake(0, 0) animated:NO]; break; case 1: [self.tableView setContentOffset:CGPointMake(0, indexOneHeight) animated:NO]; break; case 2: [self.tableView setContentOffset:CGPointMake(0, indexTwoHeight) animated:NO]; break; default: break; } } #pragma mark - goodDetailBottomViewDelegate /** 分享 */ - (void)yh_GoodDetailBottomViewClickCommissionButton { if ([AccountTool isLogin]) { KBShareImgPopView *shareView = [[KBShareImgPopView alloc] initWithFrame:self.view.bounds goodModel:self.goodModel]; CCAlertShowView *showView = [CCAlertShowView showAlertViewWithView:shareView backgroundDismissEnable:YES]; shareView.closeAction = ^{ [showView dismiss]; }; showView.backgroundView.backgroundColor = [UIColor clearColor]; [showView show]; }else{ KBLoginViewController *login = [[KBLoginViewController alloc] init]; login.loginSucc = ^{ [self request]; }; [self.navigationController presentViewController:login animated:YES completion:nil]; } } - (void)yh_GoodDetailBottomViewClickCollectButton { if ([AccountTool isLogin]) { [MobClick event:collection_count]; NSString *coupon_start_time = [self.goodModel.is_coupon boolValue] ? self.requestModel.coupon_start_time : @""; NSString *coupon_end_time = [self.goodModel.is_coupon boolValue] ? self.requestModel.coupon_end_time : @""; NSNumber *is_coupon = self.goodModel.is_coupon; NSString *coupon_price = self.goodModel.coupon_price; NSString *price = self.goodModel.price; NSString *discount_price = self.goodModel.discount_price; NSString *commission_rate = self.goodModel.commission_rate; if (!coupon_start_time) coupon_start_time = @""; if (!coupon_end_time) coupon_end_time = @""; if (!is_coupon) is_coupon = @0; if (!coupon_price) coupon_price = @""; if (!price) price = @""; if (!discount_price) discount_price = @""; if (!commission_rate) commission_rate = @""; NSDictionary *para = @{@"goods_id":self.goodModel.goods_id, @"is_coupon":is_coupon, @"coupon_price":coupon_price, @"price":price, @"discount_price":discount_price, @"commission_rate":commission_rate, @"coupon_end_time":coupon_end_time, @"coupon_start_time":coupon_start_time }; [KBGoodDetailRequestViewModel requestCollectGoodParamGoods_id:para success:^(NSString *msg) { [SVProgressHUD showSuccessWithStatus:msg]; if ([msg isEqualToString:@"收藏成功"]) { self.goodModel.is_favorites = @1; self.goodBottomView.collectButton.selected = YES; } else { self.goodModel.is_favorites = @0; self.goodBottomView.collectButton.selected = NO; } } failure:^(NSError *error) { }]; } else { KBLoginViewController *login = [[KBLoginViewController alloc] init]; login.loginSucc = ^{ [self request]; }; [self.navigationController presentViewController:login animated:YES completion:nil]; } } /** 跳到淘宝领券 */ - (void)yh_GoodDetailBottomViewClickBuyButton { [self getTicketTaoBaoUrl]; [self saveToMyCouple]; } /** 保存到已领优惠券 */ - (void)saveToMyCouple { if (![AccountTool isLogin]) { return; } NSString *category_id = self.eventModel.category_id==nil?@"":self.eventModel.category_id; NSString *source = self.eventModel.source==nil?@"":self.eventModel.source; NSString *commission_rate = self.requestModel.commission_rate==nil?@"":self.requestModel.commission_rate; NSString *discount_price = self.requestModel.discount_price==nil?@"":self.requestModel.discount_price; NSString *coupon_price = self.requestModel.coupon_price==nil?@"":self.requestModel.coupon_price; NSString *price = self.requestModel.price==nil?@"":self.requestModel.price; NSString *coupon_start_time = self.requestModel.coupon_start_time==nil?@"":self.requestModel.coupon_start_time; NSString *coupon_end_time = self.requestModel.coupon_end_time==nil?@"":self.requestModel.coupon_end_time; NSDictionary *param = @{@"goods_id":self.requestModel.goods_id, @"is_coupon":self.requestModel.is_coupon, @"category_id":category_id, @"path":source, @"commission_rate":commission_rate, @"discount_price":discount_price, @"coupon_price":coupon_price, @"price":price, @"coupon_start_time":coupon_start_time, @"coupon_end_time":coupon_end_time }; NSString *url = [NSString stringWithFormat:@"%@/api/v2/goods/orderCoupon",BaseURL]; [KBHttp post:url params:param success:^(id json) { } failure:^(NSError *error) { }]; } /** 检查用户是否开启通知 */ - (void)checkUserNotifation { if ([KBAuthorityManager isObtainUserNotificationAuthority]) { return; } NSArray *array = @[@"1",@"3",@"7",@"30"]; NSDate *date = [[NSUserDefaults standardUserDefaults] objectForKey:YHUserNofi]; if (!date) { [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:YHUserNofi]; } NSString *indexStr = [[NSUserDefaults standardUserDefaults] objectForKey:NotiIndex]; if (!indexStr) { [[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:NotiIndex]; } CGFloat timeinterval = [[NSString stringWithFormat:@"%.0f",[[NSDate date] timeIntervalSinceDate:date]] floatValue]; if (indexStr.integerValue >= array.count) { return; } NSString *countStr = array[indexStr.integerValue]; NSInteger count = countStr.integerValue; if ((timeinterval > 60*60*24*count)) { [self showPushAlertView]; NSInteger index = indexStr.integerValue; index++; [[NSUserDefaults standardUserDefaults] setObject:[NSString stringWithFormat:@"%ld",(long)index] forKey:NotiIndex]; [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:YHUserNofi]; } } /** 展示push弹窗 */ - (void)showPushAlertView { KBPushAlertView *pushAlert = [[KBPushAlertView alloc] initWithFrame:CGRectMake(0, 0, Fitsize(257), Fitsize(353)) text:@"好券收藏不过期 开启通知告诉你"]; CCAlertShowView *showView = [CCAlertShowView alertViewWithView:pushAlert]; showView.tapBackgroundDismissEnable = NO; pushAlert.cancelBlock = ^{ [showView dismiss]; [KBDetailPopQueneManager shareManager].isShowing = NO; [[NSNotificationCenter defaultCenter] postNotificationName:showAlert object:nil]; }; pushAlert.sureBlock = ^{ [self openSystemPushAction]; [showView dismiss]; [KBDetailPopQueneManager shareManager].isShowing = NO; [[NSNotificationCenter defaultCenter] postNotificationName:showAlert object:nil]; }; [[KBDetailPopQueneManager shareManager].alertArray addObject:showView]; [[NSNotificationCenter defaultCenter] postNotificationName:showAlert object:nil]; } /** 开启系统通知 */ - (void)openSystemPushAction { NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; if([[UIApplication sharedApplication]canOpenURL:url] ) { if (@available(iOS 10.0, *)) { [[UIApplication sharedApplication] openURL:url options:@{}completionHandler:^(BOOL success) { }]; } else { [[UIApplication sharedApplication]openURL:url]; } } } /** 获取商品链接 */ - (void)getTicketTaoBaoUrl { [self goBuy]; [MobClick event:pay_count]; // if (![AccountTool account]) { // KBLoginViewController *login = [[KBLoginViewController alloc] init]; // [self presentViewController:login animated:YES completion:nil]; // return; // } // // // // if ([self.flag integerValue]==1) { // UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"升级赚佣金" message:[NSString stringWithFormat:@"\n成为超级会员后,您购买商品就可以拿到%.2f元佣金哦~",[self.goodModel.super_commission_price floatValue]] preferredStyle:UIAlertControllerStyleAlert]; // UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"直接领劵" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { // [self goBuy]; // // }]; // UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"成为超级会员" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { // KBPrivilegeReferralViewController *vc=[[KBPrivilegeReferralViewController alloc]init]; // vc.flag=@(1); // vc.isSuper=@(0); // [self.navigationController pushViewController:vc animated:YES]; // }]; // [alert addAction:defaultAction]; // [alert addAction:cancelAction]; // [self presentViewController:alert animated:YES completion:nil]; // return; // }else{ // [self goBuy]; // } } -(void)goBuy{ if (goBuyUrl.length > 0) { [self jumpToTaobaoWithGoodsUrl:goBuyUrl]; }else { [SVProgressHUD show]; NSString *category_id = self.eventModel.category_id==nil?@"":self.eventModel.category_id; NSString *source = self.eventModel.source==nil?@"":self.eventModel.source; NSDictionary *param = @{@"goods_id":self.requestModel.goods_id, @"is_coupon":self.requestModel.is_coupon, @"category_id":category_id, @"path":source }; NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/orderDown",BaseURL]; [KBHttp post:url params:param success:^(id json) { if (url.length > 0) { [self jumpToTaobaoWithGoodsUrl:json[@"url"]]; } [SVProgressHUD dismiss]; } failure:^(NSError *error) { [SVProgressHUD dismiss]; [MBProgressHUD showMessage:@"加载失败"]; }]; } } - (void)jumpToTaobaoWithGoodsUrl:(NSString *)url { [KBEventTool eventWithEventType:1 origin:self.eventModel.origin category_id:self.eventModel.category_id goods_id:self.requestModel.goods_id source:self.eventModel.source]; if ([self isInstallTaobaoAPP]) { id page = [AlibcTradePageFactory page:url]; //淘客信息 AlibcTradeTaokeParams *taoKeParams=[[AlibcTradeTaokeParams alloc] init]; taoKeParams.pid = ALTK_PID; // //打开方式 AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init]; showParam.openType = AlibcOpenTypeNative; [[AlibcTradeSDK sharedInstance].tradeService show:self.navigationController page:page showParams:showParam taoKeParams:taoKeParams trackParam:nil tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) { } tradeProcessFailedCallback:^(NSError * _Nullable error) { }]; }else { KBWebDetailController *webVc = [[KBWebDetailController alloc] init]; webVc.url = url; [self.navigationController pushViewController:webVc animated:YES]; } } /** 判断是否安装淘宝app */ - (BOOL)isInstallTaobaoAPP { if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"taobao://"]]) { return YES; }else { return NO; } } #pragma mark - goodDetailViewDelegate - (void)yh_GoodDetailViewTapCoupon { [KBGoodDetailRequestViewModel requestTicketProcessParamGoods_id:self.requestModel.goods_id coupon_price:self.goodModel.coupon_price success:^(NSString *msg) { [self yh_GoodDetailBottomViewClickBuyButton]; } failure:^(NSError *error) { }]; } - (void)yh_GoodDetailViewTapShop { KBShopDetailViewController *shopVC = [[KBShopDetailViewController alloc] init]; shopVC.goodModel = self.goodModel; [self.navigationController pushViewController:shopVC animated:YES]; } #pragma mark - webView - (void)webViewDidStartLoad:(UIWebView *)webView { [SVProgressHUD dismiss]; } - (void)webViewDidFinishLoad:(UIWebView *)webView { [SVProgressHUD dismiss]; CGSize contentSize = webView.scrollView.contentSize; CGSize viewSize = self.detailDescWebView.bounds.size; float rw = viewSize.width / contentSize.width; webView.scrollView.minimumZoomScale = rw; webView.scrollView.maximumZoomScale = rw; webView.scrollView.zoomScale = rw; } - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { [SVProgressHUD dismiss]; } #pragma mark ------ wkWebView delegate ------ // main frame的导航开始请求时调用 - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation{ } // 当main frame开始加载数据失败时,会回调 - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error { } //当main frame导航完成时,会回调 - (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation{ // 页面加载完成之后调用 } #pragma mark - tableView - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSArray *pics = self.goodModel.detail_pic; return pics.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { KBDetailImgModel *model = self.goodModel.detail_pic[indexPath.row]; CGFloat imgScale = model.width.floatValue/model.height.floatValue; CGFloat imgH = SCREEN_WIDTH/imgScale; return imgH; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { KBGoodDetailImageCell *cell = [KBGoodDetailImageCell cellWithTableView:tableView]; cell.model = self.goodModel.detail_pic[indexPath.row]; return cell; } #pragma mark - collectionView - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.goodSimilarArr.count; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { CGFloat width = (SCREEN_WIDTH-5)/2; CGFloat height = width + 102; return CGSizeMake(width, height); } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { KBGoodCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath]; cell.backgroundColor = [UIColor whiteColor]; cell.backgroundView.backgroundColor = [UIColor whiteColor]; cell.contentView.backgroundColor = [UIColor whiteColor]; KBChildGoodModel *model = self.goodSimilarArr[indexPath.item]; cell.model = model; return cell; } - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionViewHeader forIndexPath:indexPath]; CALayer *lineGapLayer = [CALayer layer]; lineGapLayer.frame = CGRectMake(0, 0, kScreenWidth, FITSIZE(5)); lineGapLayer.backgroundColor = [UIColor YHColorWithHex:0xf5f4f4].CGColor; [view.layer addSublayer:lineGapLayer]; UILabel *lineGapLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, kScreenWidth, FITSIZE(40))]; lineGapLabel.backgroundColor = [UIColor whiteColor]; lineGapLabel.textColor = [UIColor YHColorWithHex:0x222222]; lineGapLabel.font = [UIFont systemFontOfSize:FITSIZE(13)]; lineGapLabel.text = @"相关推荐"; lineGapLabel.textAlignment = NSTextAlignmentCenter; [view addSubview:lineGapLabel]; return view; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section { return CGSizeMake(kScreenWidth, FITSIZE(45)); } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { KBChildGoodModel *model = self.goodSimilarArr[indexPath.item]; //详情 KBGoodDetailViewController *detailVC = [[KBGoodDetailViewController alloc] init]; DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithChildModel:model]; detailVC.requestModel = requestModel; KBEventModel *evevtModel = [[KBEventModel alloc] initWithOrigin:@"0" category_id:@"0" source:goodsDetailRecommendAction]; detailVC.eventModel = evevtModel; [self.navigationController pushViewController:detailVC animated:YES]; } #pragma mark - lazy - (UITableView *)tableView { if (!_tableView) { _tableView = [[KBTableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight-FITSIZE(55)-BottomMargin) style:UITableViewStylePlain]; _tableView.estimatedRowHeight = 0; _tableView.estimatedSectionHeaderHeight = 0; _tableView.estimatedSectionFooterHeight = 0; _tableView.delegate = self; _tableView.dataSource = self; [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"]; if (@available(iOS 11.0, *)) { _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } } return _tableView; } - (UICollectionView *)collectionView { if (!_collectionView) { UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical; flowLayout.minimumLineSpacing = FITSIZE(5); flowLayout.minimumInteritemSpacing = FITSIZE(0); _collectionView = [[KBCollectionView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, GoodSimilarViewHeight) collectionViewLayout:flowLayout]; _collectionView.scrollEnabled = NO; _collectionView.bounces = NO; _collectionView.showsVerticalScrollIndicator = NO; _collectionView.delegate = self; _collectionView.dataSource = self; [_collectionView registerClass:[KBGoodCollectionCell class] forCellWithReuseIdentifier:cellID]; [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionViewHeader]; } return _collectionView; } - (SGPageTitleView *)topTitleView { if (!_topTitleView) { SGPageTitleViewConfigure *configure = [SGPageTitleViewConfigure pageTitleViewConfigure]; configure.titleFont = [UIFont systemFontOfSize:FITSIZE(14)]; configure.titleColor = [UIColor YHColorWithHex:0x222222]; configure.titleSelectedColor = [UIColor YHColorWithHex:0xff2420]; configure.indicatorColor = [UIColor YHColorWithHex:0xff2420]; configure.indicatorScrollStyle = SGIndicatorScrollStyleHalf; _topTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(kScreenWidth/2-FITSIZE(100), KStatusBarHeight, FITSIZE(200), 44) delegate:self titleNames:@[@"宝贝",@"详情",@"推荐"] configure:configure]; _topTitleView.backgroundColor = [UIColor clearColor]; _topTitleView.alpha = 0.0; _topTitleView.isNeedBounces = NO; _topTitleView.isTitleGradientEffect = NO; _topTitleView.isOpenTitleTextZoom = YES; _topTitleView.isShowBottomSeparator = NO; } return _topTitleView; } @end