IndexViewController.m 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  1. //
  2. // IndexViewController.m
  3. // TheoryNetwork
  4. //
  5. // Created by tederen on 2019/9/20.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. //#import "DrawerView.h"
  9. #import "IndexViewController.h"
  10. #import "SurfaceSearchView.h"
  11. #import "ChannelModel.h"
  12. #import "HomeSearchController.h"
  13. #import "AddChannelController.h"
  14. #import "HttpManager.h"
  15. #import "HomeDetailController.h"
  16. #import "APIPOPOPO.h"
  17. #import "MyApprovalPageDetail.h"
  18. #import "MailListDetailVC.h"
  19. #import "NavigationController.h"
  20. #import "UIAlertController+TapGesAlertController.h"
  21. #import "HomeArticleModel.h"
  22. #import "HomeListWorkCell.h"
  23. #import "HomeTableViewCell.h"
  24. #import "SLBannerView.h"
  25. #import "MyFavoriteVC.h"
  26. #import "OtherFavoriteVC.h"
  27. #import "NoteBookVC.h"
  28. #import "OtherNoteBookVC.h"
  29. #import "BookStoreHome.h"
  30. #import "HomeMusicCell.h"
  31. #import "HomeSchoolCell.h"
  32. #import "HomeUserPrivilegeCell.h"
  33. #import "HomeWeiCousreCell.h"
  34. #import "BookWCDetailVC.h"
  35. #import "HomeProblemTopCell.h"
  36. #import "HomeGoodBookCell.h"
  37. #import "BookDetailVC.h"
  38. #import "BookSubArticeCell.h"
  39. #import "HomeTeacherCell.h"
  40. #import "BookTeacherListVC.h"
  41. #import "HKFloatManager.h"
  42. #import "HomeBigshotCell.h"
  43. #import "HomeSubModel.h"
  44. #import "HomeSubItemModel.h"
  45. #import "HomeRecommendVC.h"
  46. #import "HomeBigshotVC.h"
  47. #import "HomeDayGoodBookVC.h"
  48. #import "HomeDayGoodArticeVC.h"
  49. #import "HomeSpeakVC.h"
  50. #import "HomeWeiCousreVC.h"
  51. #import "HomeMingShiVC.h"
  52. #import "HomeUserVC.h"
  53. #import "HomeProblemVC.h"
  54. @interface IndexViewController () <SLBannerViewDelegate,AddChannelControllerDelegate>
  55. @property (nonatomic, strong) UILabel *titleLabel;
  56. @property (nonatomic, strong) UIView *bannerBgV;
  57. @property (nonatomic, strong) SLBannerView *bannerView;
  58. @property (nonatomic, strong) SurfaceSearchView *searchView;
  59. @property (nonatomic, strong) NSMutableArray *bannerImgArr;
  60. @property (nonatomic, strong) NSMutableArray * tabConfigArray;
  61. @property (nonatomic, strong) NSMutableArray * bannerModelArray;
  62. @property (nonatomic, strong) HomeArticleModel *model;
  63. @property (nonatomic, strong) TDWaitWorkModel *waitModel;
  64. @property (nonatomic, assign) NSInteger currentPage;
  65. @property (nonatomic, assign) NSInteger totalPage;
  66. @property (nonatomic, assign) NSInteger currentChannel;
  67. @property (nonatomic, assign) NSInteger unReadCount;
  68. @property (nonatomic, strong) TDButton *addButton;
  69. @property (nonatomic, strong) TDButton *musicButtton;
  70. @property (nonatomic, strong) UIView *lineV;
  71. @property (nonatomic, strong) UIView *rightView;
  72. @property (nonatomic, strong) NSMutableDictionary *articleDic;
  73. @property (nonatomic, copy) NSMutableArray *dataSource;
  74. @property (strong, nonatomic) UIAlertController *alertVC;
  75. /// 我的频道
  76. @property (copy, nonatomic) NSMutableArray *myChannel;
  77. @property (copy, nonatomic) NSString *style;
  78. @property (strong, nonatomic) NSMutableArray *chatListIMArray;
  79. @property (strong, nonatomic) NSMutableArray *dataArray;
  80. @end
  81. @implementation IndexViewController
  82. - (void)viewWillAppear:(BOOL)animated
  83. {
  84. [super viewWillAppear:animated];
  85. [self getUnreadCount];
  86. }
  87. #pragma mark - LifeCycle
  88. - (void)viewDidLoad {
  89. [super viewDidLoad];
  90. self.fd_prefersNavigationBarHidden = YES;
  91. [self loadStatusBarColor:[UIColor whiteColor]];
  92. self.view.backgroundColor = UIColorHex(F2F2F2);
  93. [self.view addSubview:self.titleLabel];
  94. [self.view addSubview:self.searchView];
  95. [self.searchView setFrame:CGRectMake(0, 0, SCREEN_WIDTH, 52)];
  96. self.bannerView = [[SLBannerView alloc] initWithFrame:CGRectMake(15, 0, SCREEN_WIDTH - 30, 125)];
  97. self.bannerView.delegate = self;
  98. self.bannerView.durTimeInterval = 0.2;
  99. self.bannerView.imgStayTimeInterval = 2.5;
  100. self.bannerBgV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 132)];
  101. self.bannerBgV.backgroundColor = [UIColor clearColor];
  102. [self.bannerBgV addSubview:self.bannerView];
  103. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  104. make.top.equalTo(self.statusBar.mas_bottom);
  105. make.left.right.equalTo(self.view);
  106. make.height.equalTo(@44);
  107. }];
  108. [self.searchView mas_makeConstraints:^(MASConstraintMaker *make) {
  109. make.top.mas_equalTo(self.titleLabel.mas_bottom);
  110. make.left.right.equalTo(self.view);
  111. make.height.mas_offset(52);
  112. }];
  113. [self getdata];
  114. WEAKSELF
  115. self.searchView.buttonBlock = ^(){
  116. HomeSearchController *homeSearch = [[HomeSearchController alloc] init];
  117. [weakSelf.navigationController pushViewController:homeSearch animated:YES];
  118. };
  119. self.searchView.bookBlock = ^(){
  120. BookStoreHome *vc = [BookStoreHome initBookStoreHome];
  121. vc.hidesBottomBarWhenPushed = YES;
  122. [weakSelf.navigationController pushViewController:vc animated:YES];
  123. };
  124. [UserManager getUserInfoDetail];
  125. // self.channelScroll.ClickSelectChannelBlock = ^(NSInteger channelId, NSString * _Nonnull StyleCss) {
  126. // weakSelf.style = StyleCss;
  127. // weakSelf.currentChannel = channelId;
  128. // for (ChannelModel * model in weakSelf.myChannel) {
  129. // model.IsSelect = NO;
  130. // }
  131. // for (ChannelModel * model in weakSelf.myChannel) {
  132. // if (model.ArticleGroupId == channelId) {
  133. // model.IsSelect = YES;
  134. // }
  135. // }
  136. // dispatch_async(dispatch_get_main_queue(), ^{
  137. // [weakSelf collectReload];
  138. // });
  139. // };
  140. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tableViewScrollTop) name:HOMESCROLLVIEWTOTOP object:nil];
  141. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(shareReturnAction:) name:SHARERETURNSUCCESS object:nil];
  142. }
  143. - (void)setCusPageVC
  144. {
  145. CGFloat height = SCREEN_HEIGHT - NAVH - 52 - self.tabBarController.tabBar.frame.size.height;
  146. WS(weakSelf);
  147. NSMutableArray * data = [NSMutableArray array];
  148. NSMutableArray * vcArr = [NSMutableArray array];
  149. for (NSInteger i = 0; i < self.myChannel.count; i ++) {
  150. ChannelModel * model = self.myChannel[i];
  151. if ([model.StyleCss isEqualToString:@"Commend"]) {
  152. [data addObject:model.ArticleGroupName];
  153. HomeRecommendVC * vc = [[HomeRecommendVC alloc] init];
  154. vc.height = height;
  155. vc.style = model.StyleCss;
  156. [vcArr addObject:vc];
  157. }
  158. if ([model.StyleCss isEqualToString:@"Cathedra"]) {
  159. [data addObject:model.ArticleGroupName];
  160. HomeBigshotVC * vc = [[HomeBigshotVC alloc] init];
  161. vc.height = height;
  162. vc.style = model.StyleCss;
  163. [vcArr addObject:vc];
  164. }
  165. if ([model.StyleCss isEqualToString:@"DayGoodBook"]) {
  166. [data addObject:model.ArticleGroupName];
  167. HomeDayGoodBookVC * vc = [[HomeDayGoodBookVC alloc] init];
  168. vc.height = height;
  169. vc.style = model.StyleCss;
  170. [vcArr addObject:vc];
  171. }
  172. if ([model.StyleCss isEqualToString:@"DayGoodText"]) {
  173. [data addObject:model.ArticleGroupName];
  174. HomeDayGoodArticeVC * vc = [[HomeDayGoodArticeVC alloc] init];
  175. vc.height = height;
  176. vc.style = model.StyleCss;
  177. [vcArr addObject:vc];
  178. }
  179. if ([model.StyleCss isEqualToString:@"ChatHearSpeak"]) {
  180. [data addObject:model.ArticleGroupName];
  181. HomeSpeakVC * vc = [[HomeSpeakVC alloc] init];
  182. vc.height = height;
  183. vc.style = model.StyleCss;
  184. [vcArr addObject:vc];
  185. }
  186. if ([model.StyleCss isEqualToString:@"DayWeBook"]) {
  187. [data addObject:model.ArticleGroupName];
  188. HomeWeiCousreVC * vc = [[HomeWeiCousreVC alloc] init];
  189. vc.height = height;
  190. vc.style = model.StyleCss;
  191. [vcArr addObject:vc];
  192. }
  193. if ([model.StyleCss isEqualToString:@"StarTeacher"]) {
  194. [data addObject:model.ArticleGroupName];
  195. HomeMingShiVC * vc = [[HomeMingShiVC alloc] init];
  196. vc.height = height;
  197. vc.style = model.StyleCss;
  198. [vcArr addObject:vc];
  199. }
  200. if ([model.StyleCss isEqualToString:@"VipSupply"]) {
  201. [data addObject:model.ArticleGroupName];
  202. HomeUserVC * vc = [[HomeUserVC alloc] init];
  203. vc.height = height;
  204. vc.style = model.StyleCss;
  205. [vcArr addObject:vc];
  206. }
  207. // if ([model.StyleCss isEqualToString:@"DayProblem"]) {///每日技能
  208. // [data addObject:model.ArticleGroupName];
  209. // HomeProblemVC * vc = [[HomeProblemVC alloc] init];
  210. // vc.height = height;
  211. // vc.style = model.StyleCss;
  212. // [vcArr addObject:vc];
  213. // }
  214. }
  215. WMZPageParam *param = PageParam()
  216. .wTitleArrSet(data)
  217. .wControllersSet(vcArr)
  218. //固定在所有子控制器底部 需要放在第一个控制器里 例如此例子
  219. .wFixFirstSet(YES)
  220. //悬浮开启
  221. .wTopSuspensionSet(YES)
  222. //等分
  223. .wMenuCellPaddingSet(45 - 21.5)
  224. .wMenuCellMarginSet(15)
  225. .wTopOffsetSet(-NAVH - 52)
  226. .wFromNaviSet(YES)
  227. .wMenuAnimalSet(PageTitleMenuNone)
  228. .wMenuTitleFontSet(15.f)
  229. .wMenuTitleSelectColorSet(UIColorHex(0x3979D3))
  230. .wMenuIndicatorYSet(6.f)
  231. .wMenuIndicatorColorSet(UIColorHex(0x3979D3))
  232. .wMenuTitleColorSet(UIColorHex(0x666666))
  233. .wMenuTitleSelectFontSet(15.f)
  234. .wMenuFixShadowSet(NO)
  235. .wMenuFixRightDataSet(@"sss")
  236. .wMenuFixWidthSet(88.5)
  237. //头部
  238. .wMenuHeadViewSet(^UIView *{
  239. return self.bannerBgV;
  240. });
  241. self.param = param;
  242. [self updatePageController];
  243. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  244. dispatch_async(dispatch_get_main_queue(), ^{
  245. for (UIView * view in weakSelf.view.subviews) {
  246. if ([view isKindOfClass:[WMZPageScroller class]]) {
  247. [view setFrame:CGRectMake(0, NAVH + 52, SCREEN_WIDTH, height)];
  248. }
  249. }
  250. UIView * view = [weakSelf setRightView];
  251. [weakSelf.upSc addSubview:view];
  252. [weakSelf.upSc bringSubviewToFront:view];
  253. [view setFrame:CGRectMake(SCREEN_WIDTH - 88.5, 0, 88.5, 45)];
  254. });
  255. });
  256. for (UIView * view in weakSelf.view.subviews) {
  257. if ([view isKindOfClass:[UIScrollView class]]) {
  258. NSLog(@"+++++++=====%@",view);
  259. UIScrollView * sView = (UIScrollView *)view;
  260. sView.showsVerticalScrollIndicator = NO;
  261. }
  262. }
  263. }
  264. - (void)getUnreadCount
  265. {
  266. WS(weakSelf);
  267. [[HttpManager sharedHttpManager] GETUrl:Host(API_APP_User_User_Uread_Count) parameters:@{} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  268. NSDictionary *dic = responseObject;
  269. WorkNumberModel *numberModel = [[WorkNumberModel alloc] initWithDictionary:dic error:nil];
  270. weakSelf.unReadCount = numberModel.allNumber;
  271. dispatch_async(dispatch_get_main_queue(), ^{
  272. [weakSelf initChatMsgIMData];
  273. });
  274. } failure:^(NSError * _Nonnull error) {
  275. }];
  276. }
  277. -(void)initChatMsgIMData{
  278. self.chatListIMArray = [NSMutableArray array];
  279. WS(weakSelf);
  280. SHOWLOADING
  281. [[HttpManager sharedHttpManager] POSTUrl:Host(Often_Contact_List) parameters:@{@"IndividualGroupId":@(0)} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  282. NSLog(@"%@",responseObject);
  283. REMOVESHOW
  284. if ([responseObject isKindOfClass:[NSArray class]]) {
  285. for (NSDictionary * dict in responseObject) {
  286. ChatMsgListImModel * model = [ChatMsgListImModel modelWithDictionary:dict];
  287. [weakSelf.chatListIMArray addObject:model];
  288. }
  289. }
  290. [weakSelf _loadAllConversationsFromDBWithIsShowHud:NO];
  291. } failure:^(NSError * _Nonnull error) {
  292. REMOVESHOW
  293. NSLog(@"%@",error);
  294. }];
  295. }
  296. - (void)_loadAllConversationsFromDBWithIsShowHud:(BOOL)aIsShowHUD
  297. {
  298. __weak typeof(self) weakself = self;
  299. self.dataArray = [NSMutableArray array];
  300. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  301. NSArray *conversations = [[EMClient sharedClient].chatManager getAllConversations];
  302. NSArray *sorted = [conversations sortedArrayUsingComparator:^(EMConversation *obj1, EMConversation *obj2) {
  303. EMMessage *message1 = [obj1 latestMessage];
  304. EMMessage *message2 = [obj2 latestMessage];
  305. if(message1.timestamp > message2.timestamp) {
  306. return(NSComparisonResult)NSOrderedAscending;
  307. } else {
  308. return(NSComparisonResult)NSOrderedDescending;
  309. }}];
  310. NSArray *models = [EMConversationHelper modelsFromEMConversations:sorted];
  311. [weakself.dataArray addObjectsFromArray:models];
  312. [weakself replaceChatData];
  313. });
  314. }
  315. - (void)replaceChatData
  316. {
  317. WS(weakSelf);
  318. [self.chatListIMArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  319. ChatMsgListImModel * chatModel = (ChatMsgListImModel *)obj;
  320. [weakSelf.dataArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  321. EMConversationModel * model = (EMConversationModel *)obj;
  322. if (chatModel.ImId == [model.emModel.conversationId integerValue]) {
  323. if (!chatModel.IsDisturb) {
  324. chatModel.redNum = model.emModel.unreadMessagesCount;
  325. weakSelf.unReadCount += model.emModel.unreadMessagesCount;
  326. }
  327. }
  328. }];
  329. }];
  330. dispatch_async(dispatch_get_main_queue(), ^{
  331. weakSelf.tabBarController.tabBar.items[2].badgeValue = weakSelf.unReadCount > 0 ? [NSString stringWithFormat:@"%ld",(long)weakSelf.unReadCount] : nil;
  332. });
  333. }
  334. - (void)messagesDidReceive:(NSArray *)aMessages
  335. {
  336. [self performSelector:@selector(getUnreadCount) withObject:nil afterDelay:0.1];
  337. }
  338. - (void)tableViewScrollTop
  339. {
  340. if (self.dataSource.count > 0) {
  341. // [self.scrollView scrollToTop];
  342. // [self.scrollView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];
  343. }
  344. }
  345. - (void)dealloc
  346. {
  347. [[NSNotificationCenter defaultCenter] removeObserver:self];
  348. }
  349. #pragma mark - NetRequest - 轮播
  350. - (void)getdata{
  351. [self loadChannelModel];
  352. WS(weakSelf);
  353. dispatch_semaphore_t sem = dispatch_semaphore_create(0);
  354. __block NSInteger httpFinishCount = 0;
  355. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  356. [[HttpManager sharedHttpManager] GETUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,HomeSlideImages_GET] parameters: @{} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  357. NSArray *arr = responseObject[@"Items"];
  358. NSLog(@"首页轮播数据%@",arr.firstObject);
  359. [weakSelf.bannerModelArray removeAllObjects];
  360. [weakSelf.bannerImgArr removeAllObjects];
  361. NSMutableArray *array = [NSMutableArray array];
  362. NSMutableArray *array2 = [NSMutableArray array];
  363. for (NSInteger i = 0; i < arr.count; i++) {
  364. NSDictionary *dic = arr[i];
  365. HomeTopImageModel *imageModel = [[HomeTopImageModel alloc] initWithDictionary:dic error:nil];
  366. [array2 addObject:imageModel];
  367. [array addObject:dic[@"ImageUrl"]];
  368. }
  369. weakSelf.bannerImgArr = array;
  370. weakSelf.bannerModelArray = array2;
  371. weakSelf.bannerView.slImages = array;
  372. if (++httpFinishCount == 2) {
  373. dispatch_semaphore_signal(sem);
  374. }
  375. } failure:^(NSError * _Nonnull error) {
  376. SHOWERROR([ZYCTool handerResultData:error]);
  377. }];
  378. [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,Article_Pindao_User_Post] parameters:@{} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  379. NSLog(@"%@",responseObject);
  380. NSArray *array = responseObject;
  381. for (NSInteger i = 0 ; i < array.count; i ++) {
  382. NSDictionary *dic = array[i];
  383. ChannelModel *model = [ChannelModel modelWithDictionary:dic];
  384. if (model.ArticleGroupId == 0) {
  385. model.IsSelect = YES;
  386. }
  387. [weakSelf.myChannel addObject:model];
  388. }
  389. if (++httpFinishCount == 2) {
  390. dispatch_semaphore_signal(sem);
  391. }
  392. } failure:^(NSError * _Nonnull error) {
  393. SHOWERROR([ZYCTool handerResultData:error]);
  394. }];
  395. dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
  396. dispatch_async(dispatch_get_main_queue(), ^{
  397. [weakSelf setCusPageVC];
  398. });
  399. });
  400. }
  401. - (void)ReGetHomeListData:(NSInteger)channelId
  402. {
  403. WS(weakSelf);
  404. switch (channelId) {
  405. case 0:
  406. {
  407. [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,Article_Notice_list_Post] parameters: @{@"page":@(self.currentPage),@"perPage":@10,@"GroupId":@(channelId)} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  408. NSDictionary *dic = (NSDictionary *)responseObject;
  409. HomeArticleModel *model = [HomeArticleModel modelWithDictionary:dic];
  410. weakSelf.totalPage = model.Count;
  411. [weakSelf.dataSource addObjectsFromArray:model.Items];
  412. } failure:^(NSError * _Nonnull error) {
  413. }];
  414. }
  415. break;
  416. case 1:
  417. {
  418. NSDictionary * paraDict = @{@"Type":@"MyChecking",@"page":@(self.currentPage),@"perPage":@10};
  419. [[HttpManager sharedHttpManager] GETUrl:Host(WorkFlowAddApproval_Post) parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) {
  420. NSDictionary *dic = (NSDictionary *)responseObject;
  421. HomeArticleModel *model = [HomeArticleModel modelWithDictionary:dic];
  422. weakSelf.totalPage = model.Count;
  423. [weakSelf.dataSource addObjectsFromArray:model.Items];
  424. } failure:^(NSError * _Nonnull error) {
  425. SHOWERROR([ZYCTool handerResultData:error])
  426. }];
  427. }
  428. break;
  429. default:
  430. {
  431. [[HttpManager sharedHttpManager] POSTUrl:Host(API_APP_PAGE_CATHEDRA) parameters:@{@"StyleCss":self.style,@"Page":@(self.currentPage),@"PerPage":@20} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  432. NSLog(@"%@",responseObject);
  433. } failure:^(NSError * _Nonnull error) {
  434. }];
  435. }
  436. break;
  437. }
  438. }
  439. - (BOOL)hidesBottomBarWhenPushed{
  440. return NO;
  441. }
  442. #pragma mark - UITableViewDataSource && UITableViewDelegate
  443. - (void)closeBtn_Click {
  444. [self.alertVC dismissViewControllerAnimated:YES completion:nil];
  445. }
  446. - (void)cellDidSelcet:(NSInteger )articleId{
  447. WEAKSELF
  448. UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  449. [closeBtn addTarget:self action:@selector(closeBtn_Click) forControlEvents:UIControlEventTouchUpInside];
  450. [closeBtn setImage:IMG(@"guanbi") forState:UIControlStateNormal];
  451. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"对此内容进行操作" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  452. self.alertVC = alertVC;
  453. [alertVC.view addSubview:closeBtn];
  454. [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  455. make.right.equalTo(alertVC.view).offset(-10);
  456. make.top.equalTo(@10);
  457. make.size.mas_equalTo(CGSizeMake(22, 22));
  458. }];
  459. UIAlertAction *actionOK = [UIAlertAction actionWithTitle:@"屏蔽TA" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  460. STRONGSELF
  461. [strongSelf homeNewsHander:articleId withTypeId:1];
  462. }];
  463. [actionOK setValue:k9 forKey:@"_titleTextColor"];
  464. UIAlertAction *actionNO = [UIAlertAction actionWithTitle:@"不感兴趣" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  465. STRONGSELF
  466. [strongSelf homeNewsHander:articleId withTypeId:2];
  467. }];
  468. [alertVC addAction:actionOK];
  469. [alertVC addAction:actionNO];
  470. [self presentViewController:alertVC animated:YES completion:^{
  471. [alertVC tapGesAlert];
  472. }];
  473. }
  474. - (void)homeNewsHander:(NSInteger )articleId withTypeId:(NSInteger)blacklistType{
  475. WS(weakSelf);
  476. [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@/%@",BaseUrl,Article_Hander_Post] parameters:@{@"ArticleId":@(articleId),@"BlacklistType":@(blacklistType)} responseStyle:DATA success:^(id _Nonnull responseObject) {
  477. // [weakSelf headRefresh];
  478. } failure:^(NSError * _Nonnull error) {
  479. }];
  480. }
  481. #pragma mark - channelScroll Block
  482. - (void)didClickAddButtonChannel{
  483. AddChannelController *addChannel = [[AddChannelController alloc] init];
  484. addChannel.modalPresentationStyle = UIModalPresentationFullScreen;
  485. addChannel.delegate = self;
  486. [self presentViewController:addChannel animated:YES completion:nil];
  487. }
  488. #pragma mark - AddChannelControllerDelegate
  489. - (void)upadateChannel{
  490. WS(weakSelf);
  491. [self loadChannelModel];
  492. [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,Article_Pindao_User_Post] parameters:@{} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  493. NSLog(@"%@",responseObject);
  494. NSArray *array = responseObject;
  495. for (NSInteger i = 0 ; i < array.count; i ++) {
  496. NSDictionary *dic = array[i];
  497. ChannelModel *model = [ChannelModel modelWithDictionary:dic];
  498. [weakSelf.myChannel addObject:model];
  499. }
  500. dispatch_async(dispatch_get_main_queue(), ^{
  501. [weakSelf setCusPageVC];
  502. });
  503. } failure:^(NSError * _Nonnull error) {
  504. }];
  505. }
  506. #pragma mark - SLBannerViewDelegate
  507. - (void)bannerView:(SLBannerView *)banner didClickImagesAtIndex:(NSInteger)index
  508. {
  509. [self getArticleDetail:index];
  510. }
  511. - (void)getArticleDetail:(NSInteger)index{
  512. HomeTopImageModel *model = self.bannerModelArray[index];
  513. NSLog(@"点击轮播图%ld",(long)model.ArticleId);
  514. WEAKSELF
  515. [[HttpManager sharedHttpManager] GETWithUrl:[NSString stringWithFormat:@"%@%ld",Article_Detail_Get,(long)model.ArticleId] parameters:@{} success:^(id _Nonnull responseObject) {
  516. Item *model = [[Item alloc]initWithDictionary:responseObject error:nil];
  517. // HomeDetailController *homeDetail = [[HomeDetailController alloc] init];
  518. // [homeDetail loadCurrentModel:itemModel];
  519. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  520. vc.type = CollectModel_Aritle;
  521. vc.Id = model.Id;
  522. [weakSelf.navigationController pushViewController:vc animated:YES];
  523. } failure:^(NSError * _Nonnull error) {
  524. SHOWERROR([ZYCTool handerResultData:error]);
  525. }];
  526. }
  527. #pragma mark - Setter
  528. - (UILabel *)titleLabel {
  529. if (!_titleLabel) {
  530. _titleLabel = [UILabel new];
  531. _titleLabel.backgroundColor = [UIColor whiteColor];
  532. _titleLabel.text = @"首页";
  533. _titleLabel.font = [UIFont systemFontOfSize:16.f];
  534. _titleLabel.textColor = UIColorHex(1A1A1A);
  535. _titleLabel.textAlignment = NSTextAlignmentCenter;
  536. }
  537. return _titleLabel;
  538. }
  539. - (SurfaceSearchView *)searchView {
  540. if (!_searchView) {
  541. _searchView = [[SurfaceSearchView alloc] init];
  542. [_searchView setBgViewColor:[UIColor clearColor]];
  543. // [_searchView setPlaceHolderText:@"输入关键字搜索"];
  544. [_searchView setMainType];
  545. }
  546. return _searchView;
  547. }
  548. - (NSMutableArray *)dataSource
  549. {
  550. if (!_dataSource) {
  551. _dataSource = [NSMutableArray array];
  552. }
  553. return _dataSource;
  554. }
  555. - (NSMutableArray *)tabConfigArray{
  556. if (!_tabConfigArray) {
  557. _tabConfigArray = [NSMutableArray array];
  558. }
  559. return _tabConfigArray;
  560. }
  561. - (NSMutableDictionary *)articleDic{
  562. if (!_articleDic) {
  563. _articleDic = [NSMutableDictionary dictionary];
  564. }
  565. return _articleDic;
  566. }
  567. - (NSMutableArray *)myChannel {
  568. if (!_myChannel) {
  569. _myChannel = [NSMutableArray array];
  570. }
  571. return _myChannel;
  572. }
  573. - (void)loadChannelModel
  574. {
  575. [self.myChannel removeAllObjects];
  576. // ChannelModel * model = [[ChannelModel alloc] init];
  577. // model.ArticleGroupId = 0;
  578. // model.ArticleGroupName = @"推荐";
  579. // model.StyleCss = @"default";
  580. // model.IsSelect = YES;
  581. // [self.myChannel addObject:model];
  582. // ChannelModel * workModel = [[ChannelModel alloc] init];
  583. // workModel.ArticleGroupId = 1;
  584. // workModel.ArticleGroupName = @"待办工作";
  585. // workModel.IsSelect = NO;
  586. // [self.myChannel addObject:workModel];
  587. // ChannelModel * sModel = [[ChannelModel alloc] init];
  588. // sModel.ArticleGroupId = 2;
  589. // sModel.ArticleGroupName = @"信源听说";
  590. // sModel.IsSelect = NO;
  591. // [self.myChannel addObject:sModel];
  592. // ChannelModel * mModel = [[ChannelModel alloc] init];
  593. // mModel.ArticleGroupId = 3;
  594. // mModel.ArticleGroupName = @"名校";
  595. // mModel.IsSelect = NO;
  596. // [self.myChannel addObject:mModel];
  597. // ChannelModel * aModel = [[ChannelModel alloc] init];
  598. // aModel.ArticleGroupId = 4;
  599. // aModel.ArticleGroupName = @"会员特供";
  600. // aModel.IsSelect = NO;
  601. // [self.myChannel addObject:aModel];
  602. // ChannelModel * bModel = [[ChannelModel alloc] init];
  603. // bModel.ArticleGroupId = 5;
  604. // bModel.ArticleGroupName = @"每日微课";
  605. // bModel.IsSelect = NO;
  606. // [self.myChannel addObject:bModel];
  607. // ChannelModel * cModel = [[ChannelModel alloc] init];
  608. // cModel.ArticleGroupId = 6;
  609. // cModel.ArticleGroupName = @"每日技能";
  610. // cModel.IsSelect = NO;
  611. // [self.myChannel addObject:cModel];
  612. // ChannelModel * dModel = [[ChannelModel alloc] init];
  613. // dModel.ArticleGroupId = 7;
  614. // dModel.ArticleGroupName = @"每日好书";
  615. // dModel.IsSelect = NO;
  616. // [self.myChannel addObject:dModel];
  617. // ChannelModel * eModel = [[ChannelModel alloc] init];
  618. // eModel.ArticleGroupId = 8;
  619. // eModel.ArticleGroupName = @"每日好文";
  620. // eModel.IsSelect = NO;
  621. // [self.myChannel addObject:eModel];
  622. // ChannelModel * fModel = [[ChannelModel alloc] init];
  623. // fModel.ArticleGroupId = 9;
  624. // fModel.ArticleGroupName = @"名师";
  625. // fModel.IsSelect = NO;
  626. // [self.myChannel addObject:fModel];
  627. // ChannelModel * gModel = [[ChannelModel alloc] init];
  628. // gModel.ArticleGroupId = 10;
  629. // gModel.ArticleGroupName = @"大咖讲座";
  630. // gModel.IsSelect = NO;
  631. // [self.myChannel addObject:gModel];
  632. }
  633. #pragma mark - 分享成功跳转
  634. - (void)shareReturnAction:(NSNotification *)noti
  635. {
  636. NSDictionary * dic = noti.userInfo;
  637. CollectModelType type = [[dic objectForKey:@"type"] intValue];
  638. NSInteger Id = [[dic objectForKey:@"Id"] integerValue];
  639. NSInteger userId = [[dic objectForKey:@"userId"] integerValue];
  640. NSString* name = [[dic objectForKey:@"name"] stringByRemovingPercentEncoding];
  641. NSString* describe = [[dic objectForKey:@"describe"] stringByRemovingPercentEncoding];
  642. switch (type) {
  643. case CollectModel_CollectFile:
  644. {
  645. if (userId == [AppUserModel sharedAppUserModel].Id) {
  646. MyFavoriteVC *vc = [MyFavoriteVC initMyFavoriteVC];
  647. vc.listType = Id == 0 ? MyFavoriteListLevelTypeA : MyFavoriteListLevelTypeB;
  648. vc.ParentId = 0;
  649. vc.FolderId = Id;
  650. vc.myTitle = Id == 0 ? @"我的收藏" :name;
  651. [self.navigationController pushViewController:vc animated:YES];
  652. }else{
  653. OtherFavoriteVC * vc = [OtherFavoriteVC initOtherFavoriteVC];
  654. vc.listType = Id == 0 ? MyFavoriteListLevelTypeA : MyFavoriteListLevelTypeB;
  655. vc.FolderId = Id;
  656. vc.Author = describe;
  657. vc.myTitle = name;
  658. vc.VisitUserId = userId;
  659. [self.navigationController pushViewController:vc animated:YES];
  660. }
  661. }
  662. break;
  663. case CollectModel_NoteFile:
  664. {
  665. if (userId == [AppUserModel sharedAppUserModel].Id) {
  666. NoteBookVC * vc = [NoteBookVC initNoteBookVC];
  667. if (Id == 0) {
  668. vc.listType = MyFavoriteListLevelTypeB;
  669. vc.myTitle = @"我的笔记";
  670. }else{
  671. vc.listType = MyFavoriteListLevelTypeC;
  672. vc.myTitle = name;
  673. }
  674. vc.ParentId = 0;
  675. vc.FolderId = Id;
  676. vc.isSubVC = YES;
  677. [self.navigationController pushViewController:vc animated:YES];
  678. }else{
  679. OtherNoteBookVC * vc = [OtherNoteBookVC initOtherNoteBookVC];
  680. vc.listType = Id == 0 ? MyFavoriteListLevelTypeA : MyFavoriteListLevelTypeB;
  681. vc.FolderId = Id;
  682. vc.Author = describe;
  683. vc.myTitle = name;
  684. vc.VisitUserId = userId;
  685. [self.navigationController pushViewController:vc animated:YES];
  686. }
  687. }
  688. break;
  689. default:
  690. {
  691. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  692. vc.type = type;
  693. vc.Id = Id;
  694. [self.navigationController pushViewController:vc animated:YES];
  695. }
  696. break;
  697. }
  698. }
  699. - (void)addChannelAction:(UIButton *)sender
  700. {
  701. [self didClickAddButtonChannel];
  702. }
  703. - (void)musicAction:(UIButton *)sender
  704. {
  705. [[HKFloatManager shared] showVideo];
  706. }
  707. - (TDButton *)addButton {
  708. if (!_addButton) {
  709. _addButton = [TDButton buttonWithType:UIButtonTypeCustom];
  710. [_addButton setImage:IMG(@"home_pdAdd_icon") forState:UIControlStateNormal];
  711. [_addButton addTarget:self action:@selector(addChannelAction:) forControlEvents:UIControlEventTouchUpInside];
  712. [_addButton setCurrentButtonHotSize:CGSizeZero];
  713. }
  714. return _addButton;
  715. }
  716. - (TDButton *)musicButtton {
  717. if (!_musicButtton) {
  718. _musicButtton = [TDButton buttonWithType:UIButtonTypeCustom];
  719. [_musicButtton setImage:IMG(@"home_music_icon") forState:UIControlStateNormal];
  720. [_musicButtton addTarget:self action:@selector(musicAction:) forControlEvents:UIControlEventTouchUpInside];
  721. [_musicButtton setCurrentButtonHotSize:CGSizeZero];
  722. }
  723. return _musicButtton;
  724. }
  725. - (UIView *)lineV
  726. {
  727. if (!_lineV) {
  728. _lineV = [UIView new];
  729. _lineV.backgroundColor = UIColorHex(0xD8D8D8);
  730. }
  731. return _lineV;
  732. }
  733. - (UIView *)rightView
  734. {
  735. if (!_rightView) {
  736. _rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 88.5, 45)];
  737. _rightView.backgroundColor = UIColorHex(0xFFFFFF);
  738. }
  739. return _rightView;
  740. }
  741. - (UIView *)setRightView
  742. {
  743. [self.rightView removeAllSubviews];
  744. [self.rightView addSubview:self.addButton];
  745. [self.rightView addSubview:self.musicButtton];
  746. [self.rightView addSubview:self.lineV];
  747. [self.addButton setFrame:CGRectMake(0, 0, 44, 45)];
  748. [self.lineV setFrame:CGRectMake(44, 13.5, 0.5, 18)];
  749. [self.musicButtton setFrame:CGRectMake(44.5, 0, 44, 45)];
  750. return self.rightView;
  751. }
  752. @end