线上所有马甲包模板,与《猎豆》同UI。域名zhuadd

HSQGoodDetailViewController.m 38KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  1. //
  2. // HSQGoodDetailViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by xiaoxi on 2018/1/22.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "HSQGoodDetailViewController.h"
  9. #import <WebKit/WebKit.h>
  10. #import "HSQGoodDetailRequestViewModel.h"
  11. #import "SDCycleScrollView.h"
  12. #import "HSQTableView.h"
  13. #import "HSQPrivilegeReferralViewController.h"
  14. #import "HSQGoodDetailBottomView.h"
  15. #import "HSQGoodDetailView.h"
  16. #import "HSQCollectionView.h"
  17. #import "HSQGoodCollectionCell.h"
  18. #import "HSQShopDetailViewController.h"
  19. #import <AlibcTradeSDK/AlibcTradeSDK.h>
  20. #import "HSQHistoryTool.h"
  21. #import "HSQHistoryModel.h"
  22. #import "HSQGoodListViewController.h"
  23. #import "HSQLoginViewController.h"
  24. #import "HSQAdWebViewController.h"
  25. #import "HSQEventTool.h"
  26. #import "HSQGotoDetailView.h"
  27. #import "SDPhotoBrowser.h"
  28. #import "HSQShareGoodsViewController.h"
  29. #import "HSQWebDetailController.h"
  30. #import "HSQLinkFansController.h"
  31. #import "HSQPrivilegeReferralViewController.h"
  32. #import "HSQModuleView.h"
  33. #import "HSQDetailHeaderTitle.h"
  34. #import "CCAlertShowView.h"
  35. #import "HSQShareImgPopView.h"
  36. #import "HSQShopInfoView.h"
  37. #import "HSQDetailGuideView.h"
  38. #import "PhoneLoginManager.h"
  39. #import "HSQGoodDetailImageCell.h"
  40. #import "HSQDetailImgModel.h"
  41. #import "HSQShareGoodViewController.h"
  42. #import "HSQShareRequestViewModel.h"
  43. #import "HSQShareInfoModel.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 = @"HSQGoodCollectionCell";
  48. static NSString *const collectionViewHeader = @"collectionViewHeader";
  49. @interface HSQGoodDetailViewController ()
  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) HSQGoodDetailModel *goodModel;
  72. @property (nonatomic, strong) HSQShareInfoModel *shareModel;
  73. @property (nonatomic, strong) UITableView *tableView;
  74. @property (nonatomic, strong) WKWebView *detailDescWebView;
  75. @property (nonatomic, strong) UIView *tableHeaderView;
  76. @property (nonatomic, strong) HSQGoodDetailView *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) HSQGoodDetailBottomView *goodBottomView;
  84. @property (nonatomic, strong) NSNumber *flag;//用户等级 1 会员 2 超级会员 3 运营商
  85. @property (nonatomic, strong) HSQModuleView *moduleView;
  86. @property (nonatomic, strong) HSQShopInfoView *shopInfoView;
  87. @property (nonatomic, strong) HSQGoodDetailBottomView *bottomView;
  88. @property (nonatomic, strong) UIView *moduleBg;
  89. @property (nonatomic, strong) HSQDetailHeaderTitle *detailHeader;
  90. @property (nonatomic, strong) HSQDetailGuideView *guideView;
  91. @property (nonatomic, strong) NSMutableArray *bannerImgArray;
  92. @end
  93. @implementation HSQGoodDetailViewController
  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. [HSQEventTool 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. HSQGoodDetailModel *mndoels=[[HSQGoodDetailModel alloc] init];
  147. [mndoels changeDetailRequestModel:_requestModel];
  148. self.goodDetailView.goodModel =mndoels;
  149. self.guideView.model = mndoels;
  150. HSQShopModel *shopmodel =[[HSQShopModel 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. HSQGoodDetailBottomView *bottomView = [[HSQGoodDetailBottomView 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 = [[HSQGoodDetailView alloc] initWithFrame:CGRectMake(0, cycleView.height, kScreenWidth, FITSIZE(110))];
  172. self.goodDetailView.delegate = self;
  173. HSQDetailGuideView *guide = [[HSQDetailGuideView 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. HSQLoginViewController *login = [[HSQLoginViewController alloc] init];
  179. [weakSelf presentViewController:login animated:YES completion:nil];
  180. return ;
  181. }
  182. HSQPrivilegeReferralViewController *Privilege = [[HSQPrivilegeReferralViewController 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 = [[HSQShopInfoView 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. HSQDetailHeaderTitle *headerTitle = [[HSQDetailHeaderTitle alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, Fitsize(34)) title:@"相关推荐"];
  194. [moduleBg addSubview:headerTitle];
  195. self.moduleView = [[HSQModuleView alloc] initWithFrame:CGRectMake(0, headerTitle.height, SCREEN_WIDTH, moduleBg.height-Fitsize(34))];
  196. self.moduleView.didSelectedGood = ^(HSQChildGoodModel *model) {
  197. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithChildModel:model];
  198. HSQGoodDetailViewController *detail = [[HSQGoodDetailViewController alloc] init];
  199. detail.requestModel = requestModel;
  200. HSQEventModel *evevtModel = [[HSQEventModel 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. HSQDetailHeaderTitle *detailHeader = [[HSQDetailHeaderTitle 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. [HSQGoodDetailRequestViewModel 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. [HSQShareRequestViewModel requestGoodDetailParamGoods_id:self.requestModel success:^(HSQShareInfoModel * _Nonnull model, NSDictionary * _Nonnull dic) {
  294. self.shareModel = model;
  295. } failure:^(NSError * _Nonnull error) {
  296. }];
  297. }
  298. }
  299. - (void)request {
  300. [HSQGoodDetailRequestViewModel requestGoodDetailParamGoods_id:self.requestModel success:^(HSQGoodDetailModel *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. HSQShopModel *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. [HSQHttp post:url params:para success:^(id json) {
  368. NSArray *list = [NSArray yy_modelArrayWithClass:[HSQChildGoodModel 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. [HSQHttp 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. [HSQHttp 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. HSQPrivilegeReferralViewController *Privilege = [[HSQPrivilegeReferralViewController alloc] init];
  444. [self.navigationController pushViewController:Privilege animated:YES];
  445. }
  446. -(void)goBuyWithModel:(HSQGoodDetailModel *)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. // HSQShareImgPopView *shareView = [[HSQShareImgPopView 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. HSQShareGoodViewController *shareVc = [[HSQShareGoodViewController alloc] init];
  488. if (self.shareModel) {
  489. shareVc.goodModel = self.shareModel;
  490. [self.navigationController pushViewController:shareVc animated:YES];
  491. }else {
  492. [LoadingView show];
  493. [HSQShareRequestViewModel requestGoodDetailParamGoods_id:self.requestModel success:^(HSQShareInfoModel * _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. HSQLoginViewController *login = [[HSQLoginViewController 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. [HSQGoodDetailRequestViewModel 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. HSQLoginViewController *login = [[HSQLoginViewController 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. [HSQGoodDetailRequestViewModel 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. HSQLoginViewController *login = [[HSQLoginViewController 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. // HSQLoginViewController *login = [[HSQLoginViewController 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 *url = [NSString stringWithFormat:@"%@/api/v2/goods/getCouponShareUrl",BaseURL];
  627. NSDictionary *para = @{@"goods_id":self.requestModel.goods_id};
  628. [HSQHttp post:url params:para success:^(id json) {
  629. [LoadingView dismiss];
  630. [self jumpToTaobaoWithGoodsUrl:json[@"coupon_share_url"]];
  631. } failure:^(NSError *error) {
  632. [LoadingView dismiss];
  633. }];
  634. }
  635. - (void)jumpToTaobaoWithGoodsUrl:(NSString *)url {
  636. [HSQEventTool eventWithEventType:1 origin:self.eventModel.origin category_id:self.eventModel.category_id goods_id:self.requestModel.goods_id source:self.eventModel.source];
  637. id<AlibcTradePage> page = [AlibcTradePageFactory page:url];
  638. //淘客信息
  639. AlibcTradeTaokeParams *taoKeParams=[[AlibcTradeTaokeParams alloc] init];
  640. taoKeParams.pid = ALTK_PID; //
  641. //打开方式
  642. AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init];
  643. showParam.openType = AlibcOpenTypeNative;
  644. [[AlibcTradeSDK sharedInstance].tradeService show:self.navigationController page:page showParams:showParam taoKeParams:taoKeParams trackParam:nil tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) {
  645. } tradeProcessFailedCallback:^(NSError * _Nullable error) {
  646. }];
  647. }
  648. /**
  649. 判断是否安装淘宝app
  650. */
  651. - (BOOL)isInstallTaobaoAPP {
  652. if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"taobao://"]]) {
  653. return YES;
  654. }else {
  655. return NO;
  656. }
  657. }
  658. #pragma mark - goodDetailViewDelegate
  659. - (void)yh_GoodDetailViewTapCoupon {
  660. [HSQGoodDetailRequestViewModel requestTicketProcessParamGoods_id:self.requestModel.goods_id coupon_price:self.goodModel.coupon_price success:^(NSString *msg) {
  661. [self yh_GoodDetailBottomViewClickBuyButton];
  662. } failure:^(NSError *error) {
  663. }];
  664. }
  665. - (void)yh_GoodDetailViewTapShop {
  666. HSQShopDetailViewController *shopVC = [[HSQShopDetailViewController alloc] init];
  667. shopVC.goodModel = self.goodModel;
  668. [self.navigationController pushViewController:shopVC animated:YES];
  669. }
  670. #pragma mark - webView
  671. - (void)webViewDidStartLoad:(UIWebView *)webView {
  672. [LoadingView dismiss];
  673. }
  674. - (void)webViewDidFinishLoad:(UIWebView *)webView {
  675. [LoadingView dismiss];
  676. CGSize contentSize = webView.scrollView.contentSize;
  677. CGSize viewSize = self.detailDescWebView.bounds.size;
  678. float rw = viewSize.width / contentSize.width;
  679. webView.scrollView.minimumZoomScale = rw;
  680. webView.scrollView.maximumZoomScale = rw;
  681. webView.scrollView.zoomScale = rw;
  682. }
  683. - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
  684. [LoadingView dismiss];
  685. }
  686. #pragma mark ------ wkWebView delegate ------
  687. // main frame的导航开始请求时调用
  688. - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation{
  689. }
  690. // 当main frame开始加载数据失败时,会回调
  691. - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error {
  692. }
  693. //当main frame导航完成时,会回调
  694. - (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation{
  695. // 页面加载完成之后调用
  696. }
  697. #pragma mark - tableView
  698. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  699. return 1;
  700. }
  701. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  702. NSArray *pics = self.goodModel.detail_pic;
  703. return pics.count;
  704. }
  705. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  706. HSQDetailImgModel *model = self.goodModel.detail_pic[indexPath.row];
  707. CGFloat imgScale = model.width.floatValue/model.height.floatValue;
  708. CGFloat imgH = SCREEN_WIDTH/imgScale;
  709. return imgH;
  710. }
  711. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  712. HSQGoodDetailImageCell *cell = [HSQGoodDetailImageCell cellWithTableView:tableView];
  713. cell.model = self.goodModel.detail_pic[indexPath.row];
  714. return cell;
  715. }
  716. #pragma mark - collectionView
  717. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  718. return 1;
  719. }
  720. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  721. return self.goodSimilarArr.count;
  722. }
  723. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  724. HSQChildGoodModel *model = self.goodSimilarArr[indexPath.row];
  725. CGFloat width = (SCREEN_WIDTH-5)/2;
  726. CGFloat height = width + 112;
  727. if (model.commission_price.length > 0) {
  728. }
  729. return CGSizeMake(width, height);
  730. }
  731. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  732. HSQGoodCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
  733. cell.backgroundColor = [UIColor whiteColor];
  734. cell.backgroundView.backgroundColor = [UIColor whiteColor];
  735. cell.contentView.backgroundColor = [UIColor whiteColor];
  736. HSQChildGoodModel *model = self.goodSimilarArr[indexPath.item];
  737. cell.model = model;
  738. return cell;
  739. }
  740. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
  741. UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionViewHeader forIndexPath:indexPath];
  742. CALayer *lineGapLayer = [CALayer layer];
  743. lineGapLayer.frame = CGRectMake(0, 0, kScreenWidth, FITSIZE(5));
  744. lineGapLayer.backgroundColor = [UIColor YHColorWithHex:0xf5f4f4].CGColor;
  745. [view.layer addSublayer:lineGapLayer];
  746. UILabel *lineGapLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, kScreenWidth, FITSIZE(40))];
  747. lineGapLabel.backgroundColor = [UIColor whiteColor];
  748. lineGapLabel.textColor = [UIColor YHColorWithHex:0x222222];
  749. lineGapLabel.font = [UIFont systemFontOfSize:FITSIZE(13)];
  750. lineGapLabel.text = @"相关推荐";
  751. lineGapLabel.textAlignment = NSTextAlignmentCenter;
  752. [view addSubview:lineGapLabel];
  753. return view;
  754. }
  755. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
  756. return CGSizeMake(kScreenWidth, FITSIZE(45));
  757. }
  758. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  759. HSQChildGoodModel *model = self.goodSimilarArr[indexPath.item];
  760. //详情
  761. HSQGoodDetailViewController *detailVC = [[HSQGoodDetailViewController alloc] init];
  762. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithChildModel:model];
  763. detailVC.requestModel = requestModel;
  764. HSQEventModel *evevtModel = [[HSQEventModel alloc] initWithOrigin:@"0" category_id:@"0" source:goodsDetailRecommendAction];
  765. detailVC.eventModel = evevtModel;
  766. [self.navigationController pushViewController:detailVC animated:YES];
  767. }
  768. #pragma mark - lazy
  769. - (UITableView *)tableView {
  770. if (!_tableView) {
  771. _tableView = [[HSQTableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight-FITSIZE(55)-BottomMargin) style:UITableViewStylePlain];
  772. _tableView.rowHeight = 0.1;
  773. _tableView.estimatedRowHeight = 0;
  774. _tableView.estimatedSectionHeaderHeight = 0;
  775. _tableView.estimatedSectionFooterHeight = 0;
  776. _tableView.delegate = self;
  777. _tableView.dataSource = self;
  778. [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
  779. if (@available(iOS 11.0, *)) {
  780. _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  781. }
  782. }
  783. return _tableView;
  784. }
  785. - (UICollectionView *)collectionView {
  786. if (!_collectionView) {
  787. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  788. flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
  789. flowLayout.minimumLineSpacing = FITSIZE(5);
  790. flowLayout.minimumInteritemSpacing = FITSIZE(0);
  791. _collectionView = [[HSQCollectionView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, GoodSimilarViewHeight) collectionViewLayout:flowLayout];
  792. _collectionView.scrollEnabled = NO;
  793. _collectionView.bounces = NO;
  794. _collectionView.showsVerticalScrollIndicator = NO;
  795. _collectionView.delegate = self;
  796. _collectionView.dataSource = self;
  797. [_collectionView registerClass:[HSQGoodCollectionCell class] forCellWithReuseIdentifier:cellID];
  798. [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionViewHeader];
  799. }
  800. return _collectionView;
  801. }
  802. - (SGPageTitleView *)topTitleView {
  803. if (!_topTitleView) {
  804. SGPageTitleViewConfigure *configure = [SGPageTitleViewConfigure pageTitleViewConfigure];
  805. configure.titleFont = [UIFont systemFontOfSize:FITSIZE(14)];
  806. configure.titleColor = [UIColor YHColorWithHex:0x222222];
  807. configure.titleSelectedColor = [UIColor YHColorWithHex:0xff2420];
  808. configure.indicatorColor = [UIColor YHColorWithHex:0xff2420];
  809. configure.indicatorScrollStyle = SGIndicatorScrollStyleHalf;
  810. _topTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(kScreenWidth/2-FITSIZE(100), KStatusBarHeight, FITSIZE(200), 44) delegate:self titleNames:@[@"宝贝",@"详情",@"推荐"] configure:configure];
  811. _topTitleView.backgroundColor = [UIColor clearColor];
  812. _topTitleView.alpha = 0.0;
  813. _topTitleView.isNeedBounces = NO;
  814. _topTitleView.isTitleGradientEffect = NO;
  815. _topTitleView.isOpenTitleTextZoom = YES;
  816. _topTitleView.isShowBottomSeparator = NO;
  817. }
  818. return _topTitleView;
  819. }
  820. - (NSMutableArray *)bannerImgArray {
  821. if (!_bannerImgArray) {
  822. _bannerImgArray = [NSMutableArray array];
  823. }
  824. return _bannerImgArray;
  825. }
  826. - (void)loadUserInfo {
  827. [HSQCacheHttp post:UserInfo params:nil success:^(id json, BOOL isCache) {
  828. //讲将数据保存到本地单例
  829. [HSQUserInfoManager shareManager].userInfoDic =json;
  830. } failure:^(NSError *error) {
  831. }];
  832. }
  833. @end