123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531 |
- //
- // KDPGoodDetailVC.m
- // KuDianProject
- //
- // Created by 学丽 on 2019/7/9.
- // Copyright © 2019 KDP. All rights reserved.
- //
- #import "KDPGoodDetailVC.h"
- #import "KDPDetailGoodInformationView.h"
- #import "KDPSellingPointView.h"
- #import "KDPShopView.h"
- #import <WebKit/WebKit.h>
- #import "KDPCollectHistoryPageVC.h"
- #import "KDPPasteView.h"
- #import <AlibcTradeSDK/AlibcTradeSDK.h>
- #define goodHeight 496+KDStatusHeight
- @interface KDPGoodDetailVC ()<UIScrollViewDelegate,UIWebViewDelegate,WKNavigationDelegate>
- {
- UIView *bottomView;
- UIButton *collectButton;
-
-
- }
- //淘口令页面
- @property(nonatomic,strong)KDPPasteView *pasteView;
- @property(nonatomic,strong)KDPIDTipView *tipView;
- @property(nonatomic,strong)UIScrollView *detailBottonView;
- @property(nonatomic,strong)KDPDetailGoodInformationView *infoView;
- @property(nonatomic,strong)KDPSellingPointView *pointView;
- @property(nonatomic,strong)KDPShopView *shopView;
- @property(nonatomic,strong)KDPGoodsModel *detailModel;
- @property(nonatomic,strong)WKWebView *detaiWebV;
- @end
- @implementation KDPGoodDetailVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self addDetailUI];
- [self addbottomView];
- self.infoView.model=self.model;
- @try {
- [self.detaiWebV removeObserver:self forKeyPath:@"scrollView.contentSize"];
- } @catch (NSException *exception) {
- }
- [self.detaiWebV addObserver:self forKeyPath:@"scrollView.contentSize" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
- [self.detailBottonView addSubview:self.detaiWebV];
- [self.detaiWebV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.shopView.mas_bottom).offset(40);
- make.width.mas_equalTo(SCREEN_WIDTH);
- make.left.mas_equalTo(0);
- }];
- [self getGoodDetail];
-
- [self.view addSubview:self.pasteView];
- [self.view addSubview:self.tipView];
- [self.tipView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.mas_equalTo(0);
- make.width.mas_equalTo(SCREEN_WIDTH);
- make.height.mas_equalTo(SCREEN_HEIGHT);
- }];
-
- }
- - (void)dealloc {
- @try{
- [self.detaiWebV removeObserver:self forKeyPath:@"scrollView.contentSize"];
- }@catch (NSException *exception) {
-
- }
- NSLog(@"释放了------------");
- }
- #pragma mark---商品详情
- -(void)getGoodDetail
- {
- if (self.model.goods_id.length<=0) {
- return;
- }
- [LoadingView show];
- [KDPNetworkRequestHTTP postURL:goodDetailURL params:@{@"goods_id":self.model.goods_id} success:^(id _Nonnull json) {
- self.detailModel=[KDPGoodsModel yy_modelWithJSON:json[@"data"]];
- if (self.detailModel.goods_point.length>0) {
- [self good_points];
- }
- self.infoView.model=self.detailModel;
- self.shopView.shopDic=self.detailModel.shop;
- [self loadRequestWeb];
- [LoadingView dismiss];
- [self isCollect];
- [self saveHistoryModel:self.detailModel];
- } failure:^(NSError * _Nonnull error) {
- [LoadingView dismiss];
- }];
- }
- #pragma mark----Web详情
- -(void)loadRequestWeb
- {
-
- NSURL *url=[NSURL URLWithString:self.detailModel.detail_url];
- NSURLRequest *requests=[NSURLRequest requestWithURL:url];
- [self.detaiWebV loadRequest:requests];
- }
- -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
- {
- CGFloat heights =[KDPublicMethod getHeightByWidth:SCREEN_WIDTH-40 title:self.detailModel.goods_point font:[UIFont systemFontOfSize:13]];
-
- if ([keyPath isEqualToString:@"scrollView.contentSize"]) {
- id height =[change valueForKey:NSKeyValueChangeNewKey];
- CGSize size;
- [(NSValue *)height getValue:&size];
- [self.detaiWebV mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(size.height);
- }];
- self.detailBottonView.contentSize=CGSizeMake(0, size.height+goodHeight+115+heights);
- }
- }
- #pragma mark---赋值。卖点
- -(void)good_points
- {
- CGFloat height =[KDPublicMethod getHeightByWidth:SCREEN_WIDTH-40 title:self.detailModel.goods_point font:[UIFont systemFontOfSize:13]];
- self.pointView.point_good =self.detailModel.goods_point;
- [self.pointView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(goodHeight);
- make.height.mas_equalTo(height+50);
- }];
- [self.shopView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.pointView.mas_bottom);
- }];
-
- }
- -(void)addbottomView
- {
- bottomView =[[UIView alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT-KDTabBarHeight, SCREEN_WIDTH, KDTabBarHeight)];
- bottomView.backgroundColor=[UIColor whiteColor];
- [self.view addSubview:bottomView];
-
- collectButton=[[UIButton alloc]initWithFrame:CGRectMake(0, 3, 86, 33)];
- collectButton.titleLabel.font=[UIFont systemFontOfSize:10];
-
- [collectButton setTitle:@"收藏" forState:UIControlStateNormal];
- [collectButton setImage:[UIImage imageNamed:@"collection_select"] forState:UIControlStateSelected];
-
- [collectButton setTitleColor:[UIColor colorWithHexString:@"#828282"] forState:UIControlStateNormal];
- [collectButton setImage:[UIImage imageNamed:@"collection_un"] forState:UIControlStateNormal];
- collectButton.adjustsImageWhenHighlighted=NO;
-
- [collectButton setButtonImageTitleStyle:ButtonImageTitleStyleCenterDown padding:3];
- [collectButton addTarget:self action:@selector(detailCollectClickButton) forControlEvents:UIControlEventTouchUpInside];
- [bottomView addSubview:collectButton];
-
-
- UIButton *buybutton =[[UIButton alloc]initWithFrame:CGRectMake(collectButton.right, 3, (SCREEN_WIDTH-96)/2, 39)];
-
- buybutton.backgroundColor=[UIColor gradientOneColor:[UIColor colorWithHexString:@"#FF235F"] toColor:[UIColor colorWithHexString:@"#FF7676"] Width:(SCREEN_WIDTH-96)/2];
- [buybutton setTitle:@"购买样品" forState:UIControlStateNormal];
- [bottomView addSubview:buybutton];
- buybutton.titleLabel.font=[UIFont systemFontOfSize:14];
- [buybutton addTarget:self action:@selector(clickBuyButton) forControlEvents:UIControlEventTouchUpInside];
- UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:buybutton.bounds byRoundingCorners:UIRectCornerTopLeft| UIRectCornerBottomLeft cornerRadii:CGSizeMake(19.5, 19.5)];
- CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
- maskLayer.frame = buybutton.bounds;
- maskLayer.path = maskPath.CGPath;
- buybutton.layer.mask = maskLayer;
-
- UIButton *getKwaiButton =[[UIButton alloc]initWithFrame:CGRectMake(buybutton.right, 3, (SCREEN_WIDTH-96)/2, 39)];
- getKwaiButton.backgroundColor=[UIColor colorWithHexString:ThemeColor];
- [getKwaiButton setTitle:@"推广到快手" forState:UIControlStateNormal];
- getKwaiButton.titleLabel.font=[UIFont systemFontOfSize:14];
- [getKwaiButton addTarget:self action:@selector(kwaiClickButton) forControlEvents:UIControlEventTouchUpInside];
- [bottomView addSubview:getKwaiButton];
- UIBezierPath *maskPaths= [UIBezierPath bezierPathWithRoundedRect:getKwaiButton.bounds byRoundingCorners:UIRectCornerTopRight| UIRectCornerBottomRight cornerRadii:CGSizeMake(19.5, 19.5)];
- CAShapeLayer *maskLayers = [[CAShapeLayer alloc] init];
- maskLayers.frame = buybutton.bounds;
- maskLayers.path = maskPaths.CGPath;
- getKwaiButton.layer.mask = maskLayers;
-
- }
- -(void)returnClickBtn
- {
- [self.navigationController popViewControllerAnimated:YES];
- }
- -(void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- self.navBar.hidden=YES;
-
- [UIApplication sharedApplication].statusBarStyle=UIStatusBarStyleDefault;
- self.navigationController.navigationBar.hidden=YES;
- self.tabBarController.tabBar.hidden=YES;
- }
- -(void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- // self.navBar.hidden=NO;
-
- [UIApplication sharedApplication].statusBarStyle=UIStatusBarStyleLightContent;
- self.tabBarController.tabBar.hidden=NO;
- }
- -(KDPDetailGoodInformationView *)infoView
- {
- if (!_infoView) {
- _infoView=[[KDPDetailGoodInformationView alloc]init];
- __weak KDPGoodDetailVC *weakself=self;
- _infoView.returnBlock = ^{
- [weakself.navigationController popViewControllerAnimated:YES];
- };
-
- }
- return _infoView;
- }
- -(KDPShopView *)shopView
- {
- if (!_shopView) {
- _shopView=[[KDPShopView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 70)];
-
-
- }
- return _shopView;
- }
- -(KDPSellingPointView *)pointView
- {
- if (!_pointView) {
- _pointView=[[KDPSellingPointView alloc]init];
-
- }
- return _pointView;
- }
- -(KDPPasteView *)pasteView
- {
- if (!_pasteView) {
- _pasteView=[[KDPPasteView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
- _pasteView.hidden=YES;
- }
- return _pasteView;
- }
- -(KDPIDTipView *)tipView
- {
- if (!_tipView) {
- _tipView =[[KDPIDTipView alloc]init];
- _tipView.hidden=YES;
- }
- return _tipView;
- }
- -(void)addDetailUI
- {
- self.view.backgroundColor=[UIColor whiteColor];
- [self.view addSubview:self.detailBottonView];
- [self.detailBottonView addSubview:self.infoView];
- [self.detailBottonView addSubview:self.pointView];
- [self.detailBottonView addSubview:self.shopView];
- [self.detailBottonView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.mas_equalTo(0);
- make.bottom.mas_equalTo(self.view.mas_bottom).offset(-KDTabBarHeight);
- }];
- [self.infoView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.mas_equalTo(0);
- make.width.mas_equalTo(SCREEN_WIDTH);
- make.height.mas_equalTo(goodHeight);
- }];
- [self.pointView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.infoView.mas_bottom);
- make.left.mas_equalTo(0);
- make.width.mas_equalTo(SCREEN_WIDTH);
- make.height.mas_equalTo(0);
-
- }];
- [self.shopView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(0);
- make.width.mas_equalTo(SCREEN_WIDTH);
- make.height.mas_equalTo(75);
- make.top.mas_equalTo(self.pointView.mas_bottom);
- }];
- [self addDetailTitle];
-
-
- UIButton *returnBtn =[[UIButton alloc]initWithFrame:CGRectMake(15, KDStatusHeight+10, 30, 30)];
- returnBtn.layer.cornerRadius=15;
- returnBtn.layer.masksToBounds=YES;
- [self.view addSubview:returnBtn];
- returnBtn.backgroundColor=[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.4];
- [returnBtn setImage:[UIImage imageNamed:@"return_white"] forState:UIControlStateNormal];
- [returnBtn addTarget:self action:@selector(exitclickButton) forControlEvents:UIControlEventTouchUpInside];
-
- UIButton * collectBtn=[[UIButton alloc]initWithFrame:CGRectMake(self.view.width-47, KDStatusHeight+10, 30, 30)];
- [collectBtn setImage:[UIImage imageNamed:@"detail_collection"] forState:UIControlStateNormal];
- collectBtn.adjustsImageWhenHighlighted=NO;
- [collectBtn addTarget:self action:@selector(collectPageClickSel) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:collectBtn];
-
-
-
-
- }
- -(void)addDetailTitle
- {
-
- UILabel *titleL=[[UILabel alloc]init];
- titleL.textColor=[UIColor colorWithHexString:fontColor];
- titleL.text=@"———— 商品详情 ————";
- titleL.font=[UIFont systemFontOfSize:14];
- titleL.textAlignment=NSTextAlignmentCenter;
- [self.detailBottonView addSubview:titleL];
- [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.shopView.mas_bottom);
- make.height.mas_equalTo(40);
- make.width.mas_equalTo(SCREEN_WIDTH);
- make.left.mas_equalTo(0);
- }];
-
-
-
-
- }
- -(void)exitclickButton
- {
- [self.navigationController popViewControllerAnimated:YES];
- }
- -(WKWebView *)detaiWebV
- {
- if (!_detaiWebV) {
- _detaiWebV= [[WKWebView alloc]init];
- _detaiWebV.navigationDelegate=self;
- _detaiWebV.scrollView.scrollEnabled=NO;
- }
- return _detaiWebV;
- }
- -(UIScrollView *)detailBottonView
- {
- if (!_detailBottonView) {
- _detailBottonView=[[UIScrollView alloc]init];
- _detailBottonView.delegate=self;
- _detailBottonView.backgroundColor=[UIColor whiteColor];
- _detailBottonView.showsVerticalScrollIndicator=NO;
-
- if (@available(iOS 11.0, *)) {
- _detailBottonView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- self.automaticallyAdjustsScrollViewInsets = NO;
- }
- _detailBottonView.showsHorizontalScrollIndicator=NO;
- _detailBottonView.contentSize=CGSizeMake(0, SCREEN_HEIGHT*2);
- }
- return _detailBottonView;
- }
- #pragma mark----收藏
- -(void)detailCollectClickButton
- {
- [LoadingView show];
- NSString *collect=self.detailModel.is_collect;
- if (collect.integerValue == 0) {//收藏
- collect=@"1";
- }else{
- collect=@"0";
- }
- NSDictionary *param=@{@"is_add":collect,@"goods_id":self.detailModel.goods_id};
- [KDPNetworkRequestHTTP postURL:collectURL params:param success:^(id _Nonnull json) {
- [LoadingView dismiss];
- if ([json[@"flag"] integerValue] == 1) {
- [MBProgressHUD showSuccess:@"收藏成功"];
- }
- self.detailModel.is_collect=collect;
- [self isCollect];
- } failure:^(NSError * _Nonnull error) {
- [LoadingView dismiss];
- }];
- }
- #pragma mark---判断是否收藏
- -(void)isCollect
- {
- if (self.detailModel.is_collect.integerValue == 1) {
- collectButton.selected = YES;
- }else{
- collectButton.selected=NO;
- }
- }
- -(void)collectPageClickSel
- {
- KDPCollectHistoryPageVC *histT=[[KDPCollectHistoryPageVC alloc]init];
-
- [self.navigationController pushViewController:histT animated:YES];
- }
- #pragma mark---推广到快手
- -(void)kwaiClickButton
- {
- if (self.detailModel.goods_id.length<=0) {
- return;
- }
- [LoadingView show];
- [KDPNetworkRequestHTTP postURL:KwaiJumpURL params:@{@"goods_id":self.detailModel.goods_id} success:^(id _Nonnull json) {
- [LoadingView dismiss];
- /**
- 弹框状态 1:用户没有快手Pid
- 2:用户有Pid,首次提示
- 3:用户有Pid,二次提示
- */
-
- NSDictionary *resultDic=(NSDictionary *)json;
- if ([resultDic.allKeys containsObject:@"alert_info"]) {//包括alert_info说明需要提示
- [UIView animateWithDuration:1 animations:^{
- self.tipView.hidden=NO;
- self.tipView.resultDic=json[@"alert_info"];
- }];
- }else{//直接跳转到快手推广
- [KDPublicMethod jumpKwaiWithURL:json[@"data"][@"kwai_url_prime"]];
-
- }
- } failure:^(NSError * _Nonnull error) {
- [LoadingView dismiss];
- }];
- }
- #pragma mark---购买样品
- -(void)clickBuyButton
- {
- [LoadingView show];
- if (self.detailModel.goods_id.length<=0) {
- return;
- }
- [KDPNetworkRequestHTTP postURL:BuyURL params:@{@"goods_id":self.detailModel.goods_id} success:^(id _Nonnull json) {
- UIPasteboard * pastboard = [UIPasteboard generalPasteboard];
- pastboard.string=json[@"data"][@"tkl"];
- if (![KDPublicMethod JumpOpenURL:KWai]) {//没有安装快手,过审用
- [self jumpTbWithURL:json[@"data"][@"url"]];
-
- }else{
- self.pasteView.pasteLabel.attributedText=[KDPublicMethod sethanggaoWithStr:[NSString stringWithFormat:@"淘口令%@已复制你可以用来分享、购买或推广",json[@"data"][@"tkl"]] linSpacing:5];
- self.pasteView.tkl=json[@"data"][@"tkl"];
- self.pasteView.hidden=NO;
- }
- [LoadingView dismiss];
- } failure:^(NSError * _Nonnull error) {
- [LoadingView dismiss];
- }];
- }
- #pragma mark---跳转淘宝购买
- -(void)jumpTbWithURL:(NSString*)url
- {
- id<AlibcTradePage> page =[AlibcTradePageFactory page:url];
-
- //打开方式
- AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init];
- showParam.openType = AlibcOpenTypeAuto;
- [[AlibcTradeSDK sharedInstance].tradeService show:self.navigationController page:page showParams:showParam taoKeParams:nil trackParam:nil tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) {
-
- } tradeProcessFailedCallback:^(NSError * _Nullable error) {
-
- }];
- }
- #pragma mark---添加历史记录
- -(void)saveHistoryModel:(KDPGoodsModel *)model
- {
- NSString *goods_id=@"";
- if (model.goods_id.length>0) {
- goods_id= model.goods_id;
- }
- NSString *price=@"";
- if (model.price.length>0) {
- price = model.price;
- }
- NSString *img=@"";
- if (model.img.length>0) {
- img =model.img;
- }
-
- NSString *commission_rate=@"";
- if (model.commission_rate.length>0) {
- commission_rate = model.commission_rate;
- }
- NSString *commission_price=@"";
- if (model.commission_price.length>0) {
- commission_price = model.commission_price;
- }
- NSString *shop_title=@"";
- if ([model.shop[@"title"] length]>0) {
- shop_title = model.shop[@"title"];
- }
- NSString *title=@"";
- if (model.title.length>0) {
- title = model.title;
- }
- NSString *volume=@"";
- if (model.volume.length>0) {
- volume = model.volume;
- }
-
- NSString *live_price=@"";
- if (model.discount_price.length>0) {
- live_price = model.discount_price;
- }
-
- NSString *shop_type=@"";
- if (model.shop_type.length>0) {
- shop_type= model.shop_type;
- }
-
- NSDictionary *paramDic =@{@"title":title,@"img":img,@"goods_id":goods_id,@"volume":volume,@"shop_type":shop_type,@"shop_title":shop_title,@"price":price,@"commission_rate":commission_rate,@"discount_price":live_price,@"commission_price":commission_price};
- [KDPNetworkRequestHTTP postURL:historyURL params:paramDic success:^(id _Nonnull json) {
- NSLog(@"%@",json);
- } failure:^(NSError * _Nonnull error) {
-
- }];
- }
- @end
|