酷店

KDPGoodDetailVC.m 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. //
  2. // KDPGoodDetailVC.m
  3. // KuDianProject
  4. //
  5. // Created by 学丽 on 2019/7/9.
  6. // Copyright © 2019 KDP. All rights reserved.
  7. //
  8. #import "KDPGoodDetailVC.h"
  9. #import "KDPDetailGoodInformationView.h"
  10. #import "KDPSellingPointView.h"
  11. #import "KDPShopView.h"
  12. #import <WebKit/WebKit.h>
  13. #import "KDPCollectHistoryPageVC.h"
  14. #import "KDPPasteView.h"
  15. #import <AlibcTradeSDK/AlibcTradeSDK.h>
  16. #define goodHeight 496+KDStatusHeight
  17. @interface KDPGoodDetailVC ()<UIScrollViewDelegate,UIWebViewDelegate,WKNavigationDelegate>
  18. {
  19. UIView *bottomView;
  20. UIButton *collectButton;
  21. }
  22. //淘口令页面
  23. @property(nonatomic,strong)KDPPasteView *pasteView;
  24. @property(nonatomic,strong)KDPIDTipView *tipView;
  25. @property(nonatomic,strong)UIScrollView *detailBottonView;
  26. @property(nonatomic,strong)KDPDetailGoodInformationView *infoView;
  27. @property(nonatomic,strong)KDPSellingPointView *pointView;
  28. @property(nonatomic,strong)KDPShopView *shopView;
  29. @property(nonatomic,strong)KDPGoodsModel *detailModel;
  30. @property(nonatomic,strong)WKWebView *detaiWebV;
  31. @end
  32. @implementation KDPGoodDetailVC
  33. - (void)viewDidLoad {
  34. [super viewDidLoad];
  35. [self addDetailUI];
  36. [self addbottomView];
  37. self.infoView.model=self.model;
  38. @try {
  39. [self.detaiWebV removeObserver:self forKeyPath:@"scrollView.contentSize"];
  40. } @catch (NSException *exception) {
  41. }
  42. [self.detaiWebV addObserver:self forKeyPath:@"scrollView.contentSize" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
  43. [self.detailBottonView addSubview:self.detaiWebV];
  44. [self.detaiWebV mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.top.mas_equalTo(self.shopView.mas_bottom).offset(40);
  46. make.width.mas_equalTo(SCREEN_WIDTH);
  47. make.left.mas_equalTo(0);
  48. }];
  49. [self getGoodDetail];
  50. [self.view addSubview:self.pasteView];
  51. [self.view addSubview:self.tipView];
  52. [self.tipView mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.left.top.mas_equalTo(0);
  54. make.width.mas_equalTo(SCREEN_WIDTH);
  55. make.height.mas_equalTo(SCREEN_HEIGHT);
  56. }];
  57. }
  58. - (void)dealloc {
  59. @try{
  60. [self.detaiWebV removeObserver:self forKeyPath:@"scrollView.contentSize"];
  61. }@catch (NSException *exception) {
  62. }
  63. NSLog(@"释放了------------");
  64. }
  65. #pragma mark---商品详情
  66. -(void)getGoodDetail
  67. {
  68. if (self.model.goods_id.length<=0) {
  69. return;
  70. }
  71. [LoadingView show];
  72. [KDPNetworkRequestHTTP postURL:goodDetailURL params:@{@"goods_id":self.model.goods_id} success:^(id _Nonnull json) {
  73. self.detailModel=[KDPGoodsModel yy_modelWithJSON:json[@"data"]];
  74. if (self.detailModel.goods_point.length>0) {
  75. [self good_points];
  76. }
  77. self.infoView.model=self.detailModel;
  78. self.shopView.shopDic=self.detailModel.shop;
  79. [self loadRequestWeb];
  80. [LoadingView dismiss];
  81. [self isCollect];
  82. [self saveHistoryModel:self.detailModel];
  83. } failure:^(NSError * _Nonnull error) {
  84. [LoadingView dismiss];
  85. }];
  86. }
  87. #pragma mark----Web详情
  88. -(void)loadRequestWeb
  89. {
  90. NSURL *url=[NSURL URLWithString:self.detailModel.detail_url];
  91. NSURLRequest *requests=[NSURLRequest requestWithURL:url];
  92. [self.detaiWebV loadRequest:requests];
  93. }
  94. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
  95. {
  96. CGFloat heights =[KDPublicMethod getHeightByWidth:SCREEN_WIDTH-40 title:self.detailModel.goods_point font:[UIFont systemFontOfSize:13]];
  97. if ([keyPath isEqualToString:@"scrollView.contentSize"]) {
  98. id height =[change valueForKey:NSKeyValueChangeNewKey];
  99. CGSize size;
  100. [(NSValue *)height getValue:&size];
  101. [self.detaiWebV mas_updateConstraints:^(MASConstraintMaker *make) {
  102. make.height.mas_equalTo(size.height);
  103. }];
  104. self.detailBottonView.contentSize=CGSizeMake(0, size.height+goodHeight+115+heights);
  105. }
  106. }
  107. #pragma mark---赋值。卖点
  108. -(void)good_points
  109. {
  110. CGFloat height =[KDPublicMethod getHeightByWidth:SCREEN_WIDTH-40 title:self.detailModel.goods_point font:[UIFont systemFontOfSize:13]];
  111. self.pointView.point_good =self.detailModel.goods_point;
  112. [self.pointView mas_updateConstraints:^(MASConstraintMaker *make) {
  113. make.top.mas_equalTo(goodHeight);
  114. make.height.mas_equalTo(height+50);
  115. }];
  116. [self.shopView mas_updateConstraints:^(MASConstraintMaker *make) {
  117. make.top.mas_equalTo(self.pointView.mas_bottom);
  118. }];
  119. }
  120. -(void)addbottomView
  121. {
  122. bottomView =[[UIView alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT-KDTabBarHeight, SCREEN_WIDTH, KDTabBarHeight)];
  123. bottomView.backgroundColor=[UIColor whiteColor];
  124. [self.view addSubview:bottomView];
  125. collectButton=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 86, KDTabBarHeight-KDTabBottomHeight-5)];
  126. collectButton.titleLabel.font=[UIFont systemFontOfSize:10];
  127. [collectButton setTitle:@"收藏" forState:UIControlStateNormal];
  128. [collectButton setImage:[UIImage imageNamed:@"collection_select"] forState:UIControlStateSelected];
  129. [collectButton setTitleColor:[UIColor colorWithHexString:@"#828282"] forState:UIControlStateNormal];
  130. [collectButton setImage:[UIImage imageNamed:@"collection_un"] forState:UIControlStateNormal];
  131. collectButton.adjustsImageWhenHighlighted=NO;
  132. [collectButton setButtonImageTitleStyle:ButtonImageTitleStyleCenterDown padding:3];
  133. [collectButton addTarget:self action:@selector(detailCollectClickButton) forControlEvents:UIControlEventTouchUpInside];
  134. [bottomView addSubview:collectButton];
  135. UIButton *buybutton =[[UIButton alloc]initWithFrame:CGRectMake(collectButton.right, 3, (SCREEN_WIDTH-96)/2, 39)];
  136. buybutton.backgroundColor=[UIColor gradientOneColor:[UIColor colorWithHexString:@"#FF235F"] toColor:[UIColor colorWithHexString:@"#FF7676"] Width:(SCREEN_WIDTH-96)/2];
  137. [buybutton setTitle:@"购买样品" forState:UIControlStateNormal];
  138. [bottomView addSubview:buybutton];
  139. buybutton.titleLabel.font=[UIFont systemFontOfSize:14];
  140. [buybutton addTarget:self action:@selector(clickBuyButton) forControlEvents:UIControlEventTouchUpInside];
  141. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:buybutton.bounds byRoundingCorners:UIRectCornerTopLeft| UIRectCornerBottomLeft cornerRadii:CGSizeMake(19.5, 19.5)];
  142. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  143. maskLayer.frame = buybutton.bounds;
  144. maskLayer.path = maskPath.CGPath;
  145. buybutton.layer.mask = maskLayer;
  146. UIButton *getKwaiButton =[[UIButton alloc]initWithFrame:CGRectMake(buybutton.right, 3, (SCREEN_WIDTH-96)/2, 39)];
  147. getKwaiButton.backgroundColor=[UIColor colorWithHexString:ThemeColor];
  148. [getKwaiButton setTitle:@"推广到快手" forState:UIControlStateNormal];
  149. getKwaiButton.titleLabel.font=[UIFont systemFontOfSize:14];
  150. [getKwaiButton addTarget:self action:@selector(kwaiClickButton) forControlEvents:UIControlEventTouchUpInside];
  151. [bottomView addSubview:getKwaiButton];
  152. UIBezierPath *maskPaths= [UIBezierPath bezierPathWithRoundedRect:getKwaiButton.bounds byRoundingCorners:UIRectCornerTopRight| UIRectCornerBottomRight cornerRadii:CGSizeMake(19.5, 19.5)];
  153. CAShapeLayer *maskLayers = [[CAShapeLayer alloc] init];
  154. maskLayers.frame = buybutton.bounds;
  155. maskLayers.path = maskPaths.CGPath;
  156. getKwaiButton.layer.mask = maskLayers;
  157. }
  158. -(void)returnClickBtn
  159. {
  160. [self.navigationController popViewControllerAnimated:YES];
  161. }
  162. -(void)viewWillAppear:(BOOL)animated
  163. {
  164. [super viewWillAppear:animated];
  165. self.navBar.hidden=YES;
  166. [UIApplication sharedApplication].statusBarStyle=UIStatusBarStyleDefault;
  167. self.navigationController.navigationBar.hidden=YES;
  168. self.tabBarController.tabBar.hidden=YES;
  169. }
  170. -(void)viewWillDisappear:(BOOL)animated
  171. {
  172. [super viewWillDisappear:animated];
  173. // self.navBar.hidden=NO;
  174. [UIApplication sharedApplication].statusBarStyle=UIStatusBarStyleLightContent;
  175. self.tabBarController.tabBar.hidden=NO;
  176. }
  177. -(KDPDetailGoodInformationView *)infoView
  178. {
  179. if (!_infoView) {
  180. _infoView=[[KDPDetailGoodInformationView alloc]init];
  181. __weak KDPGoodDetailVC *weakself=self;
  182. _infoView.returnBlock = ^{
  183. [weakself.navigationController popViewControllerAnimated:YES];
  184. };
  185. }
  186. return _infoView;
  187. }
  188. -(KDPShopView *)shopView
  189. {
  190. if (!_shopView) {
  191. _shopView=[[KDPShopView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 70)];
  192. }
  193. return _shopView;
  194. }
  195. -(KDPSellingPointView *)pointView
  196. {
  197. if (!_pointView) {
  198. _pointView=[[KDPSellingPointView alloc]init];
  199. }
  200. return _pointView;
  201. }
  202. -(KDPPasteView *)pasteView
  203. {
  204. if (!_pasteView) {
  205. _pasteView=[[KDPPasteView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  206. _pasteView.hidden=YES;
  207. }
  208. return _pasteView;
  209. }
  210. -(KDPIDTipView *)tipView
  211. {
  212. if (!_tipView) {
  213. _tipView =[[KDPIDTipView alloc]init];
  214. _tipView.hidden=YES;
  215. }
  216. return _tipView;
  217. }
  218. -(void)addDetailUI
  219. {
  220. self.view.backgroundColor=[UIColor whiteColor];
  221. [self.view addSubview:self.detailBottonView];
  222. [self.detailBottonView addSubview:self.infoView];
  223. [self.detailBottonView addSubview:self.pointView];
  224. [self.detailBottonView addSubview:self.shopView];
  225. [self.detailBottonView mas_makeConstraints:^(MASConstraintMaker *make) {
  226. make.left.right.top.mas_equalTo(0);
  227. make.bottom.mas_equalTo(self.view.mas_bottom).offset(-KDTabBarHeight);
  228. }];
  229. [self.infoView mas_makeConstraints:^(MASConstraintMaker *make) {
  230. make.left.top.mas_equalTo(0);
  231. make.width.mas_equalTo(SCREEN_WIDTH);
  232. make.height.mas_equalTo(goodHeight);
  233. }];
  234. [self.pointView mas_makeConstraints:^(MASConstraintMaker *make) {
  235. make.top.mas_equalTo(self.infoView.mas_bottom);
  236. make.left.mas_equalTo(0);
  237. make.width.mas_equalTo(SCREEN_WIDTH);
  238. make.height.mas_equalTo(0);
  239. }];
  240. [self.shopView mas_makeConstraints:^(MASConstraintMaker *make) {
  241. make.left.mas_equalTo(0);
  242. make.width.mas_equalTo(SCREEN_WIDTH);
  243. make.height.mas_equalTo(75);
  244. make.top.mas_equalTo(self.pointView.mas_bottom);
  245. }];
  246. [self addDetailTitle];
  247. UIButton *returnBtn =[[UIButton alloc]initWithFrame:CGRectMake(15, KDStatusHeight+10, 30, 30)];
  248. returnBtn.layer.cornerRadius=15;
  249. returnBtn.layer.masksToBounds=YES;
  250. [self.view addSubview:returnBtn];
  251. returnBtn.backgroundColor=[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.4];
  252. [returnBtn setImage:[UIImage imageNamed:@"return_white"] forState:UIControlStateNormal];
  253. [returnBtn addTarget:self action:@selector(exitclickButton) forControlEvents:UIControlEventTouchUpInside];
  254. UIButton * collectBtn=[[UIButton alloc]initWithFrame:CGRectMake(self.view.width-47, KDStatusHeight+10, 30, 30)];
  255. [collectBtn setImage:[UIImage imageNamed:@"detail_collection"] forState:UIControlStateNormal];
  256. collectBtn.adjustsImageWhenHighlighted=NO;
  257. [collectBtn addTarget:self action:@selector(collectPageClickSel) forControlEvents:UIControlEventTouchUpInside];
  258. [self.view addSubview:collectBtn];
  259. }
  260. -(void)addDetailTitle
  261. {
  262. UILabel *titleL=[[UILabel alloc]init];
  263. titleL.textColor=[UIColor colorWithHexString:fontColor];
  264. titleL.text=@"———— 商品详情 ————";
  265. titleL.font=[UIFont systemFontOfSize:14];
  266. titleL.textAlignment=NSTextAlignmentCenter;
  267. [self.detailBottonView addSubview:titleL];
  268. [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  269. make.top.mas_equalTo(self.shopView.mas_bottom);
  270. make.height.mas_equalTo(40);
  271. make.width.mas_equalTo(SCREEN_WIDTH);
  272. make.left.mas_equalTo(0);
  273. }];
  274. }
  275. -(void)exitclickButton
  276. {
  277. [self.navigationController popViewControllerAnimated:YES];
  278. }
  279. -(WKWebView *)detaiWebV
  280. {
  281. if (!_detaiWebV) {
  282. _detaiWebV= [[WKWebView alloc]init];
  283. _detaiWebV.navigationDelegate=self;
  284. _detaiWebV.scrollView.scrollEnabled=NO;
  285. }
  286. return _detaiWebV;
  287. }
  288. -(UIScrollView *)detailBottonView
  289. {
  290. if (!_detailBottonView) {
  291. _detailBottonView=[[UIScrollView alloc]init];
  292. _detailBottonView.delegate=self;
  293. _detailBottonView.backgroundColor=[UIColor whiteColor];
  294. _detailBottonView.showsVerticalScrollIndicator=NO;
  295. if (@available(iOS 11.0, *)) {
  296. _detailBottonView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  297. } else {
  298. self.automaticallyAdjustsScrollViewInsets = NO;
  299. }
  300. _detailBottonView.showsHorizontalScrollIndicator=NO;
  301. _detailBottonView.contentSize=CGSizeMake(0, SCREEN_HEIGHT*2);
  302. }
  303. return _detailBottonView;
  304. }
  305. #pragma mark----收藏
  306. -(void)detailCollectClickButton
  307. {
  308. [LoadingView show];
  309. NSString *collect=self.detailModel.is_collect;
  310. if (collect.integerValue == 0) {//收藏
  311. collect=@"1";
  312. }else{
  313. collect=@"0";
  314. }
  315. NSDictionary *param=@{@"is_add":collect,@"goods_id":self.detailModel.goods_id};
  316. [KDPNetworkRequestHTTP postURL:collectURL params:param success:^(id _Nonnull json) {
  317. [LoadingView dismiss];
  318. if ([json[@"flag"] integerValue] == 1) {
  319. [MBProgressHUD showSuccess:@"收藏成功"];
  320. }
  321. self.detailModel.is_collect=collect;
  322. [self isCollect];
  323. } failure:^(NSError * _Nonnull error) {
  324. [LoadingView dismiss];
  325. }];
  326. }
  327. #pragma mark---判断是否收藏
  328. -(void)isCollect
  329. {
  330. if (self.detailModel.is_collect.integerValue == 1) {
  331. collectButton.selected = YES;
  332. }else{
  333. collectButton.selected=NO;
  334. }
  335. }
  336. -(void)collectPageClickSel
  337. {
  338. KDPCollectHistoryPageVC *histT=[[KDPCollectHistoryPageVC alloc]init];
  339. [self.navigationController pushViewController:histT animated:YES];
  340. }
  341. #pragma mark---推广到快手
  342. -(void)kwaiClickButton
  343. {
  344. if (self.detailModel.goods_id.length<=0) {
  345. return;
  346. }
  347. [LoadingView show];
  348. [KDPNetworkRequestHTTP postURL:KwaiJumpURL params:@{@"goods_id":self.detailModel.goods_id} success:^(id _Nonnull json) {
  349. [LoadingView dismiss];
  350. /**
  351. 弹框状态 1:用户没有快手Pid
  352. 2:用户有Pid,首次提示
  353. 3:用户有Pid,二次提示
  354. */
  355. NSDictionary *resultDic=(NSDictionary *)json;
  356. if ([resultDic.allKeys containsObject:@"alert_info"]) {//包括alert_info说明需要提示
  357. [UIView animateWithDuration:1 animations:^{
  358. self.tipView.hidden=NO;
  359. self.tipView.resultDic=json[@"alert_info"];
  360. }];
  361. }else{//直接跳转到快手推广
  362. [KDPublicMethod jumpKwaiWithURL:json[@"data"][@"kwai_url_prime"]];
  363. }
  364. } failure:^(NSError * _Nonnull error) {
  365. [LoadingView dismiss];
  366. }];
  367. }
  368. #pragma mark---购买样品
  369. -(void)clickBuyButton
  370. {
  371. [LoadingView show];
  372. if (self.detailModel.goods_id.length<=0) {
  373. return;
  374. }
  375. [KDPNetworkRequestHTTP postURL:BuyURL params:@{@"goods_id":self.detailModel.goods_id} success:^(id _Nonnull json) {
  376. UIPasteboard * pastboard = [UIPasteboard generalPasteboard];
  377. pastboard.string=json[@"data"][@"tkl"];
  378. if (![KDPublicMethod JumpOpenURL:KWai]) {//没有安装快手,过审用
  379. [self jumpTbWithURL:json[@"data"][@"url"]];
  380. }else{
  381. self.pasteView.pasteLabel.attributedText=[KDPublicMethod sethanggaoWithStr:[NSString stringWithFormat:@"淘口令%@已复制你可以用来分享、购买或推广",json[@"data"][@"tkl"]] linSpacing:5];
  382. self.pasteView.tkl=json[@"data"][@"tkl"];
  383. self.pasteView.hidden=NO;
  384. }
  385. [LoadingView dismiss];
  386. } failure:^(NSError * _Nonnull error) {
  387. [LoadingView dismiss];
  388. }];
  389. }
  390. #pragma mark---跳转淘宝购买
  391. -(void)jumpTbWithURL:(NSString*)url
  392. {
  393. id<AlibcTradePage> page =[AlibcTradePageFactory page:url];
  394. //打开方式
  395. AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init];
  396. showParam.openType = AlibcOpenTypeAuto;
  397. [[AlibcTradeSDK sharedInstance].tradeService show:self.navigationController page:page showParams:showParam taoKeParams:nil trackParam:nil tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) {
  398. } tradeProcessFailedCallback:^(NSError * _Nullable error) {
  399. }];
  400. }
  401. #pragma mark---添加历史记录
  402. -(void)saveHistoryModel:(KDPGoodsModel *)model
  403. {
  404. NSString *goods_id=@"";
  405. if (model.goods_id.length>0) {
  406. goods_id= model.goods_id;
  407. }
  408. NSString *price=@"";
  409. if (model.price.length>0) {
  410. price = model.price;
  411. }
  412. NSString *img=@"";
  413. if (model.img.length>0) {
  414. img =model.img;
  415. }
  416. NSString *commission_rate=@"";
  417. if (model.commission_rate.length>0) {
  418. commission_rate = model.commission_rate;
  419. }
  420. NSString *commission_price=@"";
  421. if (model.commission_price.length>0) {
  422. commission_price = model.commission_price;
  423. }
  424. NSString *shop_title=@"";
  425. if ([model.shop[@"title"] length]>0) {
  426. shop_title = model.shop[@"title"];
  427. }
  428. NSString *title=@"";
  429. if (model.title.length>0) {
  430. title = model.title;
  431. }
  432. NSString *volume=@"";
  433. if (model.volume.length>0) {
  434. volume = model.volume;
  435. }
  436. NSString *live_price=@"";
  437. if (model.discount_price.length>0) {
  438. live_price = model.discount_price;
  439. }
  440. NSString *shop_type=@"";
  441. if (model.shop_type.length>0) {
  442. shop_type= model.shop_type;
  443. }
  444. 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};
  445. [KDPNetworkRequestHTTP postURL:historyURL params:paramDic success:^(id _Nonnull json) {
  446. NSLog(@"%@",json);
  447. } failure:^(NSError * _Nonnull error) {
  448. }];
  449. }
  450. @end