HomeViewController.m 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961
  1. //
  2. // HomeViewController.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 "HomeViewController.h"
  10. #import "SurfaceSearchView.h"
  11. #import "HorizonScroll.h"
  12. #import "ChannelModel.h"
  13. #import "HomeSearchController.h"
  14. #import "AddChannelController.h"
  15. #import "HttpManager.h"
  16. #import "HomeDetailController.h"
  17. #import "APIPOPOPO.h"
  18. #import "MyApprovalPageDetail.h"
  19. #import "MailListDetailVC.h"
  20. #import "NavigationController.h"
  21. #import "UIAlertController+TapGesAlertController.h"
  22. #import "HomeArticleModel.h"
  23. #import "HomeListWorkCell.h"
  24. #import "HomeTableViewCell.h"
  25. #import "SLBannerView.h"
  26. #import "MyFavoriteVC.h"
  27. #import "OtherFavoriteVC.h"
  28. #import "NoteBookVC.h"
  29. #import "OtherNoteBookVC.h"
  30. #import "BookStoreHome.h"
  31. #import "HomeMusicCell.h"
  32. #import "HomeSchoolCell.h"
  33. #import "HomeUserPrivilegeCell.h"
  34. #import "HomeWeiCousreCell.h"
  35. #import "BookWCDetailVC.h"
  36. #import "HomeProblemTopCell.h"
  37. #import "HomeGoodBookCell.h"
  38. #import "BookDetailVC.h"
  39. @interface HomeViewController () <UITableViewDataSource, UITableViewDelegate,SLBannerViewDelegate,AddChannelControllerDelegate>
  40. @property (nonatomic, strong) UILabel *titleLabel;
  41. @property (nonatomic, strong) UIView *bannerBgV;
  42. @property (nonatomic, strong) SLBannerView *bannerView;
  43. @property (nonatomic, strong) SurfaceSearchView *searchView;
  44. @property (nonatomic, strong) HorizonScroll *channelScroll;
  45. @property (nonatomic, strong) NSMutableArray *bannerImgArr;
  46. @property (nonatomic, strong) NSMutableArray * tabConfigArray;
  47. @property (nonatomic, strong) NSMutableArray * bannerModelArray;
  48. @property (nonatomic, strong) HomeArticleModel *model;
  49. @property (nonatomic, strong) TDWaitWorkModel *waitModel;
  50. @property (nonatomic, assign) NSInteger currentPage;
  51. @property (nonatomic, assign) NSInteger totalPage;
  52. @property (nonatomic, assign) NSInteger currentChannel;
  53. @property (nonatomic, strong) NSMutableDictionary *articleDic;
  54. @property (nonatomic, copy) NSMutableArray *dataSource;
  55. @property (nonatomic, strong) UITableView *tableView;
  56. @property (strong, nonatomic) UIAlertController *alertVC;
  57. /// 我的频道
  58. @property (copy, nonatomic) NSMutableArray *myChannel;
  59. @property (strong, nonatomic) UIView *noDataView;
  60. @property (nonatomic, strong) UILabel *noDataLabel;
  61. @end
  62. @implementation HomeViewController
  63. - (void)viewWillAppear:(BOOL)animated
  64. {
  65. [super viewWillAppear:animated];
  66. [self getRedBadge];
  67. }
  68. #pragma mark - LifeCycle
  69. - (void)viewDidLoad {
  70. [super viewDidLoad];
  71. [self getdata];
  72. self.fd_prefersNavigationBarHidden = YES;
  73. [self loadStatusBarColor:[UIColor whiteColor]];
  74. self.view.backgroundColor = UIColorHex(F2F2F2);
  75. [self.view addSubview:self.titleLabel];
  76. [self.view addSubview:self.searchView];
  77. [self.view addSubview:self.tableView];
  78. self.bannerView = [[SLBannerView alloc] initWithFrame:CGRectMake(15, 0, kGXScreenWidth - 30, 125)];
  79. self.bannerView.delegate = self;
  80. self.bannerView.durTimeInterval = 0.2;
  81. self.bannerView.imgStayTimeInterval = 2.5;
  82. self.bannerBgV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kGXScreenWidth, 132)];
  83. self.bannerBgV.backgroundColor = [UIColor clearColor];
  84. [self.searchView setFrame:CGRectMake(0, 0, SCREEN_WIDTH, 52)];
  85. [self.bannerBgV addSubview:self.bannerView];
  86. [self.tableView setTableHeaderView:self.bannerBgV];
  87. [self layoutSubviews];
  88. WEAKSELF
  89. self.searchView.buttonBlock = ^(){
  90. HomeSearchController *homeSearch = [[HomeSearchController alloc] init];
  91. [weakSelf.navigationController pushViewController:homeSearch animated:YES];
  92. };
  93. self.searchView.bookBlock = ^(){
  94. BookStoreHome *vc = [BookStoreHome initBookStoreHome];
  95. vc.hidesBottomBarWhenPushed = YES;
  96. [weakSelf.navigationController pushViewController:vc animated:YES];
  97. };
  98. [UserManager getUserInfoDetail];
  99. self.tableView.delegate = self;
  100. self.tableView.dataSource = self;
  101. self.tableView.estimatedRowHeight = 100.f;
  102. self.tableView.rowHeight = UITableViewAutomaticDimension;
  103. [self.tableView registerNib:[UINib nibWithNibName:@"HomeListWorkCell" bundle:nil] forCellReuseIdentifier:@"HomeListWorkCell"];
  104. [self.tableView registerNib:[UINib nibWithNibName:@"HomeMusicCell" bundle:nil] forCellReuseIdentifier:@"HomeMusicCell"];
  105. [self.tableView registerNib:[UINib nibWithNibName:@"HomeSchoolCell" bundle:nil] forCellReuseIdentifier:@"HomeSchoolCell"];
  106. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tableViewScrollTop) name:HOMESCROLLVIEWTOTOP object:nil];
  107. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(shareReturnAction:) name:SHARERETURNSUCCESS object:nil];
  108. [self setTableViewRefresh];
  109. }
  110. - (void)setTableViewRefresh{
  111. WS(weakSelf);
  112. self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  113. [weakSelf headRefresh];
  114. }];
  115. self.tableView.mj_footer = [MJRefreshBackStateFooter footerWithRefreshingBlock:^{
  116. [weakSelf footerRefresh];
  117. }];
  118. }
  119. - (void)headRefresh{
  120. [self.tableView.mj_header endRefreshing];
  121. [self.tableView.mj_footer endRefreshing];
  122. self.currentPage = 1;
  123. if (self.currentChannel == 2 || self.currentChannel == 3 || self.currentChannel == 4 || self.currentChannel == 5 || self.currentChannel == 6|| self.currentChannel == 7) {
  124. [self.tableView reloadData];
  125. }else{
  126. [self.dataSource removeAllObjects];
  127. [self ReGetHomeListData:self.currentChannel];
  128. }
  129. }
  130. - (void)footerRefresh{
  131. self.currentPage += 1;
  132. if (self.dataSource.count == self.totalPage) {
  133. self.tableView.mj_footer.hidden = YES;
  134. [self.tableView.mj_footer resetNoMoreData];
  135. return;
  136. }
  137. if (self.currentChannel == 2 || self.currentChannel == 3 || self.currentChannel == 4 || self.currentChannel == 5|| self.currentChannel == 6|| self.currentChannel == 7) {
  138. [self.tableView.mj_footer resetNoMoreData];
  139. }else{
  140. [self ReGetHomeListData:self.currentChannel];
  141. }}
  142. - (void)getRedBadge
  143. {
  144. WS(weakSelf);
  145. //获取我审批和我发起以及抄送我的未读数
  146. [[HttpManager sharedHttpManager] GETUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,@"/api/app/user/user-uread-count"] parameters:@{} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  147. NSDictionary *dic = responseObject;
  148. WorkNumberModel *numberModel = [[WorkNumberModel alloc] initWithDictionary:dic error:nil];
  149. weakSelf.tabBarController.tabBar.items[1].badgeValue = numberModel.allNumber;
  150. weakSelf.tabBarController.tabBar.items[2].badgeValue = numberModel.allNotifacationNumber;
  151. } failure:^(NSError * _Nonnull error) {
  152. }];
  153. }
  154. - (void)tableViewScrollTop
  155. {
  156. if (self.dataSource.count > 0) {
  157. [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
  158. [self.tableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];
  159. }
  160. }
  161. - (void)dealloc
  162. {
  163. [[NSNotificationCenter defaultCenter] removeObserver:self];
  164. }
  165. #pragma mark - NetRequest
  166. - (void)getdata{
  167. #pragma mark - 轮播
  168. WS(weakSelf);
  169. dispatch_semaphore_t sem = dispatch_semaphore_create(0);
  170. __block NSInteger httpFinishCount = 0;
  171. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  172. [[HttpManager sharedHttpManager] GETUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,HomeSlideImages_GET] parameters: @{} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  173. NSArray *arr = responseObject[@"Items"];
  174. NSLog(@"首页轮播数据%@",arr.firstObject);
  175. [weakSelf.bannerModelArray removeAllObjects];
  176. [weakSelf.bannerImgArr removeAllObjects];
  177. NSMutableArray *array = [NSMutableArray array];
  178. NSMutableArray *array2 = [NSMutableArray array];
  179. for (int i = 0; i < arr.count; i++) {
  180. NSDictionary *dic = arr[i];
  181. HomeTopImageModel *imageModel = [[HomeTopImageModel alloc] initWithDictionary:dic error:nil];
  182. [array2 addObject:imageModel];
  183. [array addObject:dic[@"ImageUrl"]];
  184. }
  185. weakSelf.bannerImgArr = array;
  186. weakSelf.bannerModelArray = array2;
  187. weakSelf.bannerView.slImages = array;
  188. if (++httpFinishCount == 3) {
  189. dispatch_semaphore_signal(sem);
  190. }
  191. } failure:^(NSError * _Nonnull error) {
  192. REMOVESHOW
  193. }];
  194. #pragma mark - 频道
  195. [weakSelf loadChannelModel];
  196. [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,Article_Pindao_User_Post] parameters:@{} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  197. NSLog(@"%@",responseObject);
  198. NSArray *array = responseObject;
  199. for (NSInteger i = 0 ; i < array.count; i ++) {
  200. NSDictionary *dic = array[i];
  201. ChannelModel *model = [ChannelModel modelWithDictionary:dic];
  202. if (model.ArticleGroupId == 0) {
  203. model.IsSelect = YES;
  204. }
  205. [weakSelf.myChannel addObject:model];
  206. }
  207. [weakSelf.channelScroll setChannelArray:weakSelf.myChannel];
  208. //先注释观察
  209. if (++httpFinishCount == 3) {
  210. dispatch_semaphore_signal(sem);
  211. }
  212. } failure:^(NSError * _Nonnull error) {
  213. REMOVESHOW
  214. }];
  215. #pragma mark - 列表
  216. [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,Article_Notice_list_Post] parameters: @{@"page":@(1),@"perPage":@10,@"GroupId":@(0)} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  217. NSDictionary *dic = (NSDictionary *)responseObject;
  218. HomeArticleModel *model = [HomeArticleModel modelWithDictionary:dic];
  219. [weakSelf.dataSource addObjectsFromArray:model.Items];
  220. if (++httpFinishCount == 3) {
  221. dispatch_semaphore_signal(sem);
  222. }
  223. } failure:^(NSError * _Nonnull error) {
  224. }];
  225. dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
  226. dispatch_async(dispatch_get_main_queue(), ^{
  227. REMOVESHOW
  228. [weakSelf.tableView.mj_header endRefreshing];
  229. [weakSelf.tableView.mj_footer endRefreshing];
  230. [weakSelf.tableView reloadData];
  231. });
  232. });
  233. }
  234. - (void)ReGetHomeListData:(NSInteger)channelId
  235. {
  236. WS(weakSelf);
  237. SHOWLOADING
  238. if (self.currentChannel == 1) {
  239. NSDictionary * paraDict = @{@"Type":@"MyChecking",@"page":@(self.currentPage),@"perPage":@10};
  240. [[HttpManager sharedHttpManager] GETUrl:Host(WorkFlowAddApproval_Post) parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) {
  241. REMOVESHOW
  242. NSDictionary *dic = (NSDictionary *)responseObject;
  243. HomeArticleModel *model = [HomeArticleModel modelWithDictionary:dic];
  244. [weakSelf.tableView.mj_header endRefreshing];
  245. [weakSelf.tableView.mj_footer endRefreshing];
  246. weakSelf.totalPage = model.Count;
  247. [weakSelf.dataSource addObjectsFromArray:model.Items];
  248. [weakSelf.tableView reloadData];
  249. dispatch_async(dispatch_get_main_queue(), ^{
  250. if (weakSelf.dataSource.count > 0) {
  251. weakSelf.noDataView.hidden = YES;
  252. }else{
  253. weakSelf.noDataView.hidden = NO;
  254. if (weakSelf.currentChannel == 1) {
  255. weakSelf.noDataLabel.text = @"暂无待办工作";
  256. }else{
  257. weakSelf.noDataLabel.text = @"暂无数据";
  258. }
  259. }
  260. });
  261. } failure:^(NSError * _Nonnull error) {
  262. REMOVESHOW
  263. [weakSelf.tableView.mj_header endRefreshing];
  264. [weakSelf.tableView.mj_footer endRefreshing];
  265. SHOWERROR([ZYCTool handerResultData:error])
  266. }];
  267. }else{
  268. [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,Article_Notice_list_Post] parameters: @{@"page":@(self.currentPage),@"perPage":@10,@"GroupId":@(channelId)} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  269. REMOVESHOW
  270. NSDictionary *dic = (NSDictionary *)responseObject;
  271. HomeArticleModel *model = [HomeArticleModel modelWithDictionary:dic];
  272. [weakSelf.tableView.mj_header endRefreshing];
  273. [weakSelf.tableView.mj_footer endRefreshing];
  274. weakSelf.totalPage = model.Count;
  275. [weakSelf.dataSource addObjectsFromArray:model.Items];
  276. [weakSelf.tableView reloadData];
  277. dispatch_async(dispatch_get_main_queue(), ^{
  278. if (weakSelf.dataSource.count > 0) {
  279. weakSelf.noDataView.hidden = YES;
  280. }else{
  281. weakSelf.noDataView.hidden = NO;
  282. if (weakSelf.currentChannel == 1) {
  283. weakSelf.noDataLabel.text = @"暂无待办工作";
  284. }else{
  285. weakSelf.noDataLabel.text = @"暂无数据";
  286. }
  287. }
  288. });
  289. } failure:^(NSError * _Nonnull error) {
  290. REMOVESHOW
  291. [weakSelf.tableView.mj_header endRefreshing];
  292. [weakSelf.tableView.mj_footer endRefreshing];
  293. }];
  294. }
  295. }
  296. -(void)layoutSubviews{
  297. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  298. make.top.equalTo(self.statusBar.mas_bottom);
  299. make.left.right.equalTo(self.view);
  300. make.height.equalTo(@44);
  301. }];
  302. [self.searchView mas_makeConstraints:^(MASConstraintMaker *make) {
  303. make.top.mas_equalTo(self.titleLabel.mas_bottom);
  304. make.left.right.equalTo(self.view);
  305. make.height.mas_offset(52);
  306. }];
  307. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  308. make.top.mas_equalTo(self.searchView.mas_bottom);
  309. make.left.right.bottom.equalTo(self.view);
  310. }];
  311. [self.view addSubview:self.noDataView];
  312. [self.noDataView mas_makeConstraints:^(MASConstraintMaker *make) {
  313. make.top.mas_equalTo(self.searchView.mas_bottom).offset(170);
  314. make.left.right.mas_equalTo(self.tableView);
  315. make.bottom.mas_offset(-self.tabBarController.tabBar.height);
  316. }];
  317. [self.noDataView addSubview:self.noDataLabel];
  318. [self.noDataLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  319. make.center.mas_equalTo(self.noDataView);
  320. }];
  321. }
  322. - (BOOL)hidesBottomBarWhenPushed{
  323. return NO;
  324. }
  325. #pragma mark - UITableViewDataSource && UITableViewDelegate
  326. - (void)closeBtn_Click {
  327. [self.alertVC dismissViewControllerAnimated:YES completion:nil];
  328. }
  329. - (void)cellDidSelcet:(NSInteger )articleId{
  330. WEAKSELF
  331. UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  332. [closeBtn addTarget:self action:@selector(closeBtn_Click) forControlEvents:UIControlEventTouchUpInside];
  333. [closeBtn setImage:IMG(@"guanbi") forState:UIControlStateNormal];
  334. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"对此内容进行操作" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  335. self.alertVC = alertVC;
  336. [alertVC.view addSubview:closeBtn];
  337. [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  338. make.right.equalTo(alertVC.view).offset(-10);
  339. make.top.equalTo(@10);
  340. make.size.mas_equalTo(CGSizeMake(22, 22));
  341. }];
  342. UIAlertAction *actionOK = [UIAlertAction actionWithTitle:@"屏蔽TA" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  343. STRONGSELF
  344. [strongSelf homeNewsHander:articleId withTypeId:1];
  345. }];
  346. [actionOK setValue:k9 forKey:@"_titleTextColor"];
  347. UIAlertAction *actionNO = [UIAlertAction actionWithTitle:@"不感兴趣" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  348. STRONGSELF
  349. [strongSelf homeNewsHander:articleId withTypeId:2];
  350. }];
  351. [alertVC addAction:actionOK];
  352. [alertVC addAction:actionNO];
  353. [self presentViewController:alertVC animated:YES completion:^{
  354. [alertVC tapGesAlert];
  355. }];
  356. }
  357. - (void)homeNewsHander:(NSInteger )articleId withTypeId:(NSInteger)blacklistType{
  358. WS(weakSelf);
  359. [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@/%@",BaseUrl,Article_Hander_Post] parameters:@{@"ArticleId":@(articleId),@"BlacklistType":@(blacklistType)} responseStyle:DATA success:^(id _Nonnull responseObject) {
  360. [weakSelf headRefresh];
  361. } failure:^(NSError * _Nonnull error) {
  362. }];
  363. }
  364. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  365. return self.dataSource.count;
  366. }
  367. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  368. {
  369. WS(weakSelf);
  370. self.channelScroll.ClickAddChannelBlock = ^{
  371. [weakSelf didClickAddButtonChannel];
  372. };
  373. self.channelScroll.ClickMusicBlock = ^{
  374. NSLog(@"MUSIC");
  375. };
  376. self.channelScroll.ClickSelectChannelBlock = ^(NSInteger channelId) {
  377. weakSelf.currentChannel = channelId;
  378. for (ChannelModel * model in weakSelf.myChannel) {
  379. model.IsSelect = NO;
  380. }
  381. for (ChannelModel * model in weakSelf.myChannel) {
  382. if (model.ArticleGroupId == channelId) {
  383. model.IsSelect = YES;
  384. }
  385. }
  386. [weakSelf.channelScroll.collectionView reloadData];
  387. [[HttpManager sharedHttpManager] cancelRequest];
  388. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  389. [weakSelf headRefresh];
  390. });
  391. };
  392. return self.channelScroll;
  393. }
  394. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  395. {
  396. return [UIView new];
  397. }
  398. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  399. {
  400. return 45.f;
  401. }
  402. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  403. {
  404. return 0.01f;
  405. }
  406. - (HorizonScroll *)channelScroll {
  407. if (!_channelScroll) {
  408. _channelScroll = [[HorizonScroll alloc] initWithFrame:CGRectMake(0, 0, kGXScreenWidth, 45)];
  409. _channelScroll.backgroundColor = [UIColor whiteColor];
  410. }
  411. return _channelScroll;
  412. }
  413. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  414. Item *model = self.dataSource[indexPath.row];
  415. switch (self.currentChannel) {
  416. case 1:
  417. {
  418. return 159.f + 15.f;
  419. }
  420. break;
  421. case 2:
  422. {
  423. return UITableViewAutomaticDimension;
  424. }
  425. break;
  426. case 3:
  427. {
  428. return UITableViewAutomaticDimension;
  429. }
  430. break;
  431. case 4:
  432. {
  433. return UITableViewAutomaticDimension;
  434. }
  435. break;
  436. case 5:
  437. {
  438. return UITableViewAutomaticDimension;
  439. }
  440. break;
  441. case 6:
  442. {
  443. return UITableViewAutomaticDimension;
  444. }
  445. break;
  446. case 7:
  447. {
  448. return UITableViewAutomaticDimension;
  449. }
  450. break;
  451. default:
  452. {
  453. if (model.ImageUrls.count == 0) {
  454. model.cellID = 1;
  455. }else if(model.ImageUrls.count == 1 || model.ImageUrls.count == 2){
  456. model.cellID = 2;
  457. }else{
  458. model.cellID = 3;
  459. }
  460. switch (model.cellID) {
  461. case 1:
  462. {
  463. UILabel * label = [[UILabel alloc] initWithFrame: CGRectMake(0, 0, SCREEN_WIDTH - 30, 18)];
  464. label.text = model.Title;
  465. label.font = [UIFont systemFontOfSize:18];
  466. label.numberOfLines = 2;
  467. CGSize maxSize = CGSizeMake(label.bounds.size.width, CGFLOAT_MAX);
  468. CGSize newSize = [label sizeThatFits:maxSize];
  469. int height = 50 + newSize.height;
  470. return height;
  471. }
  472. break;
  473. case 2:
  474. return 115;
  475. break;
  476. case 3:
  477. {
  478. UILabel * label = [[UILabel alloc] initWithFrame: CGRectMake(0, 0, SCREEN_WIDTH - 30, 18)];
  479. label.text = model.Title;
  480. label.font = [UIFont systemFontOfSize:18];
  481. label.numberOfLines = 2;
  482. CGSize maxSize = CGSizeMake(label.bounds.size.width, CGFLOAT_MAX);
  483. CGSize newSize = [label sizeThatFits:maxSize];
  484. int height = 86 * (kGXScreenWidth / 375.0) + 67 + newSize.height;
  485. return height;
  486. }
  487. break;
  488. default:
  489. return 70;
  490. break;
  491. }
  492. }
  493. break;
  494. }
  495. }
  496. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  497. WS(weakSelf);
  498. Item * model = self.dataSource[indexPath.row];
  499. // 待办工作
  500. switch (self.currentChannel) {
  501. case 1:
  502. {
  503. HomeListWorkCell *cell = (HomeListWorkCell *)[tableView dequeueReusableCellWithIdentifier:@"HomeListWorkCell"];
  504. if (cell != nil && self.dataSource.count > 0) {
  505. [cell loadSearchData:model];
  506. }
  507. return cell;
  508. }
  509. break;
  510. case 2:
  511. {
  512. HomeMusicCell * cell = [HomeMusicCell configCell:tableView indexPath:indexPath];
  513. return cell;
  514. }
  515. break;
  516. case 3:
  517. {
  518. HomeSchoolCell * cell = [HomeSchoolCell configCell:tableView indexPath:indexPath];
  519. [cell setData];
  520. return cell;
  521. }
  522. break;
  523. case 4:
  524. {
  525. HomeUserPrivilegeCell * cell = [HomeUserPrivilegeCell configCell:tableView indexPath:indexPath];
  526. BOOL isEnd = self.dataSource.count - 1 == indexPath.row;
  527. [cell setDataWithItem:indexPath.row isUnUser:isEnd];
  528. return cell;
  529. }
  530. break;
  531. case 5:
  532. {
  533. HomeWeiCousreCell * cell = [HomeWeiCousreCell configCell0:tableView indexPath:indexPath];
  534. return cell;
  535. }
  536. break;
  537. case 6:
  538. {
  539. if (indexPath.row == 0) {
  540. HomeProblemTopCell * cell = [HomeProblemTopCell configCell0:tableView indexPath:indexPath];
  541. [cell setData];
  542. return cell;
  543. }else{
  544. HomeProblemTopCell * cell = [HomeProblemTopCell configCell1:tableView indexPath:indexPath];
  545. return cell;
  546. }
  547. }
  548. break;
  549. case 7:
  550. {
  551. HomeGoodBookCell * cell = [HomeGoodBookCell configCell:tableView indexPath:indexPath];
  552. BOOL isEnd = self.dataSource.count - 1 == indexPath.row;
  553. [cell setDataWithItem:indexPath.row isUnUser:isEnd];
  554. cell.ClickIndexBlock = ^{
  555. BookDetailVC * vc = [BookDetailVC initBookDetailVC];
  556. vc.hidesBottomBarWhenPushed = YES;
  557. [weakSelf.navigationController pushViewController:vc animated:YES];
  558. };
  559. return cell;
  560. }
  561. break;
  562. default:
  563. {
  564. if (model.ImageUrls.count == 0) {
  565. model.cellID = 1;
  566. }else if(model.ImageUrls.count == 1 || model.ImageUrls.count == 2){
  567. model.cellID = 2;
  568. }else{
  569. model.cellID = 3;
  570. }
  571. HomeTableViewCell *cell = [HomeTableViewCell cellWithTableView:tableView AndIndex:model.cellID];
  572. if (cell != nil && self.dataSource.count > 0) {
  573. [cell.deleteButton setCurrentButtonHotSize:CGSizeZero];
  574. [cell loadCurrentItemModel:model];
  575. cell.deleteButton.hidden = YES;
  576. cell.buttonBlock = ^{
  577. [weakSelf cellDidSelcet:model.Id];
  578. };
  579. }
  580. return cell;
  581. }
  582. break;
  583. }
  584. // if (self.currentChannel == 1) {
  585. // HomeListWorkCell *cell = (HomeListWorkCell *)[tableView dequeueReusableCellWithIdentifier:@"HomeListWorkCell"];
  586. // if (cell != nil && self.dataSource.count > 0) {
  587. // [cell loadSearchData:model];
  588. // }
  589. // return cell;
  590. // }else{
  591. // // 推荐
  592. // if (model.ImageUrls.count == 0) {
  593. // model.cellID = 1;
  594. // }else if(model.ImageUrls.count == 1 || model.ImageUrls.count == 2){
  595. // model.cellID = 2;
  596. // }else{
  597. // model.cellID = 3;
  598. // }
  599. // HomeTableViewCell *cell = [HomeTableViewCell cellWithTableView:tableView AndIndex:model.cellID];
  600. // if (cell != nil && self.dataSource.count > 0) {
  601. // [cell.deleteButton setCurrentButtonHotSize:CGSizeZero];
  602. // [cell loadCurrentItemModel:model];
  603. // cell.deleteButton.hidden = YES;
  604. // cell.buttonBlock = ^{
  605. // [weakSelf cellDidSelcet:model.Id];
  606. // };
  607. // }
  608. // return cell;
  609. // }
  610. }
  611. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  612. {
  613. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  614. WS(weakSelf);
  615. Item * model = self.dataSource[indexPath.row];
  616. // 待办工作
  617. switch (self.currentChannel) {
  618. case 1:
  619. {
  620. MyApprovalPageDetail *myApprovalPageDetail = [[MyApprovalPageDetail alloc] init];
  621. [myApprovalPageDetail setActionSussBlock:^{
  622. [weakSelf headRefresh];
  623. }];
  624. if ([model.State isEqualToString:@"Meeting"]) {
  625. model.approvalText = @"上会";
  626. }else if ([model.State isEqualToString:@"Checked"]) {
  627. model.approvalText = @"审批通过";
  628. }else if ([model.State isEqualToString:@"Denied"]) {
  629. model.approvalText = @"已拒绝";
  630. }else if ([model.State isEqualToString:@"Wait"]) {
  631. model.approvalText = @"待定";
  632. }else{
  633. model.approvalText = @"待审核";
  634. }
  635. myApprovalPageDetail.pageType = Type_ONEA;
  636. myApprovalPageDetail.userId = model.UserId;
  637. myApprovalPageDetail.indexId = model.Id;
  638. myApprovalPageDetail.TodoId = model.TodoId;
  639. myApprovalPageDetail.title = model.Title;
  640. [self.navigationController pushViewController:myApprovalPageDetail animated:YES];
  641. }
  642. break;
  643. case 2:
  644. {
  645. }
  646. break;
  647. case 3:
  648. {
  649. }
  650. break;
  651. case 4:
  652. {
  653. }
  654. break;
  655. case 5:
  656. {
  657. BookWCDetailVC * vc = [BookWCDetailVC initBookWCDetailVC];
  658. vc.hidesBottomBarWhenPushed = YES;
  659. [self.navigationController pushViewController:vc animated:YES];
  660. }
  661. break;
  662. case 6:
  663. {
  664. if (indexPath.row > 0) {
  665. BookWCDetailVC * vc = [BookWCDetailVC initBookWCDetailVC];
  666. vc.hidesBottomBarWhenPushed = YES;
  667. [self.navigationController pushViewController:vc animated:YES];
  668. }
  669. }
  670. break;
  671. case 7:
  672. {
  673. }
  674. break;
  675. default:
  676. {
  677. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  678. vc.type = CollectModel_Aritle;
  679. vc.Id = model.Id;
  680. [self.navigationController pushViewController:vc animated:YES];
  681. }
  682. break;
  683. }
  684. }
  685. #pragma mark - channelScroll Block
  686. - (void)didClickAddButtonChannel{
  687. AddChannelController *addChannel = [[AddChannelController alloc] init];
  688. addChannel.modalPresentationStyle = UIModalPresentationFullScreen;
  689. addChannel.delegate = self;
  690. [self presentViewController:addChannel animated:YES completion:nil];
  691. }
  692. #pragma mark - AddChannelControllerDelegate
  693. - (void)upadateChannel{
  694. WS(weakSelf);
  695. [self loadChannelModel];
  696. [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,Article_Pindao_User_Post] parameters:@{} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  697. NSLog(@"%@",responseObject);
  698. NSArray *array = responseObject;
  699. for (NSInteger i = 0 ; i < array.count; i ++) {
  700. NSDictionary *dic = array[i];
  701. ChannelModel *model = [ChannelModel modelWithDictionary:dic];
  702. [weakSelf.myChannel addObject:model];
  703. }
  704. dispatch_async(dispatch_get_main_queue(), ^{
  705. [weakSelf.channelScroll setChannelArray:weakSelf.myChannel];
  706. if (weakSelf.channelScroll.ClickSelectChannelBlock) {
  707. weakSelf.channelScroll.ClickSelectChannelBlock(weakSelf.currentChannel);
  708. }
  709. [weakSelf.tableView reloadData];
  710. });
  711. } failure:^(NSError * _Nonnull error) {
  712. REMOVESHOW
  713. }];
  714. }
  715. #pragma mark - SLBannerViewDelegate
  716. - (void)bannerView:(SLBannerView *)banner didClickImagesAtIndex:(NSInteger)index
  717. {
  718. [self getArticleDetail:index];
  719. }
  720. - (void)getArticleDetail:(NSInteger)index{
  721. HomeTopImageModel *model = self.bannerModelArray[index];
  722. NSLog(@"点击轮播图%ld",(long)model.ArticleId);
  723. SHOWLOADING
  724. WEAKSELF
  725. [[HttpManager sharedHttpManager] GETWithUrl:[NSString stringWithFormat:@"%@%ld",Article_Detail_Get,(long)model.ArticleId] parameters:@{} success:^(id _Nonnull responseObject) {
  726. REMOVESHOW;
  727. Item *model = [[Item alloc]initWithDictionary:responseObject error:nil];
  728. // HomeDetailController *homeDetail = [[HomeDetailController alloc] init];
  729. // [homeDetail loadCurrentModel:itemModel];
  730. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  731. vc.type = CollectModel_Aritle;
  732. vc.Id = model.Id;
  733. [weakSelf.navigationController pushViewController:vc animated:YES];
  734. } failure:^(NSError * _Nonnull error) {
  735. SHOWERROR([ZYCTool handerResultData:error]);
  736. }];
  737. }
  738. #pragma mark - Setter
  739. - (UILabel *)titleLabel {
  740. if (!_titleLabel) {
  741. _titleLabel = [UILabel new];
  742. _titleLabel.backgroundColor = [UIColor whiteColor];
  743. _titleLabel.text = @"首页";
  744. _titleLabel.font = [UIFont systemFontOfSize:16.f];
  745. _titleLabel.textColor = UIColorHex(1A1A1A);
  746. _titleLabel.textAlignment = NSTextAlignmentCenter;
  747. }
  748. return _titleLabel;
  749. }
  750. - (SurfaceSearchView *)searchView {
  751. if (!_searchView) {
  752. _searchView = [[SurfaceSearchView alloc] init];
  753. [_searchView setBgViewColor:[UIColor clearColor]];
  754. // [_searchView setPlaceHolderText:@"输入关键字搜索"];
  755. [_searchView setMainType];
  756. }
  757. return _searchView;
  758. }
  759. - (UITableView * )tableView
  760. {
  761. if (!_tableView) {
  762. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  763. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  764. _tableView.backgroundColor = [UIColor clearColor];
  765. }
  766. return _tableView;
  767. }
  768. - (NSMutableArray *)dataSource
  769. {
  770. if (!_dataSource) {
  771. _dataSource = [NSMutableArray array];
  772. }
  773. return _dataSource;
  774. }
  775. - (NSMutableArray *)tabConfigArray{
  776. if (!_tabConfigArray) {
  777. _tabConfigArray = [NSMutableArray array];
  778. }
  779. return _tabConfigArray;
  780. }
  781. - (NSMutableDictionary *)articleDic{
  782. if (!_articleDic) {
  783. _articleDic = [NSMutableDictionary dictionary];
  784. }
  785. return _articleDic;
  786. }
  787. - (NSMutableArray *)myChannel {
  788. if (!_myChannel) {
  789. _myChannel = [NSMutableArray array];
  790. }
  791. return _myChannel;
  792. }
  793. - (void)loadChannelModel
  794. {
  795. [self.myChannel removeAllObjects];
  796. ChannelModel * model = [[ChannelModel alloc] init];
  797. model.ArticleGroupId = 0;
  798. model.ArticleGroupName = @"推荐";
  799. model.IsSelect = YES;
  800. [self.myChannel addObject:model];
  801. ChannelModel * workModel = [[ChannelModel alloc] init];
  802. workModel.ArticleGroupId = 1;
  803. workModel.ArticleGroupName = @"待办工作";
  804. workModel.IsSelect = NO;
  805. [self.myChannel addObject:workModel];
  806. ChannelModel * sModel = [[ChannelModel alloc] init];
  807. sModel.ArticleGroupId = 2;
  808. sModel.ArticleGroupName = @"信源听说";
  809. sModel.IsSelect = NO;
  810. [self.myChannel addObject:sModel];
  811. ChannelModel * mModel = [[ChannelModel alloc] init];
  812. mModel.ArticleGroupId = 3;
  813. mModel.ArticleGroupName = @"名校";
  814. mModel.IsSelect = NO;
  815. [self.myChannel addObject:mModel];
  816. ChannelModel * aModel = [[ChannelModel alloc] init];
  817. aModel.ArticleGroupId = 4;
  818. aModel.ArticleGroupName = @"会员特供";
  819. aModel.IsSelect = NO;
  820. [self.myChannel addObject:aModel];
  821. ChannelModel * bModel = [[ChannelModel alloc] init];
  822. bModel.ArticleGroupId = 5;
  823. bModel.ArticleGroupName = @"每日微课";
  824. bModel.IsSelect = NO;
  825. [self.myChannel addObject:bModel];
  826. ChannelModel * cModel = [[ChannelModel alloc] init];
  827. cModel.ArticleGroupId = 6;
  828. cModel.ArticleGroupName = @"每日一题";
  829. cModel.IsSelect = NO;
  830. [self.myChannel addObject:cModel];
  831. ChannelModel * dModel = [[ChannelModel alloc] init];
  832. dModel.ArticleGroupId = 7;
  833. dModel.ArticleGroupName = @"每日好书";
  834. dModel.IsSelect = NO;
  835. [self.myChannel addObject:dModel];
  836. // ChannelModel * eModel = [[ChannelModel alloc] init];
  837. // eModel.ArticleGroupId = 8;
  838. // eModel.ArticleGroupName = @"每日好文";
  839. // eModel.IsSelect = NO;
  840. // [self.myChannel addObject:eModel];
  841. }
  842. - (UIView *)noDataView
  843. {
  844. if (!_noDataView) {
  845. _noDataView = [UIView new];
  846. _noDataView.hidden = YES;
  847. _noDataView.backgroundColor = UIColorHex(0xEEEEEE);
  848. }
  849. return _noDataView;
  850. }
  851. - (UILabel *)noDataLabel
  852. {
  853. if (!_noDataLabel) {
  854. _noDataLabel = [UILabel new];
  855. _noDataLabel.textColor = UIColorHex(0xBBBBBB);
  856. _noDataLabel.font = [UIFont systemFontOfSize:14];
  857. }
  858. return _noDataLabel;
  859. }
  860. #pragma mark - 分享成功跳转
  861. - (void)shareReturnAction:(NSNotification *)noti
  862. {
  863. NSDictionary * dic = noti.userInfo;
  864. CollectModelType type = [[dic objectForKey:@"type"] intValue];
  865. NSInteger Id = [[dic objectForKey:@"Id"] integerValue];
  866. NSInteger userId = [[dic objectForKey:@"userId"] integerValue];
  867. NSString* name = [[dic objectForKey:@"name"] stringByRemovingPercentEncoding];
  868. NSString* describe = [[dic objectForKey:@"describe"] stringByRemovingPercentEncoding];
  869. switch (type) {
  870. case CollectModel_CollectFile:
  871. {
  872. if (userId == [AppUserModel sharedAppUserModel].Id) {
  873. MyFavoriteVC *vc = [MyFavoriteVC initMyFavoriteVC];
  874. vc.listType = Id == 0 ? MyFavoriteListLevelTypeA : MyFavoriteListLevelTypeB;
  875. vc.ParentId = 0;
  876. vc.FolderId = Id;
  877. vc.myTitle = Id == 0 ? @"我的收藏" :name;
  878. [self.navigationController pushViewController:vc animated:YES];
  879. }else{
  880. OtherFavoriteVC * vc = [OtherFavoriteVC initOtherFavoriteVC];
  881. vc.listType = Id == 0 ? MyFavoriteListLevelTypeA : MyFavoriteListLevelTypeB;
  882. vc.FolderId = Id;
  883. vc.Author = describe;
  884. vc.myTitle = name;
  885. vc.VisitUserId = userId;
  886. [self.navigationController pushViewController:vc animated:YES];
  887. }
  888. }
  889. break;
  890. case CollectModel_NoteFile:
  891. {
  892. if (userId == [AppUserModel sharedAppUserModel].Id) {
  893. NoteBookVC * vc = [NoteBookVC initNoteBookVC];
  894. if (Id == 0) {
  895. vc.listType = MyFavoriteListLevelTypeB;
  896. vc.myTitle = @"我的笔记";
  897. }else{
  898. vc.listType = MyFavoriteListLevelTypeC;
  899. vc.myTitle = name;
  900. }
  901. vc.ParentId = 0;
  902. vc.FolderId = Id;
  903. vc.isSubVC = YES;
  904. [self.navigationController pushViewController:vc animated:YES];
  905. }else{
  906. OtherNoteBookVC * vc = [OtherNoteBookVC initOtherNoteBookVC];
  907. vc.listType = Id == 0 ? MyFavoriteListLevelTypeA : MyFavoriteListLevelTypeB;
  908. vc.FolderId = Id;
  909. vc.Author = describe;
  910. vc.myTitle = name;
  911. vc.VisitUserId = userId;
  912. [self.navigationController pushViewController:vc animated:YES];
  913. }
  914. }
  915. break;
  916. default:
  917. {
  918. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  919. vc.type = type;
  920. vc.Id = Id;
  921. [self.navigationController pushViewController:vc animated:YES];
  922. }
  923. break;
  924. }
  925. }
  926. @end