DistributionController.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. //
  2. // DistributionController.m
  3. // BuguLive
  4. //
  5. // Created by fanwe2014 on 2016/12/27.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. #import "DistributionController.h"
  8. #import "DistributionCell.h"
  9. #import "LiveDataModel.h"
  10. @interface DistributionController ()<UITableViewDelegate,UITableViewDataSource>
  11. {
  12. int _page; //页数
  13. int _has_next; //是否还有下一页
  14. }
  15. @property (nonatomic, strong) UITableView *listTableView;
  16. @property (nonatomic, strong) NSMutableArray *dataArray; //数据数组
  17. @end
  18. @implementation DistributionController
  19. - (void)viewDidLoad
  20. {
  21. [super viewDidLoad];
  22. _dataArray = [[NSMutableArray alloc]init];
  23. _page = 1;
  24. self.view.backgroundColor = kWhiteColor;
  25. self.navigationItem.leftBarButtonItem=[UIBarButtonItem itemWithTarget:self action:@selector(backClick) image:@"com_arrow_vc_back" highImage:@"com_arrow_vc_back"];
  26. self.title = ASLocalizedString(@"分享收益");
  27. [self creatView];
  28. }
  29. - (void)creatView
  30. {
  31. if (!_listTableView)
  32. {
  33. _listTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH-64)];
  34. _listTableView.delegate =self;
  35. _listTableView.dataSource =self;
  36. _listTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  37. [self.view addSubview:_listTableView];
  38. }
  39. [_listTableView registerNib:[UINib nibWithNibName:@"DistributionCell" bundle:nil] forCellReuseIdentifier:@"DistributionCell"];
  40. [BGMJRefreshManager refresh:_listTableView target:self headerRereshAction:@selector(headerReresh) footerRereshAction:@selector(footerReresh)];
  41. }
  42. - (void)backClick
  43. {
  44. [self.navigationController popViewControllerAnimated:NO];
  45. }
  46. #pragma mark 下拉刷新
  47. - (void)headerReresh
  48. {
  49. [self loadDataWithPage:1];
  50. }
  51. #pragma mark 上拉加载
  52. - (void)footerReresh
  53. {
  54. if (_has_next == 1)
  55. {
  56. _page ++;
  57. [self loadDataWithPage:_page];
  58. }
  59. else
  60. {
  61. [BGMJRefreshManager endRefresh:_listTableView];
  62. }
  63. }
  64. - (void)loadDataWithPage:(int)page
  65. {
  66. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  67. [parmDict setObject:@"distribution" forKey:@"ctl"];
  68. [parmDict setObject:@"index" forKey:@"act"];
  69. [parmDict setObject:[NSString stringWithFormat:@"%d",page] forKey:@"p"];
  70. FWWeakify(self)
  71. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  72. FWStrongify(self)
  73. [self.dataArray removeAllObjects];
  74. if ([responseJson toInt:@"status"] == 1)
  75. {
  76. _page = [[responseJson objectForKey:@"page"]toInt:@"page"];
  77. _has_next = [[responseJson objectForKey:@"page"]toInt:@"has_next"];
  78. if ([responseJson objectForKey:@"data"])
  79. {
  80. NSArray *array = [responseJson objectForKey:@"data"];
  81. if (array && [array isKindOfClass:[NSArray class]])
  82. {
  83. if (array.count)
  84. {
  85. for (NSDictionary *dict in array)
  86. {
  87. LiveDataModel *model = [LiveDataModel mj_objectWithKeyValues:dict];
  88. [self.dataArray addObject:model];
  89. }
  90. }
  91. }
  92. }
  93. [self.listTableView reloadData];
  94. }
  95. [BGMJRefreshManager endRefresh:self.listTableView];
  96. if (!self.dataArray.count)
  97. {
  98. [self showNoContentView];
  99. }
  100. else
  101. {
  102. [self hideNoContentView];
  103. }
  104. } FailureBlock:^(NSError *error) {
  105. FWStrongify(self)
  106. [BGMJRefreshManager endRefresh:self.listTableView];
  107. }];
  108. }
  109. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  110. {
  111. return _dataArray.count;
  112. }
  113. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  114. {
  115. return 50;
  116. }
  117. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  118. {
  119. DistributionCell *cell =[tableView dequeueReusableCellWithIdentifier:@"DistributionCell"];
  120. if (_dataArray.count)
  121. {
  122. LiveDataModel *model = _dataArray[indexPath.row];
  123. [cell setCellWithModel:model];
  124. }
  125. return cell;
  126. }
  127. @end