酷店

KDPGoodDetailVC.m 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  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 setButtonImageTitleStyle:ButtonImageTitleStyleCenterDown padding:3];
  132. [collectButton addTarget:self action:@selector(detailCollectClickButton) forControlEvents:UIControlEventTouchUpInside];
  133. [bottomView addSubview:collectButton];
  134. UIButton *buybutton =[[UIButton alloc]initWithFrame:CGRectMake(collectButton.right, 3, (SCREEN_WIDTH-96)/2, 39)];
  135. buybutton.backgroundColor=[UIColor gradientOneColor:[UIColor colorWithHexString:@"#FF235F"] toColor:[UIColor colorWithHexString:@"#FF7676"] Width:(SCREEN_WIDTH-96)/2];
  136. [buybutton setTitle:@"购买样品" forState:UIControlStateNormal];
  137. [bottomView addSubview:buybutton];
  138. buybutton.titleLabel.font=[UIFont systemFontOfSize:14];
  139. [buybutton addTarget:self action:@selector(clickBuyButton) forControlEvents:UIControlEventTouchUpInside];
  140. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:buybutton.bounds byRoundingCorners:UIRectCornerTopLeft| UIRectCornerBottomLeft cornerRadii:CGSizeMake(19.5, 19.5)];
  141. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  142. maskLayer.frame = buybutton.bounds;
  143. maskLayer.path = maskPath.CGPath;
  144. buybutton.layer.mask = maskLayer;
  145. UIButton *getKwaiButton =[[UIButton alloc]initWithFrame:CGRectMake(buybutton.right, 3, (SCREEN_WIDTH-96)/2, 39)];
  146. getKwaiButton.backgroundColor=[UIColor colorWithHexString:ThemeColor];
  147. [getKwaiButton setTitle:@"推广到快手" forState:UIControlStateNormal];
  148. getKwaiButton.titleLabel.font=[UIFont systemFontOfSize:14];
  149. [getKwaiButton addTarget:self action:@selector(kwaiClickButton) forControlEvents:UIControlEventTouchUpInside];
  150. [bottomView addSubview:getKwaiButton];
  151. UIBezierPath *maskPaths= [UIBezierPath bezierPathWithRoundedRect:getKwaiButton.bounds byRoundingCorners:UIRectCornerTopRight| UIRectCornerBottomRight cornerRadii:CGSizeMake(19.5, 19.5)];
  152. CAShapeLayer *maskLayers = [[CAShapeLayer alloc] init];
  153. maskLayers.frame = buybutton.bounds;
  154. maskLayers.path = maskPaths.CGPath;
  155. getKwaiButton.layer.mask = maskLayers;
  156. }
  157. -(void)returnClickBtn
  158. {
  159. [self.navigationController popViewControllerAnimated:YES];
  160. }
  161. -(void)viewWillAppear:(BOOL)animated
  162. {
  163. [super viewWillAppear:animated];
  164. self.navBar.hidden=YES;
  165. [UIApplication sharedApplication].statusBarStyle=UIStatusBarStyleDefault;
  166. self.navigationController.navigationBar.hidden=YES;
  167. self.tabBarController.tabBar.hidden=YES;
  168. }
  169. -(void)viewWillDisappear:(BOOL)animated
  170. {
  171. [super viewWillDisappear:animated];
  172. self.navBar.hidden=NO;
  173. [UIApplication sharedApplication].statusBarStyle=UIStatusBarStyleLightContent;
  174. self.tabBarController.tabBar.hidden=NO;
  175. }
  176. -(KDPDetailGoodInformationView *)infoView
  177. {
  178. if (!_infoView) {
  179. _infoView=[[KDPDetailGoodInformationView alloc]init];
  180. __weak KDPGoodDetailVC *weakself=self;
  181. _infoView.returnBlock = ^{
  182. [weakself.navigationController popViewControllerAnimated:YES];
  183. };
  184. }
  185. return _infoView;
  186. }
  187. -(KDPShopView *)shopView
  188. {
  189. if (!_shopView) {
  190. _shopView=[[KDPShopView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 70)];
  191. }
  192. return _shopView;
  193. }
  194. -(KDPSellingPointView *)pointView
  195. {
  196. if (!_pointView) {
  197. _pointView=[[KDPSellingPointView alloc]init];
  198. }
  199. return _pointView;
  200. }
  201. -(KDPPasteView *)pasteView
  202. {
  203. if (!_pasteView) {
  204. _pasteView=[[KDPPasteView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  205. _pasteView.hidden=YES;
  206. }
  207. return _pasteView;
  208. }
  209. -(KDPIDTipView *)tipView
  210. {
  211. if (!_tipView) {
  212. _tipView =[[KDPIDTipView alloc]init];
  213. _tipView.hidden=YES;
  214. }
  215. return _tipView;
  216. }
  217. -(void)addDetailUI
  218. {
  219. self.view.backgroundColor=[UIColor whiteColor];
  220. [self.view addSubview:self.detailBottonView];
  221. [self.detailBottonView addSubview:self.infoView];
  222. [self.detailBottonView addSubview:self.pointView];
  223. [self.detailBottonView addSubview:self.shopView];
  224. [self.detailBottonView mas_makeConstraints:^(MASConstraintMaker *make) {
  225. make.left.right.top.mas_equalTo(0);
  226. make.bottom.mas_equalTo(self.view.mas_bottom).offset(-KDTabBarHeight);
  227. }];
  228. [self.infoView mas_makeConstraints:^(MASConstraintMaker *make) {
  229. make.left.top.mas_equalTo(0);
  230. make.width.mas_equalTo(SCREEN_WIDTH);
  231. make.height.mas_equalTo(goodHeight);
  232. }];
  233. [self.pointView mas_makeConstraints:^(MASConstraintMaker *make) {
  234. make.top.mas_equalTo(self.infoView.mas_bottom);
  235. make.left.mas_equalTo(0);
  236. make.width.mas_equalTo(SCREEN_WIDTH);
  237. make.height.mas_equalTo(0);
  238. }];
  239. [self.shopView mas_makeConstraints:^(MASConstraintMaker *make) {
  240. make.left.mas_equalTo(0);
  241. make.width.mas_equalTo(SCREEN_WIDTH);
  242. make.height.mas_equalTo(75);
  243. make.top.mas_equalTo(self.pointView.mas_bottom);
  244. }];
  245. [self addDetailTitle];
  246. UIButton *returnBtn =[[UIButton alloc]initWithFrame:CGRectMake(15, KDStatusHeight+10, 30, 30)];
  247. returnBtn.layer.cornerRadius=15;
  248. returnBtn.layer.masksToBounds=YES;
  249. [self.view addSubview:returnBtn];
  250. returnBtn.backgroundColor=[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.4];
  251. [returnBtn setImage:[UIImage imageNamed:@"return_white"] forState:UIControlStateNormal];
  252. [returnBtn addTarget:self action:@selector(exitclickButton) forControlEvents:UIControlEventTouchUpInside];
  253. UIButton * collectBtn=[[UIButton alloc]initWithFrame:CGRectMake(self.view.width-47, KDStatusHeight+10, 30, 30)];
  254. [collectBtn setImage:[UIImage imageNamed:@"detail_collection"] forState:UIControlStateNormal];
  255. collectBtn.adjustsImageWhenHighlighted=NO;
  256. [collectBtn addTarget:self action:@selector(collectPageClickSel) forControlEvents:UIControlEventTouchUpInside];
  257. [self.view addSubview:collectBtn];
  258. }
  259. -(void)addDetailTitle
  260. {
  261. UILabel *titleL=[[UILabel alloc]init];
  262. titleL.textColor=[UIColor colorWithHexString:fontColor];
  263. titleL.text=@"———— 商品详情 ————";
  264. titleL.font=[UIFont systemFontOfSize:14];
  265. titleL.textAlignment=NSTextAlignmentCenter;
  266. [self.detailBottonView addSubview:titleL];
  267. [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  268. make.top.mas_equalTo(self.shopView.mas_bottom);
  269. make.height.mas_equalTo(40);
  270. make.width.mas_equalTo(SCREEN_WIDTH);
  271. make.left.mas_equalTo(0);
  272. }];
  273. }
  274. -(void)exitclickButton
  275. {
  276. [self.navigationController popViewControllerAnimated:YES];
  277. }
  278. -(WKWebView *)detaiWebV
  279. {
  280. if (!_detaiWebV) {
  281. _detaiWebV= [[WKWebView alloc]init];
  282. _detaiWebV.navigationDelegate=self;
  283. _detaiWebV.scrollView.scrollEnabled=NO;
  284. }
  285. return _detaiWebV;
  286. }
  287. -(UIScrollView *)detailBottonView
  288. {
  289. if (!_detailBottonView) {
  290. _detailBottonView=[[UIScrollView alloc]init];
  291. _detailBottonView.delegate=self;
  292. _detailBottonView.backgroundColor=[UIColor whiteColor];
  293. _detailBottonView.showsVerticalScrollIndicator=NO;
  294. if (@available(iOS 11.0, *)) {
  295. _detailBottonView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  296. } else {
  297. // Fallback on earlier versions
  298. }
  299. _detailBottonView.showsHorizontalScrollIndicator=NO;
  300. _detailBottonView.contentSize=CGSizeMake(0, SCREEN_HEIGHT*2);
  301. }
  302. return _detailBottonView;
  303. }
  304. #pragma mark----收藏
  305. -(void)detailCollectClickButton
  306. {
  307. [LoadingView show];
  308. NSString *collect=self.detailModel.is_collect;
  309. if (collect.integerValue == 0) {//收藏
  310. collect=@"1";
  311. }else{
  312. collect=@"0";
  313. }
  314. NSDictionary *param=@{@"is_add":collect,@"goods_id":self.detailModel.goods_id};
  315. [KDPNetworkRequestHTTP postURL:collectURL params:param success:^(id _Nonnull json) {
  316. [LoadingView dismiss];
  317. if ([json[@"flag"] integerValue] == 1) {
  318. [MBProgressHUD showSuccess:@"收藏成功"];
  319. }
  320. self.detailModel.is_collect=collect;
  321. [self isCollect];
  322. } failure:^(NSError * _Nonnull error) {
  323. [LoadingView dismiss];
  324. }];
  325. }
  326. #pragma mark---判断是否收藏
  327. -(void)isCollect
  328. {
  329. if (self.detailModel.is_collect.integerValue == 1) {
  330. collectButton.selected = YES;
  331. }else{
  332. collectButton.selected=NO;
  333. }
  334. }
  335. -(void)collectPageClickSel
  336. {
  337. KDPCollectHistoryPageVC *histT=[[KDPCollectHistoryPageVC alloc]init];
  338. [self.navigationController pushViewController:histT animated:YES];
  339. }
  340. #pragma mark---推广到快手
  341. -(void)kwaiClickButton
  342. {
  343. if (self.detailModel.goods_id.length<=0) {
  344. return;
  345. }
  346. [LoadingView show];
  347. [KDPNetworkRequestHTTP postURL:KwaiJumpURL params:@{@"goods_id":self.detailModel.goods_id} success:^(id _Nonnull json) {
  348. [LoadingView dismiss];
  349. /**
  350. 弹框状态 1:用户没有快手Pid
  351. 2:用户有Pid,首次提示
  352. 3:用户有Pid,二次提示
  353. */
  354. NSDictionary *resultDic=(NSDictionary *)json;
  355. if ([resultDic.allKeys containsObject:@"alert_info"]) {//包括alert_info说明需要提示
  356. [UIView animateWithDuration:1 animations:^{
  357. self.tipView.hidden=NO;
  358. self.tipView.resultDic=json[@"alert_info"];
  359. }];
  360. }else{//直接跳转到快手推广
  361. [KDPublicMethod jumpKwaiWithURL:json[@"data"][@"kwai_url_prime"]];
  362. }
  363. } failure:^(NSError * _Nonnull error) {
  364. [LoadingView dismiss];
  365. }];
  366. }
  367. #pragma mark---购买样品
  368. -(void)clickBuyButton
  369. {
  370. [LoadingView show];
  371. if (self.detailModel.goods_id.length<=0) {
  372. return;
  373. }
  374. [KDPNetworkRequestHTTP postURL:BuyURL params:@{@"goods_id":self.detailModel.goods_id} success:^(id _Nonnull json) {
  375. UIPasteboard * pastboard = [UIPasteboard generalPasteboard];
  376. pastboard.string=json[@"data"][@"tkl"];
  377. if (![KDPublicMethod JumpOpenURL:KWai]) {//没有安装快手,过审用
  378. [self jumpTbWithURL:json[@"data"][@"url"]];
  379. }else{
  380. self.pasteView.pasteLabel.attributedText=[KDPublicMethod sethanggaoWithStr:[NSString stringWithFormat:@"淘口令%@已复制你可以用来分享、购买或推广",json[@"data"][@"tkl"]] linSpacing:5];
  381. self.pasteView.tkl=json[@"data"][@"tkl"];
  382. self.pasteView.hidden=NO;
  383. }
  384. [LoadingView dismiss];
  385. } failure:^(NSError * _Nonnull error) {
  386. [LoadingView dismiss];
  387. }];
  388. }
  389. #pragma mark---跳转淘宝购买
  390. -(void)jumpTbWithURL:(NSString*)url
  391. {
  392. id<AlibcTradePage> page =[AlibcTradePageFactory page:url];
  393. //打开方式
  394. AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init];
  395. showParam.openType = AlibcOpenTypeAuto;
  396. [[AlibcTradeSDK sharedInstance].tradeService show:self.navigationController page:page showParams:showParam taoKeParams:nil trackParam:nil tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) {
  397. } tradeProcessFailedCallback:^(NSError * _Nullable error) {
  398. }];
  399. }
  400. #pragma mark---添加历史记录
  401. -(void)saveHistoryModel:(KDPGoodsModel *)model
  402. {
  403. NSString *goods_id=@"";
  404. if (model.goods_id.length>0) {
  405. goods_id= model.goods_id;
  406. }
  407. NSString *price=@"";
  408. if (model.price.length>0) {
  409. price = model.price;
  410. }
  411. NSString *img=@"";
  412. if (model.img.length>0) {
  413. img =model.img;
  414. }
  415. NSString *commission_rate=@"";
  416. if (model.commission_rate.length>0) {
  417. commission_rate = model.commission_rate;
  418. }
  419. NSString *commission_price=@"";
  420. if (model.commission_price.length>0) {
  421. commission_price = model.commission_price;
  422. }
  423. NSString *shop_title=@"";
  424. if ([model.shop[@"title"] length]>0) {
  425. shop_title = model.shop[@"title"];
  426. }
  427. NSString *title=@"";
  428. if (model.title.length>0) {
  429. title = model.title;
  430. }
  431. NSString *volume=@"";
  432. if (model.volume.length>0) {
  433. volume = model.volume;
  434. }
  435. NSString *live_price=@"";
  436. if (model.discount_price.length>0) {
  437. live_price = model.discount_price;
  438. }
  439. NSString *shop_type=@"";
  440. if (model.shop_type.length>0) {
  441. shop_type= model.shop_type;
  442. }
  443. 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};
  444. [KDPNetworkRequestHTTP postURL:historyURL params:paramDic success:^(id _Nonnull json) {
  445. NSLog(@"%@",json);
  446. } failure:^(NSError * _Nonnull error) {
  447. }];
  448. }
  449. @end