《省钱达人》与《猎豆优选》UI相同版。域名tbk

DRGoodDetailViewController.m 39KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  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 "DRPrivilegeReferralViewController.h"
  14. #import "DRGoodDetailBottomView.h"
  15. #import "DRGoodDetailView.h"
  16. #import "DRCollectionView.h"
  17. #import "DRGoodCollectionCell.h"
  18. #import "DRShopDetailViewController.h"
  19. #import <AlibcTradeSDK/AlibcTradeSDK.h>
  20. #import "DRHistoryTool.h"
  21. #import "DRHistoryModel.h"
  22. #import "DRGoodListViewController.h"
  23. #import "DRLoginViewController.h"
  24. #import "DRAdWebViewController.h"
  25. #import "DREventTool.h"
  26. #import "DRGotoDetailView.h"
  27. #import "SDPhotoBrowser.h"
  28. #import "DRShareGoodsViewController.h"
  29. #import "DRWebDetailController.h"
  30. #import "DRLinkFansController.h"
  31. #import "DRPrivilegeReferralViewController.h"
  32. #import "DRModuleView.h"
  33. #import "DRDetailHeaderTitle.h"
  34. #import "CCAlertShowView.h"
  35. #import "DRShareImgPopView.h"
  36. #import "DRShopInfoView.h"
  37. #import "DRDetailGuideView.h"
  38. #import "PhoneLoginManager.h"
  39. #import "DRGoodDetailImageCell.h"
  40. #import "DRDetailImgModel.h"
  41. #import "DRShareGoodViewController.h"
  42. #import "DRShareRequestViewModel.h"
  43. #import "DRShareInfoModel.h"
  44. #define GoodSimilarViewHeight ((self.goodSimilarArr.count-1)/2+1)*FITSIZE(292)+FITSIZE(45)
  45. static CGFloat detailDescWebHeight = 0.1;
  46. static NSInteger const detailDescWebTag = 111;
  47. static NSString *const cellID = @"DRGoodCollectionCell";
  48. static NSString *const collectionViewHeader = @"collectionViewHeader";
  49. @interface DRGoodDetailViewController ()
  50. <
  51. SDCycleScrollViewDelegate,
  52. UITableViewDelegate,
  53. UITableViewDataSource,
  54. YHGoodDetailBottomViewDelegate,
  55. YHGoodDetailViewDelegate,
  56. UIWebViewDelegate,
  57. UICollectionViewDelegate,
  58. UICollectionViewDataSource,
  59. UICollectionViewDelegateFlowLayout,
  60. SGPageTitleViewDelegate,
  61. UIWebViewDelegate,
  62. WKNavigationDelegate,
  63. SDPhotoBrowserDelegate,
  64. LDDetailGuideViewDelegate
  65. >
  66. {
  67. NSInteger _page;
  68. ActivityIndicatorView *_indicatorView;
  69. BOOL isDealloc;
  70. }
  71. @property (nonatomic, strong) DRGoodDetailModel *goodModel;
  72. @property (nonatomic, strong) DRShareInfoModel *shareModel;
  73. @property (nonatomic, strong) UITableView *tableView;
  74. @property (nonatomic, strong) WKWebView *detailDescWebView;
  75. @property (nonatomic, strong) UIView *tableHeaderView;
  76. @property (nonatomic, strong) DRGoodDetailView *goodDetailView;
  77. @property (nonatomic, strong) SDCycleScrollView *cycleView;
  78. @property (nonatomic, strong) NSArray *goodSimilarArr;
  79. @property (nonatomic, strong) UICollectionView *collectionView;
  80. @property (nonatomic, strong) UIButton *backButton;
  81. @property (nonatomic, strong) SGPageTitleView *topTitleView;
  82. @property (nonatomic, strong) YYFPSLabel *fpsLabel;
  83. @property (nonatomic, strong) DRGoodDetailBottomView *goodBottomView;
  84. @property (nonatomic, strong) NSNumber *flag;//用户等级 1 会员 2 超级会员 3 运营商
  85. @property (nonatomic, strong) DRModuleView *moduleView;
  86. @property (nonatomic, strong) DRShopInfoView *shopInfoView;
  87. @property (nonatomic, strong) DRGoodDetailBottomView *bottomView;
  88. @property (nonatomic, strong) UIView *moduleBg;
  89. @property (nonatomic, strong) DRDetailHeaderTitle *detailHeader;
  90. @property (nonatomic, strong) DRDetailGuideView *guideView;
  91. @property (nonatomic, strong) NSMutableArray *bannerImgArray;
  92. @end
  93. @implementation DRGoodDetailViewController
  94. - (void)dealloc {
  95. @try{
  96. [self.detailDescWebView removeObserver:self forKeyPath:@"scrollView.contentSize"];
  97. }@catch (NSException *exception) {
  98. }
  99. NSLog(@"释放了------------");
  100. }
  101. - (void)viewWillDisappear:(BOOL)animated {
  102. [super viewWillDisappear:animated];
  103. [LoadingView dismiss];
  104. }
  105. - (void)viewDidLoad {
  106. [super viewDidLoad];
  107. [self initNavBar];
  108. [self initSubviews];
  109. // [self initHUD];
  110. [self request];
  111. [self requestShareModel];
  112. [self requestCount];
  113. [self loadUserInfo];
  114. }
  115. -(void)viewDidAppear:(BOOL)animated{
  116. [super viewDidAppear:animated];
  117. }
  118. - (void)configParam {
  119. _page = 1;
  120. }
  121. - (void)requestCount {
  122. [DREventTool eventWithEventType:0 origin:self.eventModel.origin category_id:self.eventModel.category_id goods_id:self.requestModel.goods_id source:self.eventModel.source];
  123. }
  124. - (void)viewWillAppear:(BOOL)animated {
  125. [super viewWillAppear:animated];
  126. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
  127. self.navigationController.navigationBar.hidden = YES;
  128. }
  129. - (void)didReceiveMemoryWarning {
  130. [super didReceiveMemoryWarning];
  131. }
  132. - (void)initNavBar {
  133. [self.navigationBar setNavightionBarBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:0.0]];
  134. UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
  135. leftButton.frame = CGRectMake(0, 0, FITSIZE(22), FITSIZE(22));
  136. leftButton.backgroundColor = [UIColor clearColor];
  137. [leftButton setImage:[UIImage imageNamed:@"detail_back_g"] forState:UIControlStateNormal];
  138. [leftButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  139. self.backButton = leftButton;
  140. [self.navigationBar setCustomLeftButtons:@[leftButton]];
  141. [self.navigationBar addSubview:self.topTitleView];
  142. }
  143. #pragma mark---初始化值
  144. -(void)initValues
  145. {
  146. DRGoodDetailModel *mndoels=[[DRGoodDetailModel alloc] init];
  147. [mndoels changeDetailRequestModel:_requestModel];
  148. self.goodDetailView.goodModel =mndoels;
  149. self.guideView.model = mndoels;
  150. DRShopModel *shopmodel =[[DRShopModel alloc]init];
  151. shopmodel.title= _requestModel.shop_title;
  152. [self.shopInfoView setShopInfo:shopmodel];
  153. }
  154. - (void)initSubviews {
  155. __weak typeof(self) weakSelf = self;
  156. //底部栏
  157. DRGoodDetailBottomView *bottomView = [[DRGoodDetailBottomView alloc] initWithFrame:CGRectMake(0, kScreenHeight-FITSIZE(55)-BottomMargin, kScreenWidth, FITSIZE(55))];
  158. bottomView.delegate = self;
  159. self.bottomView = bottomView;
  160. [self.view addSubview:bottomView];
  161. self.goodBottomView = bottomView;
  162. //轮播
  163. if (self.requestModel.img) {
  164. [self.bannerImgArray addObject:self.requestModel.img];
  165. }
  166. SDCycleScrollView *cycleView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, FITSIZE(375), FITSIZE(375)) delegate:self placeholderImage:[UIImage imageNamed:@""]];
  167. // cycleView.pageDotImage = [UIImage imageNamed:@"page_nor"];
  168. cycleView.imageURLStringsGroup= self.bannerImgArray;
  169. self.cycleView = cycleView;
  170. //商品信息
  171. self.goodDetailView = [[DRGoodDetailView alloc] initWithFrame:CGRectMake(0, cycleView.height, kScreenWidth, FITSIZE(110))];
  172. self.goodDetailView.delegate = self;
  173. DRDetailGuideView *guide = [[DRDetailGuideView alloc] initWithFrame:CGRectMake(0, self.goodDetailView.bottom, SCREEN_WIDTH, 0)];
  174. self.guideView = guide;
  175. self.guideView.delegate=self;
  176. guide.tapAction = ^{
  177. if (![AccountTool isLogin]) {
  178. DRLoginViewController *login = [[DRLoginViewController alloc] init];
  179. [weakSelf presentViewController:login animated:YES completion:nil];
  180. return ;
  181. }
  182. DRPrivilegeReferralViewController *Privilege = [[DRPrivilegeReferralViewController alloc] init];
  183. [weakSelf.navigationController pushViewController:Privilege animated:YES];
  184. };
  185. // if ([[PhoneLoginManager shareManager].showPhoneBtn boolValue]) {
  186. // guide.height = 0;
  187. // }
  188. //店铺信息
  189. self.shopInfoView = [[DRShopInfoView alloc] initWithFrame:CGRectMake(0, guide.bottom+5, SCREEN_WIDTH, FITSIZE(68))];
  190. //推荐模块
  191. UIView *moduleBg = [[UIView alloc] initWithFrame:CGRectMake(0, self.shopInfoView.bottom+5, SCREEN_WIDTH, Fitsize(202))];
  192. self.moduleBg = moduleBg;
  193. DRDetailHeaderTitle *headerTitle = [[DRDetailHeaderTitle alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, Fitsize(34)) title:@"相关推荐"];
  194. [moduleBg addSubview:headerTitle];
  195. self.moduleView = [[DRModuleView alloc] initWithFrame:CGRectMake(0, headerTitle.height, SCREEN_WIDTH, moduleBg.height-Fitsize(34))];
  196. self.moduleView.didSelectedGood = ^(DRChildGoodModel *model) {
  197. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithChildModel:model];
  198. DRGoodDetailViewController *detail = [[DRGoodDetailViewController alloc] init];
  199. detail.requestModel = requestModel;
  200. DREventModel *evevtModel = [[DREventModel alloc] initWithOrigin:model.origin category_id:@"0" source:goodsDetailTopRecommendAction];
  201. detail.eventModel = evevtModel;
  202. [weakSelf.navigationController pushViewController:detail animated:YES];
  203. [MobClick event:GoodsDetailRecommend];
  204. };
  205. [moduleBg addSubview:self.moduleView];
  206. self.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, moduleBg.bottom+5)];
  207. //详情webview
  208. DRDetailHeaderTitle *detailHeader = [[DRDetailHeaderTitle alloc] initWithFrame:CGRectMake(0, moduleBg.bottom+5, SCREEN_WIDTH, Fitsize(34)) title:@"宝贝详情"];
  209. self.detailHeader = detailHeader;
  210. _detailDescWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0, detailHeader.bottom, kScreenWidth, 0)];
  211. _detailDescWebView.tag = detailDescWebTag;
  212. _detailDescWebView.navigationDelegate = self;
  213. _detailDescWebView.scrollView.scrollEnabled = NO;
  214. // _detailDescWebView.scalesPageToFit = YES;
  215. [self.tableHeaderView addSubview:cycleView];
  216. [self.tableHeaderView addSubview:self.goodDetailView];
  217. [self.tableHeaderView addSubview:guide];
  218. [self.tableHeaderView addSubview:self.shopInfoView];
  219. [self.tableHeaderView addSubview:moduleBg];
  220. [self.tableHeaderView addSubview:detailHeader];
  221. [self.tableHeaderView addSubview:_detailDescWebView];
  222. self.tableView.tableHeaderView = self.tableHeaderView;
  223. [self.view addSubview:self.tableView];
  224. [self.view bringSubviewToFront:self.navigationBar];
  225. //添加监听
  226. @try{
  227. [self.detailDescWebView removeObserver:self forKeyPath:@"scrollView.contentSize"];
  228. }@catch (NSException *exception) {
  229. }
  230. [_detailDescWebView addObserver:self forKeyPath:@"scrollView.contentSize" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];
  231. [self.view bringSubviewToFront:self.navigationBar];
  232. [DRGoodDetailRequestViewModel requestGoodSimilarParamGoods_id:self.requestModel.goods_id page:@(_page) success:^(NSArray *array) {
  233. if (array.count > 0) {
  234. self.goodSimilarArr = array;
  235. self.tableView.tableFooterView = self.collectionView;
  236. }
  237. } failure:^(NSError *error) {
  238. }];
  239. [self initValues];
  240. }
  241. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
  242. if ([keyPath isEqualToString:@"scrollView.contentSize"]) {
  243. if (self.goodModel.detail_pic.count > 0) {
  244. self.detailDescWebView.height = 0;
  245. return;
  246. }
  247. id height = [change valueForKey:NSKeyValueChangeNewKey];
  248. CGSize size;
  249. [(NSValue *)height getValue:&size];
  250. if (detailDescWebHeight != size.height) {
  251. detailDescWebHeight = size.height;
  252. self.detailDescWebView.height = size.height;
  253. self.tableHeaderView.height = self.detailDescWebView.top+size.height;
  254. self.tableView.tableHeaderView = self.tableHeaderView;
  255. }
  256. }
  257. }
  258. - (void)backAction {
  259. [self.navigationController popViewControllerAnimated:YES];
  260. }
  261. #pragma mark - HUD
  262. - (void)initHUD {
  263. ActivityIndicatorView *indicatorView = [ActivityIndicatorView showInView:self.view frame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  264. _indicatorView = indicatorView;
  265. [_indicatorView startAnimating];
  266. }
  267. #pragma mark---图片点击
  268. -(void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
  269. {
  270. SDPhotoBrowser *browser = [[SDPhotoBrowser alloc] init];
  271. // browser.sourceImagesContainerView = self.cycleView;
  272. browser.currentImageIndex = index;
  273. browser.delegate = self;
  274. browser.imageCount = self.bannerImgArray.count;
  275. [browser show];
  276. }
  277. #pragma mark - SDPhotoBrowserDelegate
  278. - (NSURL *)photoBrowser:(SDPhotoBrowser *)browser highQualityImageURLForIndex:(NSInteger)index
  279. {
  280. NSString *imageName = self.bannerImgArray[index];
  281. return [NSURL URLWithString:imageName];
  282. }
  283. - (UIImage *)photoBrowser:(SDPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index
  284. {
  285. return [UIImage imageNamed:@"placeHolder"];
  286. }
  287. #pragma mark - request
  288. /**
  289. 加载分享相关的
  290. */
  291. - (void)requestShareModel {
  292. if ([AccountTool isLogin]) {
  293. [DRShareRequestViewModel requestGoodDetailParamGoods_id:self.requestModel success:^(DRShareInfoModel * _Nonnull model, NSDictionary * _Nonnull dic) {
  294. self.shareModel = model;
  295. } failure:^(NSError * _Nonnull error) {
  296. }];
  297. }
  298. }
  299. - (void)request {
  300. [DRGoodDetailRequestViewModel requestGoodDetailParamGoods_id:self.requestModel success:^(DRGoodDetailModel *model,NSDictionary *dic) {
  301. if (model) {
  302. self.goodModel = model;
  303. [self requestUserIdentity];
  304. [self requestThressRecommon];
  305. [self saveGoodsInfoAsBrowserHistoryWith:dic];
  306. if (model.is_coupon.integerValue == 0) {
  307. self.guideView.height = 0;
  308. }else{
  309. self.guideView.height = Fitsize(60);
  310. self.shopInfoView.frame=CGRectMake(0, self.guideView.bottom+5, SCREEN_WIDTH, Fitsize(68));
  311. self.moduleBg.frame=CGRectMake(0, self.shopInfoView.bottom+5, SCREEN_WIDTH, Fitsize(202));
  312. self.moduleView.frame=CGRectMake(0, FITSIZE(34), SCREEN_WIDTH, self.moduleBg.height-Fitsize(34));
  313. self.tableHeaderView.frame=CGRectMake(0, 0, SCREEN_WIDTH, self.moduleBg.bottom+5);
  314. self.detailHeader.frame=CGRectMake(0, self.moduleBg.bottom+5, SCREEN_WIDTH, Fitsize(34));
  315. self.detailDescWebView.frame=CGRectMake(0, self.detailHeader.bottom, kScreenWidth, 0);
  316. self.guideView.model=model;
  317. }
  318. [self setGoodInfoForHeader];
  319. }
  320. [_indicatorView stopAnimating];
  321. [self.tableView reloadData];
  322. } failure:^(NSError *error) {
  323. [_indicatorView stopAnimating];
  324. [MBProgressHUD showMessage:@"加载失败"];
  325. }];
  326. }
  327. - (void)setGoodInfoForHeader {
  328. self.bottomView.goodModel = self.goodModel;
  329. [self.bannerImgArray addObjectsFromArray:self.goodModel.small_img];
  330. self.cycleView.imageURLStringsGroup= self.bannerImgArray;
  331. self.goodDetailView.goodModel = self.goodModel;
  332. DRShopModel *model = self.goodModel.shop;
  333. CGFloat shopViewHeight = model==nil?0:Fitsize(68);
  334. [self.shopInfoView setShopInfo:model];
  335. self.shopInfoView.height = shopViewHeight;
  336. CGFloat topMargin = shopViewHeight>0?5:0;
  337. self.shopInfoView.y = self.guideView.bottom +topMargin;
  338. self.moduleBg.y = self.shopInfoView.bottom+5;
  339. self.detailHeader.y = self.moduleBg.bottom+5;
  340. _detailDescWebView.y = self.detailHeader.bottom;
  341. // NSURL *url = [NSURL URLWithString:self.goodModel.detail_url];
  342. NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:self.goodModel.detail_url]
  343. cachePolicy:NSURLRequestReloadIgnoringCacheData
  344. timeoutInterval:15.0];
  345. NSArray *picList = self.goodModel.detail_pic;
  346. if (picList.count == 0) {
  347. // [_detailDescWebView addObserver:self forKeyPath:@"scrollView.contentSize" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];
  348. if (@available(iOS 9.0, *)) {
  349. NSArray * types=@[WKWebsiteDataTypeCookies,WKWebsiteDataTypeLocalStorage];
  350. NSSet *websiteDataTypes= [NSSet setWithArray:types];
  351. NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0];
  352. [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:^{
  353. }];
  354. }
  355. // NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.url]];
  356. [_detailDescWebView loadRequest:request];
  357. }
  358. self.tableHeaderView.height = self.detailDescWebView.bottom;
  359. self.tableView.tableHeaderView = self.tableHeaderView;
  360. }
  361. /**
  362. 加载上部相关推荐
  363. */
  364. - (void)requestThressRecommon {
  365. NSString *url = [NSString stringWithFormat:@"%@/api/v2/goods/recommendtop",BaseURL];
  366. NSDictionary *para = @{@"goods_id":self.requestModel.goods_id};
  367. [DRHttp post:url params:para success:^(id json) {
  368. NSArray *list = [NSArray yy_modelArrayWithClass:[DRChildGoodModel class] json:json[@"data"]];
  369. [self.moduleView setRecommonData:list];
  370. } failure:^(NSError *error) {
  371. }];
  372. }
  373. - (void)requestUserIdentity {
  374. NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/userIdentity",BaseURL];
  375. [DRHttp post:url params:nil success:^(id json) {
  376. if (json[@"data"]) {
  377. NSNumber *flag=json[@"data"][@"flag"];
  378. self.flag=flag;
  379. }
  380. } failure:^(NSError *error) {
  381. self.flag=0;
  382. }];
  383. }
  384. /**
  385. 保存浏览记录
  386. */
  387. - (void)saveGoodsInfoAsBrowserHistoryWith:(NSDictionary *)dic {
  388. if (![AccountTool isLogin]) {
  389. return;
  390. }
  391. NSString *urlString = [NSString stringWithFormat:@"%@/api/v2/brower/record", BaseURL];
  392. NSDictionary *para = [self.requestModel modelToDictionary];
  393. [DRHttp post:urlString params:para success:^(id json) {
  394. } failure:^(NSError *error) {
  395. }];
  396. }
  397. #pragma mark - scrollView
  398. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  399. CGFloat offsetY = scrollView.contentOffset.y;
  400. // CGFloat standard = FITSIZE(734)-NavBarHeight;
  401. CGFloat standard = self.cycleView.height-NavBarHeight;
  402. if (offsetY > -standard && offsetY < standard) {
  403. [self.navigationBar setNavightionBarBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:offsetY/standard]];
  404. self.topTitleView.alpha = offsetY/standard;
  405. if (offsetY/standard < 0.5) {
  406. [self.backButton setImage:[UIImage imageNamed:@"detail_back_g"] forState:UIControlStateNormal];
  407. self.backButton.alpha = 1-offsetY/standard;
  408. }
  409. else {
  410. [self.backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
  411. self.backButton.alpha = offsetY/standard;
  412. }
  413. }
  414. else {
  415. }
  416. if (offsetY >= standard) {
  417. [self.navigationBar setShowNavigationBarBottomLine:YES];
  418. } else {
  419. [self.navigationBar setShowNavigationBarBottomLine:NO];
  420. }
  421. //设置导航栏头部seg下标
  422. CGFloat indexOneHeight = self.moduleView.superview.bottom+5-NavBarHeight;
  423. CGFloat indexTwoHeight;
  424. if (self.goodModel.detail_pic.count > 0) {
  425. //详情为图片数组时
  426. CGRect senctionHeight = [self.tableView rectForSection:0];
  427. indexTwoHeight = senctionHeight.size.height+self.tableHeaderView.height-NavBarHeight;
  428. }else {
  429. //详情为web
  430. indexTwoHeight = self.tableHeaderView.height-NavBarHeight;
  431. }
  432. if (offsetY < indexOneHeight) {
  433. self.topTitleView.newSelectedIndex = 0;
  434. }else if (offsetY>=indexOneHeight && offsetY<indexTwoHeight){
  435. self.topTitleView.newSelectedIndex = 1;
  436. }else {
  437. self.topTitleView.newSelectedIndex = 2;
  438. }
  439. }
  440. #pragma mark--- 特权和购买
  441. -(void)commisionClickPage
  442. {
  443. DRPrivilegeReferralViewController *Privilege = [[DRPrivilegeReferralViewController alloc] init];
  444. [self.navigationController pushViewController:Privilege animated:YES];
  445. }
  446. -(void)goBuyWithModel:(DRGoodDetailModel *)model
  447. {
  448. [self getTicketTaoBaoUrl];
  449. }
  450. #pragma mark - topTitleViewDelegate
  451. - (void)pageTitleView:(SGPageTitleView *)pageTitleView selectedIndex:(NSInteger)selectedIndex {
  452. CGFloat indexOneHeight = self.moduleView.superview.bottom+5-NavBarHeight;
  453. CGFloat indexTwoHeight;
  454. if (self.goodModel.detail_pic.count > 0) {
  455. CGRect senctionHeight = [self.tableView rectForSection:0];
  456. indexTwoHeight = senctionHeight.size.height+self.tableHeaderView.height-NavBarHeight;
  457. }else {
  458. indexTwoHeight = self.tableHeaderView.height-NavBarHeight;
  459. }
  460. switch (selectedIndex) {
  461. case 0:
  462. [self.tableView setContentOffset:CGPointMake(0, 0) animated:NO];
  463. break;
  464. case 1:
  465. [self.tableView setContentOffset:CGPointMake(0, indexOneHeight) animated:NO];
  466. break;
  467. case 2:
  468. [self.tableView setContentOffset:CGPointMake(0, indexTwoHeight) animated:NO];
  469. break;
  470. default:
  471. break;
  472. }
  473. }
  474. #pragma mark - goodDetailBottomViewDelegate
  475. /**
  476. 分享
  477. */
  478. - (void)yh_GoodDetailBottomViewClickCommissionButton {
  479. if ([AccountTool isLogin]) {
  480. // DRShareImgPopView *shareView = [[DRShareImgPopView alloc] initWithFrame:self.view.bounds goodModel:self.goodModel];
  481. // CCAlertShowView *showView = [CCAlertShowView showAlertViewWithView:shareView backgroundDismissEnable:YES];
  482. // shareView.closeAction = ^{
  483. // [showView dismiss];
  484. // };
  485. // showView.backgroundView.backgroundColor = [UIColor clearColor];
  486. // [showView show];
  487. DRShareGoodViewController *shareVc = [[DRShareGoodViewController alloc] init];
  488. if (self.shareModel) {
  489. shareVc.goodModel = self.shareModel;
  490. [self.navigationController pushViewController:shareVc animated:YES];
  491. }else {
  492. [LoadingView show];
  493. [DRShareRequestViewModel requestGoodDetailParamGoods_id:self.requestModel success:^(DRShareInfoModel * _Nonnull model, NSDictionary * _Nonnull dic) {
  494. [LoadingView dismiss];
  495. self.shareModel = model;
  496. shareVc.goodModel = self.shareModel;
  497. [self.navigationController pushViewController:shareVc animated:YES];
  498. } failure:^(NSError * _Nonnull error) {
  499. [LoadingView dismiss];
  500. }];
  501. }
  502. }else{
  503. DRLoginViewController *login = [[DRLoginViewController alloc] init];
  504. login.loginSucc = ^{
  505. [self request];
  506. };
  507. [self.navigationController presentViewController:login animated:YES completion:nil];
  508. }
  509. }
  510. -(void)yh_GoodDetailViewCollectButton{
  511. if ([AccountTool isLogin]) {
  512. [MobClick event:collection_count];
  513. NSString *coupon_start_time = [self.goodModel.is_coupon boolValue] ? self.requestModel.coupon_start_time : @"";
  514. NSString *coupon_end_time = [self.goodModel.is_coupon boolValue] ? self.requestModel.coupon_end_time : @"";
  515. NSNumber *is_coupon = self.goodModel.is_coupon;
  516. NSString *coupon_price = self.goodModel.coupon_price;
  517. NSString *price = self.goodModel.price;
  518. NSString *discount_price = self.goodModel.discount_price;
  519. NSString *commission_rate = self.goodModel.commission_rate;
  520. if (!coupon_start_time) coupon_start_time = @"";
  521. if (!coupon_end_time) coupon_end_time = @"";
  522. if (!is_coupon) is_coupon = @0;
  523. if (!coupon_price) coupon_price = @"";
  524. if (!price) price = @"";
  525. if (!discount_price) discount_price = @"";
  526. if (!commission_rate) commission_rate = @"";
  527. NSDictionary *para = @{@"goods_id":self.goodModel.goods_id,
  528. @"is_coupon":is_coupon,
  529. @"coupon_price":coupon_price,
  530. @"price":price,
  531. @"discount_price":discount_price,
  532. @"commission_rate":commission_rate,
  533. @"coupon_end_time":coupon_end_time,
  534. @"coupon_start_time":coupon_start_time
  535. };
  536. [DRGoodDetailRequestViewModel requestCollectGoodParamGoods_id:para success:^(NSString *msg) {
  537. [SVProgressHUD showSuccessWithStatus:msg];
  538. if ([msg isEqualToString:@"收藏成功"]) {
  539. self.goodModel.is_favorites = @1;
  540. {
  541. self.goodDetailView.collectButton.selected = YES;
  542. }
  543. }else {
  544. self.goodModel.is_favorites = @0;
  545. {self.goodDetailView.collectButton.selected = NO;
  546. }
  547. }
  548. } failure:^(NSError *error) {
  549. }];
  550. }
  551. else {
  552. DRLoginViewController *login = [[DRLoginViewController alloc] init];
  553. login.loginSucc = ^{
  554. [self request];
  555. };
  556. [self.navigationController presentViewController:login animated:YES completion:nil];
  557. }
  558. }
  559. - (void)yh_GoodDetailBottomViewClickCollectButton {
  560. if ([AccountTool isLogin]) {
  561. [MobClick event:collection_count];
  562. NSString *coupon_start_time = [self.goodModel.is_coupon boolValue] ? self.requestModel.coupon_start_time : @"";
  563. NSString *coupon_end_time = [self.goodModel.is_coupon boolValue] ? self.requestModel.coupon_end_time : @"";
  564. NSNumber *is_coupon = self.goodModel.is_coupon;
  565. NSString *coupon_price = self.goodModel.coupon_price;
  566. NSString *price = self.goodModel.price;
  567. NSString *discount_price = self.goodModel.discount_price;
  568. NSString *commission_rate = self.goodModel.commission_rate;
  569. if (!coupon_start_time) coupon_start_time = @"";
  570. if (!coupon_end_time) coupon_end_time = @"";
  571. if (!is_coupon) is_coupon = @0;
  572. if (!coupon_price) coupon_price = @"";
  573. if (!price) price = @"";
  574. if (!discount_price) discount_price = @"";
  575. if (!commission_rate) commission_rate = @"";
  576. NSDictionary *para = @{@"goods_id":self.goodModel.goods_id,
  577. @"is_coupon":is_coupon,
  578. @"coupon_price":coupon_price,
  579. @"price":price,
  580. @"discount_price":discount_price,
  581. @"commission_rate":commission_rate,
  582. @"coupon_end_time":coupon_end_time,
  583. @"coupon_start_time":coupon_start_time
  584. };
  585. [DRGoodDetailRequestViewModel requestCollectGoodParamGoods_id:para success:^(NSString *msg) {
  586. [SVProgressHUD showSuccessWithStatus:msg];
  587. if ([msg isEqualToString:@"收藏成功"]) {
  588. self.goodModel.is_favorites = @1;
  589. // self.goodBottomView.collectButton.selected = YES;
  590. }
  591. else {
  592. self.goodModel.is_favorites = @0;
  593. // self.goodBottomView.collectButton.selected = NO;
  594. }
  595. } failure:^(NSError *error) {
  596. }];
  597. }
  598. else {
  599. DRLoginViewController *login = [[DRLoginViewController alloc] init];
  600. login.loginSucc = ^{
  601. [self request];
  602. };
  603. [self.navigationController presentViewController:login animated:YES completion:nil];
  604. }
  605. }
  606. /**
  607. 跳到淘宝领券
  608. */
  609. - (void)yh_GoodDetailBottomViewClickBuyButton {
  610. [self getTicketTaoBaoUrl];
  611. }
  612. /**
  613. 获取商品链接
  614. */
  615. - (void)getTicketTaoBaoUrl {
  616. [MobClick event:pay_count];
  617. // if (![AccountTool account]) {
  618. // DRLoginViewController *login = [[DRLoginViewController alloc] init];
  619. // [self presentViewController:login animated:YES completion:nil];
  620. // return;
  621. // }
  622. [self goBuy];
  623. }
  624. -(void)goBuy{
  625. [LoadingView show];
  626. NSString *category_id = self.eventModel.category_id==nil?@"":self.eventModel.category_id;
  627. NSString *path = self.eventModel.source==nil?@"":self.eventModel.source;
  628. NSString *goods_id = self.requestModel.goods_id==nil?@"":self.requestModel.goods_id;
  629. NSString *is_coupon = self.requestModel.is_coupon==nil?@"":self.requestModel.is_coupon;
  630. NSDictionary *param = @{@"goods_id":goods_id,
  631. @"is_coupon":is_coupon,
  632. @"category_id":category_id,
  633. @"path":path
  634. };
  635. NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/orderDown",BaseURL];
  636. [DRHttp post:url params:param success:^(id json) {
  637. [self jumpToTaobaoWithGoodsUrl:json[@"url"]];
  638. [LoadingView dismiss];
  639. } failure:^(NSError *error) {
  640. [LoadingView dismiss];
  641. [MBProgressHUD showMessage:@"加载失败"];
  642. }];
  643. }
  644. - (void)jumpToTaobaoWithGoodsUrl:(NSString *)url {
  645. [DREventTool eventWithEventType:1 origin:self.eventModel.origin category_id:self.eventModel.category_id goods_id:self.requestModel.goods_id source:self.eventModel.source];
  646. id<AlibcTradePage> page = [AlibcTradePageFactory page:url];
  647. //淘客信息
  648. AlibcTradeTaokeParams *taoKeParams=[[AlibcTradeTaokeParams alloc] init];
  649. taoKeParams.pid = ALTK_PID; //
  650. //打开方式
  651. AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init];
  652. showParam.openType = AlibcOpenTypeNative;
  653. [[AlibcTradeSDK sharedInstance].tradeService show:self.navigationController page:page showParams:showParam taoKeParams:taoKeParams trackParam:nil tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) {
  654. } tradeProcessFailedCallback:^(NSError * _Nullable error) {
  655. }];
  656. }
  657. /**
  658. 判断是否安装淘宝app
  659. */
  660. - (BOOL)isInstallTaobaoAPP {
  661. if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"taobao://"]]) {
  662. return YES;
  663. }else {
  664. return NO;
  665. }
  666. }
  667. #pragma mark - goodDetailViewDelegate
  668. - (void)yh_GoodDetailViewTapCoupon {
  669. [DRGoodDetailRequestViewModel requestTicketProcessParamGoods_id:self.requestModel.goods_id coupon_price:self.goodModel.coupon_price success:^(NSString *msg) {
  670. [self yh_GoodDetailBottomViewClickBuyButton];
  671. } failure:^(NSError *error) {
  672. }];
  673. }
  674. - (void)yh_GoodDetailViewTapShop {
  675. DRShopDetailViewController *shopVC = [[DRShopDetailViewController alloc] init];
  676. shopVC.goodModel = self.goodModel;
  677. [self.navigationController pushViewController:shopVC animated:YES];
  678. }
  679. #pragma mark - webView
  680. - (void)webViewDidStartLoad:(UIWebView *)webView {
  681. [LoadingView dismiss];
  682. }
  683. - (void)webViewDidFinishLoad:(UIWebView *)webView {
  684. [LoadingView dismiss];
  685. CGSize contentSize = webView.scrollView.contentSize;
  686. CGSize viewSize = self.detailDescWebView.bounds.size;
  687. float rw = viewSize.width / contentSize.width;
  688. webView.scrollView.minimumZoomScale = rw;
  689. webView.scrollView.maximumZoomScale = rw;
  690. webView.scrollView.zoomScale = rw;
  691. }
  692. - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
  693. [LoadingView dismiss];
  694. }
  695. #pragma mark ------ wkWebView delegate ------
  696. // main frame的导航开始请求时调用
  697. - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation{
  698. }
  699. // 当main frame开始加载数据失败时,会回调
  700. - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error {
  701. }
  702. //当main frame导航完成时,会回调
  703. - (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation{
  704. // 页面加载完成之后调用
  705. }
  706. #pragma mark - tableView
  707. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  708. return 1;
  709. }
  710. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  711. NSArray *pics = self.goodModel.detail_pic;
  712. return pics.count;
  713. }
  714. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  715. DRDetailImgModel *model = self.goodModel.detail_pic[indexPath.row];
  716. CGFloat imgScale = model.width.floatValue/model.height.floatValue;
  717. CGFloat imgH = SCREEN_WIDTH/imgScale;
  718. return imgH;
  719. }
  720. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  721. DRGoodDetailImageCell *cell = [DRGoodDetailImageCell cellWithTableView:tableView];
  722. cell.model = self.goodModel.detail_pic[indexPath.row];
  723. return cell;
  724. }
  725. #pragma mark - collectionView
  726. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  727. return 1;
  728. }
  729. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  730. return self.goodSimilarArr.count;
  731. }
  732. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  733. DRChildGoodModel *model = self.goodSimilarArr[indexPath.row];
  734. CGFloat width = (SCREEN_WIDTH-5)/2;
  735. CGFloat height = width + 112;
  736. if (model.commission_price.length > 0) {
  737. }
  738. return CGSizeMake(width, height);
  739. }
  740. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  741. DRGoodCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
  742. cell.backgroundColor = [UIColor whiteColor];
  743. cell.backgroundView.backgroundColor = [UIColor whiteColor];
  744. cell.contentView.backgroundColor = [UIColor whiteColor];
  745. DRChildGoodModel *model = self.goodSimilarArr[indexPath.item];
  746. cell.model = model;
  747. return cell;
  748. }
  749. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
  750. UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionViewHeader forIndexPath:indexPath];
  751. CALayer *lineGapLayer = [CALayer layer];
  752. lineGapLayer.frame = CGRectMake(0, 0, kScreenWidth, FITSIZE(5));
  753. lineGapLayer.backgroundColor = [UIColor YHColorWithHex:0xf5f4f4].CGColor;
  754. [view.layer addSublayer:lineGapLayer];
  755. UILabel *lineGapLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, kScreenWidth, FITSIZE(40))];
  756. lineGapLabel.backgroundColor = [UIColor whiteColor];
  757. lineGapLabel.textColor = [UIColor YHColorWithHex:0x222222];
  758. lineGapLabel.font = [UIFont systemFontOfSize:FITSIZE(13)];
  759. lineGapLabel.text = @"相关推荐";
  760. lineGapLabel.textAlignment = NSTextAlignmentCenter;
  761. [view addSubview:lineGapLabel];
  762. return view;
  763. }
  764. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
  765. return CGSizeMake(kScreenWidth, FITSIZE(45));
  766. }
  767. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  768. DRChildGoodModel *model = self.goodSimilarArr[indexPath.item];
  769. //详情
  770. DRGoodDetailViewController *detailVC = [[DRGoodDetailViewController alloc] init];
  771. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithChildModel:model];
  772. detailVC.requestModel = requestModel;
  773. DREventModel *evevtModel = [[DREventModel alloc] initWithOrigin:@"0" category_id:@"0" source:goodsDetailRecommendAction];
  774. detailVC.eventModel = evevtModel;
  775. [self.navigationController pushViewController:detailVC animated:YES];
  776. }
  777. #pragma mark - lazy
  778. - (UITableView *)tableView {
  779. if (!_tableView) {
  780. _tableView = [[DRTableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight-FITSIZE(55)-BottomMargin) style:UITableViewStylePlain];
  781. _tableView.rowHeight = 0.1;
  782. _tableView.estimatedRowHeight = 0;
  783. _tableView.estimatedSectionHeaderHeight = 0;
  784. _tableView.estimatedSectionFooterHeight = 0;
  785. _tableView.delegate = self;
  786. _tableView.dataSource = self;
  787. [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
  788. if (@available(iOS 11.0, *)) {
  789. _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  790. }
  791. }
  792. return _tableView;
  793. }
  794. - (UICollectionView *)collectionView {
  795. if (!_collectionView) {
  796. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  797. flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
  798. flowLayout.minimumLineSpacing = FITSIZE(5);
  799. flowLayout.minimumInteritemSpacing = FITSIZE(0);
  800. _collectionView = [[DRCollectionView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, GoodSimilarViewHeight) collectionViewLayout:flowLayout];
  801. _collectionView.scrollEnabled = NO;
  802. _collectionView.bounces = NO;
  803. _collectionView.showsVerticalScrollIndicator = NO;
  804. _collectionView.delegate = self;
  805. _collectionView.dataSource = self;
  806. [_collectionView registerClass:[DRGoodCollectionCell class] forCellWithReuseIdentifier:cellID];
  807. [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionViewHeader];
  808. }
  809. return _collectionView;
  810. }
  811. - (SGPageTitleView *)topTitleView {
  812. if (!_topTitleView) {
  813. SGPageTitleViewConfigure *configure = [SGPageTitleViewConfigure pageTitleViewConfigure];
  814. configure.titleFont = [UIFont systemFontOfSize:FITSIZE(14)];
  815. configure.titleColor = [UIColor YHColorWithHex:0x222222];
  816. configure.titleSelectedColor = [UIColor YHColorWithHex:0xff2420];
  817. configure.indicatorColor = [UIColor YHColorWithHex:0xff2420];
  818. configure.indicatorScrollStyle = SGIndicatorScrollStyleHalf;
  819. _topTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(kScreenWidth/2-FITSIZE(100), KStatusBarHeight, FITSIZE(200), 44) delegate:self titleNames:@[@"宝贝",@"详情",@"推荐"] configure:configure];
  820. _topTitleView.backgroundColor = [UIColor clearColor];
  821. _topTitleView.alpha = 0.0;
  822. _topTitleView.isNeedBounces = NO;
  823. _topTitleView.isTitleGradientEffect = NO;
  824. _topTitleView.isOpenTitleTextZoom = YES;
  825. _topTitleView.isShowBottomSeparator = NO;
  826. }
  827. return _topTitleView;
  828. }
  829. - (NSMutableArray *)bannerImgArray {
  830. if (!_bannerImgArray) {
  831. _bannerImgArray = [NSMutableArray array];
  832. }
  833. return _bannerImgArray;
  834. }
  835. - (void)loadUserInfo {
  836. [DRCacheHttp post:UserInfo params:nil success:^(id json, BOOL isCache) {
  837. //讲将数据保存到本地单例
  838. [DRUserInfoManager shareManager].userInfoDic =json;
  839. } failure:^(NSError *error) {
  840. }];
  841. }
  842. @end