SocietyHomePageVC.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. //
  2. // SocietyHomePageVC.m
  3. // BuguLive
  4. //
  5. // Created by 杨仁伟 on 2017/8/21.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "SocietyHomePageVC.h"
  9. #import "SociatyHomePageCell.h"
  10. @interface SocietyHomePageVC () <UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
  11. @property (nonatomic, strong) UICollectionView *societyHPCollectionView;
  12. @property (nonatomic, strong) NSMutableArray *sociatyListArray;
  13. @property (nonatomic, assign) int currentPage;
  14. @property (nonatomic, assign) int has_next;
  15. @end
  16. static NSString *const societyHPFlag = @"societyHomePage";
  17. @implementation SocietyHomePageVC
  18. - (NSMutableArray *)sociatyListArray
  19. {
  20. if (!_sociatyListArray)
  21. {
  22. _sociatyListArray = [NSMutableArray arrayWithCapacity:0];
  23. }
  24. return _sociatyListArray;
  25. }
  26. - (void)initFWUI
  27. {
  28. [super initFWUI];
  29. CGFloat width = (kScreenW - betButtonInterval) / 2.0;
  30. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  31. layout.itemSize = CGSizeMake(width, width);
  32. layout.minimumInteritemSpacing = betButtonInterval;
  33. layout.minimumLineSpacing = 5;
  34. self.societyHPCollectionView = [[UICollectionView alloc] initWithFrame:self.societyFrame collectionViewLayout:layout];
  35. self.societyHPCollectionView.backgroundColor = kAppGrayColor8;
  36. self.societyHPCollectionView.showsVerticalScrollIndicator = NO;
  37. [self.view addSubview:self.societyHPCollectionView];
  38. self.societyHPCollectionView.delegate = self;
  39. self.societyHPCollectionView.dataSource = self;
  40. [self.societyHPCollectionView registerNib:[UINib nibWithNibName:NSStringFromClass([SociatyHomePageCell class]) bundle:nil] forCellWithReuseIdentifier:societyHPFlag];
  41. [BGMJRefreshManager refresh:self.societyHPCollectionView target:self headerRereshAction:@selector(refreshHeader) footerRereshAction:@selector(refreshFooter)];
  42. }
  43. - (void)refreshHeader
  44. {
  45. [self loadDataWithPage:1];
  46. }
  47. - (void)refreshFooter
  48. {
  49. if (_has_next == 1)
  50. {
  51. _currentPage ++;
  52. [self loadDataWithPage:_currentPage];
  53. }
  54. else
  55. {
  56. [self.societyHPCollectionView.mj_footer endRefreshingWithNoMoreData];
  57. }
  58. }
  59. #pragma mark ------------------------------------- 加载数据 ------------------------------------------
  60. - (void)loadDataWithPage:(int)page
  61. {
  62. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  63. [parmDict setObject:@"index" forKey:@"ctl"];
  64. [parmDict setObject:@"society" forKey:@"act"];
  65. [parmDict setObject:[NSNumber numberWithInt:page] forKey:@"page"];
  66. FWWeakify(self)
  67. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  68. FWStrongify(self)
  69. if ([responseJson toInt:@"status"] == 1)
  70. {
  71. if (page == 1)
  72. {
  73. [self hideNoContentView];
  74. [self.sociatyListArray removeAllObjects];
  75. }
  76. NSDictionary *pageDict = responseJson[@"page"];
  77. NSArray *array = responseJson[@"list"];
  78. self.currentPage = [pageDict toInt:@"page"];
  79. self.has_next = [pageDict toInt:@"has_next"];
  80. for (NSDictionary *dict in array)
  81. {
  82. SociatyListModel *listModel = [SociatyListModel mj_objectWithKeyValues:dict];
  83. [self.sociatyListArray addObject:listModel];
  84. }
  85. if (!self.sociatyListArray.count)
  86. {
  87. [self showNoContentView];
  88. }
  89. [self.societyHPCollectionView reloadData];
  90. [BGMJRefreshManager endRefresh:self.societyHPCollectionView];
  91. }
  92. } FailureBlock:^(NSError *error) {
  93. FWStrongify(self)
  94. [BGMJRefreshManager endRefresh:self.societyHPCollectionView];
  95. }];
  96. }
  97. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  98. {
  99. return self.sociatyListArray.count;
  100. }
  101. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath
  102. {
  103. SociatyHomePageCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:societyHPFlag forIndexPath:indexPath];
  104. SociatyListModel *listModel = self.sociatyListArray[indexPath.row];
  105. [cell.tianTuanImg sd_setImageWithURL:[NSURL URLWithString:listModel.society_image] placeholderImage:kDefaultPreloadImgSquare];
  106. cell.tianTuanNameLbl.text = listModel.society_name;
  107. cell.presidentLbl.text = [NSString stringWithFormat:ASLocalizedString(@"会长:%@"),listModel.society_chairman];
  108. cell.numberLbl.text = [NSString stringWithFormat:ASLocalizedString(@"人数:%@"),listModel.society_user_count];
  109. return cell;
  110. }
  111. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  112. {
  113. SociatyListModel *listModel = self.sociatyListArray[indexPath.row];
  114. if (self.delegate && [self.delegate respondsToSelector:@selector(pushSocietyDetail:)])
  115. {
  116. [self.delegate pushSocietyDetail:listModel];
  117. }
  118. }
  119. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  120. return UIEdgeInsetsMake(betButtonInterval, 0, 0, 0);
  121. }
  122. - (void)viewDidLoad {
  123. [super viewDidLoad];
  124. // Do any additional setup after loading the view.
  125. }
  126. - (void)didReceiveMemoryWarning {
  127. [super didReceiveMemoryWarning];
  128. // Dispose of any resources that can be recreated.
  129. }
  130. /*
  131. #pragma mark - Navigation
  132. // In a storyboard-based application, you will often want to do a little preparation before navigation
  133. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  134. // Get the new view controller using [segue destinationViewController].
  135. // Pass the selected object to the new view controller.
  136. }
  137. */
  138. @end