口袋优选

KBGoodDetailViewController.m 42KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110
  1. //
  2. // KBGoodDetailViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by xiaoxi on 2018/1/22.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBGoodDetailViewController.h"
  9. #import <WebKit/WebKit.h>
  10. #import "KBGoodDetailRequestViewModel.h"
  11. #import "SDCycleScrollView.h"
  12. #import "KBTableView.h"
  13. #import "KBGoodDetailBottomView.h"
  14. #import "KBGoodDetailView.h"
  15. #import "KBCollectionView.h"
  16. #import "KBGoodCollectionCell.h"
  17. #import "KBShopDetailViewController.h"
  18. #import <AlibcTradeSDK/AlibcTradeSDK.h>
  19. #import "KBHistoryTool.h"
  20. #import "KBHistoryModel.h"
  21. #import "KBGoodListViewController.h"
  22. #import "KBLoginViewController.h"
  23. #import "KBEventTool.h"
  24. #import "KBGotoDetailView.h"
  25. #import "KBShareGoodsViewController.h"
  26. #import "KBWebDetailController.h"
  27. #import "KBLinkFansController.h"
  28. #import "KBPrivilegeReferralViewController.h"
  29. #import "KBModuleView.h"
  30. #import "KBDetailHeaderTitle.h"
  31. #import "CCAlertShowView.h"
  32. #import "KBShareImgPopView.h"
  33. #import "KBShopInfoView.h"
  34. #import "KBDetailGuideView.h"
  35. #import "PhoneLoginManager.h"
  36. #import "PhoneLoginManager.h"
  37. #import "KBGoodDetailImageCell.h"
  38. #import "KBAuthorityManager.h"
  39. #import "KBFiveStartAlertView.h"
  40. #import "KBPushAlertView.h"
  41. #import "KBDetailPopQueneManager.h"
  42. #import <AdSupport/AdSupport.h>
  43. #define GoodSimilarViewHeight ((self.goodSimilarArr.count-1)/2+1)*FITSIZE(292)+FITSIZE(45)
  44. static NSInteger const detailDescWebTag = 111;
  45. static NSString *const cellID = @"KBGoodCollectionCell";
  46. static NSString *const collectionViewHeader = @"collectionViewHeader";
  47. static NSString *showAlert = @"AlertNotifation";
  48. @interface KBGoodDetailViewController ()
  49. <
  50. SDCycleScrollViewDelegate,
  51. UITableViewDelegate,
  52. UITableViewDataSource,
  53. YHGoodDetailBottomViewDelegate,
  54. YHGoodDetailViewDelegate,
  55. UIWebViewDelegate,
  56. UICollectionViewDelegate,
  57. UICollectionViewDataSource,
  58. UICollectionViewDelegateFlowLayout,
  59. SGPageTitleViewDelegate,
  60. UIWebViewDelegate,
  61. WKNavigationDelegate
  62. >
  63. {
  64. NSInteger _page;
  65. NSString *goBuyUrl;
  66. ActivityIndicatorView *_indicatorView;
  67. }
  68. @property (nonatomic, strong) KBGoodDetailModel *goodModel;
  69. @property (nonatomic, strong) UITableView *tableView;
  70. @property (nonatomic, strong) WKWebView *detailDescWebView;
  71. @property (nonatomic, strong) UIView *tableHeaderView;
  72. @property (nonatomic, strong) KBGoodDetailView *goodDetailView;
  73. @property (nonatomic, strong) SDCycleScrollView *cycleView;
  74. @property (nonatomic, strong) NSArray *goodSimilarArr;
  75. @property (nonatomic, strong) UICollectionView *collectionView;
  76. @property (nonatomic, strong) UIButton *backButton;
  77. @property (nonatomic, strong) SGPageTitleView *topTitleView;
  78. @property (nonatomic, strong) YYFPSLabel *fpsLabel;
  79. @property (nonatomic, strong) KBGoodDetailBottomView *goodBottomView;
  80. @property (nonatomic, strong) NSNumber *flag;//用户等级 1 会员 2 超级会员 3 运营商
  81. @property (nonatomic, strong) KBModuleView *moduleView;
  82. @property (nonatomic, strong) KBShopInfoView *shopInfoView;
  83. @property (nonatomic, strong) KBGoodDetailBottomView *bottomView;
  84. @property (nonatomic, strong) UIView *moduleBg;
  85. @property (nonatomic, strong) KBDetailHeaderTitle *detailHeader;
  86. @end
  87. @implementation KBGoodDetailViewController
  88. - (void)dealloc {
  89. [self.detailDescWebView removeObserver:self forKeyPath:@"scrollView.contentSize"];
  90. NSLog(@"释放了------------");
  91. }
  92. - (void)viewWillDisappear:(BOOL)animated {
  93. [super viewWillDisappear:animated];
  94. [SVProgressHUD dismiss];
  95. }
  96. - (void)viewDidLoad {
  97. [super viewDidLoad];
  98. [self initNavBar];
  99. [self initSubviews];
  100. [self initHUD];
  101. [self addPopAlertNotifation];
  102. [self request];
  103. [self requestCount];
  104. [self checkUserNotifation];
  105. [self loadFiveStartAlert];
  106. }
  107. -(void)viewDidAppear:(BOOL)animated{
  108. [super viewDidAppear:animated];
  109. }
  110. - (void)configParam {
  111. _page = 1;
  112. }
  113. - (void)requestCount {
  114. [KBEventTool eventWithEventType:0 origin:self.eventModel.origin category_id:self.eventModel.category_id goods_id:self.requestModel.goods_id source:self.eventModel.source];
  115. }
  116. - (void)viewWillAppear:(BOOL)animated {
  117. [super viewWillAppear:animated];
  118. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
  119. self.navigationController.navigationBar.hidden = YES;
  120. }
  121. - (void)didReceiveMemoryWarning {
  122. [super didReceiveMemoryWarning];
  123. }
  124. - (void)addPopAlertNotifation {
  125. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showAlertAction) name:showAlert object:nil];
  126. }
  127. - (void)showAlertAction {
  128. NSMutableArray *alertArray = [KBDetailPopQueneManager shareManager].alertArray;
  129. if (alertArray.count > 0) {
  130. if (![KBDetailPopQueneManager shareManager].isShowing) {
  131. CCAlertShowView *showView = alertArray.firstObject;
  132. [KBDetailPopQueneManager shareManager].isShowing = YES;
  133. [showView showInView:self.view];
  134. [[KBDetailPopQueneManager shareManager].alertArray removeObject:showView];
  135. }
  136. }
  137. }
  138. - (void)initNavBar {
  139. [self.navigationBar setNavightionBarBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:0.0]];
  140. UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
  141. leftButton.frame = CGRectMake(0, 0, FITSIZE(22), FITSIZE(22));
  142. leftButton.backgroundColor = [UIColor clearColor];
  143. [leftButton setImage:[UIImage imageNamed:@"detail_back_g"] forState:UIControlStateNormal];
  144. [leftButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  145. self.backButton = leftButton;
  146. [self.navigationBar setCustomLeftButtons:@[leftButton]];
  147. [self.navigationBar addSubview:self.topTitleView];
  148. }
  149. - (void)initSubviews {
  150. __weak typeof(self) weakSelf = self;
  151. //底部栏
  152. KBGoodDetailBottomView *bottomView = [[KBGoodDetailBottomView alloc] initWithFrame:CGRectMake(0, kScreenHeight-FITSIZE(55)-BottomMargin, kScreenWidth, FITSIZE(55))];
  153. bottomView.delegate = self;
  154. self.bottomView = bottomView;
  155. [self.view addSubview:bottomView];
  156. self.goodBottomView = bottomView;
  157. //轮播
  158. SDCycleScrollView *cycleView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, FITSIZE(375), FITSIZE(375)) delegate:self placeholderImage:[UIImage imageNamed:@""]];
  159. cycleView.currentPageDotImage = [UIImage imageNamed:@"page_sel"];
  160. cycleView.pageDotImage = [UIImage imageNamed:@"page_nor"];
  161. self.cycleView = cycleView;
  162. //商品信息
  163. self.goodDetailView = [[KBGoodDetailView alloc] initWithFrame:CGRectMake(0, cycleView.height, kScreenWidth, FITSIZE(140))];
  164. self.goodDetailView.delegate = self;
  165. KBDetailGuideView *guide = [[KBDetailGuideView alloc] initWithFrame:CGRectMake(0, self.goodDetailView.bottom, SCREEN_WIDTH, 35)];
  166. guide.tapAction = ^{
  167. KBPrivilegeReferralViewController *Privilege = [[KBPrivilegeReferralViewController alloc] init];
  168. [weakSelf.navigationController pushViewController:Privilege animated:YES];
  169. };
  170. guide.height = 0;//省钱快报不需要展示
  171. //店铺信息
  172. self.shopInfoView = [[KBShopInfoView alloc] initWithFrame:CGRectMake(0, guide.bottom+5, SCREEN_WIDTH, 0)];
  173. //推荐模块
  174. UIView *moduleBg = [[UIView alloc] initWithFrame:CGRectMake(0, self.shopInfoView.bottom+5, SCREEN_WIDTH, Fitsize(202))];
  175. self.moduleBg = moduleBg;
  176. KBDetailHeaderTitle *headerTitle = [[KBDetailHeaderTitle alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, Fitsize(34)) title:@"相关推荐" color:[UIColor gradientWidthFromColor:[UIColor YHColorWithHex:0xF62259] toColor:[UIColor YHColorWithHex:0xFC0E2F] withWidth:SCREEN_WIDTH]];
  177. [moduleBg addSubview:headerTitle];
  178. self.moduleView = [[KBModuleView alloc] initWithFrame:CGRectMake(0, headerTitle.height, SCREEN_WIDTH, moduleBg.height-Fitsize(34))];
  179. self.moduleView.didSelectedGood = ^(KBChildGoodModel *model) {
  180. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithChildModel:model];
  181. KBGoodDetailViewController *detail = [[KBGoodDetailViewController alloc] init];
  182. detail.requestModel = requestModel;
  183. KBEventModel *evevtModel = [[KBEventModel alloc] initWithOrigin:model.origin category_id:@"0" source:goodsDetailTopRecommendAction];
  184. detail.eventModel = evevtModel;
  185. [weakSelf.navigationController pushViewController:detail animated:YES];
  186. [MobClick event:GoodsDetailRecommend];
  187. };
  188. [moduleBg addSubview:self.moduleView];
  189. self.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, moduleBg.bottom+5)];
  190. //详情webview
  191. KBDetailHeaderTitle *detailHeader = [[KBDetailHeaderTitle alloc] initWithFrame:CGRectMake(0, moduleBg.bottom+5, SCREEN_WIDTH, Fitsize(34)) title:@"宝贝详情" color:[UIColor gradientWidthFromColor:[UIColor YHColorWithHex:0x8976FB] toColor:[UIColor YHColorWithHex:0x3CC1F8] withWidth:SCREEN_WIDTH]];
  192. self.detailHeader = detailHeader;
  193. _detailDescWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0, detailHeader.bottom, kScreenWidth, 0)];
  194. _detailDescWebView.tag = detailDescWebTag;
  195. _detailDescWebView.navigationDelegate = self;
  196. _detailDescWebView.scrollView.scrollEnabled = NO;
  197. // _detailDescWebView.scalesPageToFit = YES;
  198. [self.tableHeaderView addSubview:cycleView];
  199. [self.tableHeaderView addSubview:self.goodDetailView];
  200. [self.tableHeaderView addSubview:guide];
  201. [self.tableHeaderView addSubview:self.shopInfoView];
  202. [self.tableHeaderView addSubview:moduleBg];
  203. [self.tableHeaderView addSubview:detailHeader];
  204. [self.tableHeaderView addSubview:_detailDescWebView];
  205. self.tableView.tableHeaderView = self.tableHeaderView;
  206. [self.view addSubview:self.tableView];
  207. [self.view bringSubviewToFront:self.navigationBar];
  208. //添加监听
  209. @try{
  210. // [self.detailDescWebView removeObserver:self forKeyPath:@"scrollView.contentSize"];
  211. }@catch (NSException *exception) {
  212. }
  213. [_detailDescWebView addObserver:self forKeyPath:@"scrollView.contentSize" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];
  214. [self.view bringSubviewToFront:self.navigationBar];
  215. [KBGoodDetailRequestViewModel requestGoodSimilarParamGoods_id:self.requestModel.goods_id page:@(_page) success:^(NSArray *array) {
  216. if (array.count > 0) {
  217. self.goodSimilarArr = array;
  218. self.tableView.tableFooterView = self.collectionView;
  219. }
  220. } failure:^(NSError *error) {
  221. }];
  222. }
  223. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
  224. if ([keyPath isEqualToString:@"scrollView.contentSize"]) {
  225. if (self.goodModel.detail_pic.count > 0) {
  226. self.detailDescWebView.height = 0;
  227. return;
  228. }
  229. id height = [change valueForKey:NSKeyValueChangeNewKey];
  230. CGSize size;
  231. [(NSValue *)height getValue:&size];
  232. if (_detailDescWebView.height != size.height) {
  233. self.detailDescWebView.height = size.height;
  234. self.tableHeaderView.height = self.detailDescWebView.top+size.height;
  235. self.tableView.tableHeaderView = self.tableHeaderView;
  236. }
  237. }
  238. }
  239. - (void)backAction {
  240. [self.navigationController popViewControllerAnimated:YES];
  241. }
  242. #pragma mark - HUD
  243. - (void)initHUD {
  244. ActivityIndicatorView *indicatorView = [ActivityIndicatorView showInView:self.view frame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  245. _indicatorView = indicatorView;
  246. }
  247. #pragma mark - request
  248. /**
  249. 请求是否展示五星好评
  250. */
  251. - (void)loadFiveStartAlert {
  252. NSString *url = [NSString stringWithFormat:@"%@/api/v2/users/isAlertFiveStar",BaseURL];
  253. NSString *deviceUUID = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
  254. NSDictionary *para = @{@"idfa":deviceUUID};
  255. [KBHttp get:url params:para success:^(id json) {
  256. if ([json[@"data"][@"is_show"] boolValue]) {
  257. NSString *msg = json[@"data"][@"message"];
  258. [self showStartView:msg];
  259. }
  260. } failure:^(NSError *error) {
  261. }];
  262. }
  263. - (void)showStartView:(NSString *)msg {
  264. KBFiveStartAlertView *startAlert = [[KBFiveStartAlertView alloc] initWithFrame:CGRectMake(0, 0, Fitsize(257), Fitsize(333)) text:msg];
  265. CCAlertShowView *showView = [CCAlertShowView alertViewWithView:startAlert];
  266. startAlert.cancelBlock = ^{
  267. [showView dismiss];
  268. [self fiveStartCommitRequest:@"0"];
  269. [KBDetailPopQueneManager shareManager].isShowing = NO;
  270. [[NSNotificationCenter defaultCenter] postNotificationName:showAlert object:nil];
  271. };
  272. startAlert.sureBlock = ^{
  273. [self commentAndStart];
  274. [showView dismiss];
  275. [self fiveStartCommitRequest:@"1"];
  276. [KBDetailPopQueneManager shareManager].isShowing = NO;
  277. [[NSNotificationCenter defaultCenter] postNotificationName:showAlert object:nil];
  278. };
  279. [[KBDetailPopQueneManager shareManager].alertArray addObject:showView];
  280. [[NSNotificationCenter defaultCenter] postNotificationName:showAlert object:nil];
  281. }
  282. /**
  283. 提交用户评论状态
  284. */
  285. - (void)fiveStartCommitRequest:(NSString *)commit {
  286. NSString *url = [NSString stringWithFormat:@"%@/api/v2/users/fiveStarNote",BaseURL];
  287. NSString *deviceUUID = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
  288. NSDictionary *para = @{@"idfa":deviceUUID,
  289. @"commit":commit};
  290. [KBHttp get:url params:para success:^(id json) {
  291. } failure:^(NSError *error) {
  292. }];
  293. }
  294. /**
  295. 五星好评
  296. */
  297. - (void)commentAndStart {
  298. NSString * nsStringToOpen = [NSString stringWithFormat: @"itms-apps://itunes.apple.com/app/id%@?action=write-review",APP_ID];//替换为对应的APPID
  299. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:nsStringToOpen]];
  300. }
  301. - (void)request {
  302. // [SVProgressHUD show];
  303. [KBGoodDetailRequestViewModel requestGoodDetailParamGoods_id:self.requestModel success:^(KBGoodDetailModel *model,NSDictionary *dic) {
  304. if (model) {
  305. self.goodModel = model;
  306. // [self initSubviews];
  307. [self setGoodInfoForHeader];
  308. [self requestUserIdentity];
  309. [self requestThressRecommon];
  310. [self saveGoodsInfoAsBrowserHistoryWith:dic];
  311. [self.tableView reloadData];
  312. }
  313. [SVProgressHUD dismiss];
  314. [_indicatorView stopAnimating];
  315. } failure:^(NSError *error) {
  316. [SVProgressHUD dismiss];
  317. [MBProgressHUD showMessage:@"加载失败"];
  318. [_indicatorView stopAnimating];
  319. }];
  320. [self loadGoBuyUrl];
  321. }
  322. - (void)setGoodInfoForHeader {
  323. self.bottomView.goodModel = self.goodModel;
  324. self.cycleView.imageURLStringsGroup = self.goodModel.small_img;
  325. self.goodDetailView.goodModel = self.goodModel;
  326. KBShopModel *model = self.goodModel.shop;
  327. CGFloat shopViewHeight = model==nil?0:Fitsize(68);
  328. [self.shopInfoView setShopInfo:model];
  329. self.shopInfoView.height = shopViewHeight;
  330. self.moduleBg.y = self.shopInfoView.bottom+5;
  331. self.detailHeader.y = self.moduleBg.bottom+5;
  332. _detailDescWebView.y = self.detailHeader.bottom;
  333. // NSURL *url = [NSURL URLWithString:self.goodModel.detail_url];
  334. NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:self.goodModel.detail_url]
  335. cachePolicy:NSURLRequestReloadIgnoringCacheData
  336. timeoutInterval:15.0];
  337. NSArray *picList = self.goodModel.detail_pic;
  338. if (picList.count == 0) {
  339. // [_detailDescWebView addObserver:self forKeyPath:@"scrollView.contentSize" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];
  340. if (@available(iOS 9.0, *)) {
  341. NSArray * types=@[WKWebsiteDataTypeCookies,WKWebsiteDataTypeLocalStorage];
  342. NSSet *websiteDataTypes= [NSSet setWithArray:types];
  343. NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0];
  344. [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:^{
  345. }];
  346. }
  347. // NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.url]];
  348. [_detailDescWebView loadRequest:request];
  349. }
  350. self.tableHeaderView.height = self.detailDescWebView.bottom;
  351. self.tableView.tableHeaderView = self.tableHeaderView;
  352. }
  353. /**
  354. 加载购买的url
  355. */
  356. - (void)loadGoBuyUrl {
  357. NSString *category_id = self.eventModel.category_id==nil?@"":self.eventModel.category_id;
  358. NSString *source = self.eventModel.source==nil?@"":self.eventModel.source;
  359. NSString *commission_rate = self.requestModel.commission_rate==nil?@"":self.requestModel.commission_rate;
  360. NSString *discount_price = self.requestModel.discount_price==nil?@"":self.requestModel.discount_price;
  361. NSString *coupon_price = self.requestModel.coupon_price==nil?@"":self.requestModel.coupon_price;
  362. NSString *price = self.requestModel.price==nil?@"":self.requestModel.price;
  363. NSString *coupon_start_time = self.requestModel.coupon_start_time==nil?@"":self.requestModel.coupon_start_time;
  364. NSString *coupon_end_time = self.requestModel.coupon_end_time==nil?@"":self.requestModel.coupon_end_time;
  365. NSDictionary *param = @{@"goods_id":self.requestModel.goods_id,
  366. @"is_coupon":self.requestModel.is_coupon,
  367. @"category_id":category_id,
  368. @"path":source,
  369. @"commission_rate":commission_rate,
  370. @"discount_price":discount_price,
  371. @"coupon_price":coupon_price,
  372. @"price":price,
  373. @"coupon_start_time":coupon_start_time,
  374. @"coupon_end_time":coupon_end_time
  375. };
  376. NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/orderDown",BaseURL];
  377. [KBHttp post:url params:param success:^(id json) {
  378. goBuyUrl = json[@"url"];
  379. } failure:^(NSError *error) {
  380. }];
  381. }
  382. /**
  383. 加载上部相关推荐
  384. */
  385. - (void)requestThressRecommon {
  386. NSString *url = [NSString stringWithFormat:@"%@/api/v2/goods/recommendtop",BaseURL];
  387. NSDictionary *para = @{@"goods_id":self.requestModel.goods_id};
  388. [KBHttp post:url params:para success:^(id json) {
  389. NSArray *list = [NSArray yy_modelArrayWithClass:[KBChildGoodModel class] json:json[@"data"]];
  390. [self.moduleView setRecommonData:list];
  391. } failure:^(NSError *error) {
  392. }];
  393. }
  394. - (void)requestUserIdentity {
  395. NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/userIdentity",BaseURL];
  396. [KBHttp post:url params:nil success:^(id json) {
  397. if (json[@"data"]) {
  398. NSNumber *flag=json[@"data"][@"flag"];
  399. self.flag=flag;
  400. }
  401. } failure:^(NSError *error) {
  402. self.flag=0;
  403. }];
  404. }
  405. /**
  406. 保存浏览记录
  407. */
  408. - (void)saveGoodsInfoAsBrowserHistoryWith:(NSDictionary *)dic {
  409. if (![AccountTool isLogin]) {
  410. return;
  411. }
  412. NSString *urlString = [NSString stringWithFormat:@"%@/api/v2/brower/record", BaseURL];
  413. NSDictionary *para = [self.requestModel modelToDictionary];
  414. [KBHttp post:urlString params:para success:^(id json) {
  415. } failure:^(NSError *error) {
  416. }];
  417. }
  418. #pragma mark - scrollView
  419. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  420. CGFloat offsetY = scrollView.contentOffset.y;
  421. // CGFloat standard = FITSIZE(734)-NavBarHeight;
  422. CGFloat standard = self.cycleView.height-NavBarHeight;
  423. if (offsetY > -standard && offsetY < standard) {
  424. [self.navigationBar setNavightionBarBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:offsetY/standard]];
  425. self.topTitleView.alpha = offsetY/standard;
  426. if (offsetY/standard < 0.5) {
  427. [self.backButton setImage:[UIImage imageNamed:@"detail_back_g"] forState:UIControlStateNormal];
  428. self.backButton.alpha = 1-offsetY/standard;
  429. }
  430. else {
  431. [self.backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
  432. self.backButton.alpha = offsetY/standard;
  433. }
  434. }
  435. else {
  436. }
  437. if (offsetY >= standard) {
  438. [self.navigationBar setShowNavigationBarBottomLine:YES];
  439. } else {
  440. [self.navigationBar setShowNavigationBarBottomLine:NO];
  441. }
  442. //设置导航栏头部seg下标
  443. CGFloat indexOneHeight = self.moduleView.superview.bottom+5-NavBarHeight;
  444. CGFloat indexTwoHeight;
  445. if (self.goodModel.detail_pic.count > 0) {
  446. //详情为图片数组时
  447. CGRect senctionHeight = [self.tableView rectForSection:0];
  448. indexTwoHeight = senctionHeight.size.height+self.tableHeaderView.height-NavBarHeight;
  449. }else {
  450. //详情为web
  451. indexTwoHeight = self.tableHeaderView.height-NavBarHeight;
  452. }
  453. if (offsetY < indexOneHeight) {
  454. self.topTitleView.newSelectedIndex = 0;
  455. }else if (offsetY>=indexOneHeight && offsetY<indexTwoHeight){
  456. self.topTitleView.newSelectedIndex = 1;
  457. }else {
  458. self.topTitleView.newSelectedIndex = 2;
  459. }
  460. }
  461. #pragma mark - topTitleViewDelegate
  462. - (void)pageTitleView:(SGPageTitleView *)pageTitleView selectedIndex:(NSInteger)selectedIndex {
  463. CGFloat indexOneHeight = self.moduleView.superview.bottom+5-NavBarHeight;
  464. CGFloat indexTwoHeight;
  465. if (self.goodModel.detail_pic.count > 0) {
  466. CGRect senctionHeight = [self.tableView rectForSection:0];
  467. indexTwoHeight = senctionHeight.size.height+self.tableHeaderView.height-NavBarHeight;
  468. }else {
  469. indexTwoHeight = self.tableHeaderView.height-NavBarHeight;
  470. }
  471. switch (selectedIndex) {
  472. case 0:
  473. [self.tableView setContentOffset:CGPointMake(0, 0) animated:NO];
  474. break;
  475. case 1:
  476. [self.tableView setContentOffset:CGPointMake(0, indexOneHeight) animated:NO];
  477. break;
  478. case 2:
  479. [self.tableView setContentOffset:CGPointMake(0, indexTwoHeight) animated:NO];
  480. break;
  481. default:
  482. break;
  483. }
  484. }
  485. #pragma mark - goodDetailBottomViewDelegate
  486. /**
  487. 分享
  488. */
  489. - (void)yh_GoodDetailBottomViewClickCommissionButton {
  490. if ([AccountTool isLogin]) {
  491. KBShareImgPopView *shareView = [[KBShareImgPopView alloc] initWithFrame:self.view.bounds goodModel:self.goodModel];
  492. CCAlertShowView *showView = [CCAlertShowView showAlertViewWithView:shareView backgroundDismissEnable:YES];
  493. shareView.closeAction = ^{
  494. [showView dismiss];
  495. };
  496. showView.backgroundView.backgroundColor = [UIColor clearColor];
  497. [showView show];
  498. }else{
  499. KBLoginViewController *login = [[KBLoginViewController alloc] init];
  500. login.loginSucc = ^{
  501. [self request];
  502. };
  503. [self.navigationController presentViewController:login animated:YES completion:nil];
  504. }
  505. }
  506. - (void)yh_GoodDetailBottomViewClickCollectButton {
  507. if ([AccountTool isLogin]) {
  508. [MobClick event:collection_count];
  509. NSString *coupon_start_time = [self.goodModel.is_coupon boolValue] ? self.requestModel.coupon_start_time : @"";
  510. NSString *coupon_end_time = [self.goodModel.is_coupon boolValue] ? self.requestModel.coupon_end_time : @"";
  511. NSNumber *is_coupon = self.goodModel.is_coupon;
  512. NSString *coupon_price = self.goodModel.coupon_price;
  513. NSString *price = self.goodModel.price;
  514. NSString *discount_price = self.goodModel.discount_price;
  515. NSString *commission_rate = self.goodModel.commission_rate;
  516. if (!coupon_start_time) coupon_start_time = @"";
  517. if (!coupon_end_time) coupon_end_time = @"";
  518. if (!is_coupon) is_coupon = @0;
  519. if (!coupon_price) coupon_price = @"";
  520. if (!price) price = @"";
  521. if (!discount_price) discount_price = @"";
  522. if (!commission_rate) commission_rate = @"";
  523. NSDictionary *para = @{@"goods_id":self.goodModel.goods_id,
  524. @"is_coupon":is_coupon,
  525. @"coupon_price":coupon_price,
  526. @"price":price,
  527. @"discount_price":discount_price,
  528. @"commission_rate":commission_rate,
  529. @"coupon_end_time":coupon_end_time,
  530. @"coupon_start_time":coupon_start_time
  531. };
  532. [KBGoodDetailRequestViewModel requestCollectGoodParamGoods_id:para success:^(NSString *msg) {
  533. [SVProgressHUD showSuccessWithStatus:msg];
  534. if ([msg isEqualToString:@"收藏成功"]) {
  535. self.goodModel.is_favorites = @1;
  536. self.goodBottomView.collectButton.selected = YES;
  537. }
  538. else {
  539. self.goodModel.is_favorites = @0;
  540. self.goodBottomView.collectButton.selected = NO;
  541. }
  542. } failure:^(NSError *error) {
  543. }];
  544. }
  545. else {
  546. KBLoginViewController *login = [[KBLoginViewController alloc] init];
  547. login.loginSucc = ^{
  548. [self request];
  549. };
  550. [self.navigationController presentViewController:login animated:YES completion:nil];
  551. }
  552. }
  553. /**
  554. 跳到淘宝领券
  555. */
  556. - (void)yh_GoodDetailBottomViewClickBuyButton {
  557. [self getTicketTaoBaoUrl];
  558. [self saveToMyCouple];
  559. }
  560. /**
  561. 保存到已领优惠券
  562. */
  563. - (void)saveToMyCouple {
  564. if (![AccountTool isLogin]) {
  565. return;
  566. }
  567. NSString *category_id = self.eventModel.category_id==nil?@"":self.eventModel.category_id;
  568. NSString *source = self.eventModel.source==nil?@"":self.eventModel.source;
  569. NSString *commission_rate = self.requestModel.commission_rate==nil?@"":self.requestModel.commission_rate;
  570. NSString *discount_price = self.requestModel.discount_price==nil?@"":self.requestModel.discount_price;
  571. NSString *coupon_price = self.requestModel.coupon_price==nil?@"":self.requestModel.coupon_price;
  572. NSString *price = self.requestModel.price==nil?@"":self.requestModel.price;
  573. NSString *coupon_start_time = self.requestModel.coupon_start_time==nil?@"":self.requestModel.coupon_start_time;
  574. NSString *coupon_end_time = self.requestModel.coupon_end_time==nil?@"":self.requestModel.coupon_end_time;
  575. NSDictionary *param = @{@"goods_id":self.requestModel.goods_id,
  576. @"is_coupon":self.requestModel.is_coupon,
  577. @"category_id":category_id,
  578. @"path":source,
  579. @"commission_rate":commission_rate,
  580. @"discount_price":discount_price,
  581. @"coupon_price":coupon_price,
  582. @"price":price,
  583. @"coupon_start_time":coupon_start_time,
  584. @"coupon_end_time":coupon_end_time
  585. };
  586. NSString *url = [NSString stringWithFormat:@"%@/api/v2/goods/orderCoupon",BaseURL];
  587. [KBHttp post:url params:param success:^(id json) {
  588. } failure:^(NSError *error) {
  589. }];
  590. }
  591. /**
  592. 检查用户是否开启通知
  593. */
  594. - (void)checkUserNotifation {
  595. if ([KBAuthorityManager isObtainUserNotificationAuthority]) {
  596. return;
  597. }
  598. NSArray *array = @[@"1",@"3",@"7",@"30"];
  599. NSDate *date = [[NSUserDefaults standardUserDefaults] objectForKey:YHUserNofi];
  600. if (!date) {
  601. [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:YHUserNofi];
  602. }
  603. NSString *indexStr = [[NSUserDefaults standardUserDefaults] objectForKey:NotiIndex];
  604. if (!indexStr) {
  605. [[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:NotiIndex];
  606. }
  607. CGFloat timeinterval = [[NSString stringWithFormat:@"%.0f",[[NSDate date] timeIntervalSinceDate:date]] floatValue];
  608. if (indexStr.integerValue >= array.count) {
  609. return;
  610. }
  611. NSString *countStr = array[indexStr.integerValue];
  612. NSInteger count = countStr.integerValue;
  613. if ((timeinterval > 60*60*24*count)) {
  614. [self showPushAlertView];
  615. NSInteger index = indexStr.integerValue;
  616. index++;
  617. [[NSUserDefaults standardUserDefaults] setObject:[NSString stringWithFormat:@"%ld",(long)index] forKey:NotiIndex];
  618. [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:YHUserNofi];
  619. }
  620. }
  621. /**
  622. 展示push弹窗
  623. */
  624. - (void)showPushAlertView {
  625. KBPushAlertView *pushAlert = [[KBPushAlertView alloc] initWithFrame:CGRectMake(0, 0, Fitsize(257), Fitsize(353)) text:@"好券收藏不过期 开启通知告诉你"];
  626. CCAlertShowView *showView = [CCAlertShowView alertViewWithView:pushAlert];
  627. showView.tapBackgroundDismissEnable = NO;
  628. pushAlert.cancelBlock = ^{
  629. [showView dismiss];
  630. [KBDetailPopQueneManager shareManager].isShowing = NO;
  631. [[NSNotificationCenter defaultCenter] postNotificationName:showAlert object:nil];
  632. };
  633. pushAlert.sureBlock = ^{
  634. [self openSystemPushAction];
  635. [showView dismiss];
  636. [KBDetailPopQueneManager shareManager].isShowing = NO;
  637. [[NSNotificationCenter defaultCenter] postNotificationName:showAlert object:nil];
  638. };
  639. [[KBDetailPopQueneManager shareManager].alertArray addObject:showView];
  640. [[NSNotificationCenter defaultCenter] postNotificationName:showAlert object:nil];
  641. }
  642. /**
  643. 开启系统通知
  644. */
  645. - (void)openSystemPushAction {
  646. NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
  647. if([[UIApplication sharedApplication]canOpenURL:url] ) {
  648. if (@available(iOS 10.0, *)) {
  649. [[UIApplication sharedApplication] openURL:url options:@{}completionHandler:^(BOOL success) {
  650. }];
  651. } else {
  652. [[UIApplication sharedApplication]openURL:url];
  653. }
  654. }
  655. }
  656. /**
  657. 获取商品链接
  658. */
  659. - (void)getTicketTaoBaoUrl {
  660. [self goBuy];
  661. [MobClick event:pay_count];
  662. // if (![AccountTool account]) {
  663. // KBLoginViewController *login = [[KBLoginViewController alloc] init];
  664. // [self presentViewController:login animated:YES completion:nil];
  665. // return;
  666. // }
  667. //
  668. //
  669. //
  670. // if ([self.flag integerValue]==1) {
  671. // UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"升级赚佣金" message:[NSString stringWithFormat:@"\n成为超级会员后,您购买商品就可以拿到%.2f元佣金哦~",[self.goodModel.super_commission_price floatValue]] preferredStyle:UIAlertControllerStyleAlert];
  672. // UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"直接领劵" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  673. // [self goBuy];
  674. //
  675. // }];
  676. // UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"成为超级会员" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  677. // KBPrivilegeReferralViewController *vc=[[KBPrivilegeReferralViewController alloc]init];
  678. // vc.flag=@(1);
  679. // vc.isSuper=@(0);
  680. // [self.navigationController pushViewController:vc animated:YES];
  681. // }];
  682. // [alert addAction:defaultAction];
  683. // [alert addAction:cancelAction];
  684. // [self presentViewController:alert animated:YES completion:nil];
  685. // return;
  686. // }else{
  687. // [self goBuy];
  688. // }
  689. }
  690. -(void)goBuy{
  691. if (goBuyUrl.length > 0) {
  692. [self jumpToTaobaoWithGoodsUrl:goBuyUrl];
  693. }else {
  694. [SVProgressHUD show];
  695. NSString *category_id = self.eventModel.category_id==nil?@"":self.eventModel.category_id;
  696. NSString *source = self.eventModel.source==nil?@"":self.eventModel.source;
  697. NSDictionary *param = @{@"goods_id":self.requestModel.goods_id,
  698. @"is_coupon":self.requestModel.is_coupon,
  699. @"category_id":category_id,
  700. @"path":source
  701. };
  702. NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/orderDown",BaseURL];
  703. [KBHttp post:url params:param success:^(id json) {
  704. if (url.length > 0) {
  705. [self jumpToTaobaoWithGoodsUrl:json[@"url"]];
  706. }
  707. [SVProgressHUD dismiss];
  708. } failure:^(NSError *error) {
  709. [SVProgressHUD dismiss];
  710. [MBProgressHUD showMessage:@"加载失败"];
  711. }];
  712. }
  713. }
  714. - (void)jumpToTaobaoWithGoodsUrl:(NSString *)url {
  715. [KBEventTool eventWithEventType:1 origin:self.eventModel.origin category_id:self.eventModel.category_id goods_id:self.requestModel.goods_id source:self.eventModel.source];
  716. if ([self isInstallTaobaoAPP]) {
  717. id<AlibcTradePage> page = [AlibcTradePageFactory page:url];
  718. //淘客信息
  719. AlibcTradeTaokeParams *taoKeParams=[[AlibcTradeTaokeParams alloc] init];
  720. taoKeParams.pid = ALTK_PID; //
  721. //打开方式
  722. AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init];
  723. showParam.openType = AlibcOpenTypeNative;
  724. [[AlibcTradeSDK sharedInstance].tradeService show:self.navigationController page:page showParams:showParam taoKeParams:taoKeParams trackParam:nil tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) {
  725. } tradeProcessFailedCallback:^(NSError * _Nullable error) {
  726. }];
  727. }else {
  728. KBWebDetailController *webVc = [[KBWebDetailController alloc] init];
  729. webVc.url = url;
  730. [self.navigationController pushViewController:webVc animated:YES];
  731. }
  732. }
  733. /**
  734. 判断是否安装淘宝app
  735. */
  736. - (BOOL)isInstallTaobaoAPP {
  737. if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"taobao://"]]) {
  738. return YES;
  739. }else {
  740. return NO;
  741. }
  742. }
  743. #pragma mark - goodDetailViewDelegate
  744. - (void)yh_GoodDetailViewTapCoupon {
  745. [KBGoodDetailRequestViewModel requestTicketProcessParamGoods_id:self.requestModel.goods_id coupon_price:self.goodModel.coupon_price success:^(NSString *msg) {
  746. [self yh_GoodDetailBottomViewClickBuyButton];
  747. } failure:^(NSError *error) {
  748. }];
  749. }
  750. - (void)yh_GoodDetailViewTapShop {
  751. KBShopDetailViewController *shopVC = [[KBShopDetailViewController alloc] init];
  752. shopVC.goodModel = self.goodModel;
  753. [self.navigationController pushViewController:shopVC animated:YES];
  754. }
  755. #pragma mark - webView
  756. - (void)webViewDidStartLoad:(UIWebView *)webView {
  757. [SVProgressHUD dismiss];
  758. }
  759. - (void)webViewDidFinishLoad:(UIWebView *)webView {
  760. [SVProgressHUD dismiss];
  761. CGSize contentSize = webView.scrollView.contentSize;
  762. CGSize viewSize = self.detailDescWebView.bounds.size;
  763. float rw = viewSize.width / contentSize.width;
  764. webView.scrollView.minimumZoomScale = rw;
  765. webView.scrollView.maximumZoomScale = rw;
  766. webView.scrollView.zoomScale = rw;
  767. }
  768. - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
  769. [SVProgressHUD dismiss];
  770. }
  771. #pragma mark ------ wkWebView delegate ------
  772. // main frame的导航开始请求时调用
  773. - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation{
  774. }
  775. // 当main frame开始加载数据失败时,会回调
  776. - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error {
  777. }
  778. //当main frame导航完成时,会回调
  779. - (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation{
  780. // 页面加载完成之后调用
  781. }
  782. #pragma mark - tableView
  783. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  784. return 1;
  785. }
  786. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  787. NSArray *pics = self.goodModel.detail_pic;
  788. return pics.count;
  789. }
  790. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  791. KBDetailImgModel *model = self.goodModel.detail_pic[indexPath.row];
  792. CGFloat imgScale = model.width.floatValue/model.height.floatValue;
  793. CGFloat imgH = SCREEN_WIDTH/imgScale;
  794. return imgH;
  795. }
  796. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  797. KBGoodDetailImageCell *cell = [KBGoodDetailImageCell cellWithTableView:tableView];
  798. cell.model = self.goodModel.detail_pic[indexPath.row];
  799. return cell;
  800. }
  801. #pragma mark - collectionView
  802. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  803. return 1;
  804. }
  805. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  806. return self.goodSimilarArr.count;
  807. }
  808. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  809. CGFloat width = (SCREEN_WIDTH-5)/2;
  810. CGFloat height = width + 102;
  811. return CGSizeMake(width, height);
  812. }
  813. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  814. KBGoodCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
  815. cell.backgroundColor = [UIColor whiteColor];
  816. cell.backgroundView.backgroundColor = [UIColor whiteColor];
  817. cell.contentView.backgroundColor = [UIColor whiteColor];
  818. KBChildGoodModel *model = self.goodSimilarArr[indexPath.item];
  819. cell.model = model;
  820. return cell;
  821. }
  822. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
  823. UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionViewHeader forIndexPath:indexPath];
  824. CALayer *lineGapLayer = [CALayer layer];
  825. lineGapLayer.frame = CGRectMake(0, 0, kScreenWidth, FITSIZE(5));
  826. lineGapLayer.backgroundColor = [UIColor YHColorWithHex:0xf5f4f4].CGColor;
  827. [view.layer addSublayer:lineGapLayer];
  828. UILabel *lineGapLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, kScreenWidth, FITSIZE(40))];
  829. lineGapLabel.backgroundColor = [UIColor whiteColor];
  830. lineGapLabel.textColor = [UIColor YHColorWithHex:0x222222];
  831. lineGapLabel.font = [UIFont systemFontOfSize:FITSIZE(13)];
  832. lineGapLabel.text = @"相关推荐";
  833. lineGapLabel.textAlignment = NSTextAlignmentCenter;
  834. [view addSubview:lineGapLabel];
  835. return view;
  836. }
  837. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
  838. return CGSizeMake(kScreenWidth, FITSIZE(45));
  839. }
  840. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  841. KBChildGoodModel *model = self.goodSimilarArr[indexPath.item];
  842. //详情
  843. KBGoodDetailViewController *detailVC = [[KBGoodDetailViewController alloc] init];
  844. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithChildModel:model];
  845. detailVC.requestModel = requestModel;
  846. KBEventModel *evevtModel = [[KBEventModel alloc] initWithOrigin:@"0" category_id:@"0" source:goodsDetailRecommendAction];
  847. detailVC.eventModel = evevtModel;
  848. [self.navigationController pushViewController:detailVC animated:YES];
  849. }
  850. #pragma mark - lazy
  851. - (UITableView *)tableView {
  852. if (!_tableView) {
  853. _tableView = [[KBTableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight-FITSIZE(55)-BottomMargin) style:UITableViewStylePlain];
  854. _tableView.estimatedRowHeight = 0;
  855. _tableView.estimatedSectionHeaderHeight = 0;
  856. _tableView.estimatedSectionFooterHeight = 0;
  857. _tableView.delegate = self;
  858. _tableView.dataSource = self;
  859. [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
  860. if (@available(iOS 11.0, *)) {
  861. _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  862. }
  863. }
  864. return _tableView;
  865. }
  866. - (UICollectionView *)collectionView {
  867. if (!_collectionView) {
  868. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  869. flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
  870. flowLayout.minimumLineSpacing = FITSIZE(5);
  871. flowLayout.minimumInteritemSpacing = FITSIZE(0);
  872. _collectionView = [[KBCollectionView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, GoodSimilarViewHeight) collectionViewLayout:flowLayout];
  873. _collectionView.scrollEnabled = NO;
  874. _collectionView.bounces = NO;
  875. _collectionView.showsVerticalScrollIndicator = NO;
  876. _collectionView.delegate = self;
  877. _collectionView.dataSource = self;
  878. [_collectionView registerClass:[KBGoodCollectionCell class] forCellWithReuseIdentifier:cellID];
  879. [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionViewHeader];
  880. }
  881. return _collectionView;
  882. }
  883. - (SGPageTitleView *)topTitleView {
  884. if (!_topTitleView) {
  885. SGPageTitleViewConfigure *configure = [SGPageTitleViewConfigure pageTitleViewConfigure];
  886. configure.titleFont = [UIFont systemFontOfSize:FITSIZE(14)];
  887. configure.titleColor = [UIColor YHColorWithHex:0x222222];
  888. configure.titleSelectedColor = [UIColor YHColorWithHex:0xff2420];
  889. configure.indicatorColor = [UIColor YHColorWithHex:0xff2420];
  890. configure.indicatorScrollStyle = SGIndicatorScrollStyleHalf;
  891. _topTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(kScreenWidth/2-FITSIZE(100), KStatusBarHeight, FITSIZE(200), 44) delegate:self titleNames:@[@"宝贝",@"详情",@"推荐"] configure:configure];
  892. _topTitleView.backgroundColor = [UIColor clearColor];
  893. _topTitleView.alpha = 0.0;
  894. _topTitleView.isNeedBounces = NO;
  895. _topTitleView.isTitleGradientEffect = NO;
  896. _topTitleView.isOpenTitleTextZoom = YES;
  897. _topTitleView.isShowBottomSeparator = NO;
  898. }
  899. return _topTitleView;
  900. }
  901. @end