猎豆优选

LDGoodDetailViewController.m 46KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226
  1. //
  2. // LDGoodDetailViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by xiaoxi on 2018/1/22.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "LDGoodDetailViewController.h"
  9. #import <WebKit/WebKit.h>
  10. #import "LDDetailLoginView.h"
  11. #import <AlibabaAuthSDK/ALBBSDK.h>
  12. #import <AlibabaAuthSDK/ALBBSession.h>
  13. #import "LDSearchCoupleWebViewController.h"
  14. #import "LDGoodDetailRequestViewModel.h"
  15. #import "SDCycleScrollView.h"
  16. #import "LDTableView.h"
  17. #import "LDAdWebViewController.h"
  18. #import "LDPrivilegeReferralViewController.h"
  19. #import "LDGoodDetailBottomView.h"
  20. #import "LDGoodDetailView.h"
  21. #import "LDCollectionView.h"
  22. #import "LDGoodCollectionCell.h"
  23. #import "LDShopDetailViewController.h"
  24. #import <AlibcTradeSDK/AlibcTradeSDK.h>
  25. #import "LDHistoryTool.h"
  26. #import "LDHistoryModel.h"
  27. #import "LDGoodListViewController.h"
  28. #import "LDLoginViewController.h"
  29. #import "LDAdWebViewController.h"
  30. #import "LDEventTool.h"
  31. #import "LDGotoDetailView.h"
  32. #import "SDPhotoBrowser.h"
  33. #import "LDShareGoodsViewController.h"
  34. #import "LDWebDetailController.h"
  35. #import "LDLinkFansController.h"
  36. #import "LDPrivilegeReferralViewController.h"
  37. #import "LDModuleView.h"
  38. #import "LDDetailHeaderTitle.h"
  39. #import "CCAlertShowView.h"
  40. #import "LDShareImgPopView.h"
  41. #import "LDShopInfoView.h"
  42. #import "LDDetailGuideView.h"
  43. #import "PhoneLoginManager.h"
  44. #import "LDGoodDetailImageCell.h"
  45. #import "LDDetailImgModel.h"
  46. #import "LDShareGoodViewController.h"
  47. #import "LDShareRequestViewModel.h"
  48. #import "LDShareInfoModel.h"
  49. #import "LDTaobaoWebAuthorController.h"
  50. #import "LDSearchCoupleWebViewController.h"
  51. #import "LDDCCyleTipView.h"
  52. #define GoodSimilarViewHeight ((self.goodSimilarArr.count-1)/2+1)*FITSIZE(292)+FITSIZE(45)
  53. static CGFloat detailDescWebHeight = 0.1;
  54. static NSInteger const detailDescWebTag = 111;
  55. static NSString *const cellID = @"LDGoodCollectionCell";
  56. static NSString *const collectionViewHeader = @"collectionViewHeader";
  57. @interface LDGoodDetailViewController ()
  58. <
  59. SDCycleScrollViewDelegate,
  60. UITableViewDelegate,
  61. UITableViewDataSource,
  62. YHGoodDetailBottomViewDelegate,
  63. YHGoodDetailViewDelegate,
  64. UIWebViewDelegate,
  65. UICollectionViewDelegate,
  66. UICollectionViewDataSource,
  67. UICollectionViewDelegateFlowLayout,
  68. SGPageTitleViewDelegate,
  69. UIWebViewDelegate,
  70. WKNavigationDelegate,
  71. SDPhotoBrowserDelegate,
  72. LDDetailGuideViewDelegate
  73. >
  74. {
  75. NSInteger _page;
  76. ActivityIndicatorView *_indicatorView;
  77. BOOL isDealloc;
  78. NSString *shopjsonstr;
  79. LDDCCyleTipView *redTipView;//红包导图
  80. UIButton *redBtn;//有红包时候
  81. CGFloat _lastOffY;
  82. }
  83. @property (nonatomic, strong) LDGoodDetailModel *goodModel;
  84. @property (nonatomic, strong) LDShareInfoModel *shareModel;
  85. @property (nonatomic, strong) UITableView *tableView;
  86. @property (nonatomic, strong) WKWebView *detailDescWebView;
  87. @property (nonatomic, strong) UIView *tableHeaderView;
  88. @property (nonatomic, strong) LDGoodDetailView *goodDetailView;
  89. @property (nonatomic, strong) SDCycleScrollView *cycleView;
  90. @property (nonatomic, strong) NSArray *goodSimilarArr;
  91. @property (nonatomic, strong) UICollectionView *collectionView;
  92. @property (nonatomic, strong) UIButton *backButton;
  93. @property (nonatomic, strong) SGPageTitleView *topTitleView;
  94. @property (nonatomic, strong) YYFPSLabel *fpsLabel;
  95. @property (nonatomic, strong) LDGoodDetailBottomView *goodBottomView;
  96. @property (nonatomic, strong) NSNumber *flag;//用户等级 1 会员 2 超级会员 3 运营商
  97. @property (nonatomic, strong) LDModuleView *moduleView;
  98. @property (nonatomic, strong) LDShopInfoView *shopInfoView;
  99. @property (nonatomic, strong) LDGoodDetailBottomView *bottomView;
  100. @property (nonatomic, strong) UIView *moduleBg;
  101. @property (nonatomic, strong) LDDetailHeaderTitle *detailHeader;
  102. @property (nonatomic, strong) LDDetailGuideView *guideView;
  103. @property (nonatomic, strong) NSMutableArray *bannerImgArray;
  104. //登录引导
  105. @property (nonatomic, strong)LDDetailLoginView *loginView;
  106. @end
  107. @implementation LDGoodDetailViewController
  108. - (void)dealloc {
  109. @try{
  110. [self.detailDescWebView removeObserver:self forKeyPath:@"scrollView.contentSize"];
  111. }@catch (NSException *exception) {
  112. }
  113. NSLog(@"释放了------------");
  114. }
  115. - (void)viewWillDisappear:(BOOL)animated {
  116. [super viewWillDisappear:animated];
  117. [LoadingView dismiss];
  118. }
  119. - (void)viewDidLoad {
  120. [super viewDidLoad];
  121. [self initNavBar];
  122. [self initSubviews];
  123. // [self initHUD];
  124. [self request];
  125. [self requestCount];
  126. [self loadUserInfo];
  127. [self inittipRedView];
  128. }
  129. #pragma mark----红包按钮
  130. -(void)inittipRedView
  131. {
  132. if (![[PhoneLoginManager shareManager].showPhoneBtn boolValue]) {//显示手机号登陆。过审,不显示红包按钮
  133. redBtn =[[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-200, SCREEN_HEIGHT/2-50, 200, 71)];
  134. [redBtn setBackgroundImage:[UIImage imageNamed:@"detail_redtip"] forState:UIControlStateNormal];
  135. [self.view addSubview:redBtn];
  136. [redBtn addTarget:self action:@selector(clickRedView) forControlEvents:UIControlEventTouchUpInside];
  137. redBtn.adjustsImageWhenHighlighted=NO;
  138. redBtn.hidden=YES;
  139. UILabel *label =[[UILabel alloc]initWithFrame:CGRectMake(10, 10, redBtn.size.width-90, redBtn.size.height-20)];
  140. label.numberOfLines=2;
  141. label.textColor=[UIColor whiteColor];
  142. label.font=[UIFont systemFontOfSize:14];
  143. [redBtn addSubview:label];
  144. label.tag= 1111;
  145. redTipView=[[LDDCCyleTipView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  146. redTipView.backgroundColor=[UIColor colorWithRed:0 green:0 blue:0 alpha:0.6];
  147. redTipView.hidden=YES;
  148. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImageView)];
  149. [redTipView addGestureRecognizer:tap];
  150. redTipView.userInteractionEnabled=YES;
  151. [self.view addSubview:redTipView];
  152. self.view.userInteractionEnabled = YES;
  153. }
  154. }
  155. -(void)tapImageView
  156. {
  157. [UIView animateWithDuration:0.5 animations:^{
  158. redTipView.hidden=YES;
  159. }];
  160. }
  161. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
  162. {
  163. [UIView animateWithDuration:0.5 animations:^{
  164. redTipView.hidden=YES;
  165. }];
  166. }
  167. #pragma mark---红包提示
  168. -(void)clickRedView
  169. {
  170. [UIView animateWithDuration:0.5 animations:^{
  171. redTipView.hidden=NO;
  172. }];
  173. }
  174. -(void)viewDidAppear:(BOOL)animated{
  175. [super viewDidAppear:animated];
  176. }
  177. - (void)configParam {
  178. _page = 1;
  179. }
  180. - (void)requestCount {
  181. [LDEventTool eventWithEventType:0 origin:self.eventModel.origin category_id:self.eventModel.category_id goods_id:self.requestModel.goods_id source:self.eventModel.source];
  182. }
  183. - (void)viewWillAppear:(BOOL)animated {
  184. [super viewWillAppear:animated];
  185. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
  186. self.navigationController.navigationBar.hidden = YES;
  187. self.bottomView.goodModel=self.goodModel;
  188. }
  189. - (void)didReceiveMemoryWarning {
  190. [super didReceiveMemoryWarning];
  191. }
  192. - (void)initNavBar {
  193. [self.navigationBar setNavightionBarBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:0.0]];
  194. UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
  195. leftButton.frame = CGRectMake(0, 0, FITSIZE(22), FITSIZE(22));
  196. leftButton.backgroundColor = [UIColor clearColor];
  197. [leftButton setImage:[UIImage imageNamed:@"detail_back_g"] forState:UIControlStateNormal];
  198. [leftButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  199. self.backButton = leftButton;
  200. [self.navigationBar setCustomLeftButtons:@[leftButton]];
  201. [self.navigationBar addSubview:self.topTitleView];
  202. }
  203. #pragma mark---初始化值
  204. -(void)initValues
  205. {
  206. LDGoodDetailModel *mndoels=[[LDGoodDetailModel alloc] init];
  207. [mndoels changeDetailRequestModel:_requestModel];
  208. self.goodDetailView.goodModel =mndoels;
  209. self.guideView.model = mndoels;
  210. LDShopModel *shopmodel =[[LDShopModel alloc]init];
  211. shopmodel.title= _requestModel.shop_title;
  212. [self.shopInfoView setShopInfo:shopmodel];
  213. }
  214. - (void)initSubviews {
  215. __weak typeof(self) weakSelf = self;
  216. //底部栏
  217. LDGoodDetailBottomView *bottomView = [[LDGoodDetailBottomView alloc] initWithFrame:CGRectMake(0, kScreenHeight-FITSIZE(55)-BottomMargin, kScreenWidth, FITSIZE(55))];
  218. bottomView.delegate = self;
  219. self.bottomView = bottomView;
  220. [self.view addSubview:bottomView];
  221. self.goodBottomView = bottomView;
  222. //轮播
  223. if (self.requestModel.img) {
  224. [self.bannerImgArray addObject:self.requestModel.img];
  225. }
  226. SDCycleScrollView *cycleView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, FITSIZE(375), FITSIZE(375)) delegate:self placeholderImage:[UIImage imageNamed:@""]];
  227. // cycleView.pageDotImage = [UIImage imageNamed:@"page_nor"];
  228. cycleView.imageURLStringsGroup= self.bannerImgArray;
  229. self.cycleView = cycleView;
  230. //商品信息
  231. self.goodDetailView = [[LDGoodDetailView alloc] initWithFrame:CGRectMake(0, cycleView.height, kScreenWidth, FITSIZE(110))];
  232. self.goodDetailView.delegate = self;
  233. //领券模块
  234. LDDetailGuideView *guide = [[LDDetailGuideView alloc] initWithFrame:CGRectMake(0, self.goodDetailView.bottom, SCREEN_WIDTH, FITSIZE(120))];
  235. self.guideView = guide;
  236. self.guideView.delegate=self;
  237. guide.tapAction = ^{
  238. if (![AccountTool isLogin]) {
  239. LDNewLoginVC *login = [[LDNewLoginVC alloc] init];
  240. login.modalPresentationStyle = UIModalPresentationFullScreen;
  241. [weakSelf presentViewController:login animated:YES completion:nil];
  242. return ;
  243. }
  244. LDPrivilegeReferralViewController *Privilege = [[LDPrivilegeReferralViewController alloc] init];
  245. [weakSelf.navigationController pushViewController:Privilege animated:YES];
  246. };
  247. if ([[PhoneLoginManager shareManager].showPhoneBtn boolValue]) {
  248. guide.height = 0;
  249. }
  250. self.navigationItem.hidesBackButton = YES;
  251. //店铺信息
  252. self.shopInfoView = [[LDShopInfoView alloc] initWithFrame:CGRectMake(0, guide.bottom+5, SCREEN_WIDTH, FITSIZE(68))];
  253. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapShopInfo)];
  254. [self.shopInfoView addGestureRecognizer:tap];
  255. //推荐模块
  256. UIView *moduleBg = [[UIView alloc] initWithFrame:CGRectMake(0, self.shopInfoView.bottom+5, SCREEN_WIDTH, Fitsize(202))];
  257. self.moduleBg = moduleBg;
  258. LDDetailHeaderTitle *headerTitle = [[LDDetailHeaderTitle alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, Fitsize(34)) title:@"相关推荐"];
  259. [moduleBg addSubview:headerTitle];
  260. self.moduleView = [[LDModuleView alloc] initWithFrame:CGRectMake(0, headerTitle.height, SCREEN_WIDTH, moduleBg.height-Fitsize(34))];
  261. self.moduleView.didSelectedGood = ^(LDChildGoodModel *model) {
  262. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithChildModel:model];
  263. LDGoodDetailViewController *detail = [[LDGoodDetailViewController alloc] init];
  264. detail.requestModel = requestModel;
  265. LDEventModel *evevtModel = [[LDEventModel alloc] initWithOrigin:model.origin category_id:@"0" source:goodsDetailTopRecommendAction];
  266. detail.eventModel = evevtModel;
  267. [weakSelf.navigationController pushViewController:detail animated:YES];
  268. [MobClick event:GoodsDetailRecommend];
  269. };
  270. [moduleBg addSubview:self.moduleView];
  271. self.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, moduleBg.bottom+5)];
  272. //详情webview
  273. LDDetailHeaderTitle *detailHeader = [[LDDetailHeaderTitle alloc] initWithFrame:CGRectMake(0, moduleBg.bottom+5, SCREEN_WIDTH, Fitsize(34)) title:@"宝贝详情"];
  274. self.detailHeader = detailHeader;
  275. _detailDescWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0, detailHeader.bottom, kScreenWidth, 0)];
  276. _detailDescWebView.tag = detailDescWebTag;
  277. _detailDescWebView.navigationDelegate = self;
  278. _detailDescWebView.scrollView.scrollEnabled = NO;
  279. // _detailDescWebView.scalesPageToFit = YES;
  280. [self.tableHeaderView addSubview:cycleView];
  281. [self.tableHeaderView addSubview:self.goodDetailView];
  282. [self.tableHeaderView addSubview:guide];
  283. [self.tableHeaderView addSubview:self.shopInfoView];
  284. [self.tableHeaderView addSubview:moduleBg];
  285. [self.tableHeaderView addSubview:detailHeader];
  286. [self.tableHeaderView addSubview:_detailDescWebView];
  287. self.tableView.tableHeaderView = self.tableHeaderView;
  288. [self.view addSubview:self.tableView];
  289. [self.view bringSubviewToFront:self.navigationBar];
  290. //添加监听
  291. @try{
  292. [self.detailDescWebView removeObserver:self forKeyPath:@"scrollView.contentSize"];
  293. }@catch (NSException *exception) {
  294. }
  295. [_detailDescWebView addObserver:self forKeyPath:@"scrollView.contentSize" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];
  296. [self.view bringSubviewToFront:self.navigationBar];
  297. [LDGoodDetailRequestViewModel requestGoodSimilarParamGoods_id:self.requestModel.goods_id page:@(_page) success:^(NSArray *array) {
  298. if (array.count > 0) {
  299. self.goodSimilarArr = array;
  300. self.tableView.tableFooterView = self.collectionView;
  301. }
  302. } failure:^(NSError *error) {
  303. }];
  304. [self initValues];
  305. }
  306. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
  307. if ([keyPath isEqualToString:@"scrollView.contentSize"]) {
  308. if (self.goodModel.detail_pic.count > 0) {
  309. self.detailDescWebView.height = 0;
  310. return;
  311. }
  312. id height = [change valueForKey:NSKeyValueChangeNewKey];
  313. CGSize size;
  314. [(NSValue *)height getValue:&size];
  315. if (detailDescWebHeight != size.height) {
  316. detailDescWebHeight = size.height;
  317. self.detailDescWebView.height = size.height;
  318. self.tableHeaderView.height = self.detailDescWebView.top+size.height;
  319. self.tableView.tableHeaderView = self.tableHeaderView;
  320. }
  321. }
  322. }
  323. - (void)backAction {
  324. [self.navigationController popViewControllerAnimated:YES];
  325. }
  326. #pragma mark - HUD
  327. - (void)initHUD {
  328. ActivityIndicatorView *indicatorView = [ActivityIndicatorView showInView:self.view frame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  329. _indicatorView = indicatorView;
  330. [_indicatorView startAnimating];
  331. }
  332. #pragma mark---图片点击
  333. -(void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
  334. {
  335. SDPhotoBrowser *browser = [[SDPhotoBrowser alloc] init];
  336. // browser.sourceImagesContainerView = self.cycleView;
  337. browser.currentImageIndex = index;
  338. browser.delegate = self;
  339. browser.imageCount = self.bannerImgArray.count;
  340. [browser show];
  341. }
  342. #pragma mark - SDPhotoBrowserDelegate
  343. - (NSURL *)photoBrowser:(SDPhotoBrowser *)browser highQualityImageURLForIndex:(NSInteger)index
  344. {
  345. NSString *imageName = self.bannerImgArray[index];
  346. return [NSURL URLWithString:imageName];
  347. }
  348. - (UIImage *)photoBrowser:(SDPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index
  349. {
  350. return [UIImage imageNamed:@"placeHolder"];
  351. }
  352. #pragma mark - request
  353. - (void)request {
  354. [LDGoodDetailRequestViewModel requestGoodDetailParamGoods_id:self.requestModel success:^(LDGoodDetailModel *model,NSDictionary *dic) {
  355. if (model) {
  356. self.goodModel = model;
  357. [self requestUserIdentity];
  358. [self requestThressRecommon];
  359. [self saveGoodsInfoAsBrowserHistoryWith:dic];
  360. if (model.commission_price.length<= 0 && model.is_coupon.integerValue == 0 &&model.red_active_status.integerValue == 0) {//红包、券、返都没有的时候
  361. self.guideView.height = 0;
  362. }else{
  363. if (model.red_active_status.integerValue == 0 ) {//判断是否显示红包按钮
  364. redBtn.hidden = YES;
  365. }else{
  366. UILabel *labels =[redBtn viewWithTag:1111];
  367. if (model.red_active_money.floatValue != 0) {
  368. labels.text=[NSString stringWithFormat:@"下单后记得回来领取%@元红包哦",model.red_active_money];
  369. }
  370. redBtn.hidden=NO;
  371. }
  372. if (![AccountTool isLogin]) {//未登录,不显示返佣
  373. if ( model.is_coupon.integerValue ==0 && model.red_active_status.integerValue == 0) {//其中都为0的时候
  374. self.guideView.height =0;
  375. }else{
  376. self.guideView.height =FITSIZE(60);
  377. }
  378. }else{
  379. if (model.commission_price.length<=0 || model.is_coupon.integerValue ==0 || model.red_active_status.integerValue == 0) {//其中y至少有一个为0的时候
  380. self.guideView.height =FITSIZE(60);
  381. }
  382. }
  383. self.guideView.model=model;
  384. }
  385. //显示。过审不显示红包领券
  386. if ([[PhoneLoginManager shareManager].showPhoneBtn boolValue]) {
  387. self.guideView.height = 0;
  388. }
  389. self.shopInfoView.frame=CGRectMake(0, self.guideView.bottom+5, SCREEN_WIDTH, Fitsize(68));
  390. self.moduleBg.frame=CGRectMake(0, self.shopInfoView.bottom+5, SCREEN_WIDTH, Fitsize(202));
  391. self.moduleView.frame=CGRectMake(0, FITSIZE(34), SCREEN_WIDTH, self.moduleBg.height-Fitsize(34));
  392. self.tableHeaderView.frame=CGRectMake(0, 0, SCREEN_WIDTH, self.moduleBg.bottom+5);
  393. self.detailHeader.frame=CGRectMake(0, self.moduleBg.bottom+5, SCREEN_WIDTH, Fitsize(34));
  394. self.detailDescWebView.frame=CGRectMake(0, self.detailHeader.bottom, kScreenWidth, 0);
  395. [self setGoodInfoForHeader];
  396. self.bottomView.goodModel=self.goodModel;
  397. }
  398. [_indicatorView stopAnimating];
  399. [self loadshopJsonStr];
  400. [self.tableView reloadData];
  401. } failure:^(NSError *error) {
  402. [_indicatorView stopAnimating];
  403. [MBProgressHUD showMessage:@"加载失败"];
  404. }];
  405. }
  406. - (void)setGoodInfoForHeader {
  407. self.bottomView.goodModel = self.goodModel;
  408. [self.bannerImgArray addObjectsFromArray:self.goodModel.small_img];
  409. self.cycleView.imageURLStringsGroup= self.bannerImgArray;
  410. self.goodDetailView.goodModel = self.goodModel;
  411. LDShopModel *model = self.goodModel.shop;
  412. CGFloat shopViewHeight = model==nil?0:Fitsize(68);
  413. [self.shopInfoView setShopInfo:model];
  414. self.shopInfoView.height = shopViewHeight;
  415. CGFloat topMargin = shopViewHeight>0?5:0;
  416. self.shopInfoView.y = self.guideView.bottom +topMargin;
  417. self.moduleBg.y = self.shopInfoView.bottom+5;
  418. self.detailHeader.y = self.moduleBg.bottom+5;
  419. _detailDescWebView.y = self.detailHeader.bottom;
  420. NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.goodModel.detail_url]];
  421. NSArray *picList = self.goodModel.detail_pic;
  422. if (picList.count == 0) {
  423. // if (@available(iOS 9.0, *)) {
  424. // NSArray * types=@[WKWebsiteDataTypeCookies,WKWebsiteDataTypeLocalStorage];
  425. //
  426. // NSSet *websiteDataTypes= [NSSet setWithArray:types];
  427. // NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0];
  428. //
  429. // [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:^{
  430. //
  431. // }];
  432. // }
  433. // NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.url]];
  434. [_detailDescWebView loadRequest:request];
  435. }
  436. self.tableHeaderView.height = self.detailDescWebView.bottom;
  437. self.tableView.tableHeaderView = self.tableHeaderView;
  438. }
  439. /**
  440. 加载上部相关推荐
  441. */
  442. - (void)requestThressRecommon {
  443. NSString *url = [NSString stringWithFormat:@"%@/api/v2/goods/recommendtop",BaseURL];
  444. NSDictionary *para = @{@"goods_id":self.requestModel.goods_id};
  445. [LDHttp post:url params:para success:^(id json) {
  446. NSArray *list = [NSArray yy_modelArrayWithClass:[LDChildGoodModel class] json:json[@"data"]];
  447. [self.moduleView setRecommonData:list];
  448. } failure:^(NSError *error) {
  449. }];
  450. }
  451. - (void)requestUserIdentity {
  452. NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/userIdentity",BaseURL];
  453. [LDHttp post:url params:nil success:^(id json) {
  454. if (json[@"data"]) {
  455. NSNumber *flag=json[@"data"][@"flag"];
  456. self.flag=flag;
  457. }
  458. } failure:^(NSError *error) {
  459. self.flag=0;
  460. }];
  461. }
  462. /**
  463. 保存浏览记录
  464. */
  465. - (void)saveGoodsInfoAsBrowserHistoryWith:(NSDictionary *)dic {
  466. if (![AccountTool isLogin]) {
  467. return;
  468. }
  469. NSString *urlString = [NSString stringWithFormat:@"%@/api/v2/brower/record", BaseURL];
  470. NSDictionary *para = [self.requestModel modelToDictionary];
  471. [LDHttp post:urlString params:para success:^(id json) {
  472. } failure:^(NSError *error) {
  473. }];
  474. }
  475. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  476. CGFloat offsetY = scrollView.contentOffset.y;
  477. // CGFloat standard = FITSIZE(734)-NavBarHeight;
  478. CGFloat standard = self.cycleView.height-NavBarHeight;
  479. if (offsetY > -standard && offsetY < standard) {
  480. [self.navigationBar setNavightionBarBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:offsetY/standard]];
  481. self.topTitleView.alpha = offsetY/standard;
  482. if (offsetY/standard < 0.5) {
  483. [self.backButton setImage:[UIImage imageNamed:@"detail_back_g"] forState:UIControlStateNormal];
  484. self.backButton.alpha = 1-offsetY/standard;
  485. }
  486. else {
  487. [self.backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
  488. self.backButton.alpha = offsetY/standard;
  489. }
  490. }
  491. else {
  492. }
  493. if (offsetY >= standard) {
  494. [self.navigationBar setShowNavigationBarBottomLine:YES];
  495. } else {
  496. [self.navigationBar setShowNavigationBarBottomLine:NO];
  497. }
  498. //设置导航栏头部seg下标
  499. CGFloat indexOneHeight = self.moduleView.superview.bottom+5-NavBarHeight;
  500. CGFloat indexTwoHeight;
  501. if (self.goodModel.detail_pic.count > 0) {
  502. //详情为图片数组时
  503. CGRect senctionHeight = [self.tableView rectForSection:0];
  504. indexTwoHeight = senctionHeight.size.height+self.tableHeaderView.height-NavBarHeight;
  505. }else {
  506. //详情为web
  507. indexTwoHeight = self.tableHeaderView.height-NavBarHeight;
  508. }
  509. if (offsetY < indexOneHeight) {
  510. self.topTitleView.newSelectedIndex = 0;
  511. }else if (offsetY>=indexOneHeight && offsetY<indexTwoHeight){
  512. self.topTitleView.newSelectedIndex = 1;
  513. }else {
  514. self.topTitleView.newSelectedIndex = 2;
  515. }
  516. //悬浮tip移动动画
  517. if (offsetY > SCREEN_WIDTH) {
  518. CGFloat changeValue = offsetY - _lastOffY;
  519. redBtn.left += changeValue*0.5;
  520. if (redBtn.left > SCREEN_WIDTH-10) {
  521. redBtn.left = SCREEN_WIDTH-10;
  522. }
  523. if (redBtn.left < SCREEN_WIDTH-200) {
  524. redBtn.left = SCREEN_WIDTH-200;
  525. }
  526. }
  527. _lastOffY = offsetY;
  528. }
  529. #pragma mark--- 特权和购买
  530. -(void)commisionClickPage
  531. {
  532. LDPrivilegeReferralViewController *Privilege = [[LDPrivilegeReferralViewController alloc] init];
  533. [self.navigationController pushViewController:Privilege animated:YES];
  534. }
  535. -(void)goBuyWithModel:(LDGoodDetailModel *)model
  536. {
  537. [self getTicketTaoBaoUrl];
  538. }
  539. #pragma mark-红包
  540. -(void)redClickPage
  541. {
  542. if (![AccountTool isLogin]) {
  543. LDNewLoginVC *login = [[LDNewLoginVC alloc] init];
  544. login.modalPresentationStyle = UIModalPresentationFullScreen;
  545. [self presentViewController:login animated:YES completion:nil];
  546. return;
  547. }
  548. LDAdWebViewController *web = [[LDAdWebViewController alloc] init];
  549. web.url = self.goodModel.red_url;
  550. [self.navigationController pushViewController:web animated:YES];
  551. }
  552. #pragma mark - topTitleViewDelegate
  553. - (void)pageTitleView:(SGPageTitleView *)pageTitleView selectedIndex:(NSInteger)selectedIndex {
  554. CGFloat indexOneHeight = self.moduleView.superview.bottom+5-NavBarHeight;
  555. CGFloat indexTwoHeight;
  556. if (self.goodModel.detail_pic.count > 0) {
  557. CGRect senctionHeight = [self.tableView rectForSection:0];
  558. indexTwoHeight = senctionHeight.size.height+self.tableHeaderView.height-NavBarHeight;
  559. }else {
  560. indexTwoHeight = self.tableHeaderView.height-NavBarHeight;
  561. }
  562. switch (selectedIndex) {
  563. case 0:
  564. [self.tableView setContentOffset:CGPointMake(0, 0) animated:NO];
  565. break;
  566. case 1:
  567. [self.tableView setContentOffset:CGPointMake(0, indexOneHeight) animated:NO];
  568. break;
  569. case 2:
  570. [self.tableView setContentOffset:CGPointMake(0, indexTwoHeight) animated:NO];
  571. break;
  572. default:
  573. break;
  574. }
  575. }
  576. #pragma mark - goodDetailBottomViewDelegate
  577. /**
  578. 分享
  579. */
  580. - (void)yh_GoodDetailBottomViewClickCommissionButton {
  581. if ([AccountTool isLogin]) {
  582. NSString *url = [NSString stringWithFormat:@"%@/api/v2/relationAuth/isAuthOrNo",BaseURL];
  583. [LDHttp post:url params:nil success:^(id json) {
  584. NSNumber *flag = json[@"flag"];
  585. if (flag.boolValue) {
  586. //已授权
  587. LDShareGoodViewController *shareVc = [[LDShareGoodViewController alloc] init];
  588. [LoadingView show];
  589. [LDShareRequestViewModel requestGoodDetailParamGoods_id:self.requestModel success:^(LDShareInfoModel * _Nonnull model, NSDictionary * _Nonnull dic) {
  590. [LoadingView dismiss];
  591. self.shareModel = model;
  592. shareVc.goodModel = self.shareModel;
  593. [self.navigationController pushViewController:shareVc animated:YES];
  594. } failure:^(NSError * _Nonnull error) {
  595. [LoadingView dismiss];
  596. }];
  597. }else {
  598. //未授权 去授权
  599. [LDTaobaoAuthorTool taobaoAuthorManager:json[@"auth_url"] type:@"1" currentVc:self];
  600. }
  601. } failure:^(NSError *error) {
  602. }];
  603. }else{
  604. //没有登录。直接领取
  605. [self goBuy];
  606. }
  607. }
  608. -(void)yh_GoodDetailViewCollectButton{
  609. if ([AccountTool isLogin]) {
  610. [MobClick event:collection_count];
  611. NSString *coupon_start_time = [self.goodModel.is_coupon boolValue] ? self.requestModel.coupon_start_time : @"";
  612. NSString *coupon_end_time = [self.goodModel.is_coupon boolValue] ? self.requestModel.coupon_end_time : @"";
  613. NSNumber *is_coupon = self.goodModel.is_coupon;
  614. NSString *coupon_price = self.goodModel.coupon_price;
  615. NSString *price = self.goodModel.price;
  616. NSString *discount_price = self.goodModel.discount_price;
  617. NSString *commission_rate = self.goodModel.commission_rate;
  618. if (!coupon_start_time) coupon_start_time = @"";
  619. if (!coupon_end_time) coupon_end_time = @"";
  620. if (!is_coupon) is_coupon = @0;
  621. if (!coupon_price) coupon_price = @"";
  622. if (!price) price = @"";
  623. if (!discount_price) discount_price = @"";
  624. if (!commission_rate) commission_rate = @"";
  625. NSDictionary *para = @{@"goods_id":self.goodModel.goods_id,
  626. @"is_coupon":is_coupon,
  627. @"coupon_price":coupon_price,
  628. @"price":price,
  629. @"discount_price":discount_price,
  630. @"commission_rate":commission_rate,
  631. @"coupon_end_time":coupon_end_time,
  632. @"coupon_start_time":coupon_start_time
  633. };
  634. [LDGoodDetailRequestViewModel requestCollectGoodParamGoods_id:para success:^(NSString *msg) {
  635. [SVProgressHUD showSuccessWithStatus:msg];
  636. if ([msg isEqualToString:@"收藏成功"]) {
  637. self.goodModel.is_favorites = @1;
  638. {
  639. self.goodDetailView.collectButton.selected = YES;
  640. }
  641. }else {
  642. self.goodModel.is_favorites = @0;
  643. {self.goodDetailView.collectButton.selected = NO;
  644. }
  645. }
  646. } failure:^(NSError *error) {
  647. }];
  648. }
  649. else {
  650. LDNewLoginVC *login = [[LDNewLoginVC alloc] init];
  651. login.loginSucc = ^{
  652. [self request];
  653. };
  654. login.modalPresentationStyle = UIModalPresentationFullScreen;
  655. [self.navigationController presentViewController:login animated:YES completion:nil];
  656. }
  657. }
  658. - (void)yh_GoodDetailBottomViewClickCollectButton {
  659. if ([AccountTool isLogin]) {
  660. [MobClick event:collection_count];
  661. NSString *coupon_start_time = [self.goodModel.is_coupon boolValue] ? self.requestModel.coupon_start_time : @"";
  662. NSString *coupon_end_time = [self.goodModel.is_coupon boolValue] ? self.requestModel.coupon_end_time : @"";
  663. NSNumber *is_coupon = self.goodModel.is_coupon;
  664. NSString *coupon_price = self.goodModel.coupon_price;
  665. NSString *price = self.goodModel.price;
  666. NSString *discount_price = self.goodModel.discount_price;
  667. NSString *commission_rate = self.goodModel.commission_rate;
  668. if (!coupon_start_time) coupon_start_time = @"";
  669. if (!coupon_end_time) coupon_end_time = @"";
  670. if (!is_coupon) is_coupon = @0;
  671. if (!coupon_price) coupon_price = @"";
  672. if (!price) price = @"";
  673. if (!discount_price) discount_price = @"";
  674. if (!commission_rate) commission_rate = @"";
  675. NSDictionary *para = @{@"goods_id":self.goodModel.goods_id,
  676. @"is_coupon":is_coupon,
  677. @"coupon_price":coupon_price,
  678. @"price":price,
  679. @"discount_price":discount_price,
  680. @"commission_rate":commission_rate,
  681. @"coupon_end_time":coupon_end_time,
  682. @"coupon_start_time":coupon_start_time
  683. };
  684. [LDGoodDetailRequestViewModel requestCollectGoodParamGoods_id:para success:^(NSString *msg) {
  685. [SVProgressHUD showSuccessWithStatus:msg];
  686. if ([msg isEqualToString:@"收藏成功"]) {
  687. self.goodModel.is_favorites = @1;
  688. // self.goodBottomView.collectButton.selected = YES;
  689. }
  690. else {
  691. self.goodModel.is_favorites = @0;
  692. // self.goodBottomView.collectButton.selected = NO;
  693. }
  694. } failure:^(NSError *error) {
  695. }];
  696. }
  697. else {
  698. LDNewLoginVC *login = [[LDNewLoginVC alloc] init];
  699. login.loginSucc = ^{
  700. [self request];
  701. };
  702. login.modalPresentationStyle = UIModalPresentationFullScreen;
  703. [self.navigationController presentViewController:login animated:YES completion:nil];
  704. }
  705. }
  706. /**
  707. 跳到淘宝领券
  708. */
  709. - (void)yh_GoodDetailBottomViewClickBuyButton {
  710. if (![AccountTool isLogin]) {
  711. LDNewLoginVC *login = [[LDNewLoginVC alloc] init];
  712. login.modalPresentationStyle = UIModalPresentationFullScreen;
  713. [self presentViewController:login animated:YES completion:nil];
  714. return;
  715. }
  716. [self getTicketTaoBaoUrl];
  717. }
  718. /**
  719. 获取商品链接
  720. */
  721. - (void)getTicketTaoBaoUrl {
  722. [MobClick event:pay_count];
  723. // if (![AccountTool account]) {
  724. // self.loginView.model=self.goodModel;
  725. // self.loginView.hidden=NO;
  726. // return;
  727. // }
  728. //
  729. [self goBuy];
  730. }
  731. -(void)goBuy{
  732. [LoadingView show];
  733. NSString *category_id = self.eventModel.category_id==nil?@"":self.eventModel.category_id;
  734. NSString *path = self.eventModel.source==nil?@"":self.eventModel.source;
  735. NSString *goods_id = self.requestModel.goods_id==nil?@"":self.requestModel.goods_id;
  736. NSString *is_coupon = self.requestModel.is_coupon==nil?@"":self.requestModel.is_coupon;
  737. NSString *coupon_id = self.requestModel.coupon_id==nil?@"":self.requestModel.coupon_id;
  738. NSDictionary *param = @{@"goods_id":goods_id,
  739. @"is_coupon":is_coupon,
  740. @"category_id":category_id,
  741. @"path":path,
  742. @"coupon_id":coupon_id,
  743. };
  744. NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/orderDown",BaseURL];
  745. [LDHttp post:url params:param success:^(id json) {
  746. NSNumber *flag = json[@"flag"];
  747. if ([AccountTool isLogin]) {
  748. if (!flag.boolValue) {
  749. //未授权 去授权
  750. [LDTaobaoAuthorTool taobaoAuthorManager:json[@"auth_url"] type:@"2" currentVc:self];
  751. }else {
  752. //已授权 直接购买
  753. [self jumpToTaobaoWithGoodsUrl:json[@"url"]];
  754. }
  755. }else {
  756. //未登录,直接购买
  757. [self jumpToTaobaoWithGoodsUrl:json[@"url"]];
  758. }
  759. [LoadingView dismiss];
  760. } failure:^(NSError *error) {
  761. [LoadingView dismiss];
  762. if (error) {
  763. [XHToast showCenterWithText:@"加载失败"];
  764. }
  765. }];
  766. }
  767. - (void)jumpToTaobaoWithGoodsUrl:(NSString *)url {
  768. [LDEventTool eventWithEventType:1 origin:self.eventModel.origin category_id:self.eventModel.category_id goods_id:self.requestModel.goods_id source:self.eventModel.source];
  769. id<AlibcTradePage> page = [AlibcTradePageFactory page:url];
  770. //淘客信息
  771. AlibcTradeTaokeParams *taoKeParams=[[AlibcTradeTaokeParams alloc] init];
  772. taoKeParams.pid = ALTK_PID; //
  773. //打开方式
  774. AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init];
  775. showParam.openType = AlibcOpenTypeNative;
  776. [[AlibcTradeSDK sharedInstance].tradeService openByUrl:url identity:@"trade" webView:nil parentController:self.navigationController showParams:showParam taoKeParams:taoKeParams trackParam:nil tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) {
  777. } tradeProcessFailedCallback:^(NSError * _Nullable error) {
  778. }];
  779. }
  780. /**
  781. 判断是否安装淘宝app
  782. */
  783. - (BOOL)isInstallTaobaoAPP {
  784. if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"taobao://"]]) {
  785. return YES;
  786. }else {
  787. return NO;
  788. }
  789. }
  790. #pragma mark - goodDetailViewDelegate
  791. - (void)yh_GoodDetailViewTapCoupon {
  792. [LDGoodDetailRequestViewModel requestTicketProcessParamGoods_id:self.requestModel.goods_id coupon_price:self.goodModel.coupon_price success:^(NSString *msg) {
  793. [self yh_GoodDetailBottomViewClickBuyButton];
  794. } failure:^(NSError *error) {
  795. }];
  796. }
  797. - (void)yh_GoodDetailViewTapShop {
  798. LDShopDetailViewController *shopVC = [[LDShopDetailViewController alloc] init];
  799. shopVC.goodModel = self.goodModel;
  800. [self.navigationController pushViewController:shopVC animated:YES];
  801. }
  802. #pragma mark - webView
  803. - (void)webViewDidStartLoad:(UIWebView *)webView {
  804. [LoadingView dismiss];
  805. }
  806. - (void)webViewDidFinishLoad:(UIWebView *)webView {
  807. [LoadingView dismiss];
  808. CGSize contentSize = webView.scrollView.contentSize;
  809. CGSize viewSize = self.detailDescWebView.bounds.size;
  810. float rw = viewSize.width / contentSize.width;
  811. webView.scrollView.minimumZoomScale = rw;
  812. webView.scrollView.maximumZoomScale = rw;
  813. webView.scrollView.zoomScale = rw;
  814. }
  815. - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
  816. [LoadingView dismiss];
  817. }
  818. #pragma mark ------ wkWebView delegate ------
  819. // main frame的导航开始请求时调用
  820. - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation{
  821. }
  822. // 当main frame开始加载数据失败时,会回调
  823. - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error {
  824. }
  825. //当main frame导航完成时,会回调
  826. - (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation{
  827. // 页面加载完成之后调用
  828. }
  829. #pragma mark - tableView
  830. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  831. return 1;
  832. }
  833. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  834. NSArray *pics = self.goodModel.detail_pic;
  835. return pics.count;
  836. }
  837. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  838. LDDetailImgModel *model = self.goodModel.detail_pic[indexPath.row];
  839. CGFloat imgScale = model.width.floatValue/model.height.floatValue;
  840. CGFloat imgH = SCREEN_WIDTH/imgScale;
  841. return imgH;
  842. }
  843. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  844. LDGoodDetailImageCell *cell = [LDGoodDetailImageCell cellWithTableView:tableView];
  845. cell.model = self.goodModel.detail_pic[indexPath.row];
  846. return cell;
  847. }
  848. #pragma mark - collectionView
  849. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  850. return 1;
  851. }
  852. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  853. return self.goodSimilarArr.count;
  854. }
  855. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  856. LDChildGoodModel *model = self.goodSimilarArr[indexPath.row];
  857. CGFloat width = (SCREEN_WIDTH-5)/2;
  858. CGFloat height = width + 135;
  859. if (![AccountTool isLogin] && ![model.red_active_status boolValue]) {
  860. height = width +112;
  861. }
  862. return CGSizeMake(width, height);
  863. }
  864. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  865. LDGoodCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
  866. cell.backgroundColor = [UIColor whiteColor];
  867. cell.backgroundView.backgroundColor = [UIColor whiteColor];
  868. cell.contentView.backgroundColor = [UIColor whiteColor];
  869. LDChildGoodModel *model = self.goodSimilarArr[indexPath.item];
  870. cell.model = model;
  871. return cell;
  872. }
  873. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
  874. UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionViewHeader forIndexPath:indexPath];
  875. CALayer *lineGapLayer = [CALayer layer];
  876. lineGapLayer.frame = CGRectMake(0, 0, kScreenWidth, FITSIZE(5));
  877. lineGapLayer.backgroundColor = [UIColor YHColorWithHex:0xf5f4f4].CGColor;
  878. [view.layer addSublayer:lineGapLayer];
  879. UILabel *lineGapLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, kScreenWidth, FITSIZE(40))];
  880. lineGapLabel.backgroundColor = [UIColor whiteColor];
  881. lineGapLabel.textColor = [UIColor YHColorWithHex:0x222222];
  882. lineGapLabel.font = [UIFont systemFontOfSize:FITSIZE(13)];
  883. lineGapLabel.text = @"相关推荐";
  884. lineGapLabel.textAlignment = NSTextAlignmentCenter;
  885. [view addSubview:lineGapLabel];
  886. return view;
  887. }
  888. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
  889. return CGSizeMake(kScreenWidth, FITSIZE(45));
  890. }
  891. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  892. LDChildGoodModel *model = self.goodSimilarArr[indexPath.item];
  893. //详情
  894. LDGoodDetailViewController *detailVC = [[LDGoodDetailViewController alloc] init];
  895. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithChildModel:model];
  896. detailVC.requestModel = requestModel;
  897. LDEventModel *evevtModel = [[LDEventModel alloc] initWithOrigin:@"0" category_id:@"0" source:goodsDetailRecommendAction];
  898. detailVC.eventModel = evevtModel;
  899. [self.navigationController pushViewController:detailVC animated:YES];
  900. }
  901. #pragma mark - lazy
  902. - (UITableView *)tableView {
  903. if (!_tableView) {
  904. _tableView = [[LDTableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight-FITSIZE(55)-BottomMargin) style:UITableViewStylePlain];
  905. _tableView.rowHeight = 0.1;
  906. _tableView.estimatedRowHeight = 0;
  907. _tableView.estimatedSectionHeaderHeight = 0;
  908. _tableView.estimatedSectionFooterHeight = 0;
  909. _tableView.delegate = self;
  910. _tableView.dataSource = self;
  911. [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
  912. if (@available(iOS 11.0, *)) {
  913. _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  914. }
  915. }
  916. return _tableView;
  917. }
  918. - (UICollectionView *)collectionView {
  919. if (!_collectionView) {
  920. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  921. flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
  922. flowLayout.minimumLineSpacing = FITSIZE(5);
  923. flowLayout.minimumInteritemSpacing = FITSIZE(0);
  924. _collectionView = [[LDCollectionView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, GoodSimilarViewHeight) collectionViewLayout:flowLayout];
  925. _collectionView.scrollEnabled = NO;
  926. _collectionView.bounces = NO;
  927. _collectionView.showsVerticalScrollIndicator = NO;
  928. _collectionView.delegate = self;
  929. _collectionView.dataSource = self;
  930. [_collectionView registerClass:[LDGoodCollectionCell class] forCellWithReuseIdentifier:cellID];
  931. [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionViewHeader];
  932. }
  933. return _collectionView;
  934. }
  935. - (SGPageTitleView *)topTitleView {
  936. if (!_topTitleView) {
  937. SGPageTitleViewConfigure *configure = [SGPageTitleViewConfigure pageTitleViewConfigure];
  938. configure.titleFont = [UIFont systemFontOfSize:FITSIZE(14)];
  939. configure.titleColor = [UIColor YHColorWithHex:0x222222];
  940. configure.titleSelectedColor = [UIColor YHColorWithHex:0xff2420];
  941. configure.indicatorColor = [UIColor YHColorWithHex:0xff2420];
  942. configure.indicatorScrollStyle = SGIndicatorScrollStyleHalf;
  943. _topTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(kScreenWidth/2-FITSIZE(100), KStatusBarHeight, FITSIZE(200), 44) delegate:self titleNames:@[@"宝贝",@"详情",@"推荐"] configure:configure];
  944. _topTitleView.backgroundColor = [UIColor clearColor];
  945. _topTitleView.alpha = 0.0;
  946. _topTitleView.isNeedBounces = NO;
  947. _topTitleView.isTitleGradientEffect = NO;
  948. _topTitleView.isOpenTitleTextZoom = YES;
  949. _topTitleView.isShowBottomSeparator = NO;
  950. }
  951. return _topTitleView;
  952. }
  953. - (NSMutableArray *)bannerImgArray {
  954. if (!_bannerImgArray) {
  955. _bannerImgArray = [NSMutableArray array];
  956. }
  957. return _bannerImgArray;
  958. }
  959. - (void)loadUserInfo {
  960. [LDCacheHttp post:UserInfo params:nil success:^(id json, BOOL isCache) {
  961. //讲将数据保存到本地单例
  962. [LDUserInfoManager shareManager].userInfoDic =json;
  963. } failure:^(NSError *error) {
  964. }];
  965. }
  966. -(void)loadshopJsonStr
  967. {
  968. NSString *url = [NSString stringWithFormat:@"%@/api/v2/goods/backJsStr",BaseURL];
  969. [LDHttp post:url params:@{@"type":@"2"} success:^(id json) {
  970. NSString *jsonstr= json[@"jsStr"];
  971. shopjsonstr = jsonstr;
  972. } failure:^(NSError *error) {
  973. }];
  974. }
  975. #pragma mark---跳转店铺信息
  976. -(void)tapShopInfo
  977. {
  978. //点击大牌商品
  979. LDSearchCoupleWebViewController *searchCoupleWeb = [[LDSearchCoupleWebViewController alloc] init];
  980. searchCoupleWeb.url = self.goodModel.shop.shop_url;
  981. searchCoupleWeb.name = _goodModel.shop_title;
  982. if (shopjsonstr.length != 0) {
  983. searchCoupleWeb.jsString = shopjsonstr;
  984. }
  985. if ([[ALBBSession sharedInstance] isLogin] && [AccountTool isLogin]) {
  986. //进入
  987. [self.navigationController pushViewController:searchCoupleWeb animated:YES];
  988. }else if (![AccountTool isLogin]) {
  989. //未登录
  990. LDNewLoginVC *login = [[LDNewLoginVC alloc] init];
  991. login.modalPresentationStyle = UIModalPresentationFullScreen;
  992. [self presentViewController:login animated:YES completion:nil];
  993. }else if (![[ALBBSession sharedInstance] isLogin]) {
  994. //淘宝未授权
  995. ALBBSDK *albbSDK = [ALBBSDK sharedInstance];
  996. [albbSDK setAppkey:ALBC_APP_KEY];
  997. [albbSDK setAuthOption:NormalAuth];
  998. [albbSDK auth:self successCallback:^(ALBBSession *session){
  999. [[NSNotificationCenter defaultCenter] postNotificationName:ChangeTaoBaoAuthor object:nil];
  1000. [self.navigationController pushViewController:searchCoupleWeb animated:YES];
  1001. } failureCallback:^(ALBBSession *session,NSError *error){
  1002. NSLog(@"session == %@,error == %@",session,error);
  1003. }];
  1004. }
  1005. }
  1006. -(LDDetailLoginView *)loginView
  1007. {
  1008. if (!_loginView) {
  1009. _loginView =[[LDDetailLoginView alloc]init];
  1010. _loginView.hidden=YES;
  1011. }
  1012. return _loginView;
  1013. }
  1014. @end