HomeViewController.m 35 KB

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