省钱达人

DRGoodDetailViewController.m 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  1. //
  2. // DRGoodDetailViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by xiaoxi on 2018/1/22.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRGoodDetailViewController.h"
  9. #import <WebKit/WebKit.h>
  10. #import "DRGoodDetailRequestViewModel.h"
  11. #import "SDCycleScrollView.h"
  12. #import "DRTableView.h"
  13. #import "DRGoodDetailBottomView.h"
  14. #import "DRGoodDetailView.h"
  15. #import "DRCollectionView.h"
  16. #import "DRGoodCollectionCell.h"
  17. #import "DRShopDetailViewController.h"
  18. #import <AlibcTradeSDK/AlibcTradeSDK.h>
  19. #import "DRHistoryTool.h"
  20. #import "DRHistoryModel.h"
  21. #import "DRGoodListViewController.h"
  22. #import "DRLoginViewController.h"
  23. #import "DRAdWebViewController.h"
  24. #import "DREventTool.h"
  25. #import "DRGotoDetailView.h"
  26. #import "DRShareGoodsViewController.h"
  27. #import "DRWebDetailController.h"
  28. #import "DRLinkFansController.h"
  29. #import "DRPrivilegeReferralViewController.h"
  30. #import "DRModuleView.h"
  31. #import "DRDetailHeaderTitle.h"
  32. #import "CCAlertShowView.h"
  33. #import "DRShareImgPopView.h"
  34. #import "DRShopInfoView.h"
  35. #import "DRDetailGuideView.h"
  36. #import "PhoneLoginManager.h"
  37. #import "PhoneLoginManager.h"
  38. #define GoodSimilarViewHeight ((self.goodSimilarArr.count-1)/2+1)*FITSIZE(292)+FITSIZE(45)
  39. static CGFloat detailDescWebHeight = 0.1;
  40. static NSInteger const detailDescWebTag = 111;
  41. static NSString *const cellID = @"DRGoodCollectionCell";
  42. static NSString *const collectionViewHeader = @"collectionViewHeader";
  43. @interface DRGoodDetailViewController ()
  44. <
  45. SDCycleScrollViewDelegate,
  46. UITableViewDelegate,
  47. UITableViewDataSource,
  48. YHGoodDetailBottomViewDelegate,
  49. YHGoodDetailViewDelegate,
  50. UIWebViewDelegate,
  51. UICollectionViewDelegate,
  52. UICollectionViewDataSource,
  53. UICollectionViewDelegateFlowLayout,
  54. SGPageTitleViewDelegate,
  55. UIWebViewDelegate,
  56. WKNavigationDelegate
  57. >
  58. {
  59. NSInteger _page;
  60. NSString *goBuyUrl;
  61. }
  62. @property (nonatomic, strong) DRGoodDetailModel *goodModel;
  63. @property (nonatomic, strong) UITableView *tableView;
  64. @property (nonatomic, strong) WKWebView *detailDescWebView;
  65. @property (nonatomic, strong) UIView *tableHeaderView;
  66. @property (nonatomic, strong) DRGoodDetailView *goodDetailView;
  67. @property (nonatomic, strong) SDCycleScrollView *cycleView;
  68. @property (nonatomic, strong) NSArray *goodSimilarArr;
  69. @property (nonatomic, strong) UICollectionView *collectionView;
  70. @property (nonatomic, strong) UIButton *backButton;
  71. @property (nonatomic, strong) SGPageTitleView *topTitleView;
  72. @property (nonatomic, strong) YYFPSLabel *fpsLabel;
  73. @property (nonatomic, strong) DRGoodDetailBottomView *goodBottomView;
  74. @property (nonatomic, strong) NSNumber *flag;//用户等级 1 会员 2 超级会员 3 运营商
  75. @property (nonatomic, strong) DRModuleView *moduleView;
  76. @property (nonatomic, strong) DRShopInfoView *shopInfoView;
  77. @end
  78. @implementation DRGoodDetailViewController
  79. - (void)dealloc {
  80. [self.detailDescWebView removeObserver:self forKeyPath:@"scrollView.contentSize"];
  81. NSLog(@"释放了------------");
  82. }
  83. - (void)viewWillDisappear:(BOOL)animated {
  84. [super viewWillDisappear:animated];
  85. [SVProgressHUD dismiss];
  86. }
  87. - (void)viewDidLoad {
  88. [super viewDidLoad];
  89. [self initHUD];
  90. [self initNavBar];
  91. [self request];
  92. [self requestCount];
  93. }
  94. -(void)viewDidAppear:(BOOL)animated{
  95. [super viewDidAppear:animated];
  96. }
  97. - (void)configParam {
  98. _page = 1;
  99. }
  100. - (void)requestCount {
  101. [DREventTool eventWithEventType:0 origin:self.eventModel.origin category_id:self.eventModel.category_id goods_id:self.requestModel.goods_id source:self.eventModel.source];
  102. }
  103. - (void)viewWillAppear:(BOOL)animated {
  104. [super viewWillAppear:animated];
  105. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
  106. self.navigationController.navigationBar.hidden = YES;
  107. }
  108. - (void)didReceiveMemoryWarning {
  109. [super didReceiveMemoryWarning];
  110. }
  111. - (void)initNavBar {
  112. [self.navigationBar setNavightionBarBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:0.0]];
  113. UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
  114. leftButton.frame = CGRectMake(0, 0, FITSIZE(22), FITSIZE(22));
  115. leftButton.backgroundColor = [UIColor clearColor];
  116. [leftButton setImage:[UIImage imageNamed:@"detail_back_g"] forState:UIControlStateNormal];
  117. [leftButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  118. self.backButton = leftButton;
  119. [self.navigationBar setCustomLeftButtons:@[leftButton]];
  120. [self.navigationBar addSubview:self.topTitleView];
  121. }
  122. - (void)initSubviews {
  123. __weak typeof(self) weakSelf = self;
  124. //底部栏
  125. DRGoodDetailBottomView *bottomView = [[DRGoodDetailBottomView alloc] initWithFrame:CGRectMake(0, kScreenHeight-FITSIZE(55)-BottomMargin, kScreenWidth, FITSIZE(55))];
  126. bottomView.delegate = self;
  127. bottomView.goodModel = self.goodModel;
  128. [self.view addSubview:bottomView];
  129. self.goodBottomView = bottomView;
  130. //轮播
  131. SDCycleScrollView *cycleView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, FITSIZE(375), FITSIZE(375)) delegate:self placeholderImage:[UIImage imageNamed:@""]];
  132. cycleView.imageURLStringsGroup = self.goodModel.small_img;
  133. cycleView.currentPageDotImage = [UIImage imageNamed:@"page_sel"];
  134. cycleView.pageDotImage = [UIImage imageNamed:@"page_nor"];
  135. self.cycleView = cycleView;
  136. //商品信息
  137. self.goodDetailView = [[DRGoodDetailView alloc] initWithFrame:CGRectMake(0, cycleView.height, kScreenWidth, FITSIZE(140))];
  138. self.goodDetailView.delegate = self;
  139. self.goodDetailView.goodModel = self.goodModel;
  140. DRDetailGuideView *guide = [[DRDetailGuideView alloc] initWithFrame:CGRectMake(0, self.goodDetailView.bottom, SCREEN_WIDTH, 35)];
  141. guide.tapAction = ^{
  142. DRPrivilegeReferralViewController *Privilege = [[DRPrivilegeReferralViewController alloc] init];
  143. [weakSelf.navigationController pushViewController:Privilege animated:YES];
  144. };
  145. guide.height = 0;//省钱快报不需要展示
  146. //店铺信息
  147. DRShopModel *model = self.goodModel.shop;
  148. CGFloat shopViewHeight = model==nil?0:Fitsize(68);
  149. self.shopInfoView = [[DRShopInfoView alloc] initWithFrame:CGRectMake(0, guide.bottom+5, SCREEN_WIDTH, shopViewHeight) shopModel:model];
  150. //推荐模块
  151. UIView *moduleBg = [[UIView alloc] initWithFrame:CGRectMake(0, self.shopInfoView.bottom+5, SCREEN_WIDTH, Fitsize(202))];
  152. DRDetailHeaderTitle *headerTitle = [[DRDetailHeaderTitle alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, Fitsize(34)) title:@"相关推荐" color:[UIColor gradientWidthFromColor:[UIColor YHColorWithHex:0xF62259] toColor:[UIColor YHColorWithHex:0xFC0E2F] withWidth:SCREEN_WIDTH]];
  153. [moduleBg addSubview:headerTitle];
  154. self.moduleView = [[DRModuleView alloc] initWithFrame:CGRectMake(0, headerTitle.height, SCREEN_WIDTH, moduleBg.height-Fitsize(34))];
  155. self.moduleView.didSelectedGood = ^(DRChildGoodModel *model) {
  156. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithChildModel:model];
  157. DRGoodDetailViewController *detail = [[DRGoodDetailViewController alloc] init];
  158. detail.requestModel = requestModel;
  159. DREventModel *evevtModel = [[DREventModel alloc] initWithOrigin:model.origin category_id:@"0" source:goodsDetailTopRecommendAction];
  160. detail.eventModel = evevtModel;
  161. [weakSelf.navigationController pushViewController:detail animated:YES];
  162. [MobClick event:GoodsDetailRecommend];
  163. };
  164. [moduleBg addSubview:self.moduleView];
  165. self.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, moduleBg.bottom+5)];
  166. //详情webview
  167. DRDetailHeaderTitle *detailHeader = [[DRDetailHeaderTitle 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]];
  168. _detailDescWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0, detailHeader.bottom, kScreenWidth, detailDescWebHeight)];
  169. _detailDescWebView.tag = detailDescWebTag;
  170. _detailDescWebView.navigationDelegate = self;
  171. _detailDescWebView.scrollView.scrollEnabled = NO;
  172. // _detailDescWebView.scalesPageToFit = YES;
  173. NSURL *url = [NSURL URLWithString:self.goodModel.detail_url];
  174. NSURLRequest *request = [NSURLRequest requestWithURL:url];
  175. [_detailDescWebView loadRequest:request];
  176. [self.tableHeaderView addSubview:cycleView];
  177. [self.tableHeaderView addSubview:self.goodDetailView];
  178. [self.tableHeaderView addSubview:guide];
  179. [self.tableHeaderView addSubview:self.shopInfoView];
  180. [self.tableHeaderView addSubview:moduleBg];
  181. [self.tableHeaderView addSubview:detailHeader];
  182. [self.tableHeaderView addSubview:_detailDescWebView];
  183. self.tableView.tableHeaderView = self.tableHeaderView;
  184. [self.view addSubview:self.tableView];
  185. [self.view bringSubviewToFront:self.navigationBar];
  186. //添加监听
  187. @try{
  188. [self.detailDescWebView removeObserver:self forKeyPath:@"scrollView.contentSize"];
  189. }@catch (NSException *exception) {
  190. }
  191. [_detailDescWebView addObserver:self forKeyPath:@"scrollView.contentSize" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];
  192. [self.view bringSubviewToFront:self.navigationBar];
  193. [DRGoodDetailRequestViewModel requestGoodSimilarParamGoods_id:self.requestModel.goods_id page:@(_page) success:^(NSArray *array) {
  194. if (array.count > 0) {
  195. self.goodSimilarArr = array;
  196. self.tableView.tableFooterView = self.collectionView;
  197. }
  198. } failure:^(NSError *error) {
  199. }];
  200. }
  201. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
  202. if ([keyPath isEqualToString:@"scrollView.contentSize"]) {
  203. id height = [change valueForKey:NSKeyValueChangeNewKey];
  204. CGSize size;
  205. [(NSValue *)height getValue:&size];
  206. if (detailDescWebHeight != size.height) {
  207. detailDescWebHeight = size.height;
  208. self.detailDescWebView.height = size.height;
  209. self.tableHeaderView.height = self.detailDescWebView.top+size.height;
  210. self.tableView.tableHeaderView = self.tableHeaderView;
  211. }
  212. }
  213. }
  214. - (void)backAction {
  215. [self.navigationController popViewControllerAnimated:YES];
  216. }
  217. #pragma mark - HUD
  218. - (void)initHUD {
  219. [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
  220. [SVProgressHUD setForegroundColor:[UIColor YHColorWithHex:0xff2420]];
  221. [SVProgressHUD setBackgroundColor:[UIColor YHColorWithHex:0xf5f4f4]];
  222. }
  223. #pragma mark - request
  224. - (void)request {
  225. [SVProgressHUD show];
  226. [DRGoodDetailRequestViewModel requestGoodDetailParamGoods_id:self.requestModel success:^(DRGoodDetailModel *model,NSDictionary *dic) {
  227. if (model) {
  228. self.goodModel = model;
  229. [self initSubviews];
  230. [self requestUserIdentity];
  231. [self requestThressRecommon];
  232. [self saveGoodsInfoAsBrowserHistoryWith:dic];
  233. }
  234. [SVProgressHUD dismiss];
  235. } failure:^(NSError *error) {
  236. [SVProgressHUD dismiss];
  237. [MBProgressHUD showMessage:@"加载失败"];
  238. }];
  239. [self loadGoBuyUrl];
  240. }
  241. /**
  242. 加载购买的url
  243. */
  244. - (void)loadGoBuyUrl {
  245. NSDictionary *param = @{@"goods_id":self.requestModel.goods_id,
  246. @"is_coupon":self.requestModel.is_coupon
  247. };
  248. NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/orderDown",BaseURL];
  249. [DRHttp post:url params:param success:^(id json) {
  250. goBuyUrl = json[@"url"];
  251. } failure:^(NSError *error) {
  252. }];
  253. }
  254. /**
  255. 加载上部相关推荐
  256. */
  257. - (void)requestThressRecommon {
  258. NSString *url = [NSString stringWithFormat:@"%@/api/v2/goods/recommendtop",BaseURL];
  259. NSDictionary *para = @{@"goods_id":self.requestModel.goods_id};
  260. [DRHttp post:url params:para success:^(id json) {
  261. NSArray *list = [NSArray yy_modelArrayWithClass:[DRChildGoodModel class] json:json[@"data"]];
  262. [self.moduleView setRecommonData:list];
  263. } failure:^(NSError *error) {
  264. }];
  265. }
  266. - (void)requestUserIdentity {
  267. NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/userIdentity",BaseURL];
  268. [DRHttp post:url params:nil success:^(id json) {
  269. if (json[@"data"]) {
  270. NSNumber *flag=json[@"data"][@"flag"];
  271. self.flag=flag;
  272. }
  273. } failure:^(NSError *error) {
  274. self.flag=0;
  275. }];
  276. }
  277. /**
  278. 保存浏览记录
  279. */
  280. - (void)saveGoodsInfoAsBrowserHistoryWith:(NSDictionary *)dic {
  281. if (![AccountTool isLogin]) {
  282. return;
  283. }
  284. NSString *urlString = [NSString stringWithFormat:@"%@/api/v2/brower/record", BaseURL];
  285. NSDictionary *para = [self.requestModel modelToDictionary];
  286. [DRHttp post:urlString params:para success:^(id json) {
  287. } failure:^(NSError *error) {
  288. }];
  289. }
  290. #pragma mark - scrollView
  291. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  292. CGFloat offsetY = scrollView.contentOffset.y;
  293. // CGFloat standard = FITSIZE(734)-NavBarHeight;
  294. CGFloat standard = self.cycleView.height-NavBarHeight;
  295. if (offsetY > -standard && offsetY < standard) {
  296. [self.navigationBar setNavightionBarBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:offsetY/standard]];
  297. self.topTitleView.alpha = offsetY/standard;
  298. if (offsetY/standard < 0.5) {
  299. [self.backButton setImage:[UIImage imageNamed:@"detail_back_g"] forState:UIControlStateNormal];
  300. self.backButton.alpha = 1-offsetY/standard;
  301. }
  302. else {
  303. [self.backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
  304. self.backButton.alpha = offsetY/standard;
  305. }
  306. }
  307. else {
  308. }
  309. if (offsetY >= standard) {
  310. [self.navigationBar setShowNavigationBarBottomLine:YES];
  311. } else {
  312. [self.navigationBar setShowNavigationBarBottomLine:NO];
  313. }
  314. //设置导航栏头部seg下标
  315. CGFloat indexOneHeight = self.moduleView.superview.bottom+5-NavBarHeight;
  316. CGFloat indexTwoHeight = self.tableHeaderView.height-NavBarHeight;
  317. if (offsetY < indexOneHeight) {
  318. self.topTitleView.newSelectedIndex = 0;
  319. }else if (offsetY>=indexOneHeight && offsetY<indexTwoHeight){
  320. self.topTitleView.newSelectedIndex = 1;
  321. }else {
  322. self.topTitleView.newSelectedIndex = 2;
  323. }
  324. }
  325. #pragma mark - topTitleViewDelegate
  326. - (void)pageTitleView:(SGPageTitleView *)pageTitleView selectedIndex:(NSInteger)selectedIndex {
  327. CGFloat indexOneHeight = self.moduleView.superview.bottom+5-NavBarHeight;
  328. CGFloat indexTwoHeight = self.tableHeaderView.height-NavBarHeight;
  329. switch (selectedIndex) {
  330. case 0:
  331. [self.tableView setContentOffset:CGPointMake(0, 0) animated:NO];
  332. break;
  333. case 1:
  334. [self.tableView setContentOffset:CGPointMake(0, indexOneHeight) animated:NO];
  335. break;
  336. case 2:
  337. [self.tableView setContentOffset:CGPointMake(0, indexTwoHeight) animated:NO];
  338. break;
  339. default:
  340. break;
  341. }
  342. }
  343. #pragma mark - goodDetailBottomViewDelegate
  344. /**
  345. 分享
  346. */
  347. - (void)yh_GoodDetailBottomViewClickCommissionButton {
  348. if ([AccountTool isLogin]) {
  349. DRShareImgPopView *shareView = [[DRShareImgPopView alloc] initWithFrame:self.view.bounds goodModel:self.goodModel];
  350. CCAlertShowView *showView = [CCAlertShowView showAlertViewWithView:shareView backgroundDismissEnable:YES];
  351. shareView.closeAction = ^{
  352. [showView dismiss];
  353. };
  354. showView.backgroundView.backgroundColor = [UIColor clearColor];
  355. [showView show];
  356. }else{
  357. DRLoginViewController *login = [[DRLoginViewController alloc] init];
  358. login.loginSucc = ^{
  359. [self request];
  360. };
  361. [self.navigationController presentViewController:login animated:YES completion:nil];
  362. }
  363. }
  364. - (void)yh_GoodDetailBottomViewClickCollectButton {
  365. if ([AccountTool isLogin]) {
  366. [MobClick event:collection_count];
  367. NSString *coupon_start_time = [self.goodModel.is_coupon boolValue] ? self.requestModel.coupon_start_time : @"";
  368. NSString *coupon_end_time = [self.goodModel.is_coupon boolValue] ? self.requestModel.coupon_end_time : @"";
  369. NSNumber *is_coupon = self.goodModel.is_coupon;
  370. NSString *coupon_price = self.goodModel.coupon_price;
  371. NSString *price = self.goodModel.price;
  372. NSString *discount_price = self.goodModel.discount_price;
  373. NSString *commission_rate = self.goodModel.commission_rate;
  374. if (!coupon_start_time) coupon_start_time = @"";
  375. if (!coupon_end_time) coupon_end_time = @"";
  376. if (!is_coupon) is_coupon = @0;
  377. if (!coupon_price) coupon_price = @"";
  378. if (!price) price = @"";
  379. if (!discount_price) discount_price = @"";
  380. if (!commission_rate) commission_rate = @"";
  381. NSDictionary *para = @{@"goods_id":self.goodModel.goods_id,
  382. @"is_coupon":is_coupon,
  383. @"coupon_price":coupon_price,
  384. @"price":price,
  385. @"discount_price":discount_price,
  386. @"commission_rate":commission_rate,
  387. @"coupon_end_time":coupon_end_time,
  388. @"coupon_start_time":coupon_start_time
  389. };
  390. [DRGoodDetailRequestViewModel requestCollectGoodParamGoods_id:para success:^(NSString *msg) {
  391. [SVProgressHUD showSuccessWithStatus:msg];
  392. if ([msg isEqualToString:@"收藏成功"]) {
  393. self.goodModel.is_favorites = @1;
  394. self.goodBottomView.collectButton.selected = YES;
  395. }
  396. else {
  397. self.goodModel.is_favorites = @0;
  398. self.goodBottomView.collectButton.selected = NO;
  399. }
  400. } failure:^(NSError *error) {
  401. }];
  402. }
  403. else {
  404. DRLoginViewController *login = [[DRLoginViewController alloc] init];
  405. login.loginSucc = ^{
  406. [self request];
  407. };
  408. [self.navigationController presentViewController:login animated:YES completion:nil];
  409. }
  410. }
  411. /**
  412. 跳到淘宝领券
  413. */
  414. - (void)yh_GoodDetailBottomViewClickBuyButton {
  415. [self getTicketTaoBaoUrl];
  416. }
  417. /**
  418. 获取商品链接
  419. */
  420. - (void)getTicketTaoBaoUrl {
  421. [self goBuy];
  422. [MobClick event:pay_count];
  423. // if (![AccountTool account]) {
  424. // DRLoginViewController *login = [[DRLoginViewController alloc] init];
  425. // [self presentViewController:login animated:YES completion:nil];
  426. // return;
  427. // }
  428. //
  429. //
  430. //
  431. // if ([self.flag integerValue]==1) {
  432. // UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"升级赚佣金" message:[NSString stringWithFormat:@"\n成为超级会员后,您购买商品就可以拿到%.2f元佣金哦~",[self.goodModel.super_commission_price floatValue]] preferredStyle:UIAlertControllerStyleAlert];
  433. // UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"直接领劵" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  434. // [self goBuy];
  435. //
  436. // }];
  437. // UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"成为超级会员" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  438. // DRPrivilegeReferralViewController *vc=[[DRPrivilegeReferralViewController alloc]init];
  439. // vc.flag=@(1);
  440. // vc.isSuper=@(0);
  441. // [self.navigationController pushViewController:vc animated:YES];
  442. // }];
  443. // [alert addAction:defaultAction];
  444. // [alert addAction:cancelAction];
  445. // [self presentViewController:alert animated:YES completion:nil];
  446. // return;
  447. // }else{
  448. // [self goBuy];
  449. // }
  450. }
  451. -(void)goBuy{
  452. if (goBuyUrl.length > 0) {
  453. [self jumpToTaobaoWithGoodsUrl:goBuyUrl];
  454. }else {
  455. [SVProgressHUD show];
  456. NSDictionary *param = @{@"goods_id":self.requestModel.goods_id,
  457. @"is_coupon":self.requestModel.is_coupon
  458. };
  459. NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/orderDown",BaseURL];
  460. [DRHttp post:url params:param success:^(id json) {
  461. if (url.length > 0) {
  462. [self jumpToTaobaoWithGoodsUrl:json[@"url"]];
  463. }
  464. [SVProgressHUD dismiss];
  465. } failure:^(NSError *error) {
  466. [SVProgressHUD dismiss];
  467. [MBProgressHUD showMessage:@"加载失败"];
  468. }];
  469. }
  470. }
  471. - (void)jumpToTaobaoWithGoodsUrl:(NSString *)url {
  472. [DREventTool eventWithEventType:1 origin:self.eventModel.origin category_id:self.eventModel.category_id goods_id:self.requestModel.goods_id source:self.eventModel.source];
  473. if ([self isInstallTaobaoAPP]) {
  474. id<AlibcTradePage> page = [AlibcTradePageFactory page:url];
  475. //淘客信息
  476. AlibcTradeTaokeParams *taoKeParams=[[AlibcTradeTaokeParams alloc] init];
  477. taoKeParams.pid = ALTK_PID; //
  478. //打开方式
  479. AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init];
  480. showParam.openType = AlibcOpenTypeNative;
  481. [[AlibcTradeSDK sharedInstance].tradeService show:self.navigationController page:page showParams:showParam taoKeParams:taoKeParams trackParam:nil tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) {
  482. } tradeProcessFailedCallback:^(NSError * _Nullable error) {
  483. }];
  484. }else {
  485. DRAdWebViewController *webVc = [[DRAdWebViewController alloc] init];
  486. webVc.url = url;
  487. [self.navigationController pushViewController:webVc animated:YES];
  488. }
  489. }
  490. /**
  491. 判断是否安装淘宝app
  492. */
  493. - (BOOL)isInstallTaobaoAPP {
  494. if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"taobao://"]]) {
  495. return YES;
  496. }else {
  497. return NO;
  498. }
  499. }
  500. #pragma mark - goodDetailViewDelegate
  501. - (void)yh_GoodDetailViewTapCoupon {
  502. [DRGoodDetailRequestViewModel requestTicketProcessParamGoods_id:self.requestModel.goods_id coupon_price:self.goodModel.coupon_price success:^(NSString *msg) {
  503. [self yh_GoodDetailBottomViewClickBuyButton];
  504. } failure:^(NSError *error) {
  505. }];
  506. }
  507. - (void)yh_GoodDetailViewTapShop {
  508. DRShopDetailViewController *shopVC = [[DRShopDetailViewController alloc] init];
  509. shopVC.goodModel = self.goodModel;
  510. [self.navigationController pushViewController:shopVC animated:YES];
  511. }
  512. #pragma mark - webView
  513. - (void)webViewDidStartLoad:(UIWebView *)webView {
  514. [SVProgressHUD dismiss];
  515. }
  516. - (void)webViewDidFinishLoad:(UIWebView *)webView {
  517. [SVProgressHUD dismiss];
  518. CGSize contentSize = webView.scrollView.contentSize;
  519. CGSize viewSize = self.detailDescWebView.bounds.size;
  520. float rw = viewSize.width / contentSize.width;
  521. webView.scrollView.minimumZoomScale = rw;
  522. webView.scrollView.maximumZoomScale = rw;
  523. webView.scrollView.zoomScale = rw;
  524. }
  525. - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
  526. [SVProgressHUD dismiss];
  527. }
  528. #pragma mark ------ wkWebView delegate ------
  529. // main frame的导航开始请求时调用
  530. - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation{
  531. }
  532. // 当main frame开始加载数据失败时,会回调
  533. - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error {
  534. }
  535. //当main frame导航完成时,会回调
  536. - (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation{
  537. // 页面加载完成之后调用
  538. }
  539. #pragma mark - tableView
  540. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  541. return 1;
  542. }
  543. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  544. return 1;
  545. }
  546. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  547. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
  548. return cell;
  549. }
  550. #pragma mark - collectionView
  551. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  552. return 1;
  553. }
  554. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  555. return self.goodSimilarArr.count;
  556. }
  557. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  558. CGFloat width = (SCREEN_WIDTH-5)/2;
  559. CGFloat height = width + 102;
  560. return CGSizeMake(width, height);
  561. }
  562. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  563. DRGoodCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
  564. cell.backgroundColor = [UIColor whiteColor];
  565. cell.backgroundView.backgroundColor = [UIColor whiteColor];
  566. cell.contentView.backgroundColor = [UIColor whiteColor];
  567. DRChildGoodModel *model = self.goodSimilarArr[indexPath.item];
  568. cell.model = model;
  569. return cell;
  570. }
  571. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
  572. UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionViewHeader forIndexPath:indexPath];
  573. CALayer *lineGapLayer = [CALayer layer];
  574. lineGapLayer.frame = CGRectMake(0, 0, kScreenWidth, FITSIZE(5));
  575. lineGapLayer.backgroundColor = [UIColor YHColorWithHex:0xf5f4f4].CGColor;
  576. [view.layer addSublayer:lineGapLayer];
  577. UILabel *lineGapLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, kScreenWidth, FITSIZE(40))];
  578. lineGapLabel.backgroundColor = [UIColor whiteColor];
  579. lineGapLabel.textColor = [UIColor YHColorWithHex:0x222222];
  580. lineGapLabel.font = [UIFont systemFontOfSize:FITSIZE(13)];
  581. lineGapLabel.text = @"相关推荐";
  582. lineGapLabel.textAlignment = NSTextAlignmentCenter;
  583. [view addSubview:lineGapLabel];
  584. return view;
  585. }
  586. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
  587. return CGSizeMake(kScreenWidth, FITSIZE(45));
  588. }
  589. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  590. DRChildGoodModel *model = self.goodSimilarArr[indexPath.item];
  591. //详情
  592. DRGoodDetailViewController *detailVC = [[DRGoodDetailViewController alloc] init];
  593. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithChildModel:model];
  594. detailVC.requestModel = requestModel;
  595. DREventModel *evevtModel = [[DREventModel alloc] initWithOrigin:@"0" category_id:@"0" source:goodsDetailRecommendAction];
  596. detailVC.eventModel = evevtModel;
  597. [self.navigationController pushViewController:detailVC animated:YES];
  598. }
  599. #pragma mark - lazy
  600. - (UITableView *)tableView {
  601. if (!_tableView) {
  602. _tableView = [[DRTableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight-FITSIZE(55)-BottomMargin) style:UITableViewStylePlain];
  603. _tableView.rowHeight = 0.1;
  604. _tableView.estimatedRowHeight = 0;
  605. _tableView.estimatedSectionHeaderHeight = 0;
  606. _tableView.estimatedSectionFooterHeight = 0;
  607. _tableView.delegate = self;
  608. _tableView.dataSource = self;
  609. [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
  610. if (@available(iOS 11.0, *)) {
  611. _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  612. }
  613. }
  614. return _tableView;
  615. }
  616. - (UICollectionView *)collectionView {
  617. if (!_collectionView) {
  618. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  619. flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
  620. flowLayout.minimumLineSpacing = FITSIZE(5);
  621. flowLayout.minimumInteritemSpacing = FITSIZE(0);
  622. _collectionView = [[DRCollectionView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, GoodSimilarViewHeight) collectionViewLayout:flowLayout];
  623. _collectionView.scrollEnabled = NO;
  624. _collectionView.bounces = NO;
  625. _collectionView.showsVerticalScrollIndicator = NO;
  626. _collectionView.delegate = self;
  627. _collectionView.dataSource = self;
  628. [_collectionView registerClass:[DRGoodCollectionCell class] forCellWithReuseIdentifier:cellID];
  629. [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionViewHeader];
  630. }
  631. return _collectionView;
  632. }
  633. - (SGPageTitleView *)topTitleView {
  634. if (!_topTitleView) {
  635. SGPageTitleViewConfigure *configure = [SGPageTitleViewConfigure pageTitleViewConfigure];
  636. configure.titleFont = [UIFont systemFontOfSize:FITSIZE(14)];
  637. configure.titleColor = [UIColor YHColorWithHex:0x222222];
  638. configure.titleSelectedColor = [UIColor YHColorWithHex:0xff2420];
  639. configure.indicatorColor = [UIColor YHColorWithHex:0xff2420];
  640. configure.indicatorScrollStyle = SGIndicatorScrollStyleHalf;
  641. _topTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(kScreenWidth/2-FITSIZE(100), KStatusBarHeight, FITSIZE(200), 44) delegate:self titleNames:@[@"宝贝",@"详情",@"推荐"] configure:configure];
  642. _topTitleView.backgroundColor = [UIColor clearColor];
  643. _topTitleView.alpha = 0.0;
  644. _topTitleView.isNeedBounces = NO;
  645. _topTitleView.isTitleGradientEffect = NO;
  646. _topTitleView.isOpenTitleTextZoom = YES;
  647. _topTitleView.isShowBottomSeparator = NO;
  648. }
  649. return _topTitleView;
  650. }
  651. @end