Nessuna descrizione

FKRecommendController.m 41KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  1. //
  2. // FKRecommendContoller.m
  3. // FirstLink
  4. //
  5. // Created by jack on 15/11/30.
  6. // Copyright © 2015年 FirstLink. All rights reserved.
  7. //
  8. #import "FKRecommendController.h"
  9. #import "FKRecommendViewModel.h"
  10. #import "FKAdvertiseViewCell.h"
  11. #import "FKOperationImageCell.h"
  12. #import "FKRecoIconListCell.h"
  13. #import "FKRecoNewsCell.h"
  14. #import "FKRecoHeaderCell.h"
  15. #import "FKRecoLimitBuyCell.h"
  16. #import "FKRecoPromotionLimitCell.h"
  17. #import "FKRecoPromotionCategoryCell.h"
  18. #import "FKRecoOfficalActivityCell.h"
  19. #import "FKRecoBrandListCell.h"
  20. #import "FKExploreTableViewCell.h"
  21. #import "FKRecoUserRecoProductCell.h"
  22. #import "FKRecoScanRecoProductCell.h"
  23. #import "FKRecoHotProductCell.h"
  24. #import "GuideView.h"
  25. #import "FKRecommendRequest.h"
  26. #import "FKRecommendReform.h"
  27. #import "FKWeakTimerTarget.h"
  28. #import "SchemaManager.h"
  29. #import "FloatDownView.h"
  30. #import "FLControllerHelper.h"
  31. #import "WebViewController.h"
  32. #import "FKRecoNewsController.h"
  33. #import "FKHotSaleController.h"
  34. #import "FKTopicController.h"
  35. #import "FKTopicListController.h"
  36. #import "FKTopicListController.h"
  37. #import "FKEntireCategoryController.h"
  38. #import "FLExploreController.h"
  39. #import "FKExploreListController.h"
  40. #import "PindanDetailController.h"
  41. #import "FKProDetailController.h"
  42. #import "FKRecommendPageController.h"
  43. #import "FKProDetailController.h"
  44. #import "FKWindowViewManager.h"
  45. @interface FKRecommendController () <UITableViewDelegate, UITableViewDataSource, FLNetworkDelegate, FKRecoCustomCellDelegate>
  46. @property (nonatomic, strong) FKAdvertiseViewCell *advertiseView;
  47. @property (nonatomic, strong) FKRecoPromotionLimitCell *promotionLimitCell;
  48. @property (nonatomic, strong) FKRecommendViewModel *viewModel;
  49. @property (nonatomic, strong) UIButton *backTopBtn;
  50. @property (nonatomic, strong) GuideView *dsNewsGuideView;
  51. @property (nonatomic, strong) GuideView *haoHuoGuideView;
  52. @end
  53. @implementation FKRecommendController
  54. - (void)viewDidLoad {
  55. [super viewDidLoad];
  56. [self addAllSubviews];
  57. [self configRiseView];
  58. if (([FKUserManager isUserLogin]
  59. || [FKUserManager sharedManager].applicationMode == ApplicationModeVisitor)) {
  60. [self.hudView show:YES];
  61. [self requestInitialData];
  62. }
  63. [FKWeakTimerTarget scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timeCountDownCallback) userInfo:nil repeats:YES];
  64. }
  65. - (void)viewWillAppear:(BOOL)animated{
  66. [super viewWillAppear:animated];
  67. [self reqDynamicMessage];
  68. // [self.tableView reloadData];
  69. }
  70. #pragma mark - Reuqest
  71. - (void)autoRefresh {
  72. [self.refreshControl startRefreshingDirection:RefreshDirectionTop];
  73. }
  74. - (void)refreshControl:(FKRefreshControl *)refreshControl didEngageRefreshDirection:(RefreshDirection)direction {
  75. [self resetTableViewStatus];
  76. [self.advertiseView.banerView stopAutoSwitch];
  77. if (direction == RefreshDirectionTop) {
  78. [self.viewModel.contensOffsetDict removeAllObjects];
  79. [self requestInitialData];
  80. if (self.handlePageRefreshEvent) {
  81. self.handlePageRefreshEvent();
  82. }
  83. } else if (direction == RefreshDirectionBottom){
  84. [self requestMoreDailyData];
  85. }
  86. }
  87. - (void)requestMoreDailyData {
  88. [FKRecommendRequest requestMoreDataWithStartRow:[self.viewModel getAllRecommendItemCount]
  89. updateTime:self.viewModel.updateTime
  90. delegate:self];
  91. }
  92. - (void)requestInitialData {
  93. [FKRecommendRequest requestRecommendDataWithDelegate:self];
  94. [self reqDynamicMessage];
  95. }
  96. - (void)requestActivityData {
  97. [FKRecommendRequest requestActivityShareWithDelegate:self];
  98. }
  99. - (void)requestPromotionData {
  100. [FKRecommendRequest requestPromotionInfoWithDelegate:self];
  101. }
  102. - (void)requestScanRecoData {
  103. [FKRecommendRequest requestScanRecommendDataWithDelegate:self];
  104. }
  105. - (void)requestUserRecoData {
  106. if ([FKUserManager isUserLogin]) {
  107. [FKRecommendRequest requestUserRecommendDataWithDelegate:self];
  108. }
  109. }
  110. - (void)reqPointMessage {
  111. if ([FKUserManager sharedManager].applicationMode == ApplicationModeVisitor) return;
  112. [FKRecommendRequest requestPointMessage:REC_POINT_MESSAGE delegate:self];
  113. }
  114. - (void)reqDynamicMessage {
  115. if ([FKUserManager sharedManager].applicationMode == ApplicationModeVisitor) return;
  116. [FKRecommendRequest requestDynamicMsgWithIdentify:REC_DYNAMIC_MESSAGE deleagate:self];
  117. }
  118. #pragma mark - Response
  119. - (void)networkDidSuccessResponse:(NSDictionary *)response identify:(int)identify header:(MSGHeader *)header {
  120. [self.hudView hide:YES];
  121. [self finishLoadingData];
  122. [self.statusView removeFromSuperview];
  123. [self.advertiseView.banerView startAutoSwitch];
  124. if (header.code.intValue == RESPONSE_MSG_NORMAL) {
  125. if (identify == REC_INITIAL_DATA_REQ) {
  126. self.viewModel.elapseSecond = 0;
  127. self.viewModel = [FKRecommendReform parserViewModelWithDict:response];
  128. [self configAdvertiseView];
  129. [self requestUserRecoData];
  130. [self requestScanRecoData];
  131. [self requestActivityData];
  132. [self requestPromotionData];
  133. } else if (identify == REC_MORE_DATA_REQ) {
  134. NSInteger count = [FKRecommendReform parserHotProductForViewModel:self.viewModel withDict:response];
  135. if (count == 0 || count%PAGE_RECORD_COUNT > 0) {
  136. [self configTableViewNoMoreData];
  137. }
  138. } else if (identify == REC_ACTIVITY_SHARE) {
  139. self.viewModel.recoNewsItem = [FKRecommendReform parserActivityData:response];
  140. } else if (identify == REC_PROMOTION_INFO) {
  141. self.viewModel.flashSaleItem = [FKRecommendReform parserFlashSaleData:response];
  142. self.viewModel.haoHuoItem = [FKRecommendReform parserHaoHuoData:response];
  143. self.viewModel.operActivityArray = [FKRecommendReform parserOperateActivityData:response];
  144. } else if (identify == REC_POINT_MESSAGE) {
  145. NSString *pointMessage = [FKRecommendReform parserPointMessage:response];
  146. NSString *serveTime = [FKRecommendReform parserServeTimeStr:response];
  147. [self showMessage:pointMessage
  148. serveTime:serveTime
  149. identifyKey:LAST_SHOW_SCORE_MESSAGE_TIME
  150. riseType:RiseViewTypeAutoClose];
  151. return;
  152. } else if (identify == REC_DYNAMIC_MESSAGE){
  153. FKDynamicMessageItem *item = [FKRecommendReform parserDynamicItemWithDict:response];
  154. NSString *serveTime = [FKRecommendReform parserServeTimeStr:response];
  155. BOOL showRes = [self showMessage:item.message
  156. serveTime:serveTime
  157. identifyKey:LAST_SHOW_MESSAGE_TIME
  158. riseType:RiseViewTypeClickClose];
  159. if (!showRes) {
  160. // 优先展示新人及代金券提示
  161. [self reqPointMessage];
  162. }
  163. return;
  164. } else if (identify == REC_RANDOM_BRAND) {
  165. FKRecAreaItem *brandArea = [FKRecommendReform parserDateAreaWithDict:response
  166. arrayKey:@"list"
  167. idKey:nil
  168. descKey:nil
  169. className:[FKRecoBrandItem class]];
  170. self.viewModel.brandRecommendArea.dataArray = brandArea.dataArray;
  171. } else if (identify == REC_USER_DATA_REQ) {
  172. FKRecAreaItem *userRecoItem = [FKRecommendReform parserDateAreaWithDict:response
  173. arrayKey:@"list"
  174. idKey:nil
  175. descKey:@"list_desc"
  176. className:[FKHotProductItem class]];
  177. if (userRecoItem.dataArray.count > 0) {
  178. self.viewModel.userRecoArea = userRecoItem;
  179. }
  180. } else if (identify == REC_SCAN_DATA_REQ) {
  181. FKRecAreaItem *scanRecoItem = [FKRecommendReform parserDateAreaWithDict:response
  182. arrayKey:@"list"
  183. idKey:nil
  184. descKey:@"list_desc"
  185. className:[FKHotProductItem class]];
  186. if (scanRecoItem.dataArray.count > 0) {
  187. self.viewModel.scanRecoArea = scanRecoItem;
  188. }
  189. }
  190. }
  191. if (!self.viewModel || [self.viewModel allEmpty]) {
  192. [self showStatusTipInView:self.tableView image:[UIImage imageNamed:@"StatusNoOrderIcon"] title:@"没有发现商品哦"];
  193. }
  194. [self.tableView reloadData];
  195. }
  196. - (void)networkDidReceiveError:(NSError *)error identify:(int)identify header:(MSGHeader *)header {
  197. [self.hudView hide:NO];
  198. [self finishLoadingData];
  199. [self.advertiseView.banerView startAutoSwitch];
  200. [FLProgressHUDHelper showText:header.msg inView:self.view];
  201. if (identify == REC_DYNAMIC_MESSAGE){
  202. [self reqPointMessage];
  203. }
  204. }
  205. #pragma mark - tableView dataSource
  206. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  207. if (!self.viewModel) return 0;
  208. return [self.viewModel numberOfSections];
  209. }
  210. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  211. return [self.viewModel numberOfRowsInSection:section];
  212. }
  213. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  214. return CGFLOAT_MIN;
  215. }
  216. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  217. return 10;
  218. }
  219. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  220. return [self.viewModel heightForRowAtIndexPath:indexPath];
  221. }
  222. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  223. self.backTopBtn.hidden = ([self.viewModel sectionTypeForSection:indexPath.section] != kRecoSectionTypeHotProduct);
  224. kRecoCellType cellType = [self.viewModel cellTypeForIndexPath:indexPath];
  225. switch (cellType) {
  226. case kRecoCellTypeAdvertise: {
  227. return self.advertiseView;
  228. }
  229. case kRecoCellTypeOperationImage: {
  230. FKOperationImageCell *operationCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKOperationImageCell class])];
  231. [operationCell fk_configWithViewModel:self.viewModel indexPath:indexPath];
  232. return operationCell;
  233. }
  234. case kRecoCellTypeIconList: {
  235. FKRecoIconListCell *iconCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKRecoIconListCell class])];
  236. [iconCell fk_configWithViewModel:self.viewModel indexPath:indexPath];
  237. iconCell.delegate = self;
  238. iconCell.indexPath = indexPath;
  239. return iconCell;
  240. }
  241. case kRecoCellTypeRecoNews: {
  242. FKRecoNewsCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKRecoNewsCell class])];
  243. [cell fk_configWithViewModel:self.viewModel indexPath:indexPath];
  244. return cell;
  245. }
  246. case kRecoCellTypPromotionLimit: {
  247. FKRecoPromotionLimitCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKRecoPromotionLimitCell class])];
  248. [cell fk_configWithViewModel:self.viewModel indexPath:indexPath];
  249. cell.delegate = self;
  250. cell.indexPath = indexPath;
  251. self.promotionLimitCell = cell;
  252. return cell;
  253. }
  254. case kRecoCellTypPromotionCategory: {
  255. FKRecoPromotionCategoryCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKRecoPromotionCategoryCell class])];
  256. [cell fk_configWithViewModel:self.viewModel indexPath:indexPath];
  257. cell.delegate = self;
  258. cell.indexPath = indexPath;
  259. return cell;
  260. }
  261. case kRecoCellTypeHeader:{
  262. FKRecoHeaderCell *headerCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKRecoHeaderCell class])];
  263. [headerCell fk_configWithViewModel:self.viewModel indexPath:indexPath];
  264. headerCell.delegate = self;
  265. headerCell.indexPath = indexPath;
  266. return headerCell;
  267. }
  268. case kRecoCellTypeLimitBuy:{
  269. FKRecoLimitBuyCell *limitCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKRecoLimitBuyCell class])];
  270. [limitCell fk_configWithViewModel:self.viewModel indexPath:indexPath];
  271. limitCell.delegate = self;
  272. limitCell.indexPath = indexPath;
  273. return limitCell;
  274. }
  275. case kRecoCellTypeOfficalActivity:{
  276. FKRecoOfficalActivityCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKRecoOfficalActivityCell class])];
  277. [cell fk_configWithViewModel:self.viewModel indexPath:indexPath];
  278. cell.delegate = self;
  279. cell.indexPath = indexPath;
  280. return cell;
  281. }
  282. case kRecoCellTypeBrandReco: {
  283. FKRecoBrandListCell *brandCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKRecoBrandListCell class])];
  284. [brandCell fk_configWithViewModel:self.viewModel indexPath:indexPath];
  285. brandCell.delegate = self;
  286. brandCell.indexPath = indexPath;
  287. return brandCell;
  288. break;
  289. }
  290. case kRecoCellTypeOperationActivity: {
  291. FKExploreTableViewCell *operationCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKExploreTableViewCell class])];
  292. [operationCell fk_configWithViewModel:self.viewModel indexPath:indexPath];
  293. operationCell.delegate = self;
  294. operationCell.indexPath = indexPath;
  295. CGFloat offset = [self.viewModel contentOffsetForKey:indexPath.hash];
  296. [operationCell.collectionView setContentOffset:CGPointMake(offset, 0) animated:NO];
  297. return operationCell;
  298. break;
  299. }
  300. case kRecoCellTypeUserRecoProduct: {
  301. FKRecoUserRecoProductCell *productCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKRecoUserRecoProductCell class])];
  302. [productCell fk_configWithViewModel:self.viewModel indexPath:indexPath];
  303. productCell.delegate = self;
  304. productCell.indexPath = indexPath;
  305. return productCell;
  306. break;
  307. }
  308. case kRecoCellTypeScanRecoProduct: {
  309. FKRecoScanRecoProductCell *productCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKRecoScanRecoProductCell class])];
  310. [productCell fk_configWithViewModel:self.viewModel indexPath:indexPath];
  311. return productCell;
  312. break;
  313. }
  314. case kRecoCellTypeHotProduct: {
  315. FKRecoHotProductCell *productCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKRecoHotProductCell class])];
  316. [productCell fk_configWithViewModel:self.viewModel indexPath:indexPath];
  317. return productCell;
  318. break;
  319. }
  320. default:
  321. break;
  322. }
  323. return nil;
  324. }
  325. - (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  326. if ([cell isKindOfClass:[FKExploreTableViewCell class]]) {
  327. FKExploreTableViewCell *exploreCell = (FKExploreTableViewCell*)cell;
  328. [self.viewModel setContentOffset:exploreCell.collectionView.contentOffset.x forKey:indexPath.hash];
  329. }
  330. }
  331. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  332. kRecoCellType cellType = [self.viewModel cellTypeForIndexPath:indexPath];
  333. switch (cellType) {
  334. case kRecoCellTypeOperationImage: {
  335. if ([FLStringHelper isValidString:self.viewModel.operationItem.targetUrl]){
  336. [self parseURLSchema:self.viewModel.operationItem.targetUrl];
  337. [FKRecommendRequest requestBehavior:@"index_activity_banner" objType:@"activity_banner" objID:nil positionV1:nil positionV2:nil];
  338. }
  339. break;
  340. }
  341. case kRecoCellTypeRecoNews: {
  342. [self pushViewController:[FKRecoNewsController new]];
  343. [FKRecommendRequest requestBehavior:@"index_headline_banner" objType:@"headline_banner" objID:nil positionV1:nil positionV2:nil];
  344. break;
  345. }
  346. case kRecoCellTypeScanRecoProduct: {
  347. FKHotProductItem *item = [self.viewModel.scanRecoArea dataItemAtIndex:(indexPath.row - 1)];
  348. if (item) {
  349. [self pushProductDetailController:item.recoItemID];
  350. [[FKPageRouterUtil sharedInstance] pushPageRefer:PRPageDailyRecommendAlgo
  351. itemID:nil
  352. value:nil];
  353. [FKRecommendRequest requestBehavior:@"index_algo_product"
  354. objType:@"product"
  355. objID:item.recoItemID
  356. positionV1:[NSString stringWithFormat:@"%ld", (long)(indexPath.row - 1)]
  357. positionV2:nil];
  358. }
  359. break;
  360. }
  361. case kRecoCellTypeHotProduct: {
  362. FKHotProductItem *item = [self.viewModel.hotProductArea dataItemAtIndex:(indexPath.row - 1)];
  363. if (item) {
  364. [self pushProductDetailController:item.itemID];
  365. [FKRecommendRequest requestBehavior:@"index_hot_product"
  366. objType:@"product"
  367. objID:item.itemID
  368. positionV1:[NSString stringWithFormat:@"%ld", (long)(indexPath.row - 1)]
  369. positionV2:nil];
  370. }
  371. break;
  372. }
  373. default:
  374. break;
  375. }
  376. }
  377. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  378. if (self.viewModel.recoNewsItem && self.viewModel.flashSaleItem && self.viewModel.haoHuoItem) {
  379. if (scrollView.contentOffset.y > [self dsNewsGuideViewOffset]) {
  380. [self showDSNewsGuideView];
  381. }
  382. }
  383. }
  384. #pragma mark - FKRecommendBaseCellDelegate
  385. - (void)recommendClickHeaderButton:(UIButton *)button atIndexPath:(NSIndexPath *)indexPath {
  386. kRecoSectionType sectionType = [self.viewModel sectionTypeForSection:indexPath.section];
  387. switch (sectionType) {
  388. case kRecoSectionTypeOfficalActivity: {
  389. [self pushTopicListController:self.viewModel.officalActivityArea.areaID title:@"更多官网活动"];
  390. break;
  391. }
  392. case kRecoSectionTypeBrandReco: {
  393. [FKRecommendRequest requestRandomBrandWithDelegate:self];
  394. break;
  395. }
  396. case kRecoSectionTypeScanReco: {
  397. [self requestScanRecoData];
  398. break;
  399. }
  400. case kRecoSectionTypeOperationActivity: {
  401. FKTopicListController *controller = [[FKTopicListController alloc] initWithID:self.viewModel.operationActivityArea.areaID title:@"专题列表"];
  402. [self pushViewController:controller];
  403. break;
  404. }
  405. default:
  406. break;
  407. }
  408. }
  409. - (void)recommendClickCell:(id)cell atIndexPath:(NSIndexPath *)indexPath offset:(NSInteger)offset {
  410. kRecoCellType cellType = [self.viewModel cellTypeForIndexPath:indexPath];
  411. switch (cellType) {
  412. case kRecoCellTypeAdvertise: {
  413. FKAdvertiseItem *item = [self.viewModel advertiseItemAtIndex:offset];
  414. if (item && item.targetURL.length > 0) {
  415. [self parseURLSchema:item.targetURL];
  416. [FKRecommendRequest requestBehavior:@"index_banner" objType:@"banner" objID:item.itemID positionV1:[NSString stringWithFormat:@"%ld", (long)offset] positionV2:nil];
  417. }
  418. break;
  419. }
  420. case kRecoCellTypeIconList: {
  421. FKIconItem *item = [self.viewModel iconItemAtIndex:offset];
  422. if (item && item.targetUrl.length > 0) {
  423. [self.viewModel didClickNewTagAtIndex:offset];
  424. [self parseURLSchema:item.targetUrl];
  425. [FKRecommendRequest requestBehavior:@"index_icon_menu"
  426. objType:@"icon_menu"
  427. objID:item.itemID
  428. positionV1:[NSString stringWithFormat:@"%ld", (long)offset]
  429. positionV2:nil];
  430. }
  431. break;
  432. }
  433. case kRecoCellTypeLimitBuy: {
  434. FKLimitBuyItem *item = [self.viewModel limitBuyItemAtIndex:offset];
  435. if (item && item.targetUrl.length) {
  436. [self parseURLSchema:item.targetUrl];
  437. [[FKPageRouterUtil sharedInstance] pushPageRefer:PRPageDailyRecommendLimitBuy
  438. itemID:nil
  439. value:nil];
  440. [FKRecommendRequest requestBehavior:@"index_promotion"
  441. objType:@"product"
  442. objID:item.objectID
  443. positionV1:[NSString stringWithFormat:@"%ld", (long)offset]
  444. positionV2:nil];
  445. }
  446. break;
  447. }
  448. case kRecoCellTypPromotionLimit: {
  449. NSString *targetURL = self.viewModel.flashSaleItem.targetURL;
  450. if (offset == 1) {
  451. targetURL = self.viewModel.haoHuoItem.targetURL;
  452. [FKRecommendRequest requestBehavior:@"index_haohuo_banner" objType:@"haohuo_banner" objID:nil positionV1:nil positionV2:nil];
  453. } else {
  454. [FKRecommendRequest requestBehavior:@"index_promotion_banner" objType:@"promotion_banner" objID:nil positionV1:nil positionV2:nil];
  455. }
  456. [self parseURLSchema:targetURL];
  457. break;
  458. }
  459. case kRecoCellTypPromotionCategory: {
  460. if (offset < self.viewModel.operActivityArray.count) {
  461. FKOperateActivityItem *item = self.viewModel.operActivityArray[offset];
  462. [self parseURLSchema:item.targetURL];
  463. }
  464. if (offset == (self.viewModel.operActivityArray.count - 1)) {
  465. [FKRecommendRequest requestBehavior:@"index_hotsale_banner" objType:@"hotsale_banner" objID:nil positionV1:nil positionV2:nil];
  466. } else {
  467. [FKRecommendRequest requestBehavior:@"index_block_banner" objType:@"block_banner" objID:nil positionV1:nil positionV2:nil];
  468. }
  469. break;
  470. }
  471. case kRecoCellTypeOfficalActivity: {
  472. FKActivityItem *item = [self.viewModel officalActivityItemAtIndex:(indexPath.row - 1)*2 + offset];
  473. if (item && item.targetUrl.length > 0) {
  474. [self parseURLSchema:item.targetUrl];
  475. } else {
  476. [self pushTopicController:item.itemID];
  477. }
  478. [FKRecommendRequest requestBehavior:@"index_official_activity"
  479. objType:@"topic"
  480. objID:item.itemID
  481. positionV1:[NSString stringWithFormat:@"%ld", (long)(indexPath.row - 1)]
  482. positionV2:nil];
  483. break;
  484. }
  485. case kRecoCellTypeUserRecoProduct: {
  486. FKHotProductItem *item = [self.viewModel.userRecoArea dataItemAtIndex:offset];
  487. if (item) {
  488. [self pushProductDetailController:item.recoItemID];
  489. [[FKPageRouterUtil sharedInstance] pushPageRefer:PRPageDailyUserRecoAlgo
  490. itemID:nil
  491. value:nil];
  492. //
  493. [FKRecommendRequest requestBehavior:@"index_engine_product"
  494. objType:@"product"
  495. objID:item.itemID
  496. positionV1:[NSString stringWithFormat:@"%ld", (long)(offset)]
  497. positionV2:nil];
  498. }
  499. break;
  500. }
  501. case kRecoCellTypeBrandReco: {
  502. FKRecoBrandItem *item = [self.viewModel recoBrandItemAtIndex:offset];
  503. if (item && item.name.length) {
  504. [self pushExploreListController:item.name];
  505. [FKRecommendRequest requestBehavior:@"index_brand_recommend"
  506. objType:@"brand"
  507. objID:item.itemID
  508. positionV1:[NSString stringWithFormat:@"%ld", (long)offset]
  509. positionV2:nil];
  510. }
  511. break;
  512. }
  513. case kRecoCellTypeOperationActivity: {
  514. FKActivityItem *item = [self.viewModel operationActivityItemAtIndex:(indexPath.row - 1)];
  515. if (item) {
  516. if (offset < item.productArray.count) {
  517. FKActivityProductItem *productItem = item.productArray[offset];
  518. [self pushProductDetailController:productItem.itemID];
  519. [[FKPageRouterUtil sharedInstance] pushPageRefer:PRPageDailyRecommendActivity
  520. itemID:item.itemID
  521. value:item.name];
  522. [FKRecommendRequest requestBehavior:@"index_activity_list"
  523. objType:@"product"
  524. objID:productItem.itemID
  525. positionV1:[NSString stringWithFormat:@"%ld", (long)(indexPath.row - 1)]
  526. positionV2:[NSString stringWithFormat:@"%ld", (long)offset]];
  527. } else if (offset == -1) { // -1 表示点击大图或者是更多按钮
  528. if (item && item.targetUrl.length > 0) {
  529. [self parseURLSchema:item.targetUrl];
  530. } else {
  531. [self pushTopicController:item.itemID];
  532. }
  533. [FKRecommendRequest requestBehavior:@"index_activity_list"
  534. objType:@"topic"
  535. objID:item.itemID
  536. positionV1:[NSString stringWithFormat:@"%ld", (long)(indexPath.row - 1)]
  537. positionV2:nil];
  538. }
  539. }
  540. break;
  541. }
  542. default:
  543. break;
  544. }
  545. }
  546. #pragma mark - FKRecommendActivityAreaCell
  547. - (void)clickActivityCellAtIndex:(NSInteger)index {
  548. if (index < self.viewModel.activityArea.count) {
  549. FKActivityItem *item = self.viewModel.activityArea[index];
  550. [self parseURLSchema:item.targetUrl];
  551. }
  552. }
  553. #pragma mark - action
  554. - (void)clickMoreTopicBtn:(UIButton *)sender{
  555. FLExploreController *controller = [FLExploreController new];
  556. controller.hidesBottomBarWhenPushed = YES;
  557. [self pushViewController:controller];
  558. }
  559. - (void)backTopAction:(UIButton *)sender {
  560. [self.tableView setContentOffset:CGPointMake(0, 0) animated:YES];
  561. }
  562. - (void)timeCountDownCallback {
  563. self.viewModel.elapseSecond += 1;
  564. NSTimeInterval endTime = [FLStringHelper timeIntervalFromString:self.viewModel.flashSaleItem.endTime];
  565. NSTimeInterval serverTime = [FLStringHelper timeIntervalFromString:self.viewModel.serverTime];
  566. [self.promotionLimitCell setRemindTime:(MAX(0, endTime - serverTime) - self.viewModel.elapseSecond)];
  567. }
  568. - (BOOL)showMessage:(NSString *)message
  569. serveTime:(NSString *)serveTime
  570. identifyKey:(NSString *)identifyKey
  571. riseType:(RiseViewType)riseType{
  572. if (!message.length) return NO;
  573. if ([self.viewModel needShowMsgWithServeTime:serveTime key:identifyKey]){
  574. FloatDownCommand *command = [[FloatDownCommand alloc] init];
  575. command.type = riseType;
  576. command.content = message;
  577. [[FloatDownView sharedInstance] sendCommand:command];
  578. [self.viewModel didShowMsgWithServeTime:serveTime key:identifyKey];
  579. return YES;
  580. }
  581. return NO;
  582. }
  583. #pragma mark - method
  584. - (void)configTableViewNoMoreData {
  585. self.isPageHasMoreData = NO;
  586. self.refreshControl.bottomEnabled = NO;
  587. self.refreshControl.autoRefreshBottom = NO;
  588. self.tableView.tableFooterView = self.emptyFooterView;
  589. }
  590. - (void)resetTableViewStatus {
  591. self.isPageHasMoreData = YES;
  592. self.refreshControl.autoRefreshBottom = YES;
  593. self.refreshControl.bottomEnabled = YES;
  594. self.tableView.tableFooterView = nil;
  595. }
  596. - (void)configRiseView {
  597. CGRect frame = CGRectMake(0, 0, UISCREENWIDTH, DOWN_COMMAND_HEIGHT);
  598. [[FloatDownView sharedInstance] prepareFloatDownViewFrame:frame
  599. inView:self.view
  600. clickCallBack:^(id object)
  601. {
  602. }];
  603. }
  604. - (void)configAdvertiseView {
  605. if (self.viewModel.advertiseItems.count > 0) {
  606. BOOL reload = [self.viewModel isNeedReloadAdvForOldUrls:self.advertiseView.banerView.imageUrls];
  607. if (reload == YES) {
  608. self.advertiseView.banerView.imageUrls = self.viewModel.advertiseUrlArray;
  609. self.advertiseView.pageControl.numberOfPages = self.viewModel.advertiseItems.count;
  610. self.advertiseView.pageControl.currentPage = 0;
  611. }
  612. }
  613. }
  614. - (void)parseURLSchema:(NSString *)urlString {
  615. if (urlString.length > 0) {
  616. NSURL *url = [NSURL URLWithString:urlString];
  617. if ([url.scheme rangeOfString:@"HTTP" options:NSCaseInsensitiveSearch].length > 0) {
  618. [self pushWebViewController:urlString];
  619. } else {
  620. [[SchemaManager sharedManager] parserURL:url shouldCache:NO];
  621. }
  622. }
  623. }
  624. - (void)addAllSubviews{
  625. [self.view addSubview:self.tableView];
  626. [self.view addSubview:self.backTopBtn];
  627. [self.backTopBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  628. make.right.equalTo(self.view).offset(-20);
  629. make.bottom.equalTo(self.view).offset(-10);
  630. make.size.mas_equalTo(CGSizeMake(40, 40));
  631. }];
  632. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  633. make.edges.insets(UIEdgeInsetsZero);
  634. }];
  635. }
  636. #pragma mark - Show Guide View
  637. - (CGFloat)dsNewsGuideViewOffset {
  638. CGFloat offset = 0;
  639. CGFloat fixOffset = 0;
  640. if (IS_IPHONE_6P) {
  641. fixOffset = 290;
  642. } else if (IS_IPHONE_6) {
  643. fixOffset = 230;
  644. } else if (IS_IPHONE_5) {
  645. fixOffset = 162;
  646. } else if (IS_IPHONE_X) {
  647. fixOffset = 230;
  648. }
  649. for (NSInteger section = 0; section < [self.viewModel numberOfSections]; section++) {
  650. for (NSInteger row = 0; row < [self.viewModel numberOfRowsInSection:section]; row++) {
  651. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
  652. offset += [self.viewModel heightForRowAtIndexPath:indexPath];
  653. if ([self.viewModel cellTypeForIndexPath:indexPath] == kRecoCellTypeRecoNews) {
  654. return offset - fixOffset;
  655. }
  656. }
  657. }
  658. return 0;
  659. }
  660. - (void)showDSNewsGuideView {
  661. BOOL isShown = [[[NSUserDefaults standardUserDefaults] objectForKey:kShowDSNewsGuideViewKey] boolValue];
  662. if (!isShown && !IS_IPHONE_4) {
  663. self.tableView.scrollEnabled = NO;
  664. [self.tableView setContentOffset:CGPointMake(0, [self dsNewsGuideViewOffset]) animated:NO];
  665. GuideView *guideView = [[GuideView alloc] init];
  666. self.dsNewsGuideView = guideView;
  667. UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"guide_ds_news_img"]];
  668. imageView.userInteractionEnabled = YES;
  669. [imageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeDSNewsGuideView:)]];
  670. CGFloat offset = 0;
  671. if (IS_IPHONE_6P) {
  672. offset = 0;
  673. } else if (IS_IPHONE_6) {
  674. offset = -24;
  675. } else if (IS_IPHONE_5) {
  676. offset = -36;
  677. } else if (IS_IPHONE_X) {
  678. offset = 0;
  679. }
  680. [guideView addMaskView:imageView withRect:CGRectMake(0, offset, UISCREENWIDTH, UISCREENWIDTH*1334/750)];
  681. UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
  682. UIImage *image = [UIImage imageNamed:@"guide_close_button"];
  683. [closeButton setImage:image forState:UIControlStateNormal];
  684. [closeButton setImage:image forState:UIControlStateHighlighted];
  685. [closeButton addTarget:self action:@selector(closeDSNewsGuideView:) forControlEvents:UIControlEventTouchUpInside];
  686. [guideView addMaskView:closeButton withRect:CGRectMake(UISCREENWIDTH - 60, IS_IPHONE_X ? 44 : 20, 30, 31)];
  687. [[NSUserDefaults standardUserDefaults] setBool:YES forKey:kShowDSNewsGuideViewKey];
  688. [[NSUserDefaults standardUserDefaults] synchronize];
  689. self.tableView.scrollEnabled = YES;
  690. }
  691. }
  692. - (IBAction)closeDSNewsGuideView:(id)sender {
  693. [self.dsNewsGuideView removeFromSuperview];
  694. [self showHaoHuoGuideView];
  695. }
  696. - (void)showHaoHuoGuideView {
  697. BOOL isShown = [[[NSUserDefaults standardUserDefaults] objectForKey:kShowHaoHuoGuideViewKey] boolValue];
  698. if (!isShown && !IS_IPHONE_4) {
  699. GuideView *guideView = [[GuideView alloc] init];
  700. self.haoHuoGuideView = guideView;
  701. UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"guide_hao_huo_img"]];
  702. imageView.userInteractionEnabled = YES;
  703. [imageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeHaoHuoGuideView:)]];
  704. CGFloat offset = 0;
  705. if (IS_IPHONE_5) {
  706. offset = -36;
  707. } else if (IS_IPHONE_6) {
  708. offset = -24;
  709. } else if (IS_IPHONE_6P) {
  710. offset = 0;
  711. } else if (IS_IPHONE_X) {
  712. offset = 0;
  713. }
  714. [guideView addMaskView:imageView withRect:CGRectMake(0, offset, UISCREENWIDTH, UISCREENWIDTH*1334/750)];
  715. UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
  716. UIImage *image = [UIImage imageNamed:@"guide_close_button"];
  717. [closeButton setImage:image forState:UIControlStateNormal];
  718. [closeButton setImage:image forState:UIControlStateHighlighted];
  719. [closeButton addTarget:self action:@selector(closeHaoHuoGuideView:) forControlEvents:UIControlEventTouchUpInside];
  720. [guideView addMaskView:closeButton withRect:CGRectMake(UISCREENWIDTH - 60, IS_IPHONE_X ? 44 : 20, 30, 31)];
  721. [[NSUserDefaults standardUserDefaults] setBool:YES forKey:kShowHaoHuoGuideViewKey];
  722. [[NSUserDefaults standardUserDefaults] synchronize];
  723. }
  724. }
  725. - (IBAction)closeHaoHuoGuideView:(id)sender {
  726. [self.haoHuoGuideView removeFromSuperview];
  727. }
  728. #pragma mark - Push Controller
  729. - (void)pushWebViewController:(NSString *)urlString {
  730. WebViewController *newViewController = [[FLControllerHelper currentStoryBoard] instantiateViewControllerWithIdentifier:@"WebViewController"];
  731. newViewController.url = urlString;
  732. [self pushViewController:newViewController];
  733. }
  734. - (void)pushPindanDetailController:(NSString *)postId userID:(NSString *)userId{
  735. PindanDetailController *detail = [[PindanDetailController alloc]initWithUserID:userId postID:postId];
  736. [self pushViewController:detail];
  737. }
  738. - (void)pushProductDetailController:(NSString *)productID {
  739. FKProDetailController *controller = [[FKProDetailController alloc] initWithProductID:productID];
  740. [self pushViewController:controller];
  741. }
  742. - (void)pushExploreListController:(NSString *)brandname {
  743. FKExploreListController *controller = [[FKExploreListController alloc] initWithSource:FKExploreListSourceKeyword];
  744. [controller.conditionManager addConditionWithType:FKExploreConditionTypeBrand
  745. itemID:nil
  746. value:brandname];
  747. [self pushViewController:controller];
  748. }
  749. - (void)pushTopicController:(NSString *)topicID {
  750. FKTopicController *controller = [[FKTopicController alloc] init];
  751. controller.topicId = topicID;
  752. [self pushViewController:controller];
  753. }
  754. - (void)pushTopicListController:(NSString *)itemID title:(NSString *)title {
  755. FKEntireCategoryController *controller = [[FKEntireCategoryController alloc] init];
  756. controller.segmentIndex = 2;
  757. controller.isShowLeftBarItem = YES;
  758. [self pushViewController:controller];
  759. }
  760. - (void)pushViewController:(UIViewController *)controller{
  761. if ([FLControllerHelper currentController].navigationController && controller) {
  762. controller.hidesBottomBarWhenPushed = YES;
  763. [[FLControllerHelper currentController].navigationController pushViewController:controller animated:YES];
  764. }
  765. }
  766. #pragma mark - property
  767. - (UITableView *)tableView {
  768. if (_tableView == nil) {
  769. _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  770. _tableView.delegate = self;
  771. _tableView.dataSource = self;
  772. _tableView.sectionHeaderHeight = 0;
  773. _tableView.backgroundColor = UIColorFromRGB(0xf9f9f9);
  774. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  775. [_tableView registerClass:[FKOperationImageCell class] forCellReuseIdentifier:NSStringFromClass([FKOperationImageCell class])];
  776. [_tableView registerClass:[FKRecoIconListCell class] forCellReuseIdentifier:NSStringFromClass([FKRecoIconListCell class])];
  777. [_tableView registerClass:[FKRecoNewsCell class] forCellReuseIdentifier:NSStringFromClass([FKRecoNewsCell class])];
  778. [_tableView registerClass:[FKRecoHeaderCell class] forCellReuseIdentifier:NSStringFromClass([FKRecoHeaderCell class])];
  779. [_tableView registerClass:[FKRecoLimitBuyCell class] forCellReuseIdentifier:NSStringFromClass([FKRecoLimitBuyCell class])];
  780. [_tableView registerClass:[FKRecoPromotionLimitCell class] forCellReuseIdentifier:NSStringFromClass([FKRecoPromotionLimitCell class])];
  781. [_tableView registerClass:[FKRecoPromotionCategoryCell class] forCellReuseIdentifier:NSStringFromClass([FKRecoPromotionCategoryCell class])];
  782. [_tableView registerClass:[FKRecoOfficalActivityCell class] forCellReuseIdentifier:NSStringFromClass([FKRecoOfficalActivityCell class])];
  783. [_tableView registerClass:[FKRecoBrandListCell class] forCellReuseIdentifier:NSStringFromClass([FKRecoBrandListCell class])];
  784. [_tableView registerClass:[FKExploreTableViewCell class] forCellReuseIdentifier:NSStringFromClass([FKExploreTableViewCell class])];
  785. [_tableView registerClass:[FKRecoUserRecoProductCell class] forCellReuseIdentifier:NSStringFromClass([FKRecoUserRecoProductCell class])];
  786. [_tableView registerClass:[FKRecoScanRecoProductCell class] forCellReuseIdentifier:NSStringFromClass([FKRecoScanRecoProductCell class])];
  787. [_tableView registerClass:[FKRecoHotProductCell class] forCellReuseIdentifier:NSStringFromClass([FKRecoHotProductCell class])];
  788. [self initRefreshControlWithTableView:_tableView];
  789. if (@available(iOS 11.0, *)) {
  790. _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  791. }
  792. }
  793. return _tableView;
  794. }
  795. - (FKAdvertiseViewCell*)advertiseView {
  796. if (!_advertiseView) {
  797. _advertiseView = [[FKAdvertiseViewCell alloc] initWithStyle:UITableViewCellStyleDefault
  798. reuseIdentifier:nil];
  799. _advertiseView.backgroundColor = UIColorFromRGB(0xf4f4f4);
  800. _advertiseView.delegate = self;
  801. }
  802. return _advertiseView;
  803. }
  804. - (UIButton *)backTopBtn {
  805. if (_backTopBtn == nil) {
  806. _backTopBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  807. [_backTopBtn setImage:[UIImage imageNamed:@"fanhuidingbu"] forState:UIControlStateNormal];
  808. [_backTopBtn addTarget:self
  809. action:@selector(backTopAction:)
  810. forControlEvents:UIControlEventTouchUpInside];
  811. _backTopBtn.hidden = YES;
  812. }
  813. return _backTopBtn;
  814. }
  815. @end